コード例 #1
0
ファイル: ControllerSave.php プロジェクト: met-mw/SCMS
 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);
 }