/** * @copydoc ExtendedSaver::setData */ public function setData(Data $data) { parent::setData($data); if (!$data->getFieldByName('news_segment')->getRowData(0)) { $f = new Field('news_segment'); $translitedTitle = Translit::asURLSegment($data->getFieldByName('news_title')->getRowData(0)); $filter = array(); $pkF = $this->getData()->getFieldByName($this->getPK()); if ($pkF = $pkF->getRowData(0)) { $filter[$this->getPK()] = $pkF; } for ($i = 0; $i < 30; $i++) { $tempTitle = $translitedTitle; if ($i) { $tempTitle = $translitedTitle . '-' . $i; } $filter = array('news_segment' => $tempTitle); if (!$this->dbh->getScalar($this->getTableName(), 'news_segment', $filter)) { break; } else { $tempTitle = $translitedTitle . '-' . $i; } } $translitedTitle = $tempTitle; for ($i = 0, $l = sizeof(E()->getLanguage()->getLanguages()); $i < $l; $i++) { $f->setRowData($i, $translitedTitle); } $data->addField($f); } }
private function buildGroups(Field $field) { $builder = new SimpleBuilder(); $data = new Data(); $dd = new DataDescription(); $dd->load(['id' => ['type' => FieldDescription::FIELD_TYPE_INT, 'key' => true], 'link' => ['type' => FieldDescription::FIELD_TYPE_STRING], 'title' => ['type' => FieldDescription::FIELD_TYPE_STRING], 'text' => ['type' => FieldDescription::FIELD_TYPE_HTML_BLOCK]]); $builder->setDataDescription($dd); foreach ($field as $key => $id) { if ($d = $this->dbh->select('SELECT t.top_id as id, top_name as `title`, top_link as link,top_text_rtf as `text` FROM apps_tops t LEFT JOIN apps_tops_translation tt ON (tt.top_id=t.top_id) AND (lang_id=%s) WHERE (t.tg_id =%s) AND top_is_active ORDER BY top_order_num', $this->document->getLang(), $id)) { $data->load($d); $builder->setData($data); $am = new AttachmentManager($dd, $data, 'apps_tops'); $am->createFieldDescription(); $am->createField('top_id', false, $data->getFieldByName('id')->getData()); $builder->build(); $field->setRowData($key, $builder->getResult()); } else { $field->setRowData($key, null); } } }
/** * Edit ad. * Modify input DataDescription argument by adding to it an information about ad. * * @param Data $d Data. * @param DataDescription $dd Data description. */ public function edit(Data $d, DataDescription $dd) { $fds = $this->dbh->getColumnsInfo(self::TABLE_NAME); unset($fds['smap_id']); $fds['ad_id']['key'] = false; foreach ($fds as $key => $value) { $fds[$key]['tabName'] = 'TXT_ADS'; } $dd->load($fds); $data = $this->dbh->select(self::TABLE_NAME, array_keys($fds), array('smap_id' => $d->getFieldByName('smap_id')->getRowData(0))); if (is_array($data)) { //Тут как всегда проблема с загрузкой значений в мультиязычный билдер foreach ($data[0] as $fieldName => $fieldData) { $f = new Field($fieldName); for ($i = 0, $l = sizeof(E()->getLanguage()->getLanguages()); $i < $l; $i++) { $f->setRowData($i, $fieldData); } $d->addField($f); } } }
/** * Build for for editing component parameters. * The form creation is based on XML widget's data received per POST request. * * @throws SystemException 'ERR_INSUFFICIENT_DATA' * @throws SystemException 'ERR_BAD_XML_DESCR' */ protected function buildParamsForm() { if (!isset($_POST['modalBoxData'])) { throw new SystemException('ERR_INSUFFICIENT_DATA'); } if (!($widgetXML = simplexml_load_string($_POST['modalBoxData']))) { throw new SystemException('ERR_BAD_XML_DESCR'); } list($componentName) = $this->getStateParams(); $component = ComponentManager::findBlockByName($widgetXML, $componentName); $dd = new DataDescription(); $d = new Data(); $this->setType(self::COMPONENT_TYPE_FORM_ALTER); $this->setDataDescription($dd); $this->setData($d); $this->setBuilder(new Builder()); $this->js = $this->buildJS(); foreach ($component->params->children() as $param) { $paramName = (string) $param['name']; $paramType = isset($param['type']) ? (string) $param['type'] : FieldDescription::FIELD_TYPE_STRING; $fd = new FieldDescription($paramName); if (isset($param['nullable'])) { $fd->setProperty('nullable', true); } $fd->setType($paramType)->setProperty('tabName', E()->Utils->translate('TAB_PARAMS')); if ($paramType == FieldDescription::FIELD_TYPE_SELECT && isset($param['values'])) { $availableValues = array(); foreach (explode('|', (string) $param['values']) as $value) { array_push($availableValues, array('key' => $value, 'value' => $value)); } $fd->loadAvailableValues($availableValues, 'key', 'value'); } $dd->addFieldDescription($fd); $f = new Field($paramName); $f->setRowData(0, $param); $d->addField($f); } $this->addToolbar($this->loadToolbar()); }