Пример #1
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);
 }
Пример #2
0
 protected function doGetListResponse(KalturaFilterPager $pager, $type = null)
 {
     $this->validateEntryIdFiltered();
     $this->translateUserIds();
     $c = KalturaCriteria::create(CuePointPeer::OM_CLASS);
     if ($type) {
         $c->add(CuePointPeer::TYPE, $type);
     }
     $entryIds = null;
     if ($this->entryIdEqual) {
         $entryIds = array($this->entryIdEqual);
     } else {
         if ($this->entryIdIn) {
             $entryIds = explode(',', $this->entryIdIn);
         }
     }
     if (!is_null($entryIds)) {
         $entryIds = entryPeer::filterEntriesByPartnerOrKalturaNetwork($entryIds, kCurrentContext::getCurrentPartnerId());
         if (!$entryIds) {
             return array(array(), 0);
         }
         $this->entryIdEqual = null;
         $this->entryIdIn = implode(',', $entryIds);
     }
     $cuePointFilter = $this->toObject();
     $cuePointFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $list = CuePointPeer::doSelect($c);
     return array($list, $c->getRecordsCount());
 }
Пример #3
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);
         }
     }
 }
 /**
  * Called on the server side and enables you to populate the object with any data from the DB
  * 
  * @param KalturaDistributionJobData $distributionJobData
  */
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaFreewheelGenericDistributionProfile) {
         return;
     }
     $this->videoAssetFilePaths = new KalturaStringArray();
     // loads all the flavor assets that should be submitted to the remote destination site
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     foreach ($flavorAssets as $flavorAsset) {
         $videoAssetFilePath = new KalturaString();
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $videoAssetFilePath->value = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
         $this->videoAssetFilePaths[] = $videoAssetFilePath;
     }
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbAssets)) {
         $thumbAsset = reset($thumbAssets);
         $syncKey = $thumbAssets->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->thumbAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
     }
     // entry cue points
     $c = KalturaCriteria::create(CuePointPeer::OM_CLASS);
     $c->add(CuePointPeer::PARTNER_ID, $distributionJobData->entryDistribution->partnerId);
     $c->add(CuePointPeer::ENTRY_ID, $distributionJobData->entryDistribution->entryId);
     $c->add(CuePointPeer::TYPE, AdCuePointPlugin::getCuePointTypeCoreValue(AdCuePointType::AD));
     $c->addAscendingOrderByColumn(CuePointPeer::START_TIME);
     $cuePointsDb = CuePointPeer::doSelect($c);
     $this->cuePoints = KalturaCuePointArray::fromDbArray($cuePointsDb);
 }
 /**
  * @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;
 }
Пример #6
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;
 }
Пример #7
0
 public function postInsert(PropelPDO $con = null)
 {
     $dbCuePoint = CuePointPeer::retrieveByPK($this->getCuePointID());
     /* @var $dbCuePoint ThumbCuePoint */
     $dbCuePoint->setAssetId($this->getId());
     $dbCuePoint->save();
     return parent::postInsert();
 }
Пример #8
0
 public function hasPeerFieldName($fieldName)
 {
     if (strpos($fieldName, '.') === false) {
         $fieldName = strtoupper($fieldName);
         $fieldName = "cue_point.{$fieldName}";
     }
     $cuePointFields = CuePointPeer::getFieldNames(BasePeer::TYPE_COLNAME);
     return in_array($fieldName, $cuePointFields);
 }
