/**
  * Create a new progression for a User and a Step (by default, the first action is 'seen')
  * @param Step $step
  * @param User $user
  * @param string $status
  * @return \Innova\PathBundle\Entity\UserProgression
  */
 public function create(Step $step, User $user = null, $status = null)
 {
     if (empty($user)) {
         // Load current logged User
         $user = $this->securityToken->getToken()->getUser();
     }
     $progression = new UserProgression();
     $progression->setUser($user);
     $progression->setStep($step);
     if (empty($status)) {
         $status = UserProgression::getDefaultStatus();
     }
     $progression->setStatus($status);
     $this->om->persist($progression);
     $this->om->flush();
     return $progression;
 }
 /**
  * Update state of the lock for User Progression for a step.
  *
  * @param User      $user
  * @param Step      $step
  * @param bool|null $lockedcall
  * @param bool|null $lock
  * @param bool|null $authorized
  *
  * @return object UserProgression
  */
 public function updateLockedState(User $user, Step $step, $lockedcall = null, $lock = null, $authorized = null, $status = '')
 {
     // Retrieve the current progression for this step
     $progression = $this->om->getRepository('InnovaPathBundle:UserProgression')->findOneBy(['step' => $step, 'user' => $user]);
     if ($progression === null) {
         $progression = new UserProgression();
         $progression->setUser($user);
         $progression->setStep($step);
         $progression->setStatus($status);
         $progression->setAuthorized(false);
     }
     //if unlock call has changed
     if ($lockedcall !== null) {
         $progression->setLockedcall($lockedcall);
     }
     //if lock state has changed
     if ($lock !== null) {
         $progression->setLocked($lock);
     }
     //if authorization has changed
     if ($authorized !== null) {
         $progression->setAuthorized($authorized);
     }
     //if status has changed
     if ($status !== null) {
         $progression->setStatus($status);
     }
     $this->om->persist($progression);
     $this->om->flush();
     return $progression;
 }