Exemplo n.º 1
0
 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 \cmsadmin\models\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);
     }
 }
Exemplo n.º 2
0
 public function bootstrap($app)
 {
     $findProperty = Property::findOne(['class_name' => GroupAuthProperty::className()]);
     if ($findProperty) {
         $this->properties = CmsProperty::findAll(['admin_prop_id' => $findProperty->id]);
         Yii::$app->menu->on(Container::MENU_ITEM_EVENT, [$this, 'hideElements']);
     }
 }
Exemplo n.º 3
0
 public function getProperty($varName)
 {
     $value = CmsProperty::find()->where(['nav_id' => $this->id])->leftJoin('admin_property', 'admin_prop_id=admin_property.id')->select(['cms_nav_property.value', 'admin_property.class_name'])->andWhere(['admin_property.var_name' => $varName])->asArray()->one();
     if ($value) {
         return AdminProperty::getObject($value['class_name'], $value['value']);
     }
     return false;
 }
Exemplo n.º 4
0
 public function actionSaveProperties($navId)
 {
     $rows = [];
     foreach (Yii::$app->request->post() as $id => $value) {
         $rows[] = ['nav_id' => $navId, 'admin_prop_id' => $id, 'value' => $value];
     }
     foreach ($rows as $atrs) {
         $model = \cmsadmin\models\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 \cmsadmin\models\Property();
             $model->attributes = $atrs;
             $model->insert(false);
         }
     }
 }