Example #1
0
 /**
  * @param array $workflow
  * @param $from
  * @param bool $allow_jumps
  * @return Workflow
  */
 public static function workflowValidator(array $workflow, $from, $allow_jumps = false)
 {
     $validator = new Workflow(compact('workflow', 'from', 'allow_jumps'));
     $validator->setMessage("Alur tidak diperbolehkan.");
     return $validator;
 }
Example #2
0
 /**
  * @param $status
  * @return bool
  */
 public function to($status)
 {
     if ($status != $this->purchase->getStatus()) {
         $workflow = new Workflow(['workflow' => PurchaseInput::getStatusOptions(), 'from' => $this->purchase->getStatus(), 'allow_jumps' => true, 'allow_current' => false]);
         if ($workflow->isValid($status)) {
             switch ($status) {
                 case Purchase::STATUS_DELIVERED:
                     $this->assignOrderDate(false);
                     $this->assignDeliveryDate(false);
                     break;
                 case Purchase::STATUS_IN_PROGRESS:
                     $this->assignOrderDate(false);
                     $this->purchase->setDeliveredAt(null);
                     break;
                 case Purchase::STATUS_CANCELED:
                     $this->assignOrderDate(true);
                     $this->assignCancelDate(false);
                     $this->purchase->setDeliveredAt(null);
                     break;
                 case Purchase::STATUS_PLANNED:
                 default:
                     $this->purchase->setOrderedAt(null);
                     $this->purchase->setDeliveredAt(null);
                     break;
             }
             return true;
         }
     }
     throw new \RuntimeException('Invalid workflow');
 }