private function sendPaginationHeaders($limit, $offset, $size)
 {
     Header::sendPaginationHeaders($limit, $offset, $size, self::MAX_LIMIT);
 }
 private function sendPaginationHeaders($limit, $offset, $size)
 {
     Header::sendPaginationHeaders($limit, $offset, $size, $this->file_manager->getMaximumChunkSize());
 }
예제 #3
0
 /**
  * Get artifacts
  *
  * Get artifacts matching criteria of a report.
  *
  * <p>
  * By default it does not return the values of the fields for performance reasons.
  * You can ask to include some specific values with the <strong>values</strong> parameter.<br>
  * Eg:
  * <ul>
  *  <li>…?id=123&values=summary,status //add summary and status values
  *  <li>…?id=123&values=all            //add all fields values
  *  <li>…?id=123&values=               //(empty string) do not add any field values
  * </ul>
  * </p>
  *
  * <p>
  *   <strong>/!\</strong> Please note that <strong>only "all" and "" (empty string) are available</strong> for now.
  * </p>
  *
  * @url GET {id}/artifacts
  * @access hybrid
  *
  * @param int    $id      Id of the report
  * @param string $values  Which fields to include in the response. Default is no field values {@from path}{@choice ,all}
  * @param int    $limit   Number of elements displayed per page {@from path}{@min 1}
  * @param int    $offset  Position of the first element to display {@from path}{@min 0}
  *
  * @return array {@type Tuleap\Tracker\REST\Artifact\ArtifactRepresentation}
  */
 public function getArtifacts($id, $values = self::DEFAULT_VALUES, $limit = self::DEFAULT_LIMIT, $offset = self::DEFAULT_OFFSET)
 {
     $this->checkAccess();
     $this->checkLimitValue($limit);
     $user = UserManager::instance()->getCurrentUser();
     $report = $this->getReportById($user, $id);
     $matching_ids = $report->getMatchingIds();
     if (!$matching_ids['id']) {
         return array();
     }
     $matching_artifact_ids = explode(',', $matching_ids['id']);
     $nb_matching = count($matching_artifact_ids);
     $slice_matching_ids = array_slice($matching_artifact_ids, $offset, $limit);
     $artifact_factory = Tracker_ArtifactFactory::instance();
     $artifacts = $artifact_factory->getArtifactsByArtifactIdList($slice_matching_ids);
     $with_all_field_values = $values == self::ALL_VALUES;
     Header::allowOptionsGet();
     Header::sendPaginationHeaders($limit, $offset, $nb_matching, self::MAX_LIMIT);
     return $this->getListOfArtifactRepresentation($user, $artifacts, $with_all_field_values);
 }
예제 #4
0
 /**
  * Get items
  *
  * Get the items of a given kanban in a given column
  *
  * <pre>
  * /!\ Kanban REST routes are under construction and subject to changes /!\
  * </pre>
  *
  * @url GET {id}/items
  * @access hybrid
  *
  * @param int $id Id of the kanban
  * @param int $column_id Id of the column the item belongs to
  * @param int $limit  Number of elements displayed per page
  * @param int $offset Position of the first element to display
  *
  * @return Tuleap\AgileDashboard\REST\v1\Kanban\KanbanItemCollectionRepresentation
  *
  * @throws 403
  * @throws 404
  */
 public function getItems($id, $column_id, $limit = 10, $offset = 0)
 {
     $this->checkAccess();
     $user = $this->getCurrentUser();
     $kanban = $this->getKanban($user, $id);
     if (!$this->columnIsInTracker($kanban, $user, $column_id)) {
         throw new RestException(404);
     }
     $items_representation = new KanbanItemCollectionRepresentation();
     $items_representation->build($user, $kanban, $column_id, $limit, $offset);
     Header::allowOptionsGet();
     Header::sendPaginationHeaders($limit, $offset, $items_representation->total_size, self::MAX_LIMIT);
     return $items_representation;
 }
 /**
  * Get changesets
  *
  * Get the changesets of a given artifact
  *
  * @url GET {id}/changesets
  * @access hybrid
  *
  * @param int    $id     Id of the artifact
  * @param string $fields Whether you want to fetch all fields or just comments {@from path}{@choice all,comments}
  * @param int    $limit  Number of elements displayed per page {@from path}{@min 1}
  * @param int    $offset Position of the first element to display {@from path}{@min 0}
  *
  * @return array {@type Tuleap\Tracker\REST\ChangesetRepresentation}
  */
 public function getArtifactChangesets($id, $fields = Changeset::FIELDS_ALL, $limit = 10, $offset = self::DEFAULT_OFFSET)
 {
     $this->checkAccess();
     $user = UserManager::instance()->getCurrentUser();
     $artifact = $this->getArtifactById($user, $id);
     $changesets = $this->builder->getArtifactChangesetsRepresentation($user, $artifact, $fields, $offset, $limit);
     $this->sendAllowHeadersForChangesets($artifact);
     Header::sendPaginationHeaders($limit, $offset, $changesets->totalCount(), self::MAX_LIMIT);
     return $changesets->toArray();
 }
 private function sendPaginationHeaders($limit, $offset, $size)
 {
     Header::sendPaginationHeaders($limit, $offset, $size, FileManager::getMaximumChunkSize());
 }
