Example #1
0
 /**
  * Submits the quiz so that it's status will be submitted and calculates the score for the quiz
  *
  * @action submitQuiz
  * @actionAlias userEntry.submitQuiz
  * @param int $id
  * @return KalturaQuizUserEntry
  * @throws KalturaAPIException
  */
 public function submitQuizAction($id)
 {
     $dbUserEntry = UserEntryPeer::retrieveByPK($id);
     if (!$dbUserEntry) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id);
     }
     if ($dbUserEntry->getType() != QuizPlugin::getCoreValue('UserEntryType', QuizUserEntryType::QUIZ)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_TYPE, $dbUserEntry->getType());
     }
     /**
      * @var QuizUserEntry $dbUserEntry
      */
     $score = $dbUserEntry->calculateScore();
     $dbUserEntry->setScore($score);
     //		$dbUserEntry->setStatus(QuizUserEntryStatus::QUIZ_SUBMITTED);
     $dbUserEntry->setStatus(QuizPlugin::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED));
     $dbUserEntry->save();
     $userEntry = new KalturaQuizUserEntry();
     $userEntry->fromObject($dbUserEntry, $this->getResponseProfile());
     return $userEntry;
 }
Example #2
0
 /**
  * Submits the quiz so that it's status will be submitted and calculates the score for the quiz
  *
  * @action submitQuiz
  * @actionAlias userEntry.submitQuiz
  * @param int $id
  * @return KalturaQuizUserEntry
  * @throws KalturaAPIException
  */
 public function submitQuizAction($id)
 {
     $dbUserEntry = UserEntryPeer::retrieveByPK($id);
     if (!$dbUserEntry) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $id);
     }
     if ($dbUserEntry->getType() != QuizPlugin::getCoreValue('UserEntryType', QuizUserEntryType::QUIZ)) {
         throw new KalturaAPIException(KalturaQuizErrors::PROVIDED_ENTRY_IS_NOT_A_QUIZ, $id);
     }
     $dbUserEntry->setStatus(QuizPlugin::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED));
     $userEntry = new KalturaQuizUserEntry();
     $userEntry->fromObject($dbUserEntry, $this->getResponseProfile());
     $entryId = $dbUserEntry->getEntryId();
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $entryId);
     }
     $kQuiz = QuizPlugin::getQuizData($entry);
     if (!$kQuiz) {
         throw new KalturaAPIException(KalturaQuizErrors::PROVIDED_ENTRY_IS_NOT_A_QUIZ, $entryId);
     }
     list($score, $numOfCorrectAnswers) = $dbUserEntry->calculateScoreAndCorrectAnswers();
     $dbUserEntry->setScore($score);
     $dbUserEntry->setNumOfCorrectAnswers($numOfCorrectAnswers);
     if ($kQuiz->getShowGradeAfterSubmission() == KalturaNullableBoolean::TRUE_VALUE || $this->getKs()->isAdmin() == true) {
         $userEntry->score = $score;
     } else {
         $userEntry->score = null;
     }
     $c = new Criteria();
     $c->add(CuePointPeer::ENTRY_ID, $dbUserEntry->getEntryId(), Criteria::EQUAL);
     $c->add(CuePointPeer::TYPE, QuizPlugin::getCoreValue('CuePointType', QuizCuePointType::QUIZ_QUESTION));
     $dbUserEntry->setNumOfQuestions(CuePointPeer::doCount($c));
     $dbUserEntry->setStatus(QuizPlugin::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED));
     $dbUserEntry->save();
     return $userEntry;
 }
Example #3
0
 public function getMetadataObjectType()
 {
     return QuizPlugin::getCoreValue('MetadataObjectType', QuizCuePointMetadataObjectType::ANSWER_CUE_POINT);
 }
 protected function validateUserEntry()
 {
     $dbUserEntry = UserEntryPeer::retrieveByPK($this->quizUserEntryId);
     if (!$dbUserEntry) {
         throw new KalturaAPIException(KalturaErrors::USER_ENTRY_NOT_FOUND, $this->quizUserEntryId);
     }
     if ($dbUserEntry->getEntryId() !== $this->entryId) {
         throw new KalturaAPIException(KalturaCuePointErrors::USER_ENTRY_DOES_NOT_MATCH_ENTRY_ID, $this->quizUserEntryId);
     }
     if ($dbUserEntry->getStatus() === QuizPlugin::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED)) {
         throw new KalturaAPIException(KalturaQuizErrors::USER_ENTRY_QUIZ_ALREADY_SUBMITTED);
     }
     if (!kCurrentContext::$is_admin_session && $dbUserEntry->getKuserId() != kCurrentContext::getCurrentKsKuserId()) {
         throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
     }
 }
 public function getTypeListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null, $type = null)
 {
     return parent::getTypeListResponse($pager, $responseProfile, QuizPlugin::getCoreValue('CuePointType', QuizCuePointType::QUIZ_QUESTION));
 }
