Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 /**
  * Gets an array of UserEntry objects which contain a foreign key that references this object.
  *
  * If this collection has already been initialized with an identical Criteria, it returns the collection.
  * Otherwise if this kuser has previously been saved, it will retrieve
  * related UserEntrys from storage. If this kuser is new, it will return
  * an empty collection or the current collection, the criteria is ignored on a new object.
  *
  * @param      PropelPDO $con
  * @param      Criteria $criteria
  * @return     array UserEntry[]
  * @throws     PropelException
  */
 public function getUserEntrys($criteria = null, PropelPDO $con = null)
 {
     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);
             UserEntryPeer::addSelectColumns($criteria);
             $this->collUserEntrys = UserEntryPeer::doSelect($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // 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);
             UserEntryPeer::addSelectColumns($criteria);
             if (!isset($this->lastUserEntryCriteria) || !$this->lastUserEntryCriteria->equals($criteria)) {
                 $this->collUserEntrys = UserEntryPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastUserEntryCriteria = $criteria;
     return $this->collUserEntrys;
 }
Exemplo n.º 3
0
 protected function getUserPrecentageByUserAndEntryTable($entryIds, $inputFilter, $orderBy)
 {
     $userIds = $this->getUserIdsFromFilter($inputFilter);
     $noEntryIds = QuizPlugin::isWithoutValue($entryIds);
     $noUserIds = QuizPlugin::isWithoutValue($userIds);
     if ($noEntryIds && $noUserIds) {
         return array();
     }
     $c = new Criteria();
     if (!$noUserIds) {
         $c->add(UserEntryPeer::KUSER_ID, $this->getKuserIds($userIds), Criteria::IN);
     }
     if (!$noEntryIds) {
         $entryIdsArray = explode(",", $entryIds);
         $dbEntries = entryPeer::retrieveByPKs($entryIdsArray);
         if (empty($dbEntries)) {
             throw new kCoreException("", kCoreException::INVALID_ENTRY_ID, $entryIds);
         }
         $c->add(UserEntryPeer::ENTRY_ID, $entryIdsArray, Criteria::IN);
         $hasAnonymous = false;
         foreach ($dbEntries as $dbEntry) {
             $anonKuserIds = $this->getAnonymousKuserIds($dbEntry->getPartnerId());
             if (!empty($anonKuserIds)) {
                 $hasAnonymous = true;
                 break;
             }
         }
         if ($hasAnonymous) {
             $c->addAnd(UserEntryPeer::KUSER_ID, $anonKuserIds, Criteria::NOT_IN);
         }
     }
     $userEntries = UserEntryPeer::doSelect($c);
     return $this->getAggregateDataForUsers($userEntries, $orderBy);
 }
Exemplo n.º 4
0
 /**
  * @param $objectIds
  * @return array
  * @throws kCoreException
  */
 protected function getTotalReport($objectIds)
 {
     if (!$objectIds) {
         throw new kCoreException("", kCoreException::INVALID_ENTRY_ID, $objectIds);
     }
     $avg = 0;
     $dbEntry = entryPeer::retrieveByPK($objectIds);
     if (!$dbEntry) {
         throw new kCoreException("", kCoreException::INVALID_ENTRY_ID, $objectIds);
     }
     $kQuiz = self::getQuizData($dbEntry);
     if (!$kQuiz) {
         return array(array('average' => null));
     }
     $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));
     $anonKuser = $this->getAnonymousKuser($dbEntry->getPartnerId());
     if (!is_null($anonKuser)) {
         $c->add(UserEntryPeer::KUSER_ID, $anonKuser->getKuserId(), Criteria::NOT_IN);
     }
     $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));
 }
Exemplo n.º 5
0
 /**
  * @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));
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * @param $objectIds
  * @return array
  * @throws kCoreException
  */
 protected function getTotalReport($objectIds)
 {
     if (!$objectIds) {
         throw new kCoreException("", kCoreException::INVALID_ENTRY_ID, $objectIds);
     }
     $avg = 0;
     $dbEntry = entryPeer::retrieveByPK($objectIds);
     if (!$dbEntry) {
         throw new kCoreException("", kCoreException::INVALID_ENTRY_ID, $objectIds);
     }
     $kQuiz = self::getQuizData($dbEntry);
     if (!$kQuiz) {
         return array(array('average' => null));
     }
     $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);
     if ($numOfQuizzesFound) {
         $sumOfScores = 0;
         foreach ($quizzes as $quiz) {
             /**
              * @var QuizUserEntry $quiz
              */
             $sumOfScores += $quiz->getScore();
         }
         $avg = $sumOfScores / $numOfQuizzesFound;
     }
     return array(array('average' => $avg));
 }