Ejemplo n.º 1
0
 /**
  * @param StateMachineContext $context
  * @param StateMachineEvent|null $event - this is null when an item enters the SM for the first time
  * @return static
  */
 public static function nu(StateMachineContext $context, $event)
 {
     $j = new static();
     $m = $context->getModel();
     $j->role = $context->getRole();
     $user = $context->getUser();
     if ($user) {
         $j->created_by = $user->getId();
     }
     $j->model = $m::className();
     $j->sm_name = $context->getSm()->name;
     $j->attr = $context->getAttr();
     $j->model_pk = $context->getModelPk();
     if ($event) {
         $j->from_state = $event->getState()->getValue();
         $j->to_state = $event->getTargetState()->getValue();
     } else {
         $j->from_state = null;
         $j->to_state = $context->getSm()->getInitialStateValue();
     }
     $j->save();
     return $j;
 }