Exemplo n.º 1
0
 /**
  * @action get
  * @param string $id
  * @return KalturaUserEntry
  * @throws KalturaAPIException
  */
 public function getAction($id)
 {
     $dbUserEntry = UserEntryPeer::retrieveByPK($id);
     if (!$dbUserEntry) {
         throw new KalturaAPIException(KalturaErrors::USER_ENTRY_NOT_FOUND, $id);
     }
     $userEntry = KalturaUserEntry::getInstanceByType($dbUserEntry->getType());
     if (!$userEntry) {
         return null;
     }
     $userEntry->fromObject($dbUserEntry);
     return $userEntry;
 }
Exemplo n.º 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(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;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 public function postInsert(PropelPDO $con = null)
 {
     parent::postInsert($con);
     $userEntry = UserEntryPeer::retrieveByPK($this->getQuizUserEntryId());
     if (!is_null($userEntry)) {
         $userEntry->addAnswerId($this->parent_id, $this->id);
         $userEntry->save();
     }
 }
Exemplo n.º 5
0
 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);
     }
 }
Exemplo n.º 6
0
 protected function isQuizUserEntrySubmitted($quizUserEntryId)
 {
     $ans = false;
     $quizUserEntry = UserEntryPeer::retrieveByPK($quizUserEntryId);
     if ($quizUserEntry) {
         if ($quizUserEntry->getStatus() == self::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED)) {
             $ans = true;
         }
     }
     return $ans;
 }