Example #1
0
 public function createQuestionPdf()
 {
     $dbEntry = entryPeer::retrieveByPK($this->entryId);
     $title = "Here are the questions from  [" . $dbEntry->getName() . "]";
     KalturaLog::debug("Questions from  [" . $dbEntry->getName() . "]");
     $this->pdf->addTitle($title, $this->titleStyle);
     $questionType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_QUESTION);
     $questions = CuePointPeer::retrieveByEntryId($this->entryId, array($questionType));
     //arange the array so that the questions will be the key for the array
     $questArray = array();
     foreach ($questions as $question) {
         $questArray[$question->getName()] = $question;
     }
     //sort the array alphabetically according to its key; i.e. the question
     ksort($questArray, SORT_LOCALE_STRING);
     $questNum = 0;
     foreach ($questArray as $question) {
         $questNum += 1;
         $this->pdf->addList($questNum, $question->getName(), $this->listWithAddLineBeforeStyle);
         $this->pdf->addHeadline(6, "Optional Answers:", $this->heading6Style);
         $ansNum = 0;
         foreach ($question->getOptionalAnswers() as $optionalAnswer) {
             $ansNum += 1;
             $this->pdf->addList($ansNum, $optionalAnswer->getText(), $this->indentListStyle);
         }
     }
 }
Example #2
0
 /**
  * @param $entryId
  * @return int
  */
 public function calculateScore()
 {
     $finalScore = 0;
     $answerType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_ANSWER);
     $answers = CuePointPeer::retrieveByEntryId($this->getEntryId(), array($answerType));
     foreach ($answers as $answer) {
         /**
          * @var AnswerCuePoint $answer
          */
         $question = CuePointPeer::retrieveByPK($answer->getParentId());
         /**
          * @var QuestionCuePoint $question
          */
         $optionalAnswers = $question->getOptionalAnswers();
         foreach ($optionalAnswers as $optionalAnswer) {
             /**
              * @var kOptionalAnswer $optionalAnswer
              */
             if ($optionalAnswer->getKey() === $answer->getAnswerKey()) {
                 if ($optionalAnswer->getIsCorrect()) {
                     $finalScore += $optionalAnswer->getWeight();
                 }
             }
         }
     }
     return $finalScore;
 }
Example #3
0
 public function calculateScoreAndCorrectAnswers()
 {
     //TODO when we have indexing of CuePoints in the sphinx we don't need the answerIds in the custom_data since we can just get the answers of the specific userEntry
     $answerIds = $this->getAnswerIds();
     $questionType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_QUESTION);
     $questions = CuePointPeer::retrieveByEntryId($this->getEntryId(), array($questionType));
     $totalPoints = 0;
     $userPoints = 0;
     $numOfCorrectAnswers = 0;
     foreach ($questions as $question) {
         $optionalAnswers = $question->getOptionalAnswers();
         $answers = array();
         if (isset($answerIds[$question->getId()])) {
             $answerId = $answerIds[$question->getId()];
             //TODO change to retrieveByPks (multiple, only one query, no need for multiple)
             $currAnswer = CuePointPeer::retrieveByPK($answerId);
             if ($currAnswer->getIsCorrect()) {
                 $numOfCorrectAnswers++;
             }
             $answers[] = $currAnswer;
         }
         list($totalForQuestion, $userPointsForQuestion) = $this->getCorrectAnswerWeight($optionalAnswers, $answers);
         $totalPoints += $totalForQuestion;
         $userPoints += $userPointsForQuestion;
     }
     $score = $totalPoints ? $userPoints / $totalPoints : 0;
     return array($score, $numOfCorrectAnswers);
 }
Example #4
0
 public function createQuestionPdf()
 {
     $dbEntry = entryPeer::retrieveByPK($this->entryId);
     $title = "Here are the questions from  [" . $dbEntry->getName() . "]";
     $this->pdf->addTitle($title, $this->titleStyle);
     $questionType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_QUESTION);
     $questions = CuePointPeer::retrieveByEntryId($this->entryId, array($questionType));
     $questNum = 0;
     foreach ($questions as $question) {
         $questNum += 1;
         $this->pdf->addList($questNum, $question->getName(), $this->listWithAddLineBeforeStyle);
         $this->pdf->addHeadline(6, "Optional Answers:", $this->heading6Style);
         $ansNum = 0;
         foreach ($question->getOptionalAnswers() as $optionalAnswer) {
             $ansNum += 1;
             $this->pdf->addList($ansNum, $optionalAnswer->getText(), $this->indentListStyle);
         }
     }
 }
