energine
[ class tree: energine ] [ index: energine ] [ all elements ]

Source for file Field.class.php

Documentation is available at Field.class.php

  1. <?php
  2.  
  3. /**
  4.  * Класс Field.
  5.  *
  6.  * @package energine
  7.  * @subpackage core
  8.  * @author dr.Pavka
  9.  * @copyright Energine 2006
  10.  * @version $Id$
  11.  */
  12.  
  13. //require_once('core/framework/Object.class.php');
  14.  
  15. /**
  16.  * Поле данных.
  17.  *
  18.  * @package energine
  19.  * @subpackage core
  20.  * @author dr.Pavka
  21.  */
  22. class Field extends Object implements Iterator{
  23.  
  24.     /**
  25.      * @access private
  26.      * @var array набор дополнительных свойств
  27.      */
  28.     private $properties = array();
  29.  
  30.     /**
  31.      * @access private
  32.      * @var string имя поля
  33.      */
  34.     private $name;
  35.  
  36.     /**
  37.      * @access private
  38.      * @var array данные поля
  39.      */
  40.     private $data = array();
  41.  
  42.     /**
  43.      * Если права не указаны - используются права из FieldDescription (наследуются).
  44.      *
  45.      * @access private
  46.      * @var int права пользователя на поле
  47.      */
  48.     private $rights;
  49.  
  50.     /**
  51.      * @access private
  52.      * @var int индекс текущего элемента (используется для итерации)
  53.      */
  54.     private $currentIndex = 0;
  55.  
  56.  
  57.     /**
  58.      * Конструктор класса.
  59.      *
  60.      * @access public
  61.      * @param string $name иям поля
  62.      */
  63.     public function __construct($name{
  64.         parent::__construct();
  65.  
  66.         $this->name = $name;
  67.     }
  68.  
  69.     /**
  70.      * Возвращает имя поля.
  71.      *
  72.      * @access public
  73.      * @return string 
  74.      */
  75.     public function getName({
  76.         return $this->name;
  77.     }
  78.  
  79.     /**
  80.      * Устанавливает данные поля.
  81.      *
  82.      * @access public
  83.      * @param mixed $data 
  84.      * @param bool $setForAll - установить для всех строчек
  85.      *   только для перепределения данных
  86.      *   в случае если поле только создано то нужно заполнять через итератор
  87.      * @return void 
  88.      */
  89.     public function setData($data$setForAll false{
  90.         if ($setForAll{
  91.             $data array_fill(0$this->getRowCount()$data);
  92.         }
  93.         elseif (!is_array($data)) {
  94.             $data array($data);
  95.         }
  96.         $this->data = $data;
  97.     }
  98.  
  99.     /**
  100.      * Возвращает данные поля.
  101.      *
  102.      * @access public
  103.      * @return array 
  104.      */
  105.     public function getData({
  106.         return $this->data;
  107.     }
  108.  
  109.     /**
  110.      * Возвращает данные указанной строки.
  111.      *
  112.      * @access public
  113.      * @param int $rowIndex индекс строки
  114.      * @return mixed 
  115.      */
  116.     public function getRowData($rowIndex{
  117.         $result null;
  118.         if (isset($this->data[$rowIndex])) {
  119.             $result $this->data[$rowIndex];
  120.         }
  121.         return $result;
  122.     }
  123.  
  124.     /**
  125.      * Удаляет данные указанной строки.
  126.      *
  127.      * @access public
  128.      * @param int $rowIndex индекс строки
  129.      * @return mixed 
  130.      */
  131.     public function removeRowData($rowIndex{
  132.         $result false;
  133.         if (isset($this->data[$rowIndex])) {
  134.             unset($this->data[$rowIndex]);
  135.             $result true;
  136.         }
  137.         return $result;
  138.     }
  139.  
  140.     /**
  141.      * Добавляет строку данных.
  142.      *
  143.      * @access public
  144.      * @param mixed $data 
  145.      * @return void 
  146.      */
  147.     public function addRowData($data{
  148.         $this->data[$data;
  149.     }
  150.  
  151.     /**
  152.      * Устанавливает данные в указанной строке.
  153.      *
  154.      * @access public
  155.      * @param int $rowIndex индекс строки
  156.      * @param mixed $newData новые данные
  157.      * @return boolean 
  158.      */
  159.     public function setRowData($rowIndex$newData{
  160.         $result false;
  161.         //if (isset($this->data[$rowIndex])) {
  162.             $this->data[$rowIndex$newData;
  163.             $result true;
  164.         //}
  165.         return $result;
  166.     }
  167.  
  168.     /**
  169.      * Устанавливает уровень прав на поле.
  170.      *
  171.      * @access public
  172.      * @param int $rights уровень прав
  173.      * @return void 
  174.      */
  175.     public function setRights($rights{
  176.         $this->rights = $rights;
  177.     }
  178.  
  179.     /**
  180.      * Возвращает уровень прав на поле.
  181.      *
  182.      * @access public
  183.      * @return int 
  184.      */
  185.     public function getRights({
  186.         return $this->rights;
  187.     }
  188.  
  189.     /**
  190.      * Возвращает количество строк данных.
  191.      *
  192.      * @access public
  193.      * @return int 
  194.      */
  195.     public function getRowCount({
  196.         return sizeof($this->getData());
  197.     }
  198.  
  199.     /**
  200.      * Устанавливает дополнтельное свойство строки.
  201.      *
  202.      * @access public
  203.      * @param int $index индекс строки
  204.      * @param string $propertyName имя свойства
  205.      * @param mixed $propertyValue значение свойства
  206.      * @return void 
  207.      */
  208.     public function setRowProperty($index$propertyName$propertyValue{
  209.         $this->properties[$index][$propertyName$propertyValue;
  210.     }
  211.  
  212.     /**
  213.      * Возвращает значение дополнительного свойства строки.
  214.      *
  215.      * @access public
  216.      * @param int $index индекс строки
  217.      * @param string $propertyName имя свойства
  218.      * @return mixed 
  219.      */
  220.     public function getRowProperty($index$propertyName{
  221.         $result false;
  222.         if (isset($this->properties[$index][$propertyName])) {
  223.             $result $this->properties[$index][$propertyName];
  224.         }
  225.         return $result;
  226.     }
  227.  
  228.     /**
  229.      * Возвращает все дополнительные свойства строки.
  230.      *
  231.      * @access public
  232.      * @param int $index индекс строки
  233.      * @return array 
  234.      */
  235.     public function getRowProperties($index{
  236.         $result false;
  237.         if (isset($this->properties[$index]&& !empty($this->properties[$index])) {
  238.             $result $this->properties[$index];
  239.         }
  240.         return $result;
  241.     }
  242.  
  243.     /**
  244.      * Перемещает итератор на первый элемент.
  245.      *
  246.      * @access public
  247.      * @return void 
  248.      */
  249.     public function rewind({
  250.         $this->currentIndex = 0;
  251.     }
  252.  
  253.     /**
  254.      * Возвращает текущий элемент.
  255.      *
  256.      * @access public
  257.      * @return mixed 
  258.      */
  259.     public function current({
  260.         return $this->data[$this->currentIndex];
  261.     }
  262.  
  263.     /**
  264.      * Возвращает ключ текущего элемента.
  265.      *
  266.      * @access public
  267.      * @return mixed 
  268.      */
  269.     public function key({
  270.         return $this->currentIndex;
  271.     }
  272.  
  273.     /**
  274.      * Перемещает итератор на следующий элемент.
  275.      *
  276.      * @access public
  277.      * @return void 
  278.      */
  279.     public function next({
  280.         $this->currentIndex++;
  281.     }
  282.  
  283.     /**
  284.      * Проверяет, существует ли текущий элемент.
  285.      *
  286.      * @access public
  287.      * @return boolean 
  288.      */
  289.     public function valid({
  290.         return ($this->currentIndex < $this->getRowCount());
  291.     }
  292. }
В создании документации нам помог: phpDocumentor