예제 #7
0
 /**
  * Retrieve membership information for a set of users
  *
  * This resource will return user group membership information,
  * i.e. all the groups to which each one belongs,
  * for all users meeting the "query" criterion
  *
  * @url GET
  * @access protected
  * @throws 406
  *
  * @param string $query Criterion to filter the results {@choice with_ssh_key}
  * @param int $limit  Number of elements displayed per page
  * @param int $offset Position of the first element to display
  *
  * @return array {@type Tuleap\User\REST\v1\UserMembershipRepresentation}
  */
 public function get($query, $offset = 0, $limit = 10)
 {
     if ($limit > self::MAX_LIMIT) {
         throw new RestException(406, 'Maximum value for limit exceeded');
     }
     if ($query !== self::CRITERION_WITH_SSH_KEY) {
         throw new RestException(406, 'Invalid query criteria');
     }
     $current_user = $this->user_manager->getCurrentUser();
     $this->checkUserCanSeeOtherUsers($current_user);
     $users_memberships = array();
     $paginated_users = $this->user_manager->getPaginatedUsersWithSshKey($offset, $limit);
     foreach ($paginated_users->getUsers() as $user) {
         $representation = new UserMembershipRepresentation();
         $representation->build($user->getUsername(), $this->ugroup_literalizer->getUserGroupsForUser($user));
         $users_memberships[] = $representation;
     }
     Header::sendPaginationHeaders($limit, $offset, $paginated_users->getTotalCount(), self::MAX_LIMIT);
     $this->sendAllowHeaders();
     return $users_memberships;
 }
예제 #8
0
 /**
  * @throws RestException 400
  */
 private function getArtifactsMatchingQuery(PFUser $user, Tracker $tracker, $query, $offset, $limit)
 {
     $report = new Tracker_Report_REST($user, $tracker, PermissionsManager::instance(), new Tracker_ReportDao(), FormElementFactory::instance());
     try {
         $report->setRESTCriteria($query);
         $matching_ids = $report->getMatchingIds();
     } catch (InvalidCriteriaException $e) {
         throw new RestException(400, $e->getMessage());
     }
     if (!$matching_ids['id']) {
         return array();
     }
     $matching_artifact_ids = explode(',', $matching_ids['id']);
     $slice_matching_ids = array_slice($matching_artifact_ids, $offset, $limit);
     Header::sendPaginationHeaders($limit, $offset, count($matching_artifact_ids), self::MAX_LIMIT);
     $artifacts = $this->getTrackerArtifactFactory()->getArtifactsByArtifactIdList($slice_matching_ids);
     return array_filter($artifacts);
 }
예제 #9
0
 private function getUsersListRepresentation(PaginatedUserCollection $user_collection, $offset, $limit)
 {
     $this->sendAllowHeaders();
     Header::sendPaginationHeaders($limit, $offset, $user_collection->getTotalCount(), self::MAX_LIMIT);
     $list_of_user_representation = array();
     foreach ($user_collection->getUsers() as $user) {
         $user_representation = $this->is_authenticated ? new UserRepresentation() : new MinimalUserRepresentation();
         $list_of_user_representation[] = $user_representation->build($user);
     }
     return $list_of_user_representation;
 }
예제 #10
0
 /**
  * Get all possible parent artifacts for a given tracker
  *
  * Given a tracker, get all open artifacts of its parent tracker ordered by their artifact id
  * in decreasing order.
  * If the given tracker doesn't have a parent, it throws an error.
  *
  * @url GET {id}/parent_artifacts
  * @access hybrid
  *
  * @param int    $id
  * @param int    $limit  Number of elements displayed per page {@from path}{@min 1}
  * @param int    $offset Position of the first element to display {@from path}{@min 0}
  *
  * @return array {@type Tuleap\Tracker\REST\Artifact\ParentArtifactReference}
  */
 public function getParentArtifacts($id, $limit = self::DEFAULT_LIMIT, $offset = self::DEFAULT_OFFSET)
 {
     $this->checkAccess();
     $this->checkLimitValue($limit);
     $user = $this->user_manager->getCurrentUser();
     $tracker = $this->getTrackerById($user, $id);
     $parent = $this->getParentTracker($user, $tracker);
     $possible_parents_getr = new Tracker_Artifact_PossibleParentsRetriever($this->tracker_artifact_factory);
     list($label, $pagination, $display_selector) = $possible_parents_getr->getPossibleArtifactParents($parent, $user, $limit, $offset);
     if ($display_selector) {
         $nb_matching = $pagination->getTotalSize();
         Header::sendPaginationHeaders($limit, $offset, $nb_matching, self::MAX_LIMIT);
         $collection = array();
         foreach ($pagination->getArtifacts() as $artifact) {
             $reference = new ParentArtifactReference();
             $reference->build($artifact);
             $collection[] = $reference;
         }
         return $collection;
     }
 }