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; }
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; }
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; }
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; }
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; }