コード例 #1
0
ファイル: MilestoneRule.php プロジェクト: zyxist/cantiga
 public static function fetchByActivator(Connection $conn, Project $project, $activator, Entity $entity)
 {
     $data = $conn->fetchAssoc('SELECT r.*, m.`id` AS `milestone_id`, m.`name` AS `milestone_name`, m.`description` AS `milestone_description`, m.`displayOrder` AS `milestone_displayOrder`, ' . 'm.`type` AS `milestone_type`, m.`entityType` AS `milestone_entityType`, m.`deadline` AS `milestone_deadline` ' . 'FROM `' . MilestoneTables::MILESTONE_RULE_TBL . '` r ' . 'INNER JOIN `' . MilestoneTables::MILESTONE_TBL . '` m ON m.`id` = r.`milestoneId` ' . 'WHERE r.`activator` = :activator AND r.`projectId` = :projectId AND m.`entityType` = :entityType', [':activator' => $activator, ':projectId' => $project->getId(), ':entityType' => $entity->getType()]);
     if (empty($data)) {
         return false;
     }
     $item = self::fromArray($data);
     $item->project = $project;
     $item->milestone = Milestone::fromArray($data, 'milestone');
     $item->milestone->setProject($project);
     return $item;
 }
コード例 #2
0
ファイル: Entity.php プロジェクト: zyxist/cantiga
 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);
 }
コード例 #3
0
ファイル: Area.php プロジェクト: zyxist/cantiga
 /**
  * @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']);
 }
コード例 #4
0
 private function isAllowedForArea(Entity $entity, MembershipEntityInterface $who, $editable = false)
 {
     if ($entity->getType() == 'Area') {
         if (!$editable || $this->settings->get(MilestoneSettings::AREA_CAN_UPDATE_OWN_PROGRESS)->getValue()) {
             return $who->getEntity()->getId() == $entity->getId();
         }
     }
     return false;
 }
コード例 #5
0
ファイル: Group.php プロジェクト: zyxist/cantiga
 /**
  * @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']);
 }
コード例 #6
0
ファイル: Project.php プロジェクト: zyxist/cantiga
 /**
  * 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;
 }
コード例 #7
0
ファイル: Milestone.php プロジェクト: zyxist/cantiga
 /**
  * Cancels the completion of this milestone for the given entity. If <tt>$retVal</tt> is set to
  * <tt>RETURN_BOOLEAN</tt>, the method returns just true or false to indicate
  * the success or failure. If <tt>RETURN_SUMMARY</tt> is set, it returns an array that
  * describes the new status of the milestone for this entity. In this case, you have
  * to provide <tt>$timeFormatter</tt> instance, too.
  * 
  * @param Connection $conn
  * @param Entity $entity
  * @param boolean $retVal Either Milestone::RETURN_BOOLEAN (default) or Milestone::RETURN_SUMMARY
  * @param TimeFormatterInterface $timeFormatter Provide only if $retVal is set to Milestone::RETURN_SUMMARY
  * @return mixed
  * @throws ModelException
  * @throws ItemNotFoundException
  */
 public function cancel(Connection $conn, Entity $entity, $retVal = self::RETURN_BOOLEAN, TimeFormatterInterface $timeFormatter = null)
 {
     if ($this->getType() != Milestone::TYPE_BINARY) {
         throw new ModelException('Cannot change the state of the milestone!');
     }
     $currentProgress = $conn->fetchColumn('SELECT `progress` FROM `' . MilestoneTables::MILESTONE_STATUS_TBL . '` WHERE `entityId` = :entityId AND `milestoneId` = :milestoneId', [':entityId' => $entity->getId(), ':milestoneId' => $this->getId()]);
     if (false === $currentProgress) {
         throw new ItemNotFoundException('Unknown milestone status.');
     }
     if ($currentProgress == 100) {
         $conn->update(MilestoneTables::MILESTONE_STATUS_TBL, ['progress' => 0, 'completedAt' => null], ['entityId' => $entity->getId(), 'milestoneId' => $this->getId()]);
         $conn->executeUpdate('UPDATE `' . MilestoneTables::MILESTONE_PROGRESS_TBL . '` SET `completedNum` = (`completedNum` - 1) WHERE `entityId` = :entityId', [':entityId' => $entity->getId()]);
         if ($retVal == self::RETURN_BOOLEAN) {
             return true;
         } else {
             return $this->createStatusRow(0, null, $timeFormatter);
         }
     } else {
         return false;
     }
 }