Ejemplo n.º 1
0
 public static function fetchById(Connection $conn, $id)
 {
     $data = $conn->fetchAssoc('SELECT * FROM `' . CoreTables::ENTITY_TBL . '` WHERE `id` = :id', [':id' => $id]);
     if (false === $data) {
         return false;
     }
     return Entity::fromArray($data);
 }
Ejemplo n.º 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']);
 }
Ejemplo n.º 3
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']);
 }
Ejemplo n.º 4
0
 /**
  * Finds the project of the given ID, where the area registration is currently possible. False is returned,
  * if the project is not found.
  * 
  * @param Connection $conn
  * @param int $projectId
  * @return Project|boolean
  */
 public static function fetchAvailableForRegistration(Connection $conn, $projectId)
 {
     $data = $conn->fetchAssoc('SELECT p.*, ' . self::createEntityFieldList() . 'FROM `' . CoreTables::PROJECT_TBL . '` p ' . self::createEntityJoin('p') . 'WHERE p.`id` = :id AND p.`archived` = 0 AND p.`areasAllowed` = 1 AND p.`areaRegistrationAllowed` = 1', [':id' => $projectId]);
     if (empty($data)) {
         return false;
     }
     $item = self::fromArray($data);
     $item->entity = Entity::fromArray($data, 'entity');
     return $item;
 }