Example #1
0
 public static function fromDbArray($arr, KalturaDetachedResponseProfile $responseProfile = null)
 {
     $newArr = new KalturaQuizArray();
     if ($arr == null) {
         return $newArr;
     }
     foreach ($arr as $obj) {
         $kQuiz = QuizPlugin::getQuizData($obj);
         if (!is_null($kQuiz)) {
             $quiz = new KalturaQuiz();
             $quiz->fromObject($kQuiz, $responseProfile);
             $newArr[] = $quiz;
         }
     }
     return $newArr;
 }
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
 /**
  * Allows to get a quiz
  *
  * @action get
  * @param string $entryId
  * @return KalturaQuiz
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaQuizErrors::PROVIDED_ENTRY_IS_NOT_A_QUIZ
  */
 public function getAction($entryId)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $kQuiz = QuizPlugin::getQuizData($dbEntry);
     if (is_null($kQuiz)) {
         throw new KalturaAPIException(KalturaQuizErrors::PROVIDED_ENTRY_IS_NOT_A_QUIZ, $entryId);
     }
     $quiz = new KalturaQuiz();
     $quiz->fromObject($kQuiz);
     return $quiz;
 }
Example #4
0
 /**
  * creates a pdf from quiz object
  *
  * @action servePdf
  * @param string $entryId
  * @return file
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaQuizErrors::PROVIDED_ENTRY_IS_NOT_A_QUIZ
  */
 public function servePdfAction($entryId)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $kQuiz = QuizPlugin::getQuizData($dbEntry);
     if (is_null($kQuiz)) {
         throw new KalturaAPIException(KalturaQuizErrors::PROVIDED_ENTRY_IS_NOT_A_QUIZ, $entryId);
     }
     $kp = new kQuizPdf($entryId);
     $kp->createQuestionPdf();
     return $kp->submitDocument();
 }
Example #5
0
 /**
  * sends a with an api request for pdf from quiz object
  *
  * @action getUrl
  * @param string $entryId
  * @param KalturaQuizOutputType $quizOutputType
  * @return string
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaQuizErrors::PROVIDED_ENTRY_IS_NOT_A_QUIZ
  * @throws KalturaQuizErrors::QUIZ_CANNOT_BE_DOWNLOAD
  */
 public function getUrlAction($entryId, $quizOutputType)
 {
     KalturaLog::debug("Create a URL PDF Document download for entry id [ " . $entryId . " ]");
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $kQuiz = QuizPlugin::getQuizData($dbEntry);
     if (is_null($kQuiz)) {
         throw new KalturaAPIException(KalturaQuizErrors::PROVIDED_ENTRY_IS_NOT_A_QUIZ, $entryId);
     }
     //validity check
     if (!$kQuiz->getAllowDownload()) {
         throw new KalturaAPIException(KalturaQuizErrors::QUIZ_CANNOT_BE_DOWNLOAD);
     }
     $finalPath = '/api_v3/service/quiz_quiz/action/serve/quizOutputType/';
     $finalPath .= "{$quizOutputType}";
     $finalPath .= '/entryId/';
     $finalPath .= "{$entryId}";
     $ksObj = $this->getKs();
     $ksStr = $ksObj ? $ksObj->getOriginalString() : null;
     $finalPath .= "/ks/" . $ksStr;
     $partnerId = $this->getPartnerId();
     $downloadUrl = myPartnerUtils::getCdnHost($partnerId) . $finalPath;
     return $downloadUrl;
 }