Пример #9
0
 /**
  * @param $partnerId
  * @param $entryId
  */
 protected function getCuePoints($partnerId, $entryId)
 {
     $c = KalturaCriteria::create(CuePointPeer::OM_CLASS);
     $c->add(CuePointPeer::PARTNER_ID, $partnerId);
     $c->add(CuePointPeer::ENTRY_ID, $entryId);
     $c->add(CuePointPeer::TYPE, AdCuePointPlugin::getCuePointTypeCoreValue(AdCuePointType::AD));
     $c->addAscendingOrderByColumn(CuePointPeer::START_TIME);
     return CuePointPeer::doSelect($c);
 }
 public function getFieldNameFromPeer($field_name)
 {
     if ($field_name == 'force_stop') {
         return CuePointPeer::FORCE_STOP;
     }
     if ($field_name == 'duration') {
         return CuePointPeer::DURATION;
     }
     return CuePointPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME);
 }
 /**
  * Called on the server side and enables you to populate the object with any data from the DB
  * 
  * @param KalturaDistributionJobData $distributionJobData
  */
 public function __construct(KalturaDistributionJobData $distributionJobData = null)
 {
     parent::__construct($distributionJobData);
     if (!$distributionJobData) {
         return;
     }
     if (!$distributionJobData->distributionProfile instanceof KalturaHuluDistributionProfile) {
         return;
     }
     // loads all the flavor assets that should be submitted to the remote destination site
     $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     if (count($flavorAssets)) {
         $flavorAsset = reset($flavorAssets);
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
     }
     $thumbAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->thumbAssetIds));
     if (count($thumbAssets)) {
         $thumbAsset = reset($thumbAssets);
         $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $this->thumbAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
     }
     $additionalAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->assetIds));
     $this->captionLocalPaths = new KalturaStringArray();
     if (count($additionalAssets)) {
         $captionAssetFilePathArray = array();
         foreach ($additionalAssets as $additionalAsset) {
             $assetType = $additionalAsset->getType();
             $syncKey = $additionalAsset->getSyncKey(CaptionAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
             if (kFileSyncUtils::fileSync_exists($syncKey)) {
                 if ($assetType == CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION) || $assetType == AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT)) {
                     $string = new KalturaString();
                     $string->value = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
                     $this->captionLocalPaths[] = $string;
                 }
             }
         }
     }
     $tempFieldValues = unserialize($this->fieldValues);
     $pattern = '/[^A-Za-z0-9_\\-]/';
     $seriesTitle = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::SERIES_TITLE]);
     $seasonNumber = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::SEASON_NUMBER]);
     $videoEpisodeNumber = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::VIDEO_EPISODE_NUMBER]);
     $videoTitle = preg_replace($pattern, '', $tempFieldValues[HuluDistributionField::VIDEO_TITLE]);
     $this->fileBaseName = $seriesTitle . '-' . $seasonNumber . '-' . $videoEpisodeNumber . '-' . $videoTitle;
     // entry cue points
     $c = KalturaCriteria::create(CuePointPeer::OM_CLASS);
     $c->add(CuePointPeer::PARTNER_ID, $distributionJobData->entryDistribution->partnerId);
     $c->add(CuePointPeer::ENTRY_ID, $distributionJobData->entryDistribution->entryId);
     $c->add(CuePointPeer::TYPE, AdCuePointPlugin::getCuePointTypeCoreValue(AdCuePointType::AD));
     $c->addAscendingOrderByColumn(CuePointPeer::START_TIME);
     $cuePointsDb = CuePointPeer::doSelect($c);
     $this->cuePoints = KalturaCuePointArray::fromDbArray($cuePointsDb);
 }
Пример #12
0
 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());
     }
 }
Пример #13
0
 /** (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);
 }
Пример #14
0
 public function initService($serviceId, $serviceName, $actionName)
 {
     parent::initService($serviceId, $serviceName, $actionName);
     $this->applyPartnerFilterForClass('CuePoint');
     // when session is not admin, allow access to user entries only
     if (!$this->getKs() || !$this->getKs()->isAdmin()) {
         KalturaCriterion::enableTag(KalturaCriterion::TAG_USER_SESSION);
         CuePointPeer::setUserContentOnly(true);
     }
     if (!CuePointPlugin::isAllowedPartner($this->getPartnerId())) {
         throw new KalturaAPIException(KalturaErrors::FEATURE_FORBIDDEN, CuePointPlugin::PLUGIN_NAME);
     }
     if (!$this->getPartner()->getEnabledService(PermissionName::FEATURE_KALTURA_LIVE_STREAM)) {
         throw new KalturaAPIException(KalturaErrors::FEATURE_FORBIDDEN, 'Kaltura Live Streams');
     }
 }
Пример #15
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);
         }
     }
 }
Пример #16
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;
 }
Пример #17
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;
 }
Пример #18
0
 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);
     }
 }
 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;
 }
Пример #20
0
 /**
  * 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();
 }
 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);
 }
Пример #22
0
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @return     Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = new Criteria(CuePointPeer::DATABASE_NAME);
     $criteria->add(CuePointPeer::ID, $this->id);
     if ($this->alreadyInSave && count($this->modifiedColumns) == 2 && $this->isColumnModified(CuePointPeer::UPDATED_AT)) {
         $theModifiedColumn = null;
         foreach ($this->modifiedColumns as $modifiedColumn) {
             if ($modifiedColumn != CuePointPeer::UPDATED_AT) {
                 $theModifiedColumn = $modifiedColumn;
             }
         }
         $atomicColumns = CuePointPeer::getAtomicColumns();
         if (in_array($theModifiedColumn, $atomicColumns)) {
             $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
         }
     }
     return $criteria;
 }
Пример #23
0
 /**
  *
  * @param entry $clipEntry new entry to copy and adjust cue points from root entry to
  */
 public static function copyCuePointsToClipEntry(entry $clipEntry)
 {
     $clipAtts = self::getClipAttributesFromEntry($clipEntry);
     if (!is_null($clipAtts)) {
         $sourceEntry = entryPeer::retrieveByPK($clipEntry->getSourceEntryId());
         if (is_null($sourceEntry)) {
             KalturaLog::info("Didn't copy cuePoints for entry [{$clipEntry->getId()}] because source entry [" . $clipEntry->getSourceEntryId() . "] wasn't found");
             return;
         }
         $sourceEntryDuration = $sourceEntry->getLengthInMsecs();
         $clipStartTime = $clipAtts->getOffset();
         if (is_null($clipStartTime)) {
             $clipStartTime = 0;
         }
         $clipDuration = $clipAtts->getDuration();
         if (is_null($clipDuration)) {
             $clipDuration = $sourceEntryDuration;
         }
         $c = new KalturaCriteria();
         $c->add(CuePointPeer::ENTRY_ID, $clipEntry->getSourceEntryId());
         if ($clipDuration < $sourceEntryDuration) {
             $c->addAnd(CuePointPeer::START_TIME, $clipStartTime + $clipDuration, KalturaCriteria::LESS_EQUAL);
         }
         if ($clipStartTime > 0) {
             $c->addAnd(CuePointPeer::START_TIME, $clipStartTime, KalturaCriteria::GREATER_EQUAL);
             $c->addOr(CuePointPeer::START_TIME, 0, KalturaCriteria::EQUAL);
         }
         $c->addAscendingOrderByColumn(CuePointPeer::CREATED_AT);
         $rootEntryCuePointsToCopy = CuePointPeer::doSelect($c);
         if (count($rootEntryCuePointsToCopy) <= self::MAX_CUE_POINTS_TO_COPY_TO_CLIP) {
             foreach ($rootEntryCuePointsToCopy as $cuePoint) {
                 $cuePoint->copyToClipEntry($clipEntry, $clipStartTime, $clipDuration);
             }
         } else {
             KalturaLog::alert("Can't copy cuePoints for entry [{$clipEntry->getId()}] because cuePoints count exceeded max limit of [" . self::MAX_CUE_POINTS_TO_COPY_TO_CLIP . "]");
         }
     }
 }
Пример #24
0
 /**
  * @return Annotation
  */
 protected function getParent()
 {
     if (!$this->getParentId()) {
         return null;
     }
     return CuePointPeer::retrieveByPK($this->getParentId());
 }
Пример #25
0
 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());
     }
 }
Пример #26
0
 /**
  * Retrieve multiple objects by entry id.
  *
  * @param      string $entryId the entry id.
  * @param      array $types the cue point types from CuePointType enum
  * @param      PropelPDO $con the connection to use
  * @return     CuePoint
  */
 public static function retrieveByEntryId($entryId, $types = null, PropelPDO $con = null)
 {
     $criteria = KalturaCriteria::create(CuePointPeer::OM_CLASS);
     $criteria->add(CuePointPeer::ENTRY_ID, $entryId);
     $criteria->add(CuePointPeer::STATUS, CuePointStatus::DELETED, Criteria::NOT_EQUAL);
     if (!is_null($types)) {
         $criteria->add(CuePointPeer::TYPE, $types, Criteria::IN);
     }
     return CuePointPeer::doSelect($criteria, $con);
 }
Пример #27
0
 public static function doCountOnPeer(Criteria $c)
 {
     return CuePointPeer::doCount($c);
 }
 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);
 }
Пример #29
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;
 }
Пример #30
0
 /**
  * @param $objectIds
  * @param $orderBy
  * @param $questions
  * @param $ans
  * @return array
  */
 protected function getAggregateDataForQuestions($questions, $orderBy)
 {
     $ans = array();
     foreach ($questions as $question) {
         $numOfCorrectAnswers = 0;
         /**
          * @var QuestionCuePoint $question
          */
         $c = new Criteria();
         $c->add(CuePointPeer::ENTRY_ID, $question->getEntryId());
         $c->add(CuePointPeer::TYPE, QuizPlugin::getCoreValue('CuePointType', QuizCuePointType::QUIZ_ANSWER));
         $c->add(CuePointPeer::PARENT_ID, $question->getId());
         $anonKuserIds = $this->getAnonymousKuserIds($question->getPartnerId());
         if (!empty($anonKuserIds)) {
             $c->add(CuePointPeer::KUSER_ID, $anonKuserIds, Criteria::NOT_IN);
         }
         $answers = CuePointPeer::doSelect($c);
         $numOfAnswers = 0;
         foreach ($answers as $answer) {
             /**
              * @var AnswerCuePoint $answer
              */
             $quizUserEntryId = $answer->getQuizUserEntryId();
             if ($this->isQuizUserEntrySubmitted($quizUserEntryId)) {
                 $numOfAnswers++;
                 $optionalAnswers = $question->getOptionalAnswers();
                 $correct = false;
                 foreach ($optionalAnswers as $optionalAnswer) {
                     /**
                      * @var kOptionalAnswer $optionalAnswer
                      */
                     if ($optionalAnswer->getKey() === $answer->getAnswerKey()) {
                         if ($optionalAnswer->getIsCorrect()) {
                             $numOfCorrectAnswers++;
                             break;
                         }
                     }
                 }
             }
         }
         if ($numOfAnswers) {
             $pctg = $numOfCorrectAnswers / $numOfAnswers;
         } else {
             $pctg = 0.0;
         }
         $ans[] = array('question_id' => $question->getId(), 'percentage' => $pctg * 100, 'num_of_correct_answers' => $numOfCorrectAnswers, 'num_of_wrong_answers' => $numOfAnswers - $numOfCorrectAnswers);
     }
     uasort($ans, $this->getSortFunction($orderBy));
     return $ans;
 }