public function doFromObject($dbObject, KalturaDetachedResponseProfile $responseProfile = null)
 {
     parent::doFromObject($dbObject, $responseProfile);
     $dbEntry = entryPeer::retrieveByPK($dbObject->getEntryId());
     if (!QuizPlugin::validateUserEntitledForQuizEdit($dbEntry)) {
         /**
          * @var kQuiz $kQuiz
          */
         $kQuiz = QuizPlugin::validateAndGetQuiz($dbEntry);
         $dbUserEntry = UserEntryPeer::retrieveByPK($this->quizUserEntryId);
         if ($dbUserEntry && $dbUserEntry->getStatus() == QuizPlugin::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED)) {
             if (!$kQuiz->getShowCorrectAfterSubmission()) {
                 $this->isCorrect = KalturaNullableBoolean::NULL_VALUE;
                 $this->correctAnswerKeys = null;
                 $this->explanation = null;
             }
         } else {
             if (!$kQuiz->getShowResultOnAnswer()) {
                 $this->isCorrect = KalturaNullableBoolean::NULL_VALUE;
             }
             if (!$kQuiz->getShowCorrectKeyOnAnswer()) {
                 $this->correctAnswerKeys = null;
                 $this->explanation = null;
             }
         }
     }
 }
 public function validateForInsert($propertiesToSkip = array())
 {
     parent::validateForInsert($propertiesToSkip);
     $dbEntry = entryPeer::retrieveByPK($this->entryId);
     QuizPlugin::validateAndGetQuiz($dbEntry);
     if (!QuizPlugin::validateUserEntitledForQuizEdit($dbEntry)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
     }
 }
 public function validateForInsert($propertiesToSkip = array())
 {
     parent::validateForInsert($propertiesToSkip);
     $dbEntry = entryPeer::retrieveByPK($this->entryId);
     QuizPlugin::validateAndGetQuiz($dbEntry);
     if (!QuizPlugin::validateUserEntitledForQuizEdit($dbEntry)) {
         KalturaLog::debug('Update quiz questions is allowed only with admin KS or entry owner or co-editor');
         throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
     }
 }
Example #4
0
 /**
  * if user is entitled for this action will update quizData on entry
  * @param entry $dbEntry
  * @param KalturaQuiz $quiz
  * @param int $currentVersion
  * @param kQuiz|null $newQuiz
  * @return KalturaQuiz
  * @throws KalturaAPIException
  */
 private function validateAndUpdateQuizData(entry $dbEntry, KalturaQuiz $quiz, $currentVersion = 0, kQuiz $newQuiz = null)
 {
     if (!QuizPlugin::validateUserEntitledForQuizEdit($dbEntry)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
     }
     $quizData = $quiz->toObject($newQuiz);
     $quizData->setVersion($currentVersion + 1);
     QuizPlugin::setQuizData($dbEntry, $quizData);
     $dbEntry->setIsTrimDisabled(true);
     $dbEntry->save();
     $quiz->fromObject($quizData);
     return $quiz;
 }