コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 public function normalizeWidgets($oldPath)
 {
     if ($oldPath) {
         foreach (WidgetConfig::find()->where(['like', 'context', $oldPath . '%', false])->each() as $config) {
             $config->context = preg_replace("#^{$oldPath}#", $this->path, $config->context);
             $config->save();
         }
     }
 }
コード例 #3
0
ファイル: form.php プロジェクト: ezsky/yii2-platform-core
<?php 
echo Html::hiddenInput('url', $url);
?>

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

    <div class="controls">
        <div class="controls-bar well row">
            <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 (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="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()]);
?>
コード例 #4
0
 /**
  * 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.'));
     }
 }
コード例 #5
0
 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 (WidgetConfig::find()->where('widget_id=:widget_id AND context>=:context', [':widget_id' => $widget_id, ':context' => $selected_context])->each() as $configModel) {
                 $configModel->delete();
             }
         } elseif ($configModel = WidgetConfig::findOne(['widget_id' => $widget_id, 'context' => $selected_context])) {
             $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\core\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 = WidgetConfig::findOne(['widget_id' => $widget_id, 'context' => $selected_context]) 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', [':widget_id' => $widget_id, ':context' => $selected_context])->each() as $configModel) {
                     /** @var $configModel WidgetConfig */
                     $configModel->delete();
                 }
             }
             if ($modal) {
                 ModalIFrame::refreshParent();
             } else {
                 return $this->redirect($url);
             }
         }
     }
     if ($modal) {
         Yii::$app->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]);
 }
コード例 #6
0
ファイル: Widget.php プロジェクト: ezsky/yii2-platform-core
 /**
  * @return array|null|\yii\db\ActiveRecord
  */
 protected function findWidgetConfig()
 {
     $parts = empty($this->context) ? [''] : explode('/', '/' . $this->context);
     $contexts = [];
     $context = '';
     foreach ($parts as $part) {
         $context .= strlen($context) ? '/' . $part : $part;
         $contexts[] = $context;
     }
     return WidgetConfig::find()->orderBy('context desc')->where(['widget_id' => $this->id, 'context' => $contexts])->one();
 }
コード例 #7
0
<?php

use yii\helpers\Html;
use gromver\platform\core\modules\widget\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]);
}