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;
 }
Beispiel #2
0
 /**
  * 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;
     }
 }