Пример #1
0
 public function getProject($projectId)
 {
     if (!ctype_digit($projectId)) {
         throw new ModelException('Invalid project ID');
     }
     $this->transaction->requestTransaction();
     $project = Project::fetchActive($this->conn, $projectId);
     if (empty($project)) {
         throw new ItemNotFoundException('The specified project has not been found.');
     }
     return $project;
 }
Пример #2
0
 /**
  * @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']);
 }
Пример #3
0
 /**
  * @return Project
  */
 public function getItem($id)
 {
     $this->transaction->requestTransaction();
     try {
         $item = Project::fetchActive($this->conn, $id);
         if (false === $item) {
             throw new ItemNotFoundException('The specified item has not been found.', $id);
         }
         return $item;
     } catch (\Exception $ex) {
         $this->transaction->requestRollback();
         throw $ex;
     }
 }
Пример #4
0
 /**
  * @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 g.*, ' . 'm.`role` AS `membership_role`, m.`note` AS `membership_note`, ' . self::createEntityFieldList() . 'FROM `' . CoreTables::GROUP_TBL . '` g ' . self::createEntityJoin('g') . 'INNER JOIN `' . CoreTables::GROUP_MEMBER_TBL . '` m ON m.`groupId` = g.`id` ' . 'WHERE m.`userId` = :userId AND g.`slug` = :slug', [':userId' => $userId, ':slug' => $slug]);
     if (false === $data) {
         return false;
     }
     $group = self::fromArray($data);
     $group->project = Project::fetchActive($conn, $data['projectId']);
     if (false == $group->project) {
         return false;
     }
     if (!empty($data['categoryId'])) {
         $group->category = GroupCategory::fetchByProject($conn, $data['categoryId'], $group->project);
     }
     $group->entity = Entity::fromArray($data, 'entity');
     $role = $resolver->getRole('Group', $data['membership_role']);
     return new Membership($group, $role, $data['membership_note']);
 }
 public function acceptInvitation(Invitation $invitation)
 {
     $role = $this->getRole($invitation->getRole());
     $note = $invitation->getNote();
     $project = Project::fetchActive($this->conn, $invitation->getResourceId());
     $project->joinMember($this->conn, $invitation->getUser(), $role, $note);
 }