/**
  * @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]);
 }
Beispiel #2
0
 /**
  * Return Icon class name
  *
  * @param string $code
  * @param string $default
  *
  * @return string
  * @throws InvalidConfigException
  */
 public function getIcon($code, $default = '')
 {
     if (!$code) {
         return $default;
     }
     $setting = SettingModel::findOne(['code' => $code]);
     if ($setting && in_array($setting->type, [SettingModel::TYPE_ACTION, SettingModel::TYPE_GROUP])) {
         return $setting->icon;
     } else {
         return $default;
     }
 }
 /**
  * Finds the Setting model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Setting the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Setting::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }