/** * @param SimpleXMLElement $scene * @param int $partnerId * @param CuePoint $newCuePoint * @return CuePoint */ public static function parseXml(SimpleXMLElement $scene, $partnerId, CuePoint $newCuePoint = null) { $cuePoint = null; if (isset($scene['sceneId']) && $scene['sceneId']) { $cuePoint = CuePointPeer::retrieveByPK($scene['sceneId']); } if (!$cuePoint && isset($scene['systemName']) && $scene['systemName']) { $cuePoint = CuePointPeer::retrieveBySystemName($scene['entryId'], $scene['systemName']); } if (!$cuePoint) { $cuePoint = $newCuePoint; } $cuePoint->setPartnerId($partnerId); $cuePoint->setStartTime(kXml::timeToInteger($scene->sceneStartTime)); $tags = array(); foreach ($scene->tags->children() as $tag) { $value = "{$tag}"; if ($value) { $tags[] = $value; } } $cuePoint->setTags(implode(',', $tags)); $cuePoint->setEntryId($scene['entryId']); if (isset($scene['systemName'])) { $cuePoint->setSystemName($scene['systemName']); } return $cuePoint; }
/** * @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; }
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); }
public function postInsert(PropelPDO $con = null) { $dbCuePoint = CuePointPeer::retrieveByPK($this->getCuePointID()); /* @var $dbCuePoint ThumbCuePoint */ $dbCuePoint->setAssetId($this->getId()); $dbCuePoint->save(); return parent::postInsert(); }
public function validateCuePointAssociation() { $this->validatePropertyNotNull("cuePointId"); $dbCuePoint = CuePointPeer::retrieveByPK($this->cuePointId); if (!$dbCuePoint) { throw new KalturaAPIException(KalturaCuePointErrors::CUE_POINT_NOT_FOUND, $this->cuePointId); } if (!$dbCuePoint instanceof ThumbCuePoint) { throw new KalturaAPIException(KalturaCuePointErrors::CUE_POINT_PROVIDED_NOT_OF_TYPE_THUMB_CUE_POINT, $this->cuePointId); } if ($dbCuePoint->getAssetId() != null) { throw new KalturaAPIException(KalturaCuePointErrors::CUE_POINT_ALREADY_ASSOCIATED_WITH_ASSET, $dbCuePoint->getAssetId()); } }
/** (non-PHPdoc) * @see BaseCuePoint::preInsert() */ public function preInsert(PropelPDO $con = null) { $dbParentCuePoint = CuePointPeer::retrieveByPK($this->getParentId()); $optionalAnswers = $dbParentCuePoint->getOptionalAnswers(); $correctKeys = array(); foreach ($optionalAnswers as $answer) { if ($answer->getIsCorrect()) { $correctKeys[] = $answer->getKey(); } } $this->setCorrectAnswerKeys($correctKeys); $this->setExplanation($dbParentCuePoint->getExplanation()); $this->setIsCorrect(in_array($this->getAnswerKey(), $correctKeys)); return parent::preInsert($con); }
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; }
public function getCuePointByTimedThumbAsset(timedThumbAsset $timedThumbAsset) { $cuePointId = $timedThumbAsset->getCuePointID(); if (!$cuePointId) { KalturaLog::debug("CuePoint Id not found on object"); return null; } $cuePoint = CuePointPeer::retrieveByPK($cuePointId); if (!$cuePoint) { KalturaLog::debug("CuePoint with ID [{$cuePointId}] not found"); return null; } return $cuePoint; }
public static function syndicate(CuePoint $cuePoint, SimpleXMLElement $scenes, SimpleXMLElement $scene = null) { if (!$cuePoint instanceof Annotation) { return $scene; } if (!$scene) { $scene = kCuePointManager::syndicateCuePointXml($cuePoint, $scenes->addChild('scene-annotation')); } $scene->addChild('sceneEndTime', kXml::integerToTime($cuePoint->getEndTime())); if ($cuePoint->getText()) { $scene->addChild('sceneText', kMrssManager::stringToSafeXml($cuePoint->getText())); } if ($cuePoint->getParentId()) { $parentCuePoint = CuePointPeer::retrieveByPK($cuePoint->getParentId()); if ($parentCuePoint) { if ($parentCuePoint->getSystemName()) { $scene->addChild('parent', kMrssManager::stringToSafeXml($parentCuePoint->getSystemName())); } $scene->addChild('parentId', $parentCuePoint->getId()); } } return $scene; }
public function validateParentId($cuePointId = null) { if ($this->isNull('parentId')) { throw new KalturaAPIException(KalturaQuizErrors::PARENT_ID_IS_MISSING); } $dbParentCuePoint = CuePointPeer::retrieveByPK($this->parentId); if (!$dbParentCuePoint) { throw new KalturaAPIException(KalturaCuePointErrors::PARENT_CUE_POINT_NOT_FOUND, $this->parentId); } if (!$dbParentCuePoint instanceof QuestionCuePoint) { throw new KalturaAPIException(KalturaQuizErrors::WRONG_PARENT_TYPE, $this->parentId); } if ($dbParentCuePoint->getEntryId() != $this->entryId) { throw new KalturaAPIException(KalturaCuePointErrors::PARENT_CUE_POINT_DO_NOT_BELONG_TO_THE_SAME_ENTRY); } }
/** * delete cue point by id, and delete all children cue points * * @action delete * @param string $id * @throws KalturaCuePointErrors::INVALID_CUE_POINT_ID * @validateUser CuePoint id editcuepoint */ function deleteAction($id) { $dbCuePoint = CuePointPeer::retrieveByPK($id); if (!$dbCuePoint) { throw new KalturaAPIException(KalturaCuePointErrors::INVALID_CUE_POINT_ID, $id); } if ($this->getCuePointType() && $dbCuePoint->getType() != $this->getCuePointType()) { throw new KalturaAPIException(KalturaCuePointErrors::INVALID_CUE_POINT_ID, $id); } $this->validateUserLog($dbCuePoint); $dbCuePoint->setStatus(CuePointStatus::DELETED); $dbCuePoint->save(); }
/** * @param SimpleXMLElement $scene * @param int $partnerId * @param CuePoint $newCuePoint * @return CuePoint */ public static function parseXml(SimpleXMLElement $scene, $partnerId, CuePoint $newCuePoint = null) { $cuePoint = null; $entryId = $scene['entryId']; $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { throw new kCoreException("Entry [{$entryId}] not found", kCoreException::INVALID_ENTRY_ID); } if (isset($scene['sceneId']) && $scene['sceneId']) { $cuePoint = CuePointPeer::retrieveByPK($scene['sceneId']); } if (!$cuePoint && isset($scene['systemName']) && $scene['systemName']) { $cuePoint = CuePointPeer::retrieveBySystemName($entryId, $scene['systemName']); } if (!$cuePoint) { $cuePoint = $newCuePoint; } $cuePoint->setPartnerId($partnerId); $cuePoint->setStartTime(kXml::timeToInteger($scene->sceneStartTime)); $tags = array(); foreach ($scene->tags->children() as $tag) { $value = "{$tag}"; if ($value) { $tags[] = $value; } } $cuePoint->setTags(implode(',', $tags)); $cuePoint->setEntryId($entryId); if (isset($scene['systemName'])) { $cuePoint->setSystemName($scene['systemName']); } return $cuePoint; }
/** * @return Annotation */ protected function getParent() { if (!$this->getParentId()) { return null; } return CuePointPeer::retrieveByPK($this->getParentId()); }
public function validateStartTime($cuePointId = null) { if ($this->startTime === null) { $this->startTime = 0; } if ($this->startTime < 0) { throw new KalturaAPIException(KalturaCuePointErrors::START_TIME_CANNOT_BE_LESS_THAN_0); } if ($cuePointId !== null) { //update $dbCuePoint = CuePointPeer::retrieveByPK($cuePointId); if (!$dbCuePoint) { throw new KalturaAPIException(KalturaCuePointErrors::INVALID_OBJECT_ID, $cuePointId); } $dbEntry = entryPeer::retrieveByPK($dbCuePoint->getEntryId()); } else { $dbEntry = entryPeer::retrieveByPK($this->entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryId); } } if ($dbEntry->getType() != entryType::LIVE_STREAM && $dbEntry->getLengthInMsecs() && $dbEntry->getLengthInMsecs() < $this->startTime) { throw new KalturaAPIException(KalturaCuePointErrors::START_TIME_IS_BIGGER_THAN_ENTRY_END_TIME, $this->startTime, $dbEntry->getLengthInMsecs()); } }
public function getRoots() { $ret = array(); $parent = null; $roots = array($this->getId()); if ($this->getParentId()) { $ret[] = 'parent ' . $this->getParentId(); $parent = CuePointPeer::retrieveByPK($this->getParentId()); } while ($parent) { $parentId = $parent->getId(); if (in_array($parentId, $roots)) { break; } $ret[] = "root {$parentId}"; $roots[] = $parentId; if ($parent->getParentId()) { $parent = CuePointPeer::retrieveByPK($parent->getParentId()); } else { $parent = null; } } if ($this->getEntryId()) { $ret[] = 'entry ' . $this->getEntryId(); } return implode(',', $ret); }