/** * Fetches a group by its ID and the project. * * @param int $id * @param Project $project */ public function getItem($id, Project $project) { $item = Group::fetchByProject($this->conn, $id, $project); if (false === $item) { throw new ItemNotFoundException('GroupNotFound', $id); } return $item; }
/** * @param Connection $conn * @param int $projectId * @param int $userId * @return Membership */ public static function fetchMembership(Connection $conn, MembershipRoleResolver $resolver, $slug, $userId) { $data = $conn->fetchAssoc('SELECT a.*, ' . 't.`id` AS `territory_id`, t.`name` AS `territory_name`, t.`areaNum` AS `territory_areaNum`, t.`requestNum` as `territory_requestNum`, ' . 'm.`role` AS `membership_role`, m.`note` AS `membership_note`, ' . self::createEntityFieldList() . 'FROM `' . CoreTables::AREA_TBL . '` a ' . self::createEntityJoin('a') . 'INNER JOIN `' . CoreTables::TERRITORY_TBL . '` t ON t.`id` = a.`territoryId` ' . 'INNER JOIN `' . CoreTables::AREA_MEMBER_TBL . '` m ON m.`areaId` = a.`id` WHERE m.`userId` = :userId AND a.`slug` = :slug', [':userId' => $userId, ':slug' => $slug]); if (false === $data) { return false; } $item = self::fromArray($data); $item->project = Project::fetchActive($conn, $data['projectId']); if (false == $item->project) { return false; } $item->status = $item->oldStatus = AreaStatus::fetchByProject($conn, $data['statusId'], $item->project); if (!empty($data['groupId'])) { $item->group = $item->oldGroup = Group::fetchByProject($conn, $data['groupId'], $item->project); } $item->setTerritory($item->oldTerritory = Territory::fromArray($data, 'territory')); $role = $resolver->getRole('Area', $data['membership_role']); $item->entity = Entity::fromArray($data, 'entity'); return new Membership($item, $role, $data['membership_note']); }
/** * @return Group */ public function getItem($id) { $this->transaction->requestTransaction(); try { $item = Group::fetchByProject($this->conn, $id, $this->project); if (false === $item) { $this->transaction->requestRollback(); throw new ItemNotFoundException('The specified item has not been found.', $id); } return $item; } catch (Exception $exception) { $this->transaction->requestRollback(); throw $exception; } }