Example #1
0
 public function action(Requests\EditOptionRequest $request, $id)
 {
     if (!is_numeric($id)) {
         return redirect()->route('options.all');
     }
     $option = Option::find($id);
     if (is_null($option)) {
         return redirect()->route('options.all');
     }
     $option->name = $request->input('name');
     $option->value = $request->input('value');
     $option->save();
     return redirect()->route('options.all');
 }
 /**
  * 获取Option信息
  * @param string $type 类型 默认为sys
  * @param bool $refresh 强制刷新
  * @return array $config 配置数组
  */
 public static function getSiteConfig($type = 'sys', $refresh = false)
 {
     $cache_key = "config_{$type}";
     if ($refresh) {
         $config = null;
     } else {
         $config = Yii::$app->cache->get($cache_key);
     }
     if (empty($config)) {
         $options = Option::find()->where(['type' => $type])->asArray()->all();
         foreach ($options as $op) {
             $config[$op['name']] = $op['value'];
         }
         $dp = new DbDependency();
         $dp->sql = (new Query())->select('MAX(update_time)')->from(Option::tableName())->createCommand()->rawSql;
         Yii::$app->cache->set($cache_key, $config, 3600, $dp);
     }
     return $config;
 }
Example #3
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $poll = Poll::with('options')->find($id);
     $profile = Profile::find(Auth::user()->profile->id);
     if ($poll->profile->contains($profile->id)) {
         $profiles = Apartment::find(Auth::user()->profile->defaultApartment)->profiles()->approved()->get();
         $stats = DB::table('profile_poll')->wherePollId($id)->groupBy('option_id')->get([DB::raw('option_id as option'), DB::raw('count(option_id) as option_count')]);
         if (count($stats) > 0) {
             foreach ($stats as $list) {
                 $option[] = Option::find($list->option)->option;
                 $option_count[] = intval($list->option_count);
             }
         } else {
             $option[] = 'No Polling held yet';
             $option_count[] = '0';
         }
         $title = $poll->title;
         return view('polls.result', compact('profiles', 'title', 'stats', 'poll', 'option', 'option_count'));
     } else {
         $list = Poll::with('options')->find($id);
         return view('polls.show', compact('list'));
     }
 }
Example #4
0
 public function delete($idx)
 {
     Option::find($idx)->delete();
 }
Example #5
0
 /**
  * Confirm it is unique.
  *
  * @param Request $request
  * @param $id
  */
 private function uniqueKey(Request $request, $id)
 {
     if (!Option::find($id) || Option::find($id)->key != $request->get('key')) {
         $this->validate($request, ['key' => 'unique:options'], [], ['key' => '数组键名']);
     }
 }
 /**
  * update option value.
  *
  * @param string $id
  *
  * @return Redirect
  */
 public function updateOptionValue(Request $request, $id)
 {
     $language = $request->session()->get('language');
     $option = Option::find($request->option_id);
     // check if this language exists
     if (!isset($option->{$language})) {
         $option->{$language} = $option->default;
     }
     // get the current values
     $current = $option->{$language};
     $current[key($current)][$request->id] = $request->name;
     // save the new name
     $option->{$language} = $current;
     if ($language == config('app.locale')) {
         $option->default = $current;
     }
     $option->save();
     // redirect
     $request->session()->flash('success', trans('options.option') . ' ' . trans('crud.updated'));
     return redirect()->back();
 }