Source for file MultiLanguageBuilder.class.php

Documentation is available at MultiLanguageBuilder.class.php

  1. /**
  2.  * Класс MultiLanguageBuilder.
  3.  *
  4.  * @package energine
  5.  * @subpackage core
  6.  * @author dr.Pavka
  7.  * @copyright ColoCall 2006
  8.  * @version $Id: fsource_energine_core_frameworkMultiLanguageBuilder.class.php.html,v 1.1 2007/09/17 14:32:34 pavka Exp $
  9.  */
  10.  
  11. require_once 'core/framework/Builder.class.php';
  12.  
  13. /**
  14.  * Построитель для мультиязычных компонентов.
  15.  *
  16.  * @package energine
  17.  * @subpackage core
  18.  */
  19. class MultiLanguageBuilder extends Builder {
  20.  
  21.     /**
  22.      * Конструктор класса.
  23.      *
  24.      * @access public
  25.      * @return void 
  26.      */
  27.     public function __construct({
  28.         parent::__construct();
  29.     }
  30.  
  31.     /**
  32.      * Построение результата.
  33.      *
  34.      * @access protected
  35.      * @return void 
  36.      */
  37.     protected function run({
  38.         $lang Language::getInstance();
  39.  
  40.         $dom_recordSet $this->result->createElement('recordset');
  41.         $this->result->appendChild($dom_recordSet);
  42.         $records array();
  43.         $correlation array();
  44.  
  45.         // для режима списка и режима редактирования (когда есть данные)
  46.         if ($this->data{
  47.             foreach ($this->dataDescription->getFieldDescriptions(as $fieldName => $fieldInfo{
  48.                 $fieldData $this->data->getFieldByName($fieldName);
  49.                 // если это первичный ключ
  50.                 if ($fieldInfo->getPropertyValue('key'=== true{
  51.                     $fieldInfo->addProperty('tabName'$this->translate('TXT_PROPERTIES'));
  52.                     $i 0;
  53.                     while ($i $fieldData->getRowCount()) {
  54.                         $rowData $fieldData->getRowData($i);
  55.                         $index (is_null($rowData))?0:$rowData;
  56.  
  57.                         $correlation[$i$index;
  58.                         if (!isset($records[$index])) {
  59.                             $records[$index][$this->createField($fieldName$fieldInfo$rowData);
  60.                         }
  61.                         $i++;
  62.                     }
  63.                 }
  64.                 // если это мультиязычное поле
  65.                 elseif ($fieldInfo->isMultilanguage()) {
  66. //                    $title = $fieldInfo->getPropertyValue('title');
  67.                     foreach ($fieldData->getData(as $key => $data{
  68.                         $langID $this->data->getFieldByName('lang_id')->getRowData($key);
  69.                         $dataProperties $fieldData->getRowProperties($key);
  70.                         $fieldInfo->addProperty('language'$langID);
  71.                         $fieldInfo->addProperty('tabName'$lang->getNameByID($langID));
  72.                         $dom_field $this->createField($fieldName$fieldInfo$data$dataProperties);
  73.                         $records[$correlation[$key]][$dom_field;
  74.                     }
  75.                 }
  76.                 // все остальные поля
  77.                 elseif (!$fieldInfo->getPropertyValue('languageID')) {
  78.                     $i 0;
  79.                     $tmp = array_flip($correlation);
  80.                     foreach ($tmp as $key => $value{
  81.                         $fieldValue false;
  82.                         if (in_array($fieldInfo->getType()array(FieldDescription::FIELD_TYPE_MULTIFieldDescription::FIELD_TYPE_SELECT))) {
  83.                             if ($this->data && $this->data->getFieldByName($fieldName)) {
  84.                                 if ($fieldInfo->getType(== FieldDescription::FIELD_TYPE_SELECT{
  85.                                     $data array($this->data->getFieldByName($fieldName)->getRowData($i));
  86.                                 }
  87.                                 else {
  88.                                     $data $this->data->getFieldByName($fieldName)->getRowData($i);
  89.                                 }
  90.                             }
  91.                             else {
  92.                                 $data false;
  93.                             }
  94.                             $fieldValue $this->createOptions($fieldInfo$data);
  95.                         }
  96.                         elseif (!$this->data{
  97.                             $fieldValue false;
  98.                         }
  99.                         elseif ($this->data->getFieldByName($fieldName)) {
  100.                             $fieldValue $fieldData->getRowData($value);
  101.                         }
  102.  
  103.                         $dataProperties ($fieldData)?$fieldData->getRowProperties($value):false;
  104.                         if (is_null($fieldInfo->getPropertyValue('tabName'))) {
  105.                             $fieldInfo->addProperty('tabName'$this->translate('TXT_PROPERTIES'));
  106.                         }
  107.                         else {
  108.                             $fieldInfo->addProperty('tabName'$fieldInfo->getPropertyValue('tabName'));
  109.                         }
  110.  
  111.                         $dom_field $this->createField($fieldName$fieldInfo$fieldValue$dataProperties);
  112.                         $records[$correlation[$value]][$dom_field;
  113.                         $i++;
  114.                     }
  115.                 }
  116.             }
  117.             foreach ($records as $key => $value{
  118.                 $dom_record $this->result->createElement('record');
  119.                 foreach ($value as $val{
  120.                     $dom_record->appendChild($val);
  121.                 }
  122.                 $dom_recordSet->appendChild($dom_record);
  123.             }
  124.         }
  125.         // для режима вставки (когда данные отсутствуют)
  126.         else {
  127.             $dom_record $this->result->createElement('record');
  128.             foreach ($this->dataDescription->getFieldDescriptions(as $fieldName => $fieldInfo{
  129.                 if ($fieldInfo->isMultilanguage()) {
  130.                     //$title = $fieldInfo->getPropertyValue('title');
  131.                     foreach (array_keys($lang->getLanguages()) as $langID{
  132.                         $fieldInfo->addProperty('language'$langID);
  133.                         $fieldInfo->addProperty('tabName'$lang->getNameByID($langID));
  134.                         $dom_record->appendChild($this->createField($fieldName$fieldInfo''));
  135.                     }
  136.                 }
  137.                 elseif (!$fieldInfo->getPropertyValue('languageID')){
  138.                     if (in_array($fieldInfo->getType()array(FieldDescription::FIELD_TYPE_MULTIFieldDescription::FIELD_TYPE_SELECT))) {
  139.                         $fieldValue $this->createOptions($fieldInfo);
  140.                     }
  141.                     else {
  142.                         $fieldValue false;
  143.                     }
  144.  
  145.                     if (is_null($fieldInfo->getPropertyValue('tabName'))) {
  146.                         $fieldInfo->addProperty('tabName'$this->translate('TXT_PROPERTIES'));
  147.                     }
  148.                     else {
  149.                         $fieldInfo->addProperty('tabName'$fieldInfo->getPropertyValue('tabName'));
  150.                     }
  151.  
  152.                     $dom_record->appendChild($this->createField($fieldName$fieldInfo$fieldValue));
  153.                 }
  154.             }
  155.             $dom_recordSet->setAttribute('empty''empty');
  156.             $dom_recordSet->appendChild($dom_record);
  157.         }
  158.     }
  159. }

Documentation generated on Mon, 17 Sep 2007 13:30:48 +0300 by phpDocumentor 1.4.0a2