Example #1
0
 /**
  * Attach control.
  *
  * @param Control $control Control element.
  * @param Control $position Control position. If it is not set than the control will be placed at the end.
  */
 public function attachControl(Control $control, Control $position = NULL)
 {
     $control->setIndex(arrayPush($this->controls, $control));
     $control->attach($this);
 }
Example #2
0
 /**
  * Load multilingual data.
  * @return array|bool|mixed
  */
 private function multiLoadData()
 {
     $data = false;
     $lang = E()->getLanguage();
     $lang = $lang->getLanguages();
     $dbFields = [];
     $filter = $order = $limit = '';
     //Создаем перечень полей  в формате array('имя основной таблицы' => array('имя поля'=>'имя таблицы.имя поля'), 'имя таблицыпереводов' => array('имя поля'=>'имя таблицы.имя поля'))
     foreach ($this->getDataDescription() as $fieldName => $field) {
         //Не включаем в набор идентификатор языка и PK
         if (!$field->getPropertyValue('languageID') && $field->getPropertyValue('key') !== true) {
             //не включаем в набор поля полученные  из конфигурации
             if (is_null($field->getPropertyValue('customField'))) {
                 //поля не приведенные к булеану
                 if (!($field->getPropertyValue('origType') && $field->getType() == FieldDescription::FIELD_TYPE_BOOL)) {
                     $dbFields[$field->getPropertyValue('tableName')][$fieldName] = $field->getPropertyValue('tableName') . '.' . $fieldName;
                 } else {
                     $dbFields[$field->getPropertyValue('tableName')][$fieldName] = ' IF((' . $field->getPropertyValue('tableName') . '.' . $fieldName . ' IS NOT NULL) AND (' . $field->getPropertyValue('tableName') . '.' . $fieldName . ' <> ""), 1, 0) AS ' . $fieldName;
                 }
             }
         }
     }
     $filterCondition = $this->getFilter();
     if (!empty($filterCondition)) {
         $filter = $this->dbh->buildWhereCondition($filterCondition) . ($this->getParam('onlyCurrentLang') ? ' AND lang_id = ' . $this->getDataLanguage() : '');
     } elseif ($this->getDataLanguage() && $this->getParam('onlyCurrentLang')) {
         $filter = ' WHERE lang_id = ' . $this->getDataLanguage();
     }
     if ($this->getOrder()) {
         $order = $this->dbh->buildOrderCondition($this->getOrder());
     }
     if (!is_null($this->getLimit())) {
         $limit = $this->getLimit();
         $limit = $this->dbh->buildLimitStatement($limit);
     }
     //Если существует листалка указываем ей количество записей
     if ($this->getType() != self::COMPONENT_TYPE_FORM_ADD) {
         $request = sprintf('SELECT ' . ($this->pager ? ' SQL_CALC_FOUND_ROWS ' : '') . ' %s.%s, %s.lang_id,
     	       %s
     	       %s
     	       FROM %1$s
     	       LEFT JOIN %3$s ON %3$s.%2$s = %1$s.%2$s
     	       %s
     	       %s
     	       %s
     	       ', $this->getTableName(), $this->getPK(), $this->getTranslationTableName(), isset($dbFields[$this->getTableName()]) ? implode(',', $dbFields[$this->getTableName()]) : '', isset($dbFields[$this->getTranslationTableName()]) ? (isset($dbFields[$this->getTableName()]) ? ',' : '') . implode(',', $dbFields[$this->getTranslationTableName()]) : '', $filter, $order, $limit);
         $data = $this->dbh->select($request);
         if ($this->pager) {
             $this->pager->setRecordsCount($this->dbh->getScalar('SELECT FOUND_ROWS() as c'));
         }
         //Если данные не только для текущего языка
         if ($data && (!$this->getDataLanguage() || $this->getDataLanguage() && !$this->getParam('onlyCurrentLang') && isset($dbFields[$this->getTranslationTableName()]))) {
             //формируем матрицу
             foreach ($data as $row) {
                 $matrix[$row[$this->getPK()]][$row['lang_id']] = $row;
             }
             //формируем образец
             //в нем все языкозависимые поля заполнены nullами
             foreach (array_keys($dbFields[$this->getTranslationTableName()]) as $fieldName) {
                 $translationColumns[] = 'NULL as ' . $fieldName;
             }
             $request = sprintf('
                 SELECT %s, %s %s
                 FROM %s
                 WHERE %s IN(%s)
             ', $this->getPK(), isset($dbFields[$this->getTableName()]) ? implode(',', $dbFields[$this->getTableName()]) . ',' : '', implode(',', $translationColumns), $this->getTableName(), $this->getPK(), implode(',', array_keys($matrix)));
             $res = $this->dbh->select($request);
             foreach ($res as $row) {
                 $template[$row[$this->getPK()]] = $row;
             }
             $data = [];
             if ($this->getDataLanguage() && !$this->getParam('onlyCurrentLang')) {
                 $lang = [$this->getDataLanguage() => $lang[$this->getDataLanguage()]];
             }
             foreach ($matrix as $ltagID => $langVersions) {
                 foreach (array_keys($lang) as $langID) {
                     if (isset($langVersions[$langID])) {
                         $data[] = $langVersions[$langID];
                     } else {
                         $data[arrayPush($data, $template[$ltagID])]['lang_id'] = $langID;
                     }
                 }
             }
         }
     } else {
         $i = 0;
         $dbFields = array_merge(isset($dbFields[$this->getTableName()]) ? array_keys($dbFields[$this->getTableName()]) : [], array_keys($dbFields[$this->getTranslationTableName()]));
         $dbFields = array_flip($dbFields);
         foreach ($dbFields as $key => $value) {
             $dbFields[$key] = '';
         }
         foreach (array_keys($lang) as $langID) {
             $data[$i][$this->getPK()] = null;
             $data[$i]['lang_id'] = $langID;
             $data[$i] = array_merge($data[$i], $dbFields);
             $i++;
         }
     }
     return $data;
 }
Example #3
0
 /**
  * Attach new filed.
  * @param FilterField $field New filter field.
  */
 public function attachField(FilterField $field)
 {
     $field->setIndex(arrayPush($this->fields, $field));
     $field->attach($this);
 }
Example #4
0
 /**
  * @copydoc DBDataSet::loadData
  */
 protected function loadData()
 {
     // Для действия main не выводим данные
     // Для действия save определяем другой формат данных
     if ($this->getState() == self::DEFAULT_STATE_NAME or $this->getState() == 'move') {
         $result = false;
     } elseif ($this->getState() == 'save') {
         if (!isset($_POST[$this->getTableName()])) {
             throw new SystemException('ERR_NO_DATA', SystemException::ERR_CRITICAL);
         }
         $data = $_POST[$this->getTableName()];
         //Приводим данные к стандартному виду
         $result = [$data];
         if ($this->getTranslationTableName()) {
             if (!isset($_POST[$this->getTranslationTableName()])) {
                 throw new SystemException('ERR_NO_DATA', SystemException::ERR_CRITICAL);
             }
             $result = [];
             $multidata = $_POST[$this->getTranslationTableName()];
             foreach ($multidata as $langID => $langValues) {
                 $idx = arrayPush($result, $data);
                 $result[$idx]['lang_id'] = $langID;
                 foreach ($langValues as $fieldName => $fieldValue) {
                     $result[$idx][$fieldName] = $fieldValue;
                 }
             }
         }
     } else {
         $result = parent::loadData();
     }
     return $result;
 }
Example #5
0
 /**
  * Attach control.
  *
  * @param Control $control
  */
 public function attachControl(Control $control)
 {
     $control->setIndex(arrayPush($this->controls, $control));
     $control->attach($this->getToolbar());
 }