public function getRole($id)
 {
     if (!ctype_digit($id)) {
         throw new ModelException('Invalid role ID');
     }
     return $this->roleResolver->getRole('Area', $id);
 }
 /**
  * @param $membershipEntity Entity whose members we want to view
  * @return array
  */
 public function findMembers(MembershipEntityInterface $membershipEntity)
 {
     $stmt = $this->conn->prepare('SELECT i.`id`, i.`name`, i.`avatar`, i.`lastVisit`, p.`location`, m.`role` AS `membershipRole`, m.`note` AS `membershipNote` ' . 'FROM `' . CoreTables::USER_TBL . '` i ' . 'INNER JOIN `' . CoreTables::USER_PROFILE_TBL . '` p ON p.`userId` = i.`id` ' . 'INNER JOIN `' . $this->membershipTable() . '` m ON m.`userId` = i.`id` ' . 'WHERE m.`' . $this->entityColumn() . '` = :entityId AND i.`active` = 1 AND i.`removed` = 0 ' . 'ORDER BY i.`name`');
     $stmt->bindValue(':entityId', $membershipEntity->getId());
     $stmt->execute();
     $results = [];
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $results[] = ['id' => $row['id'], 'name' => $row['name'], 'avatar' => $row['avatar'], 'lastVisit' => $row['lastVisit'], 'location' => $row['location'], 'membership' => new Membership($membershipEntity, $this->roleResolver->getRole($this->entityName(), $row['membershipRole']), $row['membershipNote'])];
     }
     $stmt->closeCursor();
     return $results;
 }
 private function buildRepresentations(User $user)
 {
     $projects = $this->conn->fetchAll('SELECT p.`id`, p.`name`, p.`slug`, c.`role`, c.`note` FROM `' . CoreTables::PROJECT_TBL . '` p ' . 'INNER JOIN `' . CoreTables::PROJECT_MEMBER_TBL . '` c ON c.`projectId` = p.`id` ' . 'WHERE p.`archived` = 0 AND c.`userId` = :userId ORDER BY p.`name`', [':userId' => $user->getId()]);
     $items = array();
     foreach ($projects as $proj) {
         $items[] = new ProjectRepresentation($proj['slug'], $proj['name'], 'project_dashboard', 'ProjectNominative: 0', 'primary', $this->resolver->getRole('Project', $proj['role']), $proj['note']);
     }
     return $items;
 }
Example #4
0
 private function buildRepresentations(User $user)
 {
     $projects = $this->conn->fetchAll('SELECT g.`id`, g.`name`, g.`slug`, c.`role`, c.`note` FROM `' . CoreTables::GROUP_TBL . '` g ' . 'INNER JOIN `' . CoreTables::GROUP_MEMBER_TBL . '` c ON c.`groupId` = g.`id` ' . 'WHERE c.`userId` = :userId ORDER BY g.`name`', [':userId' => $user->getId()]);
     $items = array();
     foreach ($projects as $proj) {
         $items[] = new ProjectRepresentation($proj['slug'], $proj['name'], 'group_dashboard', 'GroupNominative: 0', 'default', $this->resolver->getRole('Group', $proj['role']), $proj['note']);
     }
     return $items;
 }
Example #5
0
 private function buildRepresentations(User $user)
 {
     $projects = $this->conn->fetchAll('SELECT a.`id`, a.`name`, a.`slug`, c.`role`, c.`note` FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . CoreTables::AREA_MEMBER_TBL . '` c ON c.`areaId` = a.`id` ' . 'WHERE c.`userId` = :userId ORDER BY a.`name`', [':userId' => $user->getId()]);
     $items = array();
     foreach ($projects as $proj) {
         $items[] = new ProjectRepresentation($proj['slug'], $proj['name'], 'area_dashboard', 'AreaNominative: 0', 'purple', $this->resolver->getRole('Area', $proj['role']), $proj['note']);
     }
     return $items;
 }
Example #6
0
 public static function fetchLinkedProfile(Connection $conn, MembershipRoleResolver $roleResolver, IdentifiableInterface $item, Join $join, QueryElement $element)
 {
     $qb = QueryBuilder::select()->field('u.*')->field('p.*')->field('m.role AS `membership_role`')->field('m.note AS `membership_note`')->field('l.`id`', 'language_id')->field('l.`name`', 'language_name')->field('l.`locale`', 'language_locale')->from(CoreTables::USER_TBL, 'u')->join(CoreTables::USER_PROFILE_TBL, 'p', QueryClause::clause('p.`userId` = u.`id`'))->join(CoreTables::LANGUAGE_TBL, 'l', QueryClause::clause('l.`id` = p.`settingsLanguageId`'))->join($join)->where(QueryOperator::op('AND')->expr(QueryClause::clause('u.`active` = 1 AND u.`removed` = 0'))->expr($element));
     $data = $qb->fetchAssoc($conn);
     if (false === $data) {
         return false;
     }
     $user = User::fromArray($data);
     $membership = new Membership($item, $roleResolver->getRole(get_class($item), $data['membership_role']), $data['membership_note']);
     User::installMembershipInformation($user, $membership);
     return $user;
 }
Example #7
0
 public function findMembers(Connection $conn, MembershipRoleResolver $roleResolver)
 {
     $stmt = $conn->prepare('SELECT u.id, u.name, p.role, p.note FROM `' . CoreTables::USER_TBL . '` u ' . 'INNER JOIN `' . CoreTables::AREA_MEMBER_TBL . '` p ON p.`userId` = u.`id` WHERE p.`areaId` = :areaId ORDER BY p.role DESC, u.name');
     $stmt->bindValue(':areaId', $this->getId());
     $stmt->execute();
     $result = array();
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $role = $roleResolver->getRole('Area', $row['role']);
         $row['roleName'] = $role->getName();
         $result[] = $row;
     }
     $stmt->closeCursor();
     return $result;
 }
Example #8
0
 public function approve(Connection $conn, MembershipRoleResolver $resolver)
 {
     $this->status = $conn->fetchColumn('SELECT `status` FROM `' . CoreTables::AREA_REQUEST_TBL . '` WHERE `id` = :id', [':id' => $this->id]);
     if ($this->status == self::STATUS_VERIFICATION) {
         $this->lastUpdatedAt = time();
         $this->status = self::STATUS_APPROVED;
         $conn->update(CoreTables::AREA_REQUEST_TBL, ['lastUpdatedAt' => $this->lastUpdatedAt, 'status' => $this->status], ['id' => $this->getId()]);
         $area = new Area();
         $area->setName($this->name);
         $area->setProject($this->project);
         $area->setTerritory($this->territory);
         $area->setReporter($this->requestor);
         // oops, naming inconsistency
         $id = $area->insert($conn);
         $conn->update(CoreTables::AREA_REQUEST_TBL, ['areaId' => $id], ['id' => $this->getId()]);
         $area->joinMember($conn, $this->requestor, $resolver->getHighestRole('Area'), '');
         return $area;
     }
     return false;
 }