/**
  * @return bool
  */
 public function isVisible()
 {
     if (!parent::isVisible()) {
         return false;
     }
     return Validate::validate(new HasBehavior(HasRelatedProperties::className()), $this->controller->model)->isValid();
 }
Exemple #2
0
 /**
  * @param ActiveRecord $activeRecord
  * @return \skeeks\sx\validate\Result
  */
 public function validate($activeRecord)
 {
     if (Validate::validate(new IsSame($this->_activeRecordForComparison), $activeRecord)->isValid()) {
         return $this->_bad(\Yii::t('app', "Essence same"));
     }
     return $this->_ok();
 }
Exemple #3
0
 /**
  * @param ActiveRecord $activeRecord
  * @return \skeeks\sx\validate\Result
  */
 public function validate($activeRecord)
 {
     if (Validate::validate(new NotNewRecord(), $activeRecord)->isValid() && Validate::validate(new NotNewRecord(), $this->_activeRecordForComparison)->isValid()) {
         if ($activeRecord->primaryKey == $this->_activeRecordForComparison->primaryKey) {
             return $this->_ok();
         }
     }
     return $this->_bad(\Yii::t('app', 'Essence different'));
 }
Exemple #4
0
 /**
  * @param Component $component
  * @return \skeeks\sx\validate\Result
  */
 public function validate($component)
 {
     foreach ($this->_behaviors as $behaviorName) {
         $validate = Validate::validate(new HasBehavior($behaviorName), $component);
         if ($validate->isValid()) {
             return $this->_ok();
         }
     }
     return $this->_bad(\Yii::t('app', 'No behavior'));
 }
Exemple #5
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $params = $request->getQueryParams();
     $sourceOriginalFile = File::object($pathInfo);
     $extension = $sourceOriginalFile->getExtension();
     if (!$extension) {
         return false;
     }
     if (Validate::validate(new AllowExtension(), $extension)->isInvalid()) {
         return false;
     }
     return ['cms/imaging/process', $params];
 }
 public function checkAdvancedAccess()
 {
     if (Validate::validate(new HasBehavior(BlameableBehavior::className()), $this->controller->model)->isValid()) {
         //Если такая привилегия заведена, нужно ее проверять.
         if ($permission = \Yii::$app->authManager->getPermission(CmsManager::PERMISSION_ALLOW_MODEL_UPDATE_ADVANCED)) {
             if (!\Yii::$app->user->can($permission->name, ['model' => $this->controller->model])) {
                 return false;
             }
         }
     } else {
         //Если такая привилегия заведена, нужно ее проверять.
         if ($permission = \Yii::$app->authManager->getPermission(CmsManager::PERMISSION_ALLOW_MODEL_UPDATE_ADVANCED)) {
             if (!\Yii::$app->user->can($permission->name)) {
                 return false;
             }
         }
     }
     return true;
 }
