public function attachToCriteria(Criteria $c) { $limit = $this->pageSize; if ($limit > baseObjectFilter::getMaxInValues()) { $limit = baseObjectFilter::getMaxInValues(); } $page = max($this->minPageIndex, $this->pageIndex); $offset = ($page - 1) * $limit; $c->setLimit($limit); if ($offset > 0) { $c->setOffset($offset); } }
protected function doGetListResponse(KalturaFilterPager $pager, array $types = null) { $this->validateEntryIdFiltered(); myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2; // verify access to the relevant entries - either same partner as the KS or kaltura network if ($this->entryIdEqual) { $entryIds = array($this->entryIdEqual); } else { if ($this->entryIdIn) { $entryIds = explode(',', $this->entryIdIn); } else { throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL, 'KalturaAssetFilter::entryIdEqual/KalturaAssetFilter::entryIdIn'); } } $entryIds = array_slice($entryIds, 0, baseObjectFilter::getMaxInValues()); $c = KalturaCriteria::create(entryPeer::OM_CLASS); $c->addAnd(entryPeer::ID, $entryIds, Criteria::IN); $criterionPartnerOrKn = $c->getNewCriterion(entryPeer::PARTNER_ID, kCurrentContext::getCurrentPartnerId()); $criterionPartnerOrKn->addOr($c->getNewCriterion(entryPeer::DISPLAY_IN_SEARCH, mySearchUtils::DISPLAY_IN_SEARCH_KALTURA_NETWORK)); $c->addAnd($criterionPartnerOrKn); $dbEntries = entryPeer::doSelect($c); if (!$dbEntries) { return array(array(), 0); } $entryIds = array(); foreach ($dbEntries as $dbEntry) { $entryIds[] = $dbEntry->getId(); } $this->entryIdEqual = null; $this->entryIdIn = implode(',', $entryIds); // get the flavors $flavorAssetFilter = new AssetFilter(); $this->toObject($flavorAssetFilter); $c = new Criteria(); $flavorAssetFilter->attachToCriteria($c); if ($types) { $c->add(assetPeer::TYPE, $types, Criteria::IN); } $pager->attachToCriteria($c); $list = assetPeer::doSelect($c); $resultCount = count($list); if ($resultCount && $resultCount < $pager->pageSize) { $totalCount = ($pager->pageIndex - 1) * $pager->pageSize + $resultCount; } else { KalturaFilterPager::detachFromCriteria($c); $totalCount = assetPeer::doCount($c); } myDbHelper::$use_alternative_con = null; return array($list, $totalCount); }
/** * List cue point objects by filter and pager * * @action list * @param KalturaCuePointFilter $filter * @param KalturaFilterPager $pager * @return KalturaCuePointListResponse */ function listAction(KalturaCuePointFilter $filter = null, KalturaFilterPager $pager = null) { if (!$pager) { $pager = new KalturaFilterPager(); $pager->pageSize = baseObjectFilter::getMaxInValues(); // default to the max for compatibility reasons } if (!$filter) { $filter = new KalturaCuePointFilter(); } return $filter->getTypeListResponse($pager, $this->getResponseProfile(), $this->getCuePointType()); }
public static function filterEntriesByPartnerOrKalturaNetwork(array $entryIds, $partnerId) { $validatedEntries = array_intersect($entryIds, self::$validatedEntries); $entryIds = array_diff($entryIds, self::$validatedEntries); if (count($entryIds)) { $entryIds = array_slice($entryIds, 0, baseObjectFilter::getMaxInValues()); $c = KalturaCriteria::create(entryPeer::OM_CLASS); $c->addAnd(entryPeer::ID, $entryIds, Criteria::IN); if ($partnerId >= 0) { $criterionPartnerOrKn = $c->getNewCriterion(entryPeer::PARTNER_ID, $partnerId); $criterionPartnerOrKn->addOr($c->getNewCriterion(entryPeer::DISPLAY_IN_SEARCH, mySearchUtils::DISPLAY_IN_SEARCH_KALTURA_NETWORK)); $c->addAnd($criterionPartnerOrKn); } $dbEntries = self::doSelect($c); foreach ($dbEntries as $dbEntry) { $validatedEntries[] = $dbEntry->getId(); } } return $validatedEntries; }
/** * Search caption asset items by filter, pager and free text * * @action searchEntries * @param KalturaBaseEntryFilter $entryFilter * @param KalturaCaptionAssetItemFilter $captionAssetItemFilter * @param KalturaFilterPager $captionAssetItemPager * @return KalturaBaseEntryListResponse */ public function searchEntriesAction(KalturaBaseEntryFilter $entryFilter = null, KalturaCaptionAssetItemFilter $captionAssetItemFilter = null, KalturaFilterPager $captionAssetItemPager = null) { if (!$captionAssetItemPager) { $captionAssetItemPager = new KalturaFilterPager(); } if (!$captionAssetItemFilter) { $captionAssetItemFilter = new KalturaCaptionAssetItemFilter(); } $captionAssetItemFilter->validatePropertyNotNull(array("contentLike", "contentMultiLikeOr", "contentMultiLikeAnd")); $captionAssetItemCoreFilter = new CaptionAssetItemFilter(); $captionAssetItemFilter->toObject($captionAssetItemCoreFilter); $entryIdChunks = array(NULL); if ($entryFilter || kEntitlementUtils::getEntitlementEnforcement()) { $entryCoreFilter = new entryFilter(); if ($entryFilter) { $entryFilter->toObject($entryCoreFilter); } $entryCoreFilter->setPartnerSearchScope($this->getPartnerId()); $this->addEntryAdvancedSearchFilter($captionAssetItemFilter, $entryCoreFilter); $entryCriteria = KalturaCriteria::create(entryPeer::OM_CLASS); $entryCoreFilter->attachToCriteria($entryCriteria); $entryCriteria->setLimit(self::MAX_NUMBER_OF_ENTRIES); $entryCriteria->applyFilters(); $entryIds = $entryCriteria->getFetchedIds(); if (!$entryIds || !count($entryIds)) { $entryIds = array('NOT_EXIST'); } $entryIdChunks = array_chunk($entryIds, self::SIZE_OF_ENTRIES_CHUNK); } $entries = array(); $counter = 0; $shouldSortCaptionFiltering = $entryFilter->orderBy ? true : false; $captionAssetItemCriteria = KalturaCriteria::create(CaptionAssetItemPeer::OM_CLASS); $captionAssetItemCoreFilter->attachToCriteria($captionAssetItemCriteria); $captionAssetItemCriteria->setGroupByColumn('str_entry_id'); $captionAssetItemCriteria->setSelectColumn('str_entry_id'); foreach ($entryIdChunks as $chunk) { $currCriteria = clone $captionAssetItemCriteria; if ($chunk) { $currCriteria->add(CaptionAssetItemPeer::ENTRY_ID, $chunk, KalturaCriteria::IN); } else { $captionAssetItemPager->attachToCriteria($currCriteria); } $currCriteria->applyFilters(); $currEntries = $currCriteria->getFetchedIds(); //sorting this chunk according to results of first sphinx query if ($shouldSortCaptionFiltering) { $currEntries = array_intersect($entryIds, $currEntries); } $entries = array_merge($entries, $currEntries); $counter += $currCriteria->getRecordsCount(); } $inputPageSize = $captionAssetItemPager->pageSize; $inputPageIndex = $captionAssetItemPager->pageIndex; //page index & size validation - no negative values & size not too big $pageSize = max(min($inputPageSize, baseObjectFilter::getMaxInValues()), 0); $pageIndex = max($captionAssetItemPager::MIN_PAGE_INDEX, $inputPageIndex) - 1; $firstIndex = $pageSize * $pageIndex; $entries = array_slice($entries, $firstIndex, $pageSize); $dbList = entryPeer::retrieveByPKs($entries); if ($shouldSortCaptionFiltering) { //results ids mapping $entriesMapping = array(); foreach ($dbList as $item) { $entriesMapping[$item->getId()] = $item; } $dbList = array(); foreach ($entries as $entryId) { if (isset($entriesMapping[$entryId])) { $dbList[] = $entriesMapping[$entryId]; } } } $list = KalturaBaseEntryArray::fromDbArray($dbList, $this->getResponseProfile()); $response = new KalturaBaseEntryListResponse(); $response->objects = $list; $response->totalCount = $counter; return $response; }
public function calcPageSize() { return max(min($this->pageSize, baseObjectFilter::getMaxInValues()), 0); }