Example #1
0
 /**
  * Update meta data for current media.
  *
  * @param $meta_name
  * @param $meta_value
  *
  * @return bool
  */
 public function upMeta($meta_name, $meta_value)
 {
     /* @var $model \common\models\MediaMeta */
     $model = MediaMeta::find()->andWhere(['meta_name' => $meta_name])->andWhere(['media_id' => $this->id])->one();
     if (is_array($meta_value) || is_object($meta_value)) {
         $meta_value = Json::encode($meta_value);
     }
     $model->meta_value = $meta_value;
     return $model->save();
 }
 /**
  * Updates an existing Menu model.
  * If update is successful, the browser will be redirected to the 'view' page.
  *
  * @param integer $id
  *
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($menuOrder = Yii::$app->request->post('MenuOrder')) {
             $this->saveMenuItem(Json::decode($menuOrder));
         }
     }
     Yii::$app->getSession()->setFlash('success', Yii::t('content', 'Menu successfully saved.'));
     return $this->redirect(['/content/menu/index', 'id' => $id]);
 }
 /**
  * Updates an existing PostType model.
  * If update is successful, the browser will be redirected to the 'view' page.
  *
  * @param integer $id
  *
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $taxonomies = ArrayHelper::map(Taxonomy::find()->all(), 'id', 'taxonomy_name');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // Delete all PostTypeTaxonomy where post_type_id this id
         PostTypeTaxonomy::deleteAll(['post_type_id' => $id]);
         // Refill PostTypeTaxonomy for this model
         //var_dump(Yii::$app->request->post('PostTypeTaxonomy')); exit;
         if (($postTypeTaxonomy = Yii::$app->request->post('PostTypeTaxonomy')) && ($taxonomyIds = Json::decode($postTypeTaxonomy['taxonomyIds']))) {
             foreach ($taxonomyIds as $taxonomy_id) {
                 $postTypeTaxonomy = new PostTypeTaxonomy();
                 $postTypeTaxonomy->post_type_id = $model->id;
                 $postTypeTaxonomy->taxonomy_id = $taxonomy_id;
                 $postTypeTaxonomy->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model, 'taxonomy' => new Taxonomy(), 'taxonomies' => $taxonomies]);
 }
Example #4
0
 /**
  * Update meta data for current media.
  *
  * @param $meta_name
  * @param $meta_value
  *
  * @return bool
  */
 public function upMeta($meta_name, $meta_value)
 {
     $model = PostMeta::find()->andWhere(['meta_name' => $meta_name])->andWhere(['post_id' => $this->id])->one();
     if (is_array($meta_value) || is_object($meta_value)) {
         $meta_value = Json::encode($meta_value);
     }
     if ($model !== null) {
         $model->meta_value = $meta_value;
         return $model->save();
     } else {
         return $this->setMeta($meta_name, $meta_value);
     }
 }
 /**
  * Generate response in the form of a string of json.
  *
  * @param bool $printResponse
  *
  * @return array
  */
 public function getResponse($printResponse = true)
 {
     if ($printResponse) {
         $this->head();
         $content = Json::encode($this->response);
         $redirect = stripslashes(Yii::$app->request->getQueryParam('redirect'));
         if ($redirect) {
             $this->setHeader('Location', sprintf($redirect, rawurlencode($content)));
             return null;
         }
         echo $content;
     }
     return $this->response;
 }
 /**
  * Update activated widget via ajax.
  *
  * @param $id integer
  */
 public function actionAjaxUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->widget_config = Json::encode($model->widget_config);
         $model->save();
     }
 }
Example #7
0
 /**
  * Get widget configuration as array
  *
  * @return mixed
  */
 public function getConfig()
 {
     return Json::decode($this->widget_config);
 }