Example #6
0
 public function applyDefaultValues()
 {
     parent::applyDefaultValues();
     $this->setType(QuizPlugin::getCoreValue('UserEntryType', QuizUserEntryType::QUIZ));
 }
Example #7
0
 /**
  * @param $objectIds
  * @param $orderBy
  * @param $questions
  * @param $ans
  * @return array
  */
 protected function getAggregateDataForQuestions($questions, $orderBy)
 {
     $ans = array();
     foreach ($questions as $question) {
         $numOfCorrectAnswers = 0;
         /**
          * @var QuestionCuePoint $question
          */
         $c = new Criteria();
         $c->add(CuePointPeer::ENTRY_ID, $question->getEntryId());
         $c->add(CuePointPeer::TYPE, QuizPlugin::getCoreValue('CuePointType', QuizCuePointType::QUIZ_ANSWER));
         $c->add(CuePointPeer::PARENT_ID, $question->getId());
         $anonKuserIds = $this->getAnonymousKuserIds($question->getPartnerId());
         if (!empty($anonKuserIds)) {
             $c->add(CuePointPeer::KUSER_ID, $anonKuserIds, Criteria::NOT_IN);
         }
         $answers = CuePointPeer::doSelect($c);
         $numOfAnswers = 0;
         foreach ($answers as $answer) {
             /**
              * @var AnswerCuePoint $answer
              */
             $quizUserEntryId = $answer->getQuizUserEntryId();
             if ($this->isQuizUserEntrySubmitted($quizUserEntryId)) {
                 $numOfAnswers++;
                 $optionalAnswers = $question->getOptionalAnswers();
                 $correct = false;
                 foreach ($optionalAnswers as $optionalAnswer) {
                     /**
                      * @var kOptionalAnswer $optionalAnswer
                      */
                     if ($optionalAnswer->getKey() === $answer->getAnswerKey()) {
                         if ($optionalAnswer->getIsCorrect()) {
                             $numOfCorrectAnswers++;
                             break;
                         }
                     }
                 }
             }
         }
         if ($numOfAnswers) {
             $pctg = $numOfCorrectAnswers / $numOfAnswers;
         } else {
             $pctg = 0.0;
         }
         $ans[] = array('question_id' => $question->getId(), 'percentage' => $pctg * 100, 'num_of_correct_answers' => $numOfCorrectAnswers, 'num_of_wrong_answers' => $numOfAnswers - $numOfCorrectAnswers);
     }
     uasort($ans, $this->getSortFunction($orderBy));
     return $ans;
 }
Example #8
0
 /**
  * @param $objectIds
  * @param $c criteria
  * @return criteria
  */
 protected function createGetCuePointByUserIdsCriteria($objectIds, $c)
 {
     $c->add(CuePointPeer::TYPE, QuizPlugin::getCoreValue('CuePointType', QuizCuePointType::QUIZ_ANSWER));
     $userIds = QuizPlugin::getObjectIdsAsArray($objectIds);
     $kuserIds = array();
     foreach ($userIds as $userId) {
         $kuser = kuserPeer::getKuserByPartnerAndUid(kCurrentContext::$ks_partner_id, $userId);
         if ($kuser) {
             $kuserIds[] = $kuser->getKuserId();
         }
     }
     $c->add(CuePointPeer::KUSER_ID, $kuserIds, Criteria::IN);
     return $c;
 }
Example #9
0
 /**
  * KalturaQuizUserEntry constructor.
  */
 public function __construct()
 {
     $this->type = QuizPlugin::getCoreValue('UserEntryType', QuizUserEntryType::QUIZ);
 }