/**
  * @inheritdoc
  */
 protected function findWidgetConfig()
 {
     $parts = empty($this->context) ? [''] : explode('/', '/' . $this->context);
     $contexts = [];
     $context = '';
     foreach ($parts as $part) {
         $context .= strlen($context) ? '/' . $part : $part;
         $contexts[] = $context;
     }
     return WidgetConfigPersonal::find()->orderBy('context desc')->where(['widget_id' => $this->id, 'language' => Yii::$app->language, 'context' => $contexts, 'created_by' => Yii::$app->user->id])->one();
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = WidgetConfigPersonal::find()->with('owner');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['{{%grom_widget_config_personal}}.id' => $this->id, '{{%grom_widget_config_personal}}.valid' => $this->valid, '{{%grom_widget_config_personal}}.created_at' => $this->created_at, '{{%grom_widget_config_personal}}.updated_at' => $this->updated_at, '{{%grom_widget_config_personal}}.updated_by' => $this->updated_by, '{{%grom_widget_config_personal}}.lock' => $this->lock, '{{%grom_widget_config_personal}}.language' => $this->language]);
     $query->andFilterWhere(['like', '{{%grom_widget_config_personal}}.widget_id', $this->widget_id])->andFilterWhere(['like', '{{%grom_widget_config_personal}}.widget_class', $this->widget_class])->andFilterWhere(['like', '{{%grom_widget_config_personal}}.context', $this->context])->andFilterWhere(['like', '{{%grom_widget_config_personal}}.url', $this->url])->andFilterWhere(['like', '{{%grom_widget_config_personal}}.params', $this->params]);
     if ($this->created_by) {
         $query->joinWith('owner')->andWhere(['or', ['{{%grom_widget_config_personal}}.created_by' => $this->created_by], ['like', '{{%grom_user}}.username', $this->created_by]]);
     }
     return $dataProvider;
 }
 public function run($modal = null)
 {
     if (!($widget_id = Yii::$app->request->getBodyParam('widget_id'))) {
         throw new BadRequestHttpException(Yii::t('gromver.platform', "Widget ID isn't specified"));
     }
     if (!($widget_class = Yii::$app->request->getBodyParam('widget_class'))) {
         throw new BadRequestHttpException(Yii::t('gromver.platform', "Widget Class isn't specified"));
     }
     if (($widget_context = Yii::$app->request->getBodyParam('widget_context')) === null) {
         throw new BadRequestHttpException(Yii::t('gromver.platform', "Widget Context isn't specified"));
     }
     $selected_context = Yii::$app->request->getBodyParam('selected_context', $widget_context);
     $task = Yii::$app->request->getBodyParam('task');
     if (($url = Yii::$app->request->getBodyParam('url')) === null) {
         throw new BadRequestHttpException(Yii::t('gromver.platform', "Widget page url isn't specified"));
     }
     //$url = Yii::$app->request->getBodyParam('url', Yii::$app->request->getReferrer());
     if ($task == 'delete') {
         if (Yii::$app->request->getBodyParam('bulk-method')) {
             foreach (WidgetConfigPersonal::find()->where('widget_id=:widget_id AND context>=:context AND language=:language', [':widget_id' => $widget_id, ':context' => $selected_context, ':language' => Yii::$app->language])->each() as $configModel) {
                 $configModel->delete();
             }
         } elseif ($configModel = WidgetConfigPersonal::findOne(['widget_id' => $widget_id, 'context' => $selected_context, 'language' => Yii::$app->language])) {
             $configModel->delete();
         }
         if ($modal) {
             ModalIFrame::refreshParent();
         }
     }
     $widget_config = Yii::$app->request->getBodyParam('widget_config', '[]');
     $widgetConfig = Json::decode($widget_config);
     $widgetConfig['id'] = $widget_id;
     $widgetConfig['context'] = $selected_context;
     $widgetConfig['skipInit'] = true;
     /** @var \gromver\platform\basic\modules\widget\widgets\Widget $widget */
     $widget = new $widget_class($widgetConfig);
     $model = new ObjectModel($widget);
     if (($task == 'save' || $task == 'refresh') && $model->load(Yii::$app->request->post())) {
         if ($model->validate() && $task == 'save') {
             $configModel = WidgetConfigPersonal::findOne(['widget_id' => $widget_id, 'context' => $selected_context, 'language' => Yii::$app->language]) or $configModel = new WidgetConfigPersonal();
             $configModel->loadDefaultValues();
             $configModel->widget_id = $widget_id;
             $configModel->widget_class = $widget_class;
             $configModel->context = $selected_context;
             $configModel->url = $url;
             $configModel->setParamsArray($model->toArray());
             $configModel->save();
             if (Yii::$app->request->getBodyParam('bulk-method')) {
                 foreach (WidgetConfigPersonal::find()->where('widget_id=:widget_id AND context>:context AND language=:language', [':widget_id' => $widget_id, ':context' => $selected_context, ':language' => Yii::$app->language])->each() as $configModel) {
                     /** @var $configModel WidgetConfigPersonal */
                     $configModel->delete();
                 }
             }
             if ($modal) {
                 ModalIFrame::refreshParent();
             } else {
                 return $this->redirect($url);
             }
         }
     }
     if ($modal) {
         Yii::$app->grom->applyModalLayout();
     }
     return $this->controller->render($this->view, ['model' => $model, 'widget' => $widget, 'widget_id' => $widget_id, 'widget_class' => $widget_class, 'widget_config' => $widget_config, 'widget_context' => $widget_context, 'selected_context' => $selected_context, 'url' => $url]);
 }
 /**
  * Finds the WidgetConfig model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return WidgetConfigPersonal the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = WidgetConfigPersonal::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.'));
     }
 }
Exemplo n.º 5
0
<?php 
echo Html::hiddenInput('url', $url);
?>

<?php 
echo Html::hiddenInput('widget_config', $widget_config);
?>

    <div class="controls">
        <div class="controls-bar well">
            <div class="controls-bar__actions">
                <?php 
echo Html::submitButton('<span class="glyphicon glyphicon-floppy-save"></span> ' . Yii::t('gromver.platform', 'Save'), ['class' => 'btn btn-success', 'name' => 'task', 'value' => 'save']);
?>
                <?php 
if (WidgetConfigPersonal::find()->where(['widget_id' => $widget_id, 'context' => $selected_context])->exists()) {
    echo Html::submitButton('<span class="glyphicon glyphicon-trash"></span> ' . Yii::t('gromver.platform', 'Delete'), ['class' => 'btn btn-danger', 'name' => 'task', 'value' => 'delete']);
}
?>
            </div>
            <div class="controls-bar__method">
                <?php 
echo Html::checkbox('bulk-method', false, ['label' => Yii::t('gromver.platform', 'Apply action to the subordinated contexts')]);
?>
            </div>
        </div>

        <div class="context-bar form-group">
            <?php 
echo $this->render('_contexts', ['widget_id' => $widget_id, 'widget_context' => $widget_context, 'selected_context' => $selected_context, 'loaded_context' => $widget->getLoadedContext()]);
?>
Exemplo n.º 6
0
<?php

use yii\helpers\Html;
use gromver\platform\basic\modules\widget\models\WidgetConfigPersonal;
/**
 * @var yii\web\View $this
 * @var string $widget_id
 * @var string $widget_context
 * @var string $selected_context
 * @var string $loaded_context
 */
$contexts = empty($widget_context) ? [''] : explode('/', '/' . $widget_context);
$context = '';
foreach ($contexts as $i => $part) {
    $context .= strlen($context) ? '/' . $part : $part;
    $class = 'btn btn-link ';
    $class .= WidgetConfigPersonal::find()->where(['widget_id' => $widget_id, 'context' => $context])->exists() ? 'defined' : 'undefined';
    if ($loaded_context == $context) {
        $class .= ' loaded';
    }
    if ($selected_context == $context) {
        $class .= ' selected';
    }
    $description = empty($part) ? Yii::t('gromver.platform', 'Default') : $part;
    if ($i) {
        echo Html::tag('span', ' / ', ['class' => 'separator']);
    }
    echo Html::submitButton($description, ['class' => $class, 'name' => 'selected_context', 'value' => $context]);
}