/** * Sets progress and returns result information * * If given step is null that means, that just started the course. * * @param \Calculus\UserBundle\Entity\Profile $profile * @param \Calculus\BaranekBundle\Entity\Step $step * @return \Array */ public function setProgress(\Calculus\UserBundle\Entity\Profile $profile, \Calculus\BaranekBundle\Entity\Step $step = null) { $course = $profile->getCourse(); $old_step = $profile->getStep(); $steps = $course->getSteps(); if ($old_step === null && $step === null) { $this->response["status"] = true; $this->response["nextStepIndex"] = 0; $profile->setStep($steps->first()); } else { if ($old_step !== null && $old_step->getId() === $step->getId() && $old_step->getId() === $steps->last()->getId()) { $profile->setStep(); $profile->setCourse(); $this->addRewards($profile, $course); $this->response["status"] = true; $this->response["wasLast"] = true; } else { if ($old_step !== null && $old_step->getId() === $step->getId()) { if ($steps->contains($old_step)) { $new_index = $steps->indexOf($old_step) + 1; $new_step = $steps->get($new_index); $this->response["nextStepIndex"] = $new_index; $this->response["status"] = true; $profile->setStep($new_step); } } } } return $this->response; }