/**
  * Removes a tag from a contest
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  * @throws ForbiddenAccessException
  */
 public static function apiRemoveTag(Request $r)
 {
     // Authenticate logged user
     self::authenticateRequest($r);
     // Check whether problem exists
     Validators::isStringNonEmpty($r['problem_alias'], 'problem_alias');
     try {
         $problem = ProblemsDAO::getByAlias($r['problem_alias']);
         $tag = TagsDAO::getByName($r['name']);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     if (is_null($problem)) {
         throw new NotFoundException('problem');
     } elseif (is_null($tag)) {
         throw new NotFoundException('tag');
     }
     if (!Authorization::IsProblemAdmin($r['current_user_id'], $problem)) {
         throw new ForbiddenAccessException();
     }
     $problem_tag = new ProblemsTags();
     $problem_tag->problem_id = $problem->problem_id;
     $problem_tag->tag_id = $tag->tag_id;
     // Delete the role
     try {
         ProblemsTagsDAO::delete($problem_tag);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     return array('status' => 'ok');
 }