/**
  * Search caption asset items by filter, pager and free text
  * 
  * @action search
  * @param KalturaBaseEntryFilter $entryFilter
  * @param KalturaCaptionAssetItemFilter $captionAssetItemFilter
  * @param KalturaFilterPager $captionAssetItemPager
  * @return KalturaCaptionAssetItemListResponse
  */
 function searchAction(KalturaBaseEntryFilter $entryFilter = null, KalturaCaptionAssetItemFilter $captionAssetItemFilter = null, KalturaFilterPager $captionAssetItemPager = null)
 {
     if (!$captionAssetItemPager) {
         $captionAssetItemPager = new KalturaFilterPager();
     }
     if (!$captionAssetItemFilter) {
         $captionAssetItemFilter = new KalturaCaptionAssetItemFilter();
     }
     $captionAssetItemCoreFilter = new CaptionAssetItemFilter();
     $captionAssetItemFilter->toObject($captionAssetItemCoreFilter);
     if ($entryFilter) {
         $entryCoreFilter = new entryFilter();
         $entryFilter->toObject($entryCoreFilter);
         $this->addEntryAdvancedSearchFilter($captionAssetItemFilter, $entryCoreFilter);
         $entryCriteria = KalturaCriteria::create(entryPeer::OM_CLASS);
         $entryCoreFilter->attachToCriteria($entryCriteria);
         $entryCriteria->applyFilters();
         $entryIds = $entryCriteria->getFetchedIds();
         if (!$entryIds || !count($entryIds)) {
             $entryIds = array('NOT_EXIST');
         }
         $captionAssetItemCoreFilter->setEntryIdIn($entryIds);
     }
     $captionAssetItemCriteria = KalturaCriteria::create(CaptionAssetItemPeer::OM_CLASS);
     $captionAssetItemCoreFilter->attachToCriteria($captionAssetItemCriteria);
     $captionAssetItemPager->attachToCriteria($captionAssetItemCriteria);
     $dbList = CaptionAssetItemPeer::doSelect($captionAssetItemCriteria);
     $list = KalturaCaptionAssetItemArray::fromDbArray($dbList);
     $response = new KalturaCaptionAssetItemListResponse();
     $response->objects = $list;
     $response->totalCount = $captionAssetItemCriteria->getRecordsCount();
     return $response;
 }
 function search(KalturaBaseEntryFilter $entryFilter = null, KalturaCaptionAssetItemFilter $captionAssetItemFilter = null, KalturaFilterPager $captionAssetItemPager = null)
 {
     $kparams = array();
     if ($entryFilter !== null) {
         $this->client->addParam($kparams, "entryFilter", $entryFilter->toParams());
     }
     if ($captionAssetItemFilter !== null) {
         $this->client->addParam($kparams, "captionAssetItemFilter", $captionAssetItemFilter->toParams());
     }
     if ($captionAssetItemPager !== null) {
         $this->client->addParam($kparams, "captionAssetItemPager", $captionAssetItemPager->toParams());
     }
     $this->client->queueServiceActionCall("captionsearch_captionassetitem", "search", $kparams);
     if ($this->client->isMultiRequest()) {
         return $this->client->getMultiRequestResult();
     }
     $resultObject = $this->client->doQueue();
     $this->client->throwExceptionIfError($resultObject);
     $this->client->validateObjectType($resultObject, "KalturaCaptionAssetItemListResponse");
     return $resultObject;
 }
 /**
  * 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;
 }