public function testPublicClarificationsCanBeViewed()
 {
     // Get a problem
     $problemData = ProblemsFactory::createProblem();
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create our contestant who will submit the clarification
     $contestant = UserFactory::createUser();
     // Create our contestant who will try to view the clarification
     $contestant2 = UserFactory::createUser();
     // Create the clarification, note that contestant will create it
     $this->detourBroadcasterCalls();
     $clarificationData = ClarificationsFactory::createClarification($problemData, $contestData, $contestant);
     // Manually set the just created clarification to PUBLIC
     $clarification = ClarificationsDAO::getByPK($clarificationData['response']['clarification_id']);
     $clarification->setPublic('1');
     ClarificationsDAO::save($clarification);
     // Prepare the request object
     $r = new Request();
     $r['clarification_id'] = $clarificationData['response']['clarification_id'];
     // Log in with the author of the clarification
     $r['auth_token'] = $this->login($contestant2);
     // Call API
     $response = ClarificationController::apiDetails($r);
     // Check the data we got
     $this->assertClarification($r['clarification_id'], $response);
 }
Ejemplo n.º 2
0
 /**
  * Update a clarification
  * 
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  */
 public static function apiUpdate(Request $r)
 {
     // Authenticate user
     self::authenticateRequest($r);
     // Validate request
     self::validateUpdate($r);
     // Update clarification
     $valueProperties = array("message", "answer", "public");
     $clarification = $r['clarification'];
     self::updateValueProperties($r, $clarification, $valueProperties);
     $r['clarification'] = $clarification;
     // Let DB handle time update
     $time = time();
     $clarification->time = gmdate('Y-m-d H:i:s', $time);
     // Save the clarification
     try {
         ClarificationsDAO::save($clarification);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     $r['problem'] = $r['contest'] = $r['user'] = null;
     self::clarificationUpdated($r, $time);
     $response = array();
     $response["status"] = "ok";
     return $response;
 }