public function actionParams($modal = null)
 {
     $paramsPath = Yii::getAlias($this->module->paramsPath);
     $paramsFile = $paramsPath . DIRECTORY_SEPARATOR . 'params.php';
     $params = $this->module->params;
     $model = new ObjectModel(PlatformParams::className());
     $model->setAttributes($params);
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate() && Yii::$app->request->getBodyParam('task') !== 'refresh') {
             FileHelper::createDirectory($paramsPath);
             try {
                 file_put_contents($paramsFile, '<?php return ' . var_export($model->toArray(), true) . ';');
                 @chmod($paramsFile, 0777);
                 Yii::$app->session->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Configuration saved.'));
                 if ($modal) {
                     ModalIFrame::refreshParent();
                 }
             } catch (\Exception $e) {
                 Yii::$app->session->setFlash(Alert::TYPE_DANGER, $e->getMessage());
             }
         }
     }
     if ($modal) {
         Yii::$app->grom->applyModalLayout();
     }
     return $this->render('params', ['model' => $model]);
 }
 /**
  * @param $user User
  * @return ObjectModel | null
  */
 protected function extractParamsModel($user)
 {
     if ($this->module->userParamsClass) {
         try {
             $attributes = $user->getParamsArray();
         } catch (InvalidParamException $e) {
             $attributes = [];
         }
         $model = new ObjectModel($this->module->userParamsClass);
         $model->setAttributes($attributes);
         return $model;
     }
 }
 public function actionParams($type = 'main', $modal = null)
 {
     /*$paramsPath = Yii::getAlias($this->module->paramsPath);
             $paramsFile = $paramsPath . DIRECTORY_SEPARATOR . 'params.php';
     
             $params = $this->module->params;
     
             $model = new ObjectModel(MainParams::className());
             $model->setAttributes($params);*/
     /** @var \gromver\platform\core\components\ParamsObject $params */
     $params = Yii::$app->paramsManager->{$type};
     $model = new ObjectModel($params);
     $model->setAttributes($params->toArray());
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate() && Yii::$app->request->getBodyParam('task') !== 'refresh') {
             try {
                 $params->load($model->toArray())->save();
                 Yii::$app->session->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Configuration saved.'));
                 if ($modal) {
                     ModalIFrame::refreshParent();
                 }
             } catch (\Exception $e) {
                 Yii::$app->session->setFlash(Alert::TYPE_DANGER, $e->getMessage());
             }
         }
     }
     if ($modal) {
         Yii::$app->applyModalLayout();
     }
     $items = [];
     foreach (Yii::$app->paramsManager->getParamsInfo() as $itemType => $info) {
         /** @var \gromver\platform\core\components\ParamsObject $params */
         $params = Yii::$app->paramsManager->{$itemType};
         $items[] = ['label' => $params->paramsName(), 'url' => ['params', 'type' => $itemType, 'modal' => $modal], 'active' => $itemType == $type];
     }
     return $this->render('params', ['paramsMenuItems' => $items, 'model' => $model]);
 }
示例#4
0
 /**
  * Возвращает html кнопки настройки виджета, или false, если у пользователя нет доступа
  * @return string | bool
  */
 public function widgetConfigControl()
 {
     if (!$this->hasConfigureAccess()) {
         return false;
     }
     $objectModel = new ObjectModel($this->className());
     $objectModel->setAttributes($this->_config);
     return ModalIFrame::widget(['options' => ['class' => 'btn btn-default', 'title' => Yii::t('gromver.platform', 'Configure widget')], 'label' => '<i class="glyphicon glyphicon-cog"></i>', 'url' => [$this->getConfigureRoute(), 'modal' => 1], 'formOptions' => ['method' => 'post', 'params' => ['url' => Yii::$app->request->getAbsoluteUrl(), 'widget_id' => $this->id, 'widget_class' => $this->className(), 'widget_context' => $this->context, 'widget_config' => Json::encode($objectModel->toArray(array_keys($this->_config)))]]]);
 }
示例#5
0
 public function widgetConfigControl()
 {
     ob_start();
     ob_implicit_flush(false);
     $formId = $this->getId() . '-form';
     ModalIFrame::begin(['modalOptions' => ['header' => Yii::t('gromver.platform', 'Widget "{name}" (ID: {id})', ['name' => $this->className(), 'id' => $this->id]), 'size' => Modal::SIZE_LARGE], 'buttonOptions' => ['class' => 'btn btn-default', 'tag' => 'button', 'onclick' => "jQuery('#{$formId}').submit()", 'title' => Yii::t('gromver.platform', 'Configure widget')]]);
     echo Html::beginForm(['/grom/widget/default/configure', 'modal' => 1], 'post', ['id' => $formId]);
     echo Html::hiddenInput('url', Yii::$app->request->getAbsoluteUrl());
     echo Html::hiddenInput('widget_id', $this->id);
     echo Html::hiddenInput('widget_class', $this->className());
     echo Html::hiddenInput('widget_context', $this->context);
     $objectModel = new ObjectModel($this->className());
     $objectModel->setAttributes($this->_config);
     echo Html::hiddenInput('widget_config', Json::encode($objectModel->toArray(array_keys($this->_config))));
     echo '<i class="glyphicon glyphicon-cog"></i>';
     echo Html::endForm();
     ModalIFrame::end();
     return ob_get_clean();
 }