public function destroy($id)
 {
     $user = Auth::user();
     $entry = UserContestEntry::where(['user_id' => $user->user_id])->findOrFail($id);
     $contest = Contest::findOrFail($entry->contest_id);
     priv_check('ContestEntryDestroy', $entry)->ensureCan();
     $entry->deleteWithFile();
     return $contest->userEntries($user);
 }
Esempio n. 2
0
 public function gimmeZip($id)
 {
     set_time_limit(300);
     $contest = Contest::findOrFail($id);
     $entries = UserContestEntry::where('contest_id', $id)->with('user')->get();
     $tmpBase = sys_get_temp_dir() . "/c{$id}-" . time();
     $workingFolder = "{$tmpBase}/working";
     $outputFolder = "{$tmpBase}/out";
     try {
         if (!is_dir($workingFolder)) {
             mkdir($workingFolder, 0755, true);
         }
         if (!is_dir($outputFolder)) {
             mkdir($outputFolder, 0755, true);
         }
         // fetch entries
         foreach ($entries as $entry) {
             $targetDir = "{$workingFolder}/" . ($entry->user ?? new \App\Models\DeletedUser())->username . " ({$entry->user_id})/";
             if (!is_dir($targetDir)) {
                 mkdir($targetDir, 0755, true);
             }
             copy($entry->fileUrl(), "{$targetDir}/" . sanitize_filename($entry->original_filename));
         }
         // zip 'em
         $zipOutput = "{$outputFolder}/contest-{$id}.zip";
         $zip = new \ZipArchive();
         $zip->open($zipOutput, \ZipArchive::CREATE);
         foreach (glob("{$workingFolder}/**/*.*") as $file) {
             // we just want the path relative to the working folder root
             $new_filename = str_replace("{$workingFolder}/", '', $file);
             $zip->addFile($file, $new_filename);
         }
         $zip->close();
         // send 'em on their way
         header('Content-Disposition: attachment; filename=' . basename($zipOutput));
         header('Content-Type: application/zip');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
         header('Pragma: public');
         header('Content-Length: ' . filesize($zipOutput));
         readfile($zipOutput);
     } finally {
         deltree($tmpBase);
     }
 }
Esempio n. 3
0
 public function show($id)
 {
     $contest = Contest::findOrFail($id);
     $user = Auth::user();
     if (!$contest->visible && (!$user || !$user->isAdmin())) {
         abort(404);
     }
     if ($contest->isVotingStarted() && isset($contest->extra_options['children'])) {
         $contestIds = $contest->extra_options['children'];
     } else {
         $contestIds = [$id];
     }
     $contests = Contest::with('entries', 'entries.contest', 'entries.user')->whereIn('id', $contestIds)->orderByRaw(DB::raw('FIELD(id, ' . implode(',', $contestIds) . ')'))->get();
     if ($contest->isVotingStarted()) {
         return view('contests.voting')->with('contestMeta', $contest)->with('contests', $contests);
     } else {
         return view('contests.enter')->with('contestMeta', $contest)->with('contest', $contests->first());
     }
 }
Esempio n. 4
0
 public function downloadStandings($cid)
 {
     $contest = Contest::findOrFail($cid);
     $standings = $contest->getStandings();
     $participants = $standings['participants'];
     $problems = $standings['problems'];
     $details = $standings['details'];
     $document = ['contest' => $contest, 'participants' => $participants, 'problems' => $problems, 'standings' => $details];
     $json = json_encode($document);
     return response($json)->header('Content-disposition', 'attachment; filename=c' . $contest->id . '-standings.json')->header('Content-type', 'application/json');
 }