diff --git a/backend/components/ToggleAction.php b/backend/components/ToggleAction.php
index 4c4a191..808b348 100644
--- a/backend/components/ToggleAction.php
+++ b/backend/components/ToggleAction.php
@@ -14,100 +14,101 @@ use Yii;
class ToggleAction extends Action
{
- /**
- * @var string name of the model
- */
- public $modelClass;
- /**
- * @var string model attribute
- */
- public $attribute = 'active';
- /**
- * @var string scenario model
- */
- public $scenario = null;
- /**
- * @var string|array additional condition for loading the model
- */
- public $andWhere;
- /**
- * @var string|int|boolean|Expression what to set active models to
- */
- public $onValue = 1;
- /**
- * @var string|int|boolean what to set inactive models to
- */
- public $offValue = 0;
- /**
- * @var bool whether to set flash messages or not
- */
- public $setFlash = false;
- /**
- * @var string flash message on success
- */
- public $flashSuccess = "Model saved";
- /**
- * @var string flash message on error
- */
- public $flashError = "Error saving Model";
- /**
- * @var string|array URL to redirect to
- */
- public $redirect;
- /**
- * @var string pk field name
- */
- public $primaryKey = 'id';
+ /**
+ * @var string name of the model
+ */
+ public $modelClass;
+ /**
+ * @var string model attribute
+ */
+ public $attribute = 'active';
+ /**
+ * @var string scenario model
+ */
+ public $scenario = null;
+ /**
+ * @var string|array additional condition for loading the model
+ */
+ public $andWhere;
+ /**
+ * @var string|int|boolean|Expression what to set active models to
+ */
+ public $onValue = 1;
+ /**
+ * @var string|int|boolean what to set inactive models to
+ */
+ public $offValue = 0;
+ /**
+ * @var bool whether to set flash messages or not
+ */
+ public $setFlash = false;
+ /**
+ * @var string flash message on success
+ */
+ public $flashSuccess = 'Model saved';
+ /**
+ * @var string flash message on error
+ */
+ public $flashError = 'Error saving Model';
+ /**
+ * @var string|array URL to redirect to
+ */
+ public $redirect;
+ /**
+ * @var string pk field name
+ */
+ public $primaryKey = 'id';
- public function run($id)
- {
- if (!Yii::$app->request->getIsPost()) {
- throw new MethodNotAllowedHttpException();
- }
- $id = (int)$id;
- $result = null;
- if (empty($this->modelClass) || !class_exists($this->modelClass)) {
- throw new InvalidConfigException("Model class doesn't exist");
- }
- /* @var $modelClass \yii\db\ActiveRecord */
- $modelClass = $this->modelClass;
- $attribute = $this->attribute;
- $model = $modelClass::find()->where([$this->primaryKey => $id]);
- if (!empty($this->andWhere)) {
- $model->andWhere($this->andWhere);
- }
- $model = $model->one();
- if (!is_null($this->scenario)) {
- $model->scenario = $this->scenario;
- }
- if (!$model->hasAttribute($this->attribute)) {
- throw new InvalidConfigException("Attribute doesn't exist");
- }
- if ($model->$attribute == $this->onValue) {
- $model->$attribute = $this->offValue;
- } elseif ($this->onValue instanceof Expression && $model->$attribute != $this->offValue) {
- $model->$attribute = $this->offValue;
- } else {
- $model->$attribute = $this->onValue;
- }
- if ($model->save()) {
- if ($this->setFlash) {
- Yii::$app->session->setFlash('success', $this->flashSuccess);
- }
- } else {
- if ($this->setFlash) {
- Yii::$app->session->setFlash('error', $this->flashError);
- }
- }
- if (Yii::$app->request->getIsAjax()) {
- Yii::$app->end();
- }
- /* @var $controller \yii\web\Controller */
- $controller = $this->controller;
- if (!empty($this->redirect)) {
- return $controller->redirect($this->redirect);
- }
- return $controller->redirect(Yii::$app->request->getReferrer());
- }
-}
\ No newline at end of file
+ public function run($id)
+ {
+ if (!Yii::$app->request->getIsPost()) {
+ throw new MethodNotAllowedHttpException();
+ }
+ $id = (int)$id;
+ $result = null;
+ if (empty($this->modelClass) || !class_exists($this->modelClass)) {
+ throw new InvalidConfigException("Model class doesn't exist");
+ }
+ /* @var $modelClass \yii\db\ActiveRecord */
+ $modelClass = $this->modelClass;
+ $attribute = $this->attribute;
+ $model = $modelClass::find()->where([$this->primaryKey => $id]);
+ if (!empty($this->andWhere)) {
+ $model->andWhere($this->andWhere);
+ }
+ $model = $model->one();
+ if (!is_null($this->scenario)) {
+ $model->scenario = $this->scenario;
+ }
+ if (!$model->hasAttribute($this->attribute)) {
+ throw new InvalidConfigException("Attribute doesn't exist");
+ }
+ if ($model->$attribute == $this->onValue) {
+ $model->$attribute = $this->offValue;
+ } elseif ($this->onValue instanceof Expression && $model->$attribute != $this->offValue) {
+ $model->$attribute = $this->offValue;
+ } else {
+ $model->$attribute = $this->onValue;
+ }
+ if ($model->save()) {
+ if ($this->setFlash) {
+ Yii::$app->session->setFlash('success', $this->flashSuccess);
+ }
+ } else {
+ if ($this->setFlash) {
+ Yii::$app->session->setFlash('error', $this->flashError);
+ }
+ }
+ if (Yii::$app->request->getIsAjax()) {
+ Yii::$app->end();
+ }
+ /* @var $controller \yii\web\Controller */
+ $controller = $this->controller;
+ if (!empty($this->redirect)) {
+ return $controller->redirect($this->redirect);
+ }
+
+ return $controller->redirect(Yii::$app->request->getReferrer());
+ }
+}
diff --git a/backend/components/ToggleColumn.php b/backend/components/ToggleColumn.php
index 0a2823c..1576a72 100644
--- a/backend/components/ToggleColumn.php
+++ b/backend/components/ToggleColumn.php
@@ -13,122 +13,88 @@ use Yii;
class ToggleColumn extends DataColumn
{
- /**
- * Toggle action that will be used as the toggle action in your controller
- * @var string
- */
- public $action = 'toggle';
-
-
- /**
- * @var string pk field name
- */
- public $primaryKey = 'primaryKey';
-
- /**
- * Whether to use ajax or not
- * @var bool
- */
- public $enableAjax = true;
-
- /**
- * @var string glyphicon for 'on' value
- */
- public $iconOn = 'ok';
-
- /**
- * @var string glyphicon for 'off' value
- */
- public $iconOff = 'remove';
-
- /**
- * @var string text to display on the 'on' link
- */
- public $onText;
-
- /**
- * @var string text to display on the 'off' link
- */
- public $offText;
-
- /**
- * @var string text to display next to the 'on' link
- */
- public $displayValueText = false;
-
- /**
- * @var string text to display next to the 'on' link
- */
- public $onValueText;
-
- /**
- * @var string text to display next to the 'off' link
- */
- public $offValueText;
-
-
- public function init()
- {
- if ($this->onText === null) {
- $this->onText = Yii::t('main', 'On');
- }
- if ($this->offText === null) {
- $this->offText = Yii::t('main', 'Off');
- }
- if ($this->onValueText === null) {
- $this->onValueText = Yii::t('main', 'Active');
- }
- if ($this->offValueText === null) {
- $this->offValueText = Yii::t('main', 'Inactive');
- }
- if ($this->enableAjax) {
- $this->registerJs();
- }
- }
-
- /**
- * @inheritdoc
- */
- protected function renderDataCellContent($model, $key, $index)
- {
- $url = [$this->action, 'id' => $model->{$this->primaryKey}];
-
- $attribute = $this->attribute;
- $value = $model->$attribute;
-
- if ($value === null || $value == true) {
- $icon = $this->iconOn;
- $title = $this->offText;
- $valueText = $this->onValueText;
- $color = 'green';
- } else {
- $icon = $this->iconOff;
- $title = $this->onText;
- $valueText = $this->offValueText;
- $color = 'red';
- }
- return Html::a(
- '',
- $url,
- [
- 'title' => $title,
- 'class' => 'toggle-column',
- 'style' => 'color:' . $color,
- 'data-method' => 'post',
- 'data-pjax' => '0',
- ]
- ) . ( $this->displayValueText ? " {$valueText}" : "" );
- }
-
- /**
- * Registers the ajax JS
- */
- public function registerJs()
- {
- if(Yii::$app->request->isAjax) {
- return;
- }
- $js = <<<'JS'
+ /**
+ * Toggle action that will be used as the toggle action in your controller
+ * @var string
+ */
+ public $action = 'toggle';
+
+
+ /**
+ * @var string pk field name
+ */
+ public $primaryKey = 'primaryKey';
+
+ /**
+ * Whether to use ajax or not
+ * @var bool
+ */
+ public $enableAjax = true;
+
+ /**
+ * @var string glyphicon for 'on' value
+ */
+ public $iconOn = 'ok';
+
+ /**
+ * @var string glyphicon for 'off' value
+ */
+ public $iconOff = 'remove';
+
+ /**
+ * @var string text to display on the 'on' link
+ */
+ public $onText;
+
+ /**
+ * @var string text to display on the 'off' link
+ */
+ public $offText;
+
+ /**
+ * @var string text to display next to the 'on' link
+ */
+ public $displayValueText = false;
+
+ /**
+ * @var string text to display next to the 'on' link
+ */
+ public $onValueText;
+
+ /**
+ * @var string text to display next to the 'off' link
+ */
+ public $offValueText;
+
+
+ public function init()
+ {
+ if ($this->onText === null) {
+ $this->onText = Yii::t('main', 'On');
+ }
+ if ($this->offText === null) {
+ $this->offText = Yii::t('main', 'Off');
+ }
+ if ($this->onValueText === null) {
+ $this->onValueText = Yii::t('main', 'Active');
+ }
+ if ($this->offValueText === null) {
+ $this->offValueText = Yii::t('main', 'Inactive');
+ }
+ if ($this->enableAjax) {
+ $this->registerJs();
+ }
+ }
+
+ /**
+ * Registers the ajax JS
+ */
+ public function registerJs()
+ {
+ if (Yii::$app->request->isAjax) {
+ return;
+ }
+ $js = <<<'JS'
$(document.body).on("click", "a.toggle-column", function(e) {
e.preventDefault();
$.post($(this).attr("href"), function(data) {
@@ -138,6 +104,41 @@ $(document.body).on("click", "a.toggle-column", function(e) {
return false;
});
JS;
- $this->grid->view->registerJs($js, View::POS_READY, 'zx-toggle-column');
- }
-}
\ No newline at end of file
+ $this->grid->view->registerJs($js, View::POS_READY, 'zx-toggle-column');
+ }
+
+ /**
+ * @inheritdoc
+ */
+ protected function renderDataCellContent($model, $key, $index)
+ {
+ $url = [$this->action, 'id' => $model->{$this->primaryKey}];
+
+ $attribute = $this->attribute;
+ $value = $model->$attribute;
+
+ if ($value === null || $value == true) {
+ $icon = $this->iconOn;
+ $title = $this->offText;
+ $valueText = $this->onValueText;
+ $color = 'green';
+ } else {
+ $icon = $this->iconOff;
+ $title = $this->onText;
+ $valueText = $this->offValueText;
+ $color = 'red';
+ }
+
+ return Html::a(
+ '',
+ $url,
+ [
+ 'title' => $title,
+ 'class' => 'toggle-column',
+ 'style' => 'color:' . $color,
+ 'data-method' => 'post',
+ 'data-pjax' => '0',
+ ]
+ ) . ($this->displayValueText ? " {$valueText}" : '');
+ }
+}
diff --git a/backend/components/menu/widgets/MenuEditorWidget.php b/backend/components/menu/widgets/MenuEditorWidget.php
index 127a271..7983f9e 100644
--- a/backend/components/menu/widgets/MenuEditorWidget.php
+++ b/backend/components/menu/widgets/MenuEditorWidget.php
@@ -6,43 +6,43 @@
namespace backend\components\menu\widgets;
-
use core\entities\menu\Menu;
use core\entities\menu\MenuItem;
use yii\base\Widget;
class MenuEditorWidget extends Widget
{
- public $menu_id;
+ public $menu_id;
+
+ public function run()
+ {
+ $menu = Menu::findOne($this->menu_id);
+ $items = $menu->items;
- public function run()
- {
- $menu = Menu::findOne($this->menu_id);
- $items = $menu->items;
+ return $this->render('menu', [
+ 'items' => $this->getMenu($items),
+ 'menu' => $menu,
+ ]);
+ }
- return $this->render('menu', [
- 'items' => $this->getMenu($items),
- 'menu' => $menu,
- ]);
- }
+ /**
+ * @param $items MenuItem[]
+ *
+ * @return array
+ */
+ private function getMenu($items, $paren_id = null)
+ {
+ $array = [];
+ foreach ($items as $item) {
+ if ($item->parent_id != $paren_id) {
+ continue;
+ }
+ $array[$item->id]['item'] = $item;
+ if ($children = $item->children) {
+ $array[$item->id]['children'] = $this->getMenu($children, $item->id);
+ }
+ }
- /**
- * @param $items MenuItem[]
- *
- * @return array
- */
- private function getMenu($items, $paren_id = null)
- {
- $array = [];
- foreach ($items as $item) {
- if ($item->parent_id != $paren_id) {
- continue;
- }
- $array[$item->id]['item'] = $item;
- if ($children = $item->children) {
- $array[$item->id]['children'] = $this->getMenu($children, $item->id);
- }
- }
- return $array;
- }
+ return $array;
+ }
}
diff --git a/backend/forms/rbac/RbacCreatePermissionForm.php b/backend/forms/rbac/RbacCreatePermissionForm.php
index eab1234..092d50c 100644
--- a/backend/forms/rbac/RbacCreatePermissionForm.php
+++ b/backend/forms/rbac/RbacCreatePermissionForm.php
@@ -6,7 +6,6 @@
namespace backend\forms\rbac;
-
use yii\base\Model;
use Yii;
@@ -40,4 +39,4 @@ class RbacCreatePermissionForm extends Model
'data' => Yii::t('user', 'Permission Data'),
];
}
-}
\ No newline at end of file
+}
diff --git a/backend/forms/rbac/RbacCreateRoleForm.php b/backend/forms/rbac/RbacCreateRoleForm.php
index 2427daa..bd7d8b3 100644
--- a/backend/forms/rbac/RbacCreateRoleForm.php
+++ b/backend/forms/rbac/RbacCreateRoleForm.php
@@ -6,7 +6,6 @@
namespace backend\forms\rbac;
-
use yii\base\Model;
use Yii;
@@ -40,4 +39,4 @@ class RbacCreateRoleForm extends Model
'data' => Yii::t('user', 'Role Data'),
];
}
-}
\ No newline at end of file
+}
diff --git a/backend/forms/rbac/RbacEditPermissionForm.php b/backend/forms/rbac/RbacEditPermissionForm.php
index c9caad9..d1b0cb4 100644
--- a/backend/forms/rbac/RbacEditPermissionForm.php
+++ b/backend/forms/rbac/RbacEditPermissionForm.php
@@ -50,4 +50,4 @@ class RbacEditPermissionForm extends Model
'data' => Yii::t('user', 'Permission Data'),
];
}
-}
\ No newline at end of file
+}
diff --git a/backend/forms/rbac/RbacEditRoleForm.php b/backend/forms/rbac/RbacEditRoleForm.php
index fa7b5e2..c74647d 100644
--- a/backend/forms/rbac/RbacEditRoleForm.php
+++ b/backend/forms/rbac/RbacEditRoleForm.php
@@ -50,4 +50,4 @@ class RbacEditRoleForm extends Model
'data' => Yii::t('user', 'Role Data'),
];
}
-}
\ No newline at end of file
+}
diff --git a/backend/forms/rbac/RbacUpdateChildren.php b/backend/forms/rbac/RbacUpdateChildren.php
index c87f26c..fabe3f6 100644
--- a/backend/forms/rbac/RbacUpdateChildren.php
+++ b/backend/forms/rbac/RbacUpdateChildren.php
@@ -6,7 +6,6 @@
namespace backend\forms\rbac;
-
use yii\base\Model;
class RbacUpdateChildren extends Model
@@ -20,4 +19,4 @@ class RbacUpdateChildren extends Model
[['roles', 'permissions'], 'each', 'rule' => ['string']],
];
}
-}
\ No newline at end of file
+}