Esempio n. 1
0
 /**
  * @return string
  */
 public function run()
 {
     if (Yii::$app->request->isPost) {
         $setting = Yii::$app->request->post('Setting');
         if (isset($_FILES['Setting'])) {
             foreach ($_FILES['Setting']['name'] as $key => $value) {
                 $model = Setting::findOne(['code' => $key]);
                 $model->file = UploadedFile::getInstance($model, $key);
                 if ($model->file != null && $model->upload()) {
                     $model->updateAttributes(['value' => $value]);
                 }
             }
         }
         if ($setting != null) {
             foreach ($setting as $key => $value) {
                 if ($value !== '' || $value != null) {
                     if (is_array($value)) {
                         Setting::updateAll(['value' => implode(",", $value)], ['code' => $key]);
                     } else {
                         Setting::updateAll(['value' => $value], ['code' => $key]);
                     }
                 }
             }
         }
         Yii::$app->session->setFlash('alert', ['body' => Yii::t('setting', 'Settings has been successfully saved'), 'options' => ['class' => 'alert-success']]);
     }
     if (Module::hasMultiLanguage()) {
         $title = Translate::setting();
     } else {
         $title = Yii::t('setting', 'Setting');
     }
     $currentSetting = Setting::findOne(['code' => $this->id]);
     return $this->controller->render('index', ['title' => $title, 'code' => $currentSetting !== null ? $currentSetting->code : null]);
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = ['verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['POST']]], 'access' => ['class' => AccessControl::className(), 'rules' => [['allow' => true, 'roles' => ['@']]]]];
     if (Module::hasUserRole()) {
         if (Module::hasMultiLanguage()) {
             return ArrayHelper::merge($behaviors, ['role' => ['class' => RoleFilter::className(), 'name' => Translate::setting(), 'actions' => ['index' => Translate::index(), 'create' => Translate::create(), 'update' => Translate::update(), 'delete' => Translate::delete()]]]);
         } else {
             return ArrayHelper::merge($behaviors, ['role' => ['class' => RoleFilter::className(), 'name' => 'Setting', 'actions' => ['index' => Yii::t('setting', 'List'), 'create' => Yii::t('setting', 'Create'), 'update' => Yii::t('setting', 'Update'), 'delete' => Yii::t('setting', 'Delete')]]]);
         }
     } else {
         return $behaviors;
     }
 }