Пример #1
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $parentPK = (int) Param::get('parent_pk', false)->asInteger(false);
     $pageNumber = Param::get('structure-page', false)->asInteger(false);
     $itemsPerPage = Param::get('structure-items-per-page', false)->asInteger(false);
     $addItemUrl = '/admin/modules/structures/edit/';
     if ($parentPK != 0) {
         $addItemUrl .= "?parent_pk={$parentPK}";
     }
     $manifest = $this->ModuleInstaller->getManifest($this->ModuleDirectory);
     $dataGridView = new ViewDataGrid();
     $retriever = new StructureRetriever();
     $dataGrid = new DataGrid('structure', '', 'id', $manifest['meta']['alias'], $pageNumber, $itemsPerPage, $manifest['meta']['description']);
     $dataGrid->addHiddenField('parent_pk', $parentPK);
     $dataGrid->getMenu()->addElement(new Item('Добавить элемент структуры', $addItemUrl));
     $dataGrid->addAction(new Action('id', '/admin/modules/structures/edit/', 'edit', '', [], ['class' => 'glyphicon glyphicon-pencil'], 'Редактировать'))->addAction(new Action('id', '/admin/modules/structures/delete/', 'delete', '', [], ['class' => 'glyphicon glyphicon-trash'], 'Удалить', true));
     $dataGrid->addHeader(new Header('id', '№', null, ['class' => 'text-center', 'style' => 'width: 50px;'], ['class' => 'text-center'], true, Param::get('structure-filter-id', false)->asString(false)))->addHeader(new Header('name', 'Наименование', new ViewLink('/admin/modules/structures/?parent_pk={label}', false, 'id'), ['class' => 'text-center', 'style' => 'width: 300px'], [], true, Param::get('structure-filter-name', false)->asString(false)))->addHeader(new Header('parent_structure_name', 'Родитель', null, ['class' => 'text-center', 'style' => 'width: 300px;'], [], true, Param::get('structure-filter-parent_structure_name', false)->asString(false), 'name', 'parent_structure'))->addHeader(new Header('path', 'Путь', null, ['class' => 'text-center', 'style' => 'width: 300px;'], [], true, Param::get('structure-filter-path', false)->asString(false)))->addHeader(new Header('module_alias', 'Модуль', null, ['class' => 'text-center', 'style' => 'width: 300px;'], [], true, Param::get('structure-filter-module_alias', false)->asString(false), 'alias', 'module'))->addHeader(new Header('anchor', 'Фрагмент', new ViewSwitch(), ['class' => 'text-center'], ['class' => 'text-center'], true, Param::get('structure-filter-anchor', false)->asString(false)))->addHeader(new Header('frame', 'Фрейм', new ViewEmpty(), ['class' => 'text-center'], ['class' => 'text-center'], true, Param::get('structure-filter-frame', false)->asString(false)))->addHeader(new Header('seo_title', 'SEO T', new ViewEmpty(), ['class' => 'text-center', 'style' => 'width: 80px;'], ['class' => 'text-center'], true, Param::get('structure-filter-seo_title', false)->asString(false)))->addHeader(new Header('seo_description', 'SEO D', new ViewEmpty(), ['class' => 'text-center', 'style' => 'width: 80px;'], ['class' => 'text-center'], true, Param::get('structure-filter-seo_description', false)->asString(false)))->addHeader(new Header('seo_keywords', 'SED K', new ViewEmpty(), ['class' => 'text-center', 'style' => 'width: 80px;'], ['class' => 'text-center'], true, Param::get('structure-filter-seo_keywords', false)->asString(false)))->addHeader(new Header('is_main', '<span class="glyphicon glyphicon-home" title="Главная"></span>', new ViewSwitch(), ['class' => 'text-center', 'style' => 'width: 50px;'], ['class' => 'text-center'], true, Param::get('structure-filter-is_main', false)->asString(false)))->addHeader(new Header('priority', '<span class="glyphicon glyphicon-sort-by-attributes" title="Приоритет"></span>', new ViewSwitch(), ['class' => 'text-center', 'style' => 'width: 50px;'], ['class' => 'text-center'], true, Param::get('structure-filter-priority', false)->asString(false)))->addHeader(new Header('active', '<span class="glyphicon glyphicon-asterisk" title="Активность"></span>', new ViewSwitch(), ['class' => 'text-center', 'style' => 'width: 50px;'], ['class' => 'text-center'], true, Param::get('structure-filter-active', false)->asString(false)));
     $structures = $retriever->getStructures($parentPK, $dataGrid->getFilterConditions('structure'), $dataGrid->Pagination->getLimit(), $dataGrid->Pagination->getOffset());
     $dataSet = new ArrayDataSet($structures);
     $dataGrid->addDataSet($dataSet);
     $dataGridView->dataGrid = $dataGrid;
     // Подготовка хлебных крошек
     $viewBreadcrumbs = new ViewBreadcrumbs();
     $viewBreadcrumbs->Breadcrumbs = [new Breadcrumb('Панель управления', '/admin'), new Breadcrumb('Структура сайта', '/modules/structures')];
     $breadcrumbsParentPK = $parentPK;
     $structureBreadcrumbs = [];
     while ($breadcrumbsParentPK) {
         /** @var Structure $oParentStructure */
         $oParentStructure = DataSource::factory(Structure::cls(), $breadcrumbsParentPK);
         $structureBreadcrumbs[] = new Breadcrumb($oParentStructure->name, "?parent_pk={$oParentStructure->getPrimaryKey()}", true);
         $breadcrumbsParentPK = $oParentStructure->structure_id;
     }
     $viewBreadcrumbs->Breadcrumbs = array_merge($viewBreadcrumbs->Breadcrumbs, array_reverse($structureBreadcrumbs));
     $this->Frame->bindView('breadcrumbs', $viewBreadcrumbs);
     $this->Frame->bindView('content', $dataGridView);
     $this->Frame->render();
 }
Пример #2
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $StructureHelper = new StructureHelper(SFW_APP_ROOT . 'Controllers' . DIRECTORY_SEPARATOR);
     $structureId = Param::post('structure-id', false)->asInteger(false);
     $name = Param::post('structure-name')->noEmpty('Заполните поле "Наименование"')->asString();
     $description = Param::post('structure-description')->asString();
     $parent = Param::post('structure-parent')->asInteger(true, 'Поле "Родительский раздел" заполнено неверно.');
     $path = Param::post('structure-path')->asString();
     $frame = Param::post('structure-frame')->asString();
     $module = Param::post('structure-module')->asInteger(true, 'Поле "Модуль" заполнено неверно.');
     $anchor = (int) Param::post('structure-anchor', false)->exists();
     $priority = Param::post('structure-priority', false)->asString();
     $isMain = (int) Param::post('structure-is-main', false)->exists();
     $active = (int) Param::post('structure-active', false)->exists();
     $seoTitle = Param::post('structure-seo-title', false)->asString();
     $seoDescription = Param::post('structure-seo-description', false)->asString();
     $seoKeywords = Param::post('structure-seo-keywords', false)->asString();
     $accept = Param::post('structure-accept', false);
     if (SCMSNotificationLog::instance()->hasProblems()) {
         $this->Response->send();
         return;
     }
     /** @var Structure $oStructure */
     $oStructure = DataSource::factory(Structure::cls(), $structureId == 0 ? null : $structureId);
     $oldPath = $StructureHelper->getPath($oStructure);
     $oStructure->name = $name;
     $oStructure->description = $description;
     $oStructure->structure_id = $parent;
     $oStructure->path = $path;
     $oStructure->frame = $frame;
     $oStructure->module_id = $module;
     $oStructure->anchor = $anchor;
     $oStructure->priority = $priority;
     $oStructure->is_main = $isMain;
     $oStructure->active = $active;
     $oStructure->seo_title = $seoTitle;
     $oStructure->seo_description = $seoDescription;
     $oStructure->seo_keywords = $seoKeywords;
     if (!$oStructure->getPrimaryKey()) {
         $oStructure->deleted = false;
     }
     if ($isMain) {
         $retriever = new StructureRetriever();
         $retriever->clearMainFlag();
     }
     $oStructure->commit();
     if ($oStructure->module_id) {
         $this->saveStructureSettings($oStructure);
     }
     if ($structureId != 0) {
         $StructureHelper->removeProxyController($oldPath);
     }
     $StructureHelper->createProxyController($StructureHelper->getPath($oStructure));
     if (!SCMSNotificationLog::instance()->hasProblems()) {
         SCMSNotificationLog::instance()->pushMessage("Структура \"{$oStructure->name}\" успешно " . ($structureId == 0 ? 'добавлена' : 'отредактирована') . ".");
     }
     $redirect = "/admin/modules/structures/edit/?pk={$oStructure->getPrimaryKey()}";
     if ($accept->exists()) {
         $redirect = '/admin/modules/structures/' . ($oStructure->structure_id == 0 ? '' : "?parent_pk={$oStructure->structure_id}");
     } elseif ($structureId != 0) {
         $redirect = '';
     }
     $this->Response->send($redirect);
 }