Example #5
0
 public function calculateScore()
 {
     $answerIds = $this->getAnswerIds();
     $questionType = QuizPlugin::getCuePointTypeCoreValue(QuizCuePointType::QUIZ_QUESTION);
     $questions = CuePointPeer::retrieveByEntryId($this->getEntryId(), array($questionType));
     $totalPoints = 0;
     $userPoints = 0;
     foreach ($questions as $question) {
         $optionalAnswers = $question->getOptionalAnswers();
         $answers = array();
         if (isset($answerIds[$question->getId()])) {
             $answerId = $answerIds[$question->getId()];
             $currAnswer = CuePointPeer::retrieveByPK($answerId);
             $answers[] = $currAnswer;
         }
         list($totalForQuestion, $userPointsForQuestion) = $this->getCorrectAnswerWeight($optionalAnswers, $answers);
         $totalPoints += $totalForQuestion;
         $userPoints += $userPointsForQuestion;
     }
     return $totalPoints ? $userPoints / $totalPoints : 0;
 }
Example #6
0
 public function objectReplaced(BaseObject $object, BaseObject $replacingObject, BatchJob $raisedJob = null)
 {
     //replacement as a result of convertLiveSegmentFinished
     if (!$replacingObject->getIsTemporary()) {
         return true;
     }
     $c = new Criteria();
     $c->add(CuePointPeer::ENTRY_ID, $object->getId());
     if (CuePointPeer::doCount($c) > self::MAX_CUE_POINTS_TO_COPY_TO_CLIP) {
         KalturaLog::alert("Can't handle cuePoints after replacement for entry [{$object->getId()}] because cuePoints count exceeded max limit of [" . self::MAX_CUE_POINTS_TO_COPY_TO_CLIP . "]");
         return true;
     }
     $clipAttributes = self::getClipAttributesFromEntry($replacingObject);
     //replacement as a result of trimming
     if (!is_null($clipAttributes)) {
         kEventsManager::setForceDeferredEvents(true);
         $this->deleteCuePoints($c);
         //copy cuepoints from replacement entry
         $replacementCuePoints = CuePointPeer::retrieveByEntryId($replacingObject->getId());
         foreach ($replacementCuePoints as $cuePoint) {
             $newCuePoint = $cuePoint->copyToEntry($object);
             $newCuePoint->save();
         }
         kEventsManager::flushEvents();
     } else {
         if (PermissionPeer::isValidForPartner(CuePointPermissionName::REMOVE_CUE_POINTS_WHEN_REPLACING_MEDIA, $object->getPartnerId())) {
             $this->deleteCuePoints($c);
         }
     }
     return true;
 }
 public function contribute(BaseObject $object, SimpleXMLElement $mrss, kMrssParameters $mrssParams = null)
 {
     if (!$object instanceof entry) {
         return;
     }
     $cuePoints = CuePointPeer::retrieveByEntryId($object->getId());
     if (!count($cuePoints)) {
         return;
     }
     $scenes = $mrss->addChild('scenes');
     kCuePointManager::syndicate($cuePoints, $scenes);
 }
Example #8
0
 public static function getCuePointSearchData(entry $entry)
 {
     $indexOnEntryTypes = self::getIndexOnEntryTypes();
     if (!count($indexOnEntryTypes)) {
         return;
     }
     $dataByType = array();
     CuePointPeer::setUseCriteriaFilter(false);
     $cuePointObjects = CuePointPeer::retrieveByEntryId($entry->getId(), $indexOnEntryTypes);
     CuePointPeer::setUseCriteriaFilter(true);
     foreach ($cuePointObjects as $cuePoint) {
         /* @var $cuePoint CuePoint */
         $contributedData = $cuePoint->contributeData();
         if (!$contributedData) {
             continue;
         }
         $cuePointType = $cuePoint->getType();
         if (!isset($dataByType[$cuePointType])) {
             $dataByType[$cuePointType] = array();
         }
         $contributedData = self::buildDataToIndexOnEntry($contributedData, $cuePointType, $cuePoint->getPartnerId(), $cuePoint->getId(), $cuePoint->getSubType());
         $dataByType[$cuePointType][] = $contributedData;
     }
     $data = array();
     foreach ($dataByType as $type => $typeData) {
         $data = array_merge($data, $typeData);
     }
     $dataField = CuePointPlugin::getSearchFieldName(CuePointPlugin::SEARCH_FIELD_DATA);
     $searchValues = array($dataField => CuePointPlugin::PLUGIN_NAME . "_" . $entry->getPartnerId() . ' ' . implode(' ', $data) . ' ' . CuePointPlugin::SEARCH_TEXT_SUFFIX);
     return $searchValues;
 }