Exemple #7
0
    public function renderNodes($models)
    {
        $options["item"] = function ($model) {
            $isOpen = false;
            $isActive = false;
            $controller = \Yii::$app->cms->moduleCms()->createControllerByID("admin-tree");
            $controller->setModel($model);
            $child = "";
            foreach ($this->_openedTmp as $activeNode) {
                if (Validate::validate(new IsSame($activeNode), $model)->isValid()) {
                    $isOpen = true;
                    break;
                }
            }
            if ($isOpen && $model->children) {
                $child = $this->renderNodes($model->children);
            }
            $openCloseLink = "";
            $currentLink = "";
            if ($model->children) {
                $openedIds = $this->_getOpenIds();
                if ($isOpen) {
                    $newOptionsOpen = [];
                    foreach ($openedIds as $id) {
                        if ($id != $model->id) {
                            $newOptionsOpen[] = $id;
                        }
                    }
                    $urlOptionsOpen = array_unique($newOptionsOpen);
                    $params = \Yii::$app->request->getQueryParams();
                    $params[$this->openedRequestName] = $urlOptionsOpen;
                    $currentLink = UrlHelper::construct("cms/admin-tree/index")->setData($params);
                    $openCloseLink = Html::a(Html::tag("span", "", ["class" => "glyphicon glyphicon-minus", "title" => \Yii::t('app', "Minimize")]), $currentLink, ['class' => 'btn btn-xs btn-default']);
                } else {
                    $urlOptionsOpen = array_unique(array_merge($openedIds, [$model->id]));
                    $params = \Yii::$app->request->getQueryParams();
                    $params[$this->openedRequestName] = $urlOptionsOpen;
                    $currentLink = UrlHelper::construct("cms/admin-tree/index")->setData($params);
                    $openCloseLink = Html::a(Html::tag("span", "", ["class" => "glyphicon glyphicon-plus", "title" => \Yii::t('app', "Restore")]), $currentLink, ['class' => 'btn btn-xs btn-default']);
                }
                $openCloseLink = Html::tag("div", $openCloseLink, ["class" => "sx-node-open-close"]);
            }
            if ($this->_getMode() == 'multi') {
                $params = \Yii::$app->request->getQueryParams();
                $isSelected = in_array($model->id, $this->_getSelectedIds()) ? true : false;
                if ($isSelected) {
                    $result = [];
                    foreach ($this->_getSelectedIds() as $id) {
                        if ($id != $model->id) {
                            $result[] = $id;
                        }
                    }
                    $params[$this->selectedRequestName] = $result;
                } else {
                    $params[$this->selectedRequestName] = array_unique(array_merge($this->_getSelectedIds(), [$model->id]));
                }
                $link = UrlHelper::construct("cms/admin-tree/index")->setData($params);
                $controllElement = Html::checkbox('tree_id', $isSelected, ['value' => $model->id, 'style' => 'float: left; margin-left: 5px; margin-right: 5px;', 'onclick' => new JsExpression(<<<JS
        sx.Tree.select("{$model->id}", "{$link}"); return false;
JS
)]);
            } else {
                if ($this->_getMode() == 'single') {
                    $params = \Yii::$app->request->getQueryParams();
                    $isSelected = in_array($model->id, $this->_getSelectedIds()) ? true : false;
                    if ($isSelected) {
                        $params[$this->selectedRequestName] = [];
                    } else {
                        $params[$this->selectedRequestName] = [$model->id];
                    }
                    $link = UrlHelper::construct("cms/admin-tree/index")->setData($params);
                    $controllElement = Html::radio('tree_id', $isSelected, ['value' => $model->id, 'class' => 'sx-readio', 'style' => 'float: left; margin-left: 5px; margin-right: 5px;', 'onclick' => new JsExpression(<<<JS
        sx.Tree.selectSingle("{$model->id}");
JS
)]);
                } else {
                    if ($this->_getMode() == 'combo') {
                        $params = \Yii::$app->request->getQueryParams();
                        $isSelected = in_array($model->id, $this->_getSelectedIds()) ? true : false;
                        if ($isSelected) {
                            $result = [];
                            foreach ($this->_getSelectedIds() as $id) {
                                if ($id != $model->id) {
                                    $result[] = $id;
                                }
                            }
                            $params[$this->selectedRequestName] = $result;
                        } else {
                            $params[$this->selectedRequestName] = array_unique(array_merge($this->_getSelectedIds(), [$model->id]));
                        }
                        $link = UrlHelper::construct("cms/admin-tree/index")->setData($params);
                        $controllElement = Html::radio('tree_id', false, ['value' => $model->id, 'class' => 'sx-readio', 'style' => 'float: left; margin-left: 5px; margin-right: 5px;', 'onclick' => new JsExpression(<<<JS
                        sx.Tree.selectSingle("{$model->id}");
JS
)]);
                        $controllElement .= Html::checkbox('tree_id', $isSelected, ['value' => $model->id, 'style' => 'float: left; margin-left: 5px; margin-right: 5px;', 'onclick' => new JsExpression(<<<JS
        sx.Tree.select("{$model->id}", "{$link}"); return false;
JS
)]);
                    } else {
                        $controllElement = '';
                    }
                }
            }
            /**
             * @var $model \skeeks\cms\models\Tree
             */
            $additionalName = '';
            if ($model->level == 0) {
                if ($model->site) {
                    $additionalName = $model->site->name;
                }
            } else {
                if ($model->name_hidden) {
                    $additionalName = $model->name_hidden;
                }
            }
            $link = Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $model->getAbsoluteUrl(), ["target" => "_blank", "class" => "btn-tree-node-controll btn btn-default btn-xs show-at-site", "title" => \Yii::t('app', "Show at site")]);
            $subsection = \Yii::t('app', 'Create subsection');
            return Html::tag("li", Html::tag("div", $openCloseLink . $controllElement . Html::tag("div", Html::a($model->name . ($additionalName ? ' [' . $additionalName . ']' : ''), $currentLink), ["class" => "sx-label-node level-" . $model->level . " status-" . $model->active]) . ($model->treeType ? Html::tag("div", $model->treeType->name, ["class" => "pull-left sx-tree-type"]) : '') . Html::tag("div", DropdownControllerActions::widget(["controller" => $controller, "renderFirstAction" => false, "containerClass" => "dropdown pull-left", 'clientOptions' => ['pjax-id' => 'sx-pjax-tree']]) . Html::tag("div", <<<HTML
                                        <a href="#" class="btn-tree-node-controll btn btn-default btn-xs add-tree-child" title="{$subsection}" data-id={$model->id}><span class="glyphicon glyphicon-plus"></span></a>
HTML
, ["class" => "pull-left sx-controll-act"]) . Html::tag("div", $link, ["class" => "pull-left sx-controll-act"]), ["class" => "sx-controll-node row"]), ["class" => "row"]) . $child, ["class" => "sx-tree-node " . ($isActive ? " active" : "") . ($isOpen ? " open" : ""), "data-id" => $model->id]);
        };
        $ul = Html::ul($models, $options);
        return $ul;
    }
Exemple #8
0
    ?>
    <?php 
    echo $form->field($model, 'created_at')->widget(\kartik\datecontrol\DateControl::classname(), ['type' => \kartik\datecontrol\DateControl::FORMAT_DATETIME]);
}
?>

<?php 
if ($model->hasAttribute('updated_at')) {
    ?>
    <?php 
    echo $form->field($model, 'updated_at')->widget(\kartik\datecontrol\DateControl::classname(), ['type' => \kartik\datecontrol\DateControl::FORMAT_DATETIME]);
}
?>

<?php 
if (Validate::validate(new HasBehavior(\skeeks\cms\models\behaviors\TimestampPublishedBehavior::className()), $model)->isValid()) {
    ?>
    <?php 
    echo $form->field($model, 'published_at')->widget(\kartik\datecontrol\DateControl::classname(), ['type' => \kartik\datecontrol\DateControl::FORMAT_DATETIME]);
}
?>

<?php 
if ($model->hasAttribute('published_to')) {
    ?>
    <?php 
    echo $form->field($model, 'published_to')->widget(\kartik\datecontrol\DateControl::classname(), ['type' => \kartik\datecontrol\DateControl::FORMAT_DATETIME]);
}
?>

<?php 
 /**
  * @return array
  */
 public function behaviors()
 {
     $behaviors = ArrayHelper::merge(parent::behaviors(), ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['post'], 'delete-multi' => ['post']]], 'accessDelete' => ['class' => AdminAccessControl::className(), 'only' => ['delete'], 'rules' => [['allow' => true, 'matchCallback' => function ($rule, $action) {
         if (Validate::validate(new HasBehavior(BlameableBehavior::className()), $this->model)->isValid()) {
             //Если такая привилегия заведена, нужно ее проверять.
             if ($permission = \Yii::$app->authManager->getPermission(CmsManager::PERMISSION_ALLOW_MODEL_DELETE)) {
                 if (!\Yii::$app->user->can($permission->name, ['model' => $this->model])) {
                     return false;
                 }
             }
         }
         return true;
     }]]]]);
     return $behaviors;
 }
Exemple #10
0
 /**
  * Процесс вставки ноды одна в другую. Можно вставлять как уже сохраненную модель с дочерними элементами, так и еще не сохраненную.
  *
  * @param Tree $target
  * @return $this
  * @throws Exception
  * @throws \skeeks\sx\validate\Exception
  */
 public function processAddNode(Tree $target)
 {
     //Текущая сущьность должна быть уже сохранена, и не равна $target
     Validate::ensure(new ChainAnd([new NotNewRecord(), new NotSame($target)]), $this);
     //Если раздел который мы пытаемся добавить новый, то у него нет детей и он
     if ($target->isNewRecord) {
         $this->processCreateNode($target);
         return $this;
     } else {
         $target->setAttributesForFutureParent($this);
         if (!$target->save(false)) {
             throw new Exception(\Yii::t('app', "Unable to move: ") . Json::encode($target->attributes));
         }
         $this->processNormalize();
     }
     return $this;
 }