Example #1
0
 public static function apiArbitrateRequest(Request $r)
 {
     $result = array("status" => "ok");
     if (is_null($r["resolution"])) {
         throw new InvalidParameterException("invalidParameters");
     }
     // user must be admin of contest to arbitrate security
     $current_ses = SessionController::getCurrentSession($r);
     try {
         $r["contest"] = ContestsDAO::getByAlias($r["contest_alias"]);
     } catch (Exception $e) {
         throw new NotFoundException($e);
     }
     if (is_null($r["contest"])) {
         throw new NotFoundException("contestNotFound");
     }
     $r["target_user"] = UsersDAO::FindByUsername($r["username"]);
     $request = ContestUserRequestDAO::getByPK($r["target_user"]->user_id, $r["contest"]->contest_id);
     if (is_null($request)) {
         throw new InvalidParameterException("userNotInListOfRequests");
     }
     if ($r["resolution"] === "false") {
         // "false" casts to true.
         $resolution = false;
     } else {
         $resolution = (bool) $r["resolution"];
     }
     $request->setAccepted($resolution);
     $request->setExtraNote($r["note"]);
     $request->setLastUpdate(gmdate('Y-m-d H:i:s'));
     ContestUserRequestDAO::save($request);
     // Save this action in the history
     $history = new ContestUserRequestHistory();
     $history->user_id = $request->user_id;
     $history->contest_id = $request->user_id;
     $history->time = $request->last_update;
     $history->admin_id = $current_ses["id"];
     $history->accepted = $request->accepted;
     ContestUserRequestHistoryDAO::save($history);
     self::$log->info("Arbitrated contest for user, new accepted user_id=" . $r["target_user"]->user_id . ", state=" . $resolution);
     return $result;
 }
 public static function apiArbitrateRequest(Request $r)
 {
     $result = array('status' => 'ok');
     if (is_null($r['resolution'])) {
         throw new InvalidParameterException('invalidParameters');
     }
     // user must be admin of contest to arbitrate security
     $current_ses = SessionController::getCurrentSession($r);
     try {
         $r['contest'] = ContestsDAO::getByAlias($r['contest_alias']);
     } catch (Exception $e) {
         throw new NotFoundException($e);
     }
     if (is_null($r['contest'])) {
         throw new NotFoundException('contestNotFound');
     }
     $r['target_user'] = UsersDAO::FindByUsername($r['username']);
     $request = ContestUserRequestDAO::getByPK($r['target_user']->user_id, $r['contest']->contest_id);
     if (is_null($request)) {
         throw new InvalidParameterException('userNotInListOfRequests');
     }
     if ($r['resolution'] === 'false') {
         // "false" casts to true.
         $resolution = false;
     } else {
         $resolution = (bool) $r['resolution'];
     }
     $request->setAccepted($resolution);
     $request->setExtraNote($r['note']);
     $request->setLastUpdate(gmdate('Y-m-d H:i:s'));
     ContestUserRequestDAO::save($request);
     // Save this action in the history
     $history = new ContestUserRequestHistory();
     $history->user_id = $request->user_id;
     $history->contest_id = $request->user_id;
     $history->time = $request->last_update;
     $history->admin_id = $current_ses['id'];
     $history->accepted = $request->accepted;
     ContestUserRequestHistoryDAO::save($history);
     self::$log->info('Arbitrated contest for user, new accepted user_id=' . $r['target_user']->user_id . ', state=' . $resolution);
     return $result;
 }