public function listData(DataTable $dataTable, TranslatorInterface $translator) { $qb = QueryBuilder::select()->field('i.id', 'id'); if (!$this->root instanceof Area) { $qb->field('a.id', 'areaId'); $qb->field('a.name', 'areaName'); $qb->join(CoreTables::AREA_TBL, 'a', QueryClause::clause('a.id = i.areaId')); } $qb->field('i.subject', 'subject')->field('i.createdAt', 'createdAt')->field('i.status', 'status')->field('u.id', 'responderId')->field('u.name', 'responder')->field('i.duplicate', 'duplicate')->from(EdkTables::MESSAGE_TBL, 'i')->leftJoin(CoreTables::USER_TBL, 'u', QueryClause::clause('u.id = i.responderId'))->orderBy('i.status', 'ASC')->orderBy('i.createdAt', 'ASC'); if ($this->root instanceof Area) { $qb->where(QueryClause::clause('i.`areaId` = :areaId', ':areaId', $this->root->getId())); } elseif ($this->root instanceof Group) { $qb->where(QueryClause::clause('a.`groupId` = :groupId', ':groupId', $this->root->getId())); } elseif ($this->root instanceof Project) { $qb->where(QueryClause::clause('a.`projectId` = :projectId', ':projectId', $this->root->getId())); } $qb->postprocess(function ($row) use($translator) { $row['statusText'] = $translator->trans(EdkMessage::statusText($row['status']), [], 'edk'); $row['statusLabel'] = EdkMessage::statusLabel($row['status']); $row['createdAt'] = $this->timeFormatter->ago($row['createdAt']); return $row; }); $recordsTotal = QueryBuilder::copyWithoutFields($qb)->field('COUNT(i.id)', 'cnt')->where($dataTable->buildCountingCondition($qb->getWhere()))->fetchCell($this->conn); $recordsFiltered = QueryBuilder::copyWithoutFields($qb)->field('COUNT(i.id)', 'cnt')->where($dataTable->buildFetchingCondition($qb->getWhere()))->fetchCell($this->conn); $dataTable->processQuery($qb); return $dataTable->createAnswer($recordsTotal, $recordsFiltered, $qb->where($dataTable->buildFetchingCondition($qb->getWhere()))->fetchAll($this->conn)); }
public function findMilestoneProgressForAreasInGroup(Group $group) { $totalMilestones = $this->conn->fetchColumn('SELECT COUNT(`id`) FROM `' . MilestoneTables::MILESTONE_TBL . '` WHERE `projectId` = :projectId AND `entityType` = \'Area\'', [':projectId' => $group->getProject()->getId()]); $results = $this->conn->fetchAll('SELECT a.`id`, a.`name`, a.`entityId`, p.`completedNum` ' . 'FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . MilestoneTables::MILESTONE_PROGRESS_TBL . '` p ON p.`entityId` = a.`entityId` ' . 'WHERE a.`groupId` = :groupId ' . 'ORDER BY p.`completedNum` DESC, a.`name`', [':groupId' => $group->getId()]); foreach ($results as &$result) { $this->processResult($totalMilestones, $result); } return $results; }
public function countParticipants() { $this->transaction->requestTransaction(); try { return $this->conn->fetchColumn('SELECT SUM(s.`participantNum`) + SUM(s.`externalParticipantNum`) ' . 'FROM `' . EdkTables::REGISTRATION_SETTINGS_TBL . '` s ' . 'INNER JOIN `' . EdkTables::ROUTE_TBL . '` r ON r.`id` = s.`routeId` ' . 'INNER JOIN `' . CoreTables::AREA_TBL . '` a ON r.`areaId` = a.`id` ' . $this->createWhereClause(), [':itemId' => $this->root->getId()]); } catch (Exception $ex) { $this->transaction->requestRollback(); throw $ex; } }
public function countRoutes() { $this->transaction->requestTransaction(); try { return $this->conn->fetchColumn('SELECT COUNT(r.`id`) ' . 'FROM `' . EdkTables::ROUTE_TBL . '` r ' . 'INNER JOIN `' . CoreTables::AREA_TBL . '` a ON r.`areaId` = a.`id` ' . $this->createWhereClause(), [':itemId' => $this->root->getId()]); } catch (Exception $ex) { $this->transaction->requestRollback(); throw $ex; } }
public function listData(DataTable $dataTable) { $qb = QueryBuilder::select()->field('i.id', 'id')->field('i.name', 'name')->field('r.mandatoryCourseNum', 'mandatoryCourseNum')->field('r.passedCourseNum', 'passedCourseNum')->field('r.failedCourseNum', 'failedCourseNum')->from(CoreTables::AREA_TBL, 'i')->join(CourseTables::COURSE_PROGRESS_TBL, 'r', QueryClause::clause('r.areaId = i.id'))->leftJoin(CoreTables::GROUP_TBL, 'g', QueryClause::clause('g.id = i.groupId')); if (null !== $this->group) { $qb->where(QueryClause::clause('i.`groupId` = :groupId', ':groupId', $this->group->getId())); } else { $qb->where(QueryClause::clause('i.`projectId` = :projectId', ':projectId', $this->project->getId())); } $recordsTotal = QueryBuilder::copyWithoutFields($qb)->field('COUNT(i.id)', 'cnt')->where($dataTable->buildCountingCondition($qb->getWhere()))->fetchCell($this->conn); $recordsFiltered = QueryBuilder::copyWithoutFields($qb)->field('COUNT(i.id)', 'cnt')->where($dataTable->buildFetchingCondition($qb->getWhere()))->fetchCell($this->conn); $qb->postprocess(function ($row) { if ($row['mandatoryCourseNum'] == 0) { $row['progress'] = 0; } else { $row['progress'] = $row['passedCourseNum'] / $row['mandatoryCourseNum'] * 100; } return $row; }); $dataTable->processQuery($qb); return $dataTable->createAnswer($recordsTotal, $recordsFiltered, $qb->where($dataTable->buildFetchingCondition($qb->getWhere()))->fetchAll($this->conn)); }
public function getFormChoices() { $this->transaction->requestTransaction(); $stmt = $this->conn->prepare('SELECT `id`, `name` FROM `' . CoreTables::AREA_TBL . '` WHERE `groupId` = :groupId ORDER BY `name`'); $stmt->bindValue(':groupId', $this->group->getId()); $stmt->execute(); $result = array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $result[$row['name']] = $row['id']; } $stmt->closeCursor(); return $result; }
public static function fetchByGroup(Connection $conn, $id, Group $group) { $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`, ' . self::createEntityFieldList() . 'FROM `' . CoreTables::AREA_TBL . '` a ' . self::createEntityJoin('a') . 'INNER JOIN `' . CoreTables::TERRITORY_TBL . '` t ON t.`id` = a.`territoryId` ' . 'WHERE a.`id` = :id AND a.`groupId` = :groupId', [':id' => $id, ':groupId' => $group->getId()]); if (false === $data) { return false; } $item = Area::fromArray($data); $item->group = $group; $item->project = Project::fetchActive($conn, $data['projectId']); if (false == $item->project) { return false; } $item->status = $item->oldStatus = AreaStatus::fetchByProject($conn, $data['statusId'], $item->project); $item->setTerritory($item->oldTerritory = Territory::fromArray($data, 'territory')); $item->entity = Entity::fromArray($data, 'entity'); return $item; }
public function findGroupAreas(Group $group) { $this->transaction->requestTransaction(); try { return $this->conn->fetchAll('SELECT a.`id`, a.`name`, a.`memberNum`, s.`id` AS `statusId`, s.`name` AS `statusName`, s.`label` AS `statusLabel`, t.`id` AS `territoryId`, t.`name` AS `territoryName` ' . 'FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . CoreTables::AREA_STATUS_TBL . '` s ON s.`id` = a.`statusId` ' . 'INNER JOIN `' . CoreTables::TERRITORY_TBL . '` t ON t.`id` = a.`territoryId` ' . 'WHERE a.`groupId` = :id ORDER BY a.`name`', [':id' => $group->getId()]); } catch (Exception $exception) { $this->transaction->requestRollback(); throw $exception; } }