Exemplo n.º 1
0
 public function configure($array)
 {
     FlexformField::deleteAll("FK_template = {$this->id} AND name NOT IN ( '" . implode('\', \'', $array) . "' )");
     foreach ($array as $key => $value) {
         if (FlexformField::find()->where(['FK_template' => $this->id, 'name' => $value])->one() == null) {
             $model = new FlexformField();
             $model->name = $value;
             $model->order = $key;
             $model->FK_template = $this->id;
             $model->save();
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Method saves to template given values 
  * @throws InvalidValueException
  * @return mixed json encoded array with status 
  */
 public function actionSaveTemplate()
 {
     if (!isset($_POST['templateId'])) {
         throw new InvalidValueException("Template id missing.");
     }
     $model = FlexformTemplate::findOne($_POST['templateId']);
     foreach (\Yii::$app->request->post($model->modelClass, null) as $key => $value) {
         $field = FlexformField::find()->where(['name' => $key, 'FK_template' => $_POST['templateId']])->one();
         if (!isset($field)) {
             continue;
         }
         if (is_array($value)) {
             $field->value = implode(',', $value);
         } else {
             $field->value = $value;
         }
         $field->save();
     }
     return json_encode(['status' => 1]);
 }