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

Source for file SimpleBuilder.class.php

Documentation is available at SimpleBuilder.class.php

  1. <?php
  2.  
  3. /**
  4.  * Класс SimpleBuilder.
  5.  *
  6.  * @package energine
  7.  * @subpackage core
  8.  * @author 1m.dm
  9.  * @copyright Energine 2006
  10.  * @version $Id$
  11.  */
  12.  
  13. //require_once('core/framework/Builder.class.php');
  14.  
  15. /**
  16.  * Построитель XML-документа.
  17.  *
  18.  * @package energine
  19.  * @subpackage core
  20.  * @author 1m.dm
  21.  */
  22. class SimpleBuilder extends Builder {
  23.     /**
  24.      * Title
  25.      *
  26.      * @var string 
  27.      * @access private
  28.      */
  29.     private $title;
  30.  
  31.     /**
  32.      * Конструктор класса.
  33.      *
  34.      * @param string recordset title
  35.      * @access public
  36.      * @return void 
  37.      */
  38.     public function __construct($title ''{
  39.         parent::__construct();
  40.         $this->title = $title;
  41.     }
  42.  
  43.     /**
  44.      * Построение результата.
  45.      *
  46.      * @access protected
  47.      * @return void 
  48.      */
  49.     protected function run({
  50.         $dom_recordSet $this->result->createElement('recordset');
  51.         $this->result->appendChild($dom_recordSet);
  52.         if ($this->data->isEmpty(|| !$this->data->getRowCount()) {
  53.             $dom_recordSet->setAttribute('empty''empty');
  54.         }
  55.         $rowCount 0;
  56.         $i 0;
  57.         do {
  58.             if (!$this->data->isEmpty()) {
  59.                 $rowCount $this->data->getRowCount();
  60.             }
  61.  
  62.             $dom_record $this->result->createElement('record');
  63.  
  64.             foreach ($this->dataDescription->getFieldDescriptions(as $fieldName => $fieldInfo{
  65.                 $fieldProperties false;
  66.                 if ($fieldInfo->getPropertyValue('tabName'=== null{
  67.                     $fieldInfo->setProperty('tabName'$this->title);
  68.                 }
  69.  
  70.                 // если тип поля предполагает выбор из нескольких значений - создаем соответствующие узлы
  71.                 if (in_array($fieldInfo->getType()array(FieldDescription::FIELD_TYPE_MULTIFieldDescription::FIELD_TYPE_SELECT))) {
  72.                     if ($this->data && $this->data->getFieldByName($fieldName)) {
  73.                         if ($fieldInfo->getType(== FieldDescription::FIELD_TYPE_SELECT{
  74.                             $data array($this->data->getFieldByName($fieldName)->getRowData($i));
  75.                         }
  76.                         else {
  77.                             $data $this->data->getFieldByName($fieldName)->getRowData($i);
  78.                         }
  79.                     }
  80.                     else {
  81.                         $data false;
  82.                     }
  83.                     $fieldValue $this->createOptions($fieldInfo$data);
  84.                 }
  85.                 elseif ($this->data->isEmpty()) {
  86.                     $fieldValue false;
  87.                 }
  88.                 elseif ($this->data->getFieldByName($fieldName)) {
  89.                     $fieldProperties $this->data->getFieldByName($fieldName)->getRowProperties($i);
  90.                     $fieldValue $this->data->getFieldByName($fieldName)->getRowData($i);
  91.                 }
  92.                 else {
  93.                     $fieldValue false;
  94.                 }
  95.  
  96.                 $dom_field $this->createField($fieldName$fieldInfo$fieldValue$fieldProperties);
  97.                 $dom_record->appendChild($dom_field);
  98.             }
  99.  
  100.             $dom_recordSet->appendChild($dom_record);
  101.             $i++;
  102.         }
  103.         while ($i $rowCount);
  104.     }
  105. }
В создании документации нам помог: phpDocumentor