Esempio n. 1
0
 /**
  * Fires the rule against the given entity, using the callback that produces the new status
  * for the milestone.
  * 
  * @param Connection $conn
  * @param Entity $entity
  * @param callback $callback
  */
 public function fireRule(Connection $conn, Entity $entity, $callback)
 {
     if ($this->milestone->isBeforeDeadline()) {
         $result = $callback();
         if (!$result instanceof NewMilestoneStatus) {
             throw new LogicException('Cannot fire the milestone rule \'' . $this->activator + '\': the callback did not return a NewMilestoneStatus instance!');
         }
         if ($result->isChanged()) {
             if ($this->milestone->getType() == Milestone::TYPE_BINARY) {
                 if ($result->isCompleted()) {
                     $this->milestone->complete($conn, $entity);
                 } else {
                     $this->milestone->cancel($conn, $entity);
                 }
             } else {
                 $this->milestone->updateProgress($conn, $entity, $result->getProgress());
             }
         }
     }
 }
 public function completeMilestone(Entity $entity, Milestone $milestone, MembershipEntityInterface $who)
 {
     $this->transaction->requestTransaction();
     try {
         $result = $milestone->complete($this->conn, $entity, Milestone::RETURN_SUMMARY, $this->timeFormatter);
         if (false === $result) {
             throw new ModelException('This milestone is already completed!');
         }
         return $result;
     } catch (Exception $exception) {
         $this->transaction->requestRollback();
         throw $exception;
     }
 }