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

Source for file Select.class.php

Documentation is available at Select.class.php

  1. <?php
  2. /**
  3.  * Содержит класс Select
  4.  *
  5.  * @package energine
  6.  * @subpackage share
  7.  * @author dr.Pavka
  8.  * @copyright Energine 2006
  9.  * @version $Id$
  10.  */
  11.  
  12. /**
  13.  * Выпадающий список
  14.  *
  15.  * @package energine
  16.  * @subpackage share
  17.  * @author dr.Pavka
  18.  */
  19. class Select extends Control {
  20.  
  21.     /**
  22.      * Элементы списка
  23.      *
  24.      * @access private
  25.      * @var array 
  26.      */
  27.     private $items;
  28.  
  29.     /**
  30.      *
  31.      *
  32.      * @access public
  33.      */
  34.     public function __construct($id$action false$title false{
  35.         parent::__construct($id);
  36.         $this->type = 'select';
  37.         if ($title)   $this->setAttribute('title',   $title);
  38.         if ($action)  $this->setAttribute('action',  $action);
  39.     }
  40.     /**
  41.      * Перегружаем родительский метод для получения возможности загрузить значения опций
  42.      *
  43.      * @param SimpleXMLElement $description 
  44.      * @return void 
  45.      * @access public
  46.      */
  47.     public function loadFromXml(SimpleXMLElement $description{
  48.         parent::loadFromXml($description);
  49.         if($description->options){
  50.             foreach ($description->options->option as $item){
  51.                 $this->addItem((string)$item['id'],(string)$item);        
  52.             }
  53.         }
  54.     }    
  55.  
  56.     /**
  57.      * Добавляет item
  58.      * @param string 
  59.      * @param string 
  60.      * @param array $itemProperties array(
  61.      *                                   $attr_name => attr_value
  62.      *                               )
  63.      * @return void 
  64.      * @access public
  65.      */
  66.     public function addItem($id$value$itemProperties array()) {
  67.         $this->items[$idarray(
  68.            'value' => DBWorker::_translate($value),
  69.            'properties' => $itemProperties
  70.         );
  71.     }
  72.     /**
  73.      * Переопределенный вывод елемента
  74.      * 
  75.      * @return DOMNode 
  76.      * @access public
  77.      */
  78.     public function build(){
  79.         $result parent::build();
  80.         if(!empty($this->items)){
  81.             $options $this->doc->createElement('options');
  82.             foreach ($this->items as $itemID=>$itemData){
  83.                    $option $this->doc->createElement('option'$itemData['value']);
  84.                    $option->setAttribute('id'$itemID);
  85.                    if(!empty($itemData['properties'])){
  86.                        foreach ($itemData['properties'as $key=>$value){
  87.                            $option->setAttribute($key$value);
  88.                        }
  89.                    }
  90.                    $options->appendChild($option);
  91.             }
  92.             $result->appendChild($options);
  93.             
  94.         }
  95.         return $result;
  96.     }
  97.  
  98.     /**
  99.      *
  100.      *
  101.      * @param string $id 
  102.      * @return void 
  103.      * @access public
  104.      */
  105.     public function removeItem($id{
  106.         if(isset($this->items[$id])){
  107.             unset($this->items[$id]);
  108.         }
  109.     }
  110.  
  111.     /**
  112.      *
  113.      *
  114.      * @param string $id 
  115.      * @return array 
  116.      * @access public
  117.      */
  118.     public function getItem($id{
  119.         $result null;
  120.         if(isset($this->items[$id])){
  121.                $result $this->items[$id];
  122.         }
  123.         return $result;
  124.     }
  125. }
В создании документации нам помог: phpDocumentor