Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * Returns number of steps before given one (given one is also count)
  * 
  * @param Calculus\BaranekBundle\Entity\Step type $step
  * @return integer - number of steps before given one (given one is also count)
  */
 public function getPassedNo(\Calculus\BaranekBundle\Entity\Step $step) : int
 {
     $order_val = $step->getOrderValue();
     $course_id = $step->getCourse()->getId();
     $result = $this->createQueryBuilder('s')->select('s.id')->where('s.course = :course_id AND s.order_value <= :order_val ')->setParameter('course_id', $course_id)->setParameter('order_val', $order_val)->getQuery()->getResult();
     return count($result);
 }
Пример #3
0
 /**
  * Checks if user's answers are correct.
  * 
  * @param \Calculus\BaranekBundle\Entity\Step $step
  * @param \Array $answers
  * @return boolean
  */
 public function check(\Calculus\BaranekBundle\Entity\Step $step, array $answers) : bool
 {
     $type = $step->getStructureType();
     try {
         $checker = $this->factory->getChecker($type);
     } catch (\Exception $ex) {
         return false;
     }
     return $checker->isCorrect($answers);
 }