Example #1
0
 /**
  * @param int $parentStructureId
  *
  * @return Structure[]
  */
 protected function getStructuresByParentId($parentStructureId = 0)
 {
     $oStructures = DataSource::factory(Structure::cls());
     $oStructures->builder()->where("structure_id={$parentStructureId}")->whereAnd()->where("active=1")->order('priority');
     /** @var Structure[] $aStructures */
     $aStructures = $oStructures->findAll();
     return $aStructures;
 }
Example #2
0
 public function actionIndex()
 {
     $this->needAuthenticate();
     $structureId = Param::get('id')->asInteger();
     /** @var Structure $oStructure */
     $oStructure = DataSource::factory(Structure::cls(), $structureId);
     $name = $oStructure->name;
     $this->deepDelete($oStructure);
     SCMSNotificationLog::instance()->pushMessage("Структура \"{$name}\" успешно удалена.");
     $this->Response->send();
 }
Example #3
0
 public function getPath(Structure $oStructure)
 {
     $path = [];
     /** @var Structure $oCurrentStructure */
     $oCurrentStructure = $oStructure;
     $path[] = ucfirst($oCurrentStructure->path);
     while ($oCurrentStructure->structure_id != 0) {
         $oCurrentStructure = DataSource::factory(Structure::cls(), $oCurrentStructure->structure_id);
         $path[] = ucfirst($oCurrentStructure->path);
     }
     return implode('\\', array_reverse($path));
 }
Example #4
0
 public function getStructures()
 {
     /** @var Structure[] $aStructures */
     $aStructures = $this->findRelationCache($this->getPrimaryKeyName(), Structure::cls());
     if (empty($aStructures)) {
         $oStructures = DataSource::factory(Structure::cls());
         $oStructures->builder()->where("module_id={$this->getPrimaryKey()}");
         $aStructures = $oStructures->findAll();
         foreach ($aStructures as $oStructure) {
             $this->addRelationCache($this->getPrimaryKeyName(), $oStructure);
             $oStructure->addRelationCache('module_id', $this);
         }
     }
 }
Example #5
0
 public function getStructure()
 {
     /** @var Structure[] $aStructures */
     $aStructures = $this->findRelationCache('structure_id', Structure::cls());
     if (empty($aStructures)) {
         $oStructures = DataSource::factory(Structure::cls());
         $oStructures->builder()->where("id={$this->structure_id}");
         $aStructures = $oStructures->findAll();
         foreach ($aStructures as $oStructure) {
             $this->addRelationCache('structure_id', $oStructure);
             $oStructure->addRelationCache($oStructure->getPrimaryKeyName(), $this);
         }
     }
     return isset($aStructures[0]) ? $aStructures[0] : null;
 }
Example #6
0
 public function actionIndex()
 {
     if (CoreFunctions::isAJAX() && !$this->EmployeeAuthentication->authenticated()) {
         SCMSNotificationLog::instance()->pushError('Нет доступа!');
         $this->Response->send();
         return;
     }
     $this->needAuthenticate();
     $frameName = Param::get('name', true)->asString(true, 'Недопустимое имя фрейма!');
     $FrameFile = new File(SFW_MODULES_FRAMES . $frameName);
     if (!$FrameFile->exists()) {
         SCMSNotificationLog::instance()->pushError("Фрейм с именем \"{$frameName}\" не найден!");
     }
     if (SCMSNotificationLog::instance()->hasProblems()) {
         $this->Response->send();
         return;
     }
     $oStructures = DataSource::factory(Structure::cls());
     $oStructures->builder()->where('deleted=0')->whereAnd()->where("frame='{$frameName}'");
     /** @var Structure[] $aStructures */
     $aStructures = $oStructures->findAll();
     if (sizeof($aStructures) > 0) {
         $structureNames = [];
         foreach ($aStructures as $oStructure) {
             $structureNames[] = $oStructure->name;
         }
         SCMSNotificationLog::instance()->pushError("Фрейм \"{$frameName}\" нельзя удалять, пока он используется в структуре сайта. На данный момент фрейм назначен разделам: \"" . implode('", "', $structureNames) . '"');
     }
     if (SCMSNotificationLog::instance()->hasProblems()) {
         $this->Response->send();
         return;
     }
     try {
         $FrameFile->delete();
     } catch (Exception $e) {
         SCMSNotificationLog::instance()->pushError('При удалении фрейма произошла ошибка.');
     }
     if (!SCMSNotificationLog::instance()->hasProblems()) {
         SCMSNotificationLog::instance()->pushMessage("Фрейм \"{$frameName}\" успешно удалён.");
     }
     $this->Response->send();
 }
Example #7
0
 public function actionAjaxModuleConfig()
 {
     $this->needAuthenticate();
     $structureId = Param::get('structure_id')->noEmpty('Пропущен обязательный параметр "structure_id".')->asInteger(true, '"structure_id" должен быть числом.');
     if ($structureId == 0) {
         SCMSNotificationLog::instance()->pushError("Не указана целевая структура.");
         $this->Response->send();
         exit;
     }
     $moduleId = Param::get('module_id')->noEmpty('Пропущен обязательный параметр "module_id".')->asInteger(true, '"structure_id" должен быть числом.');
     /** @var Structure $oStructure */
     $oStructure = DataSource::factory(Structure::cls(), $structureId);
     /** @var Module $oModule */
     $oModule = DataSource::factory(Module::cls(), $moduleId == 0 ? null : $moduleId);
     ob_start();
     $view = $this->getModuleConfigView($oStructure, $oModule);
     $view->render();
     $form = ob_get_clean();
     $this->Response->send('', ['form' => $form]);
 }
Example #8
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();
 }
Example #9
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);
 }
Example #10
0
 protected function bindStructure()
 {
     $structure = DataSource::factory(Structure::cls());
     $structure->builder()->where('path=' . $structure->field('path')->type->toQueryWithQuotes(basename($this->currentPath)))->limit(1);
     $structures = $structure->findAll();
     $this->structure = reset($structures);
 }