/** * @param KalturaFilterPager $pager * @param KalturaDetachedResponseProfile $responseProfile * @return KalturaListResponse */ public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null) { $response = new KalturaUserEntryListResponse(); if (in_array(kCurrentContext::getCurrentSessionType(), array(kSessionBase::SESSION_TYPE_NONE, kSessionBase::SESSION_TYPE_WIDGET))) { $response->totalCount = 0; return $response; } $c = new Criteria(); if (!is_null($this->userIdEqualCurrent) && $this->userIdEqualCurrent) { $this->userIdEqual = kCurrentContext::getCurrentKsKuserId(); } else { $this->fixFilterUserId(); } $userEntryFilter = $this->toObject(); $userEntryFilter->attachToCriteria($c); $pager->attachToCriteria($c); $list = UserEntryPeer::doSelect($c); $resultCount = count($list); if ($resultCount && $resultCount < $pager->pageSize) { $totalCount = ($pager->pageIndex - 1) * $pager->pageSize + $resultCount; } else { KalturaFilterPager::detachFromCriteria($c); $totalCount = UserEntryPeer::doCount($c); } $response->totalCount = $totalCount; $response->objects = KalturaUserEntryArray::fromDbArray($list, $responseProfile); return $response; }
public static function setDefaultCriteriaFilter() { if (self::$s_criteria_filter == null) { self::$s_criteria_filter = new criteriaFilter(); } $c = KalturaCriteria::create(UserEntryPeer::OM_CLASS); // when session is not admin, allow access to user's userEntries only if (kCurrentContext::$ks && !kCurrentContext::$is_admin_session) { $c->addAnd(UserEntryPeer::KUSER_ID, kCurrentContext::getCurrentKsKuserId()); } self::$s_criteria_filter->setFilter($c); }
/** * @action get * @param string $id * @return KalturaUserEntry * @throws KalturaAPIException */ public function getAction($id) { $dbUserEntry = UserEntryPeer::retrieveByPK($id); if (!$dbUserEntry) { throw new KalturaAPIException(KalturaErrors::USER_ENTRY_NOT_FOUND, $id); } $userEntry = KalturaUserEntry::getInstanceByType($dbUserEntry->getType()); if (!$userEntry) { return null; } $userEntry->fromObject($dbUserEntry); return $userEntry; }
/** * 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(KalturaErrors::INVALID_OBJECT_TYPE, $dbUserEntry->getType()); } /** * @var QuizUserEntry $dbUserEntry */ $score = $dbUserEntry->calculateScore(); $dbUserEntry->setScore($score); // $dbUserEntry->setStatus(QuizUserEntryStatus::QUIZ_SUBMITTED); $dbUserEntry->setStatus(QuizPlugin::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED)); $dbUserEntry->save(); $userEntry = new KalturaQuizUserEntry(); $userEntry->fromObject($dbUserEntry, $this->getResponseProfile()); return $userEntry; }
/** * 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; }
public function postInsert(PropelPDO $con = null) { parent::postInsert($con); $userEntry = UserEntryPeer::retrieveByPK($this->getQuizUserEntryId()); if (!is_null($userEntry)) { $userEntry->addAnswerId($this->parent_id, $this->id); $userEntry->save(); } }
protected function validateUserEntry() { $dbUserEntry = UserEntryPeer::retrieveByPK($this->quizUserEntryId); if (!$dbUserEntry) { throw new KalturaAPIException(KalturaErrors::USER_ENTRY_NOT_FOUND, $this->quizUserEntryId); } if ($dbUserEntry->getEntryId() !== $this->entryId) { throw new KalturaAPIException(KalturaCuePointErrors::USER_ENTRY_DOES_NOT_MATCH_ENTRY_ID, $this->quizUserEntryId); } if ($dbUserEntry->getStatus() === QuizPlugin::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED)) { throw new KalturaAPIException(KalturaQuizErrors::USER_ENTRY_QUIZ_ALREADY_SUBMITTED); } if (!kCurrentContext::$is_admin_session && $dbUserEntry->getKuserId() != kCurrentContext::getCurrentKsKuserId()) { throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID); } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this kuser is new, it will return * an empty collection; or if this kuser has previously * been saved, it will retrieve related UserEntrys from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in kuser. */ public function getUserEntrysJoinentry($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(kuserPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collUserEntrys === null) { if ($this->isNew()) { $this->collUserEntrys = array(); } else { $criteria->add(UserEntryPeer::KUSER_ID, $this->id); $this->collUserEntrys = UserEntryPeer::doSelectJoinentry($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(UserEntryPeer::KUSER_ID, $this->id); if (!isset($this->lastUserEntryCriteria) || !$this->lastUserEntryCriteria->equals($criteria)) { $this->collUserEntrys = UserEntryPeer::doSelectJoinentry($criteria, $con, $join_behavior); } } $this->lastUserEntryCriteria = $criteria; return $this->collUserEntrys; }
protected function getFieldNameFromPeer($field_name) { $res = UserEntryPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME); return $res; }
/** * 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(UserEntryPeer::DATABASE_NAME); $criteria->add(UserEntryPeer::ID, $this->id); if ($this->alreadyInSave) { if ($this->isColumnModified(UserEntryPeer::CUSTOM_DATA)) { if (!is_null($this->custom_data_md5)) { $criteria->add(UserEntryPeer::CUSTOM_DATA, "MD5(cast(" . UserEntryPeer::CUSTOM_DATA . " as char character set latin1)) = '{$this->custom_data_md5}'", Criteria::CUSTOM); } else { $criteria->add(UserEntryPeer::CUSTOM_DATA, NULL, Criteria::ISNULL); } } if (count($this->modifiedColumns) == 2 && $this->isColumnModified(UserEntryPeer::UPDATED_AT)) { $theModifiedColumn = null; foreach ($this->modifiedColumns as $modifiedColumn) { if ($modifiedColumn != UserEntryPeer::UPDATED_AT) { $theModifiedColumn = $modifiedColumn; } } $atomicColumns = UserEntryPeer::getAtomicColumns(); if (in_array($theModifiedColumn, $atomicColumns)) { $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL); } } } return $criteria; }
protected function isQuizUserEntrySubmitted($quizUserEntryId) { $ans = false; $quizUserEntry = UserEntryPeer::retrieveByPK($quizUserEntryId); if ($quizUserEntry) { if ($quizUserEntry->getStatus() == self::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED)) { $ans = true; } } return $ans; }
/** * @param $objectIds * @return array * @throws Exception */ protected function getTotalReport($objectIds) { if (!$objectIds) { throw new Exception(KalturaQuizErrors::ENTRY_ID_NOT_GIVEN); } $avg = -1; $dbEntry = entryPeer::retrieveByPK($objectIds); if (!$dbEntry) { throw new Exception(KalturaErrors::ENTRY_ID_NOT_FOUND, $objectIds); } /** * @var kQuiz $kQuiz */ $kQuiz = QuizPlugin::validateAndGetQuiz($dbEntry); $c = new Criteria(); $c->add(UserEntryPeer::ENTRY_ID, $objectIds); $c->add(UserEntryPeer::TYPE, QuizPlugin::getCoreValue('UserEntryType', QuizUserEntryType::QUIZ)); $c->add(UserEntryPeer::STATUS, QuizPlugin::getCoreValue('UserEntryStatus', QuizUserEntryStatus::QUIZ_SUBMITTED)); $quizzes = UserEntryPeer::doSelect($c); $numOfQuizzesFound = count($quizzes); KalturaLog::debug("Found {$numOfQuizzesFound} quizzes that were submitted"); if ($numOfQuizzesFound) { $sumOfScores = 0; foreach ($quizzes as $quiz) { /** * @var QuizUserEntry $quiz */ $sumOfScores += $quiz->getScore(); } $avg = $sumOfScores / $numOfQuizzesFound; } return array(array('average' => $avg)); }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(UserEntryPeer::DATABASE_NAME); $criteria->add(UserEntryPeer::ID, $pks, Criteria::IN); $objs = UserEntryPeer::doSelect($criteria, $con); } return $objs; }