Ejemplo n.º 1
0
 /**
  * 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('writesdown', 'Menu successfully saved.'));
     return $this->redirect(['/menu/index', 'id' => $id]);
 }
Ejemplo n.º 2
0
 /**
  * Register needed scrips
  */
 public function registerClientScript()
 {
     $view = $this->getView();
     MediaModalAsset::register($view);
     $callbackName = ArrayHelper::remove($this->callback, 'name');
     $callbackValue = ArrayHelper::remove($this->callback, 'value');
     if ($callbackName) {
         $view->registerJs('var ' . $callbackName . ' = ' . $callbackValue, $view::POS_END);
     }
     $settings['title'] = $this->title;
     $settings['url'] = Url::to(['media-browser/index', 'post' => $this->post, 'type' => $this->type, 'editor' => $this->editor, 'multiple' => $this->multiple, 'callback' => $callbackName]);
     $settings = Json::htmlEncode($settings);
     $view->registerJs('$("#' . $this->id . '").mediamodal(' . $settings . ')');
 }
Ejemplo n.º 3
0
 /**
  * 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();
     }
 }
Ejemplo n.º 4
0
 /**
  * Update meta data for current post.
  *
  * @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);
     }
     $model->meta_value = $meta_value;
     return $model->save();
 }
Ejemplo n.º 5
0
 /**
  * Get widget configuration as array
  *
  * @return mixed
  */
 public function getConfig()
 {
     return Json::decode($this->widget_config);
 }
Ejemplo n.º 6
0
 /**
  * Updates an existing Module 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->module_config = Json::encode($model->module_config);
         if ($model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('update', ['model' => $model]);
 }
Ejemplo n.º 7
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();
 }
Ejemplo n.º 8
0
 /**
  * Update meta data for current post.
  *
  * @param $meta_name
  * @param $meta_value
  *
  * @return bool
  */
 public function upMeta($meta_name, $meta_value)
 {
     /* @var $model \common\models\PostMeta */
     $model = PostMeta::findOne(['meta_name' => $meta_name, 'post_id' => $this->id]);
     if (is_array($meta_value) || is_object($meta_value)) {
         $meta_value = Json::encode($meta_value);
     }
     $model->meta_value = $meta_value;
     return $model->save();
 }
Ejemplo n.º 9
0
 /**
  * Update option with name as key.
  *
  * @param string $name
  * @param string|array $value
  * @return bool
  */
 public static function up($name, $value)
 {
     /* @var $model \common\models\Option */
     $model = static::findOne(['name' => $name]);
     if (is_array($value) || is_object($value)) {
         $model->value = Json::encode($value);
     } else {
         $model->value = $value;
     }
     return $model->save();
 }
Ejemplo n.º 10
0
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="library-left">
                    <ul class="media-container clearfix"></ul>
                </div>
                <div class="library-right">
                    <div class="media-details"></div>
                    <div class="media-form"></div>
                </div>
                <div class="library-footer">
                    <?php 
echo Html::button(Yii::t('writesdown', 'Insert Media'), ['class' => 'insert-media btn btn-primary pull-right btn-flat']);
?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php 
echo $this->render('_template-upload');
echo $this->render('_template-download');
echo $this->render('_template-details');
echo $this->render('_template-form', ['model' => $model]);
$options = Json::encode(['url' => ['json' => Url::to(['get-json']), 'update' => Url::to(['/media/ajax-update']), 'upload' => Url::to(['/media/ajax-upload']), 'insert' => Yii::$app->request->get('editor', false) ? Url::to(['editor-insert']) : Url::to(['field-insert'])], 'editor' => (bool) Yii::$app->request->get('editor', false), 'multiple' => (bool) Yii::$app->request->get('multiple', false), 'callback' => Yii::$app->request->get('callback', false)]);
$this->registerJs('jQuery("#media-browser").mediabrowser(' . $options . ')');
?>

Ejemplo n.º 11
0
 /**
  * Update option with option_name as key.
  *
  * @param string       $option_name
  * @param string|array $option_value
  *
  * @return bool
  */
 public static function up($option_name, $option_value)
 {
     /* @var $model \common\models\Option */
     $model = static::find()->where(['option_name' => $option_name])->one();
     if (is_array($option_value) || is_object($option_value)) {
         $model->option_value = Json::encode($option_value);
     } else {
         $model->option_value = $option_value;
     }
     return $model->save();
 }
Ejemplo n.º 12
0
 /**
  * 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
         $postTypeTaxonomy = Yii::$app->request->post('PostTypeTaxonomy');
         if ($taxonomyIds = Json::decode($postTypeTaxonomy['taxonomyIds'])) {
             foreach ($taxonomyIds as $taxonomyId) {
                 $postTypeTaxonomy = new PostTypeTaxonomy();
                 $postTypeTaxonomy->post_type_id = $model->id;
                 $postTypeTaxonomy->taxonomy_id = $taxonomyId;
                 $postTypeTaxonomy->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model, 'taxonomy' => new Taxonomy(), 'taxonomies' => $taxonomies]);
 }
 /**
  * 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;
 }
Ejemplo n.º 14
0
 /**
  * Get config as array.
  *
  * @return mixed
  */
 public function getConfig()
 {
     return Json::decode($this->module_config);
 }
Ejemplo n.º 15
0
 /**
  * Insert URL of media to input field.
  *
  * @return string
  */
 public function actionFieldInsert()
 {
     $files = [];
     foreach (Yii::$app->request->post('Media') as $media) {
         $mediaUploadHandler = new MediaUploadHandler(null, false);
         $file = $mediaUploadHandler->get(ArrayHelper::getValue($media, 'id'), $mediaUploadHandler::NOT_PRINT_RESPONSE);
         $files[] = ArrayHelper::getValue($file, 'file');
     }
     return Json::encode($files);
 }
Ejemplo n.º 16
0
 /**
  * Update meta data for current media.
  *
  * @param string $name
  * @param string|array $value
  * @return bool
  */
 public function upMeta($name, $value)
 {
     /* @var $model \common\models\MediaMeta */
     $model = MediaMeta::findOne(['name' => $name, 'media_id' => $this->id]);
     if (is_array($value) || is_object($value)) {
         $value = Json::encode($value);
     }
     $model->value = $value;
     return $model->save();
 }