Ejemplo n.º 1
0
 /**
  * Update the specified resource in storage.
  *
  * @return Response
  */
 public function update(GeneralRequest $request)
 {
     Setting::where('name', 'title')->update(['value' => $request->input('title')]);
     Setting::where('name', 'subtitle')->update(['value' => $request->input('subtitle')]);
     Setting::where('name', 'keywords')->update(['value' => $request->input('keywords')]);
     Setting::where('name', 'description')->update(['value' => $request->input('description')]);
     Setting::where('name', 'paginate_size')->update(['value' => $request->input('paginate_size')]);
     event(new SettingsChangedEvent());
     flash()->success(trans('flash_messages.settings_general_success'));
     return redirect('admin/settings/general');
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(GeneralRequest $request)
 {
     $club = $request->all();
     Club::create($club);
     return redirect('clubs');
 }
Ejemplo n.º 3
0
 public function postCombineJsonStandings(Requests\GeneralRequest $req)
 {
     $n = intval($req->get('_n_file_inputs'));
     $inputs = [];
     for ($i = 0; $i < $n; $i += 1) {
         $iname = 'in' . strval($i + 1);
         if ($req->isFileFieldOK($iname)) {
             $fpath = $req->file($iname)->getRealPath();
             $contents = File::get($fpath);
             $data = $this->getStandingsInfoFromJson($contents);
             if (!is_null($data)) {
                 $inputs[] = $data;
             }
             File::delete($fpath);
         }
     }
     header('Content-type: application/json');
     header('Content-disposition: attachment; filename=combined-standings.json');
     // Did we recover any good inputs?
     $n = count($inputs);
     if ($n == 0) {
         return json_encode(null);
     }
     // Are they from the same contest?
     for ($i = 1; $i < $n; $i += 1) {
         if ($inputs[0]->contest != $inputs[$i]->contest) {
             return json_encode(null);
         }
         if (count($inputs[0]->problems) != count($inputs[$i]->problems)) {
             return json_encode(null);
         }
         for ($j = 0; $j < count($inputs[0]->problems); $j += 1) {
             if ($inputs[0]->problems[$j] != $inputs[$i]->problems[$j]) {
                 return json_encode(null);
             }
         }
     }
     $document = ['contest' => $inputs[0]->contest, 'problems' => $inputs[0]->problems, 'participants' => $inputs[0]->participants, 'standings' => $inputs[0]->standings];
     // If so, let's join them!
     $seen_participants = [];
     foreach ($inputs[0]->participants as $pa) {
         if (!isset($seen_participants[$pa->id])) {
             $seen_participants[$pa->id] = true;
         }
     }
     for ($i = 1; $i < $n; $i += 1) {
         foreach ($inputs[$i]->participants as $pa) {
             if (isset($seen_participants[$pa->id])) {
                 continue;
             }
             $seen_participants[$pa->id] = true;
             $document['participants'][] = $pa;
             $document['standings'][$pa->id] = $inputs[$i]->standings[$pa->id];
         }
     }
     // Sort participants according to their result summary
     uasort($document['participants'], function ($x, $y) use(&$document) {
         $a = $document['standings'][$x->id];
         $b = $document['standings'][$y->id];
         if ($a['summary']['total'] != $b['summary']['total']) {
             return $b['summary']->total - $a['summary']['total'];
         }
         return $a['summary']['penalty'] - $b['summary']['penalty'];
     });
     // Send the combined document
     return json_encode($document);
 }