Inheritance: extends Illuminate\Database\Eloquent\Model
 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);
 }
 public function show($id)
 {
     $contest = Contest::with('entries')->with('entries.contest')->findOrFail($id);
     $user = Auth::user();
     if (!$contest->visible && (!$user || !$user->isAdmin())) {
         abort(404);
     }
     if ($contest->isVotingStarted()) {
         return view("contests.voting.{$contest->type}")->with('contest', $contest);
     } else {
         return view('contests.enter')->with('contest', $contest);
     }
 }
Beispiel #3
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);
     }
 }
Beispiel #4
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());
     }
 }
 /**
  * This command processes the Data pulled from twitter
  */
 public function actionProcessData()
 {
     $CurrentDate = new \DateTime('NOW');
     $crawlerDataCollection = CrawlerData::findAll(['parsed_at' => null]);
     $json_data = [];
     $regex = [];
     foreach ($crawlerDataCollection as $crawlerData) {
         $Contest = Contest::findOne($crawlerData->contest_id);
         $contestRegex = CrawlerProfile::findOne(['id' => $Contest->crawler_profile_id]);
         if ($Contest->custom_regex_entry == null) {
             $regex["entry"] = $contestRegex->regex_entry;
         } else {
             $regex["entry"] = $Contest->custom_regex_entry;
         }
         if ($Contest->custom_regex_rating == null) {
             $regex["rating"] = $contestRegex->regex_rating;
         } else {
             $regex["rating"] = $Contest->custom_regex_rating;
         }
         $jsonData = Json::decode($crawlerData->data, true);
         foreach ($jsonData["statuses"] as $id => $tweet) {
             // Get tweet creation date
             $TweetDate = DateTime::createFromFormat("D M d H:i:s T Y", $tweet["created_at"]);
             // check if Tweet creation date is within restrictions!
             if ($TweetDate->format('Y-m-d') >= $Contest->parse_from && $TweetDate->format('Y-m-d') <= $Contest->parse_to) {
                 $Tweet = $this->CreateTweetEntry($tweet, $Contest->id, $regex);
                 if ($Tweet != null) {
                     $Contest->last_parsed_tweet_id = $Tweet->id;
                 }
             }
         }
         if (array_key_exists("next_results", $jsonData["search_metadata"])) {
             $Contest->next_result_query = $jsonData["search_metadata"]["next_results"];
         } else {
             // Set new refresh URL only if we have processed new tweets
             if (sizeof($jsonData["statuses"]) > 0) {
                 $Contest->next_result_query = $jsonData["search_metadata"]["refresh_url"];
             }
         }
         if ($Contest->save()) {
             $this->stdout("Last Tweet ID for Contest " . $Contest->name . " saved!\n", Console::FG_GREEN);
             // Update Entries with new Data
             $this->UpdateContestEntries($Contest);
         } else {
             $this->stdout("Error Saving Tweet !\n", Console::BOLD);
             $this->stdout(print_r($Contest->errors) . "\n", Console::BOLD);
         }
         $parsed_at = new DateTime('NOW');
         $crawlerData->parsed_at = $parsed_at->format('Y-m-d H:i:s');
         //save parsed_at time
         $crawlerData->save();
     }
 }
Beispiel #6
0
    <?php 
$form = ActiveForm::begin();
?>

    <h2>@<?php 
echo Html::encode($model->user->screen_name);
?>
</h2>

    <p class="well well-sm"><?php 
echo Html::encode($model->text);
?>
</p>  

    <?php 
echo $form->field($model, 'contest_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Contest::find()->all(), 'id', 'name'), 'options' => ['placeholder' => 'Select a Contest ...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'entry_id')->widget(DepDrop::classname(), ['data' => ArrayHelper::map(Entry::find()->where(['contest_id' => $model->contest_id])->all(), 'id', 'name'), 'options' => ['placeholder' => Yii::t('app', 'Select a Entry ...')], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['allowClear' => true]], 'pluginOptions' => ['depends' => ['tweet-contest_id'], 'url' => Url::to(['/entry/contest-entries']), 'loadingText' => Yii::t('app', 'Loading Entries ...')]]);
?>

    <?php 
echo $form->field($model, 'rating')->textInput(['maxlength' => 4]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContest()
 {
     return $this->hasOne(Contest::className(), ['id' => 'contest_id']);
 }
 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');
 }
 /**
  * Finds the Contest model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Contest the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Contest::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }