/** * Gets a list of tags * * @param Request $r */ public function apiList(Request $r) { self::authenticateRequest($r); $param = ""; if (!is_null($r["term"])) { $param = "term"; } else { if (!is_null($r["query"])) { $param = "query"; } else { throw new InvalidParameterException("parameterEmpty", "query"); } } try { $tags = TagsDAO::FindByName($r[$param]); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } $response = array(); foreach ($tags as $tag) { $entry = array("name" => $tag->name); array_push($response, $entry); } return $response; }
/** * Gets a list of tags * * @param Request $r */ public function apiList(Request $r) { self::authenticateRequest($r); $param = ''; if (!is_null($r['term'])) { $param = 'term'; } elseif (!is_null($r['query'])) { $param = 'query'; } else { throw new InvalidParameterException('parameterEmpty', 'query'); } try { $tags = TagsDAO::FindByName($r[$param]); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } $response = array(); foreach ($tags as $tag) { $entry = array('name' => $tag->name); array_push($response, $entry); } return $response; }
/** * 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'); }