/**
  *
  * {@inheritDoc}
  * @see \yii\base\BootstrapInterface::bootstrap()
  */
 public function bootstrap($app)
 {
     $findProperty = Property::findOne(['class_name' => GroupAuthProperty::className()]);
     if ($findProperty) {
         Yii::$app->menu->on(Menu::MENU_ITEM_EVENT, [$this, 'hideElements'], CmsProperty::findAll(['admin_prop_id' => $findProperty->id]));
     }
 }
 public function actionSaveProperties($navId)
 {
     $rows = [];
     $doNotDeleteList = [];
     foreach (Yii::$app->request->post() as $id => $value) {
         $rows[] = ['nav_id' => $navId, 'admin_prop_id' => $id, 'value' => is_array($value) ? Json::encode($value) : $value];
         $doNotDeleteList[] = $id;
     }
     foreach ($rows as $atrs) {
         $model = Property::find()->where(['admin_prop_id' => $atrs['admin_prop_id'], 'nav_id' => $navId])->one();
         if ($model) {
             if (empty($atrs['value']) && $atrs['value'] != 0) {
                 $model->delete();
             } else {
                 // update
                 $model->value = $atrs['value'];
                 $model->update(false);
             }
         } else {
             $model = new Property();
             $model->attributes = $atrs;
             $model->insert(false);
         }
     }
     foreach (Property::find()->where(['nav_id' => $navId])->andWhere(['not in', 'admin_prop_id', $doNotDeleteList])->all() as $prop) {
         $prop->delete(false);
     }
 }
Beispiel #3
0
 /**
  *
  */
 public function getProperties()
 {
     if ($this->_properties === null) {
         $this->_properties = CmsProperty::find()->where(['nav_id' => $this->id])->with('adminProperty')->all();
     }
     return $this->_properties;
 }