示例#1
0
 /**
  * @throws WidgetMissedIdException
  * @throws \yii\base\InvalidConfigException
  * @throws \Exception
  */
 public function init()
 {
     if (!isset($this->id) || empty($this->id)) {
         throw new WidgetMissedIdException('Specify widget ' . __CLASS__ . '::id.');
     }
     if (!isset($this->context)) {
         $this->context = Yii::$app->request->getPathInfo();
     }
     $parts = empty($this->context) ? [''] : explode('/', '/' . $this->context);
     $contexts = [];
     $context = '';
     foreach ($parts as $part) {
         $context .= strlen($context) ? '/' . $part : $part;
         $contexts[] = $context;
     }
     if ($model = WidgetConfig::find()->orderBy('context desc')->where(['widget_id' => $this->id, 'language' => Yii::$app->language, 'context' => $contexts])->one()) {
         /** @var $model WidgetConfig */
         if ($model->widget_class != $this->className()) {
             throw new InvalidConfigException("DB's widget configuration is adjusted for a widget " . $model->widget_class . " that doesn't correspond to the current widget " . $this->className());
         }
         $this->_loadedContext = $model->context;
         foreach ($model->getParamsArray() as $key => $value) {
             if (!array_key_exists($key, $this->_config) && $this->hasProperty($key)) {
                 $this->{$key} = $value;
             }
         }
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = WidgetConfig::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'valid' => $this->valid, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'lock' => $this->lock]);
     $query->andFilterWhere(['like', 'widget_id', $this->widget_id])->andFilterWhere(['like', 'widget_class', $this->widget_class])->andFilterWhere(['like', 'context', $this->context])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'params', $this->params]);
     return $dataProvider;
 }
 /**
  * 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 WidgetConfig the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = WidgetConfig::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.'));
     }
 }
示例#4
0
    <?php 
echo Html::hiddenInput('url', $url);
?>

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

    <div class="controls-bar">
        <div class="pull-right">
            <?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 (WidgetConfig::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="method pull-left">
            <?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()]);
?>
示例#5
0
<?php

use yii\helpers\Html;
use gromver\platform\common\models\WidgetConfig;
/**
 * @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 .= WidgetConfig::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]);
}
 public function actionConfigure($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 (WidgetConfig::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 = WidgetConfig::findOne(['widget_id' => $widget_id, 'context' => $selected_context, 'language' => Yii::$app->language])) {
             $configModel->delete();
         }
         if ($modal) {
             ModalIFrame::refreshPage();
         }
     }
     $widget_config = Yii::$app->request->getBodyParam('widget_config', '[]');
     $widgetConfig = Json::decode($widget_config);
     $widgetConfig['id'] = $widget_id;
     $widgetConfig['context'] = $selected_context;
     $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 = WidgetConfig::findOne(['widget_id' => $widget_id, 'context' => $selected_context, 'language' => Yii::$app->language]) or $configModel = new WidgetConfig();
             $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 (WidgetConfig::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 WidgetConfig */
                     $configModel->delete();
                 }
             }
             if ($modal) {
                 ModalIFrame::refreshPage();
             } else {
                 return $this->redirect($url);
             }
         }
     }
     if ($modal) {
         Yii::$app->grom->layout = 'modal';
     }
     return $this->render('_formConfig', ['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]);
 }