protected function applyFilterFields(baseObjectFilter $filter) { /* @var $filter cuePointFilter */ // Reduce the cache expiry when fetching live stream cuepoints $entryId = $filter->get('_in_entry_id'); if ($entryId && strpos($entryId, ',') === false) { $entry = entryPeer::retrieveByPK($entryId); if ($entry && $entry->getType() == entryType::LIVE_STREAM) { kApiCache::setExpiry(self::LIVE_ENTRY_CUE_POINT_CACHE_EXPIRY_SECONDS); } } if ($filter->get('_free_text')) { $this->sphinxSkipped = false; $freeTexts = $filter->get('_free_text'); KalturaLog::debug("Attach free text [{$freeTexts}]"); $this->addFreeTextToMatchClauseByMatchFields($freeTexts, CuePointFilter::FREE_TEXT_FIELDS); } $filter->unsetByName('_free_text'); if ($filter->get('_eq_is_public')) { $this->sphinxSkipped = false; $isPublic = $filter->get('_eq_is_public'); $this->addCondition('is_public' . " = " . $isPublic); } $filter->unsetByName('_eq_is_public'); return parent::applyFilterFields($filter); }
protected function applyFilterFields(baseObjectFilter $filter) { if ($filter->get('_eq_object_type')) { $filter->set('_eq_object_type', Tag::getIndexedFieldValue('TagPeer::OBJECT_TYPE', $filter->get('_eq_object_type'), kCurrentContext::getCurrentPartnerId())); } if ($filter->get('_likex_tag')) { /* * We replace the spaces with '=' because when we index the tags we also replace them this way. This way when we search the sphinx for expressions using spaces that the first word in them is less than 3 letters * we can still find them. */ $filter->set('_likex_tag', str_replace(" ", "=", $filter->get('_likex_tag'))); } parent::applyFilterFields($filter); }
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); }
protected function applyFilterFields(baseObjectFilter $filter) { /* @var $filter AnswerCuePointFilter */ if ($filter->get('_eq_quiz_user_entry_id')) { $userEntryId = $filter->get('_eq_quiz_user_entry_id'); $searchValue = $userEntryId . kCurrentContext::getCurrentPartnerId() . QuizPlugin::SEARCH_TEXT_SUFFIX; $this->addMatch("(@plugins_data {$searchValue})"); } $filter->unsetByName('_eq_quiz_user_entry_id'); if ($filter->get('_in_quiz_user_entry_id')) { $userEntryIds = explode(',', $filter->get('_in_quiz_user_entry_id')); foreach ($userEntryIds as &$userEntryId) { $userEntryId .= kCurrentContext::getCurrentPartnerId() . QuizPlugin::SEARCH_TEXT_SUFFIX; } $searchValues = implode(' | ', $userEntryIds); $this->addMatch("(@plugins_data ({$searchValues}))"); } $filter->unsetByName('_in_quiz_user_entry_id'); return parent::applyFilterFields($filter); }
public function attachToFinalCriteria(Criteria $criteria) { if (!is_null($this->get('_partner_permissions_exist'))) { if (is_null($this->get('_in_id'))) { $mandatoryParameter = "_in_id"; throw new kCoreException("Mandatory parameter {$mandatoryParameter} missing from the filter", kCoreException::MISSING_MANDATORY_PARAMETERS, $mandatoryParameter); } $permissions = explode(',', $this->get('_partner_permissions_exist')); $tmpCriteria = new Criteria(); $tmpCriteria->addSelectColumn(PermissionPeer::PARTNER_ID); $tmpCriteria->addAnd(PermissionPeer::NAME, $permissions, Criteria::IN); $ids = explode(',', $this->get('_in_id')); $tmpCriteria->addAnd(PermissionPeer::PARTNER_ID, $ids, Criteria::IN); $tmpCriteria->addAnd(PermissionPeer::STATUS, PermissionStatus::ACTIVE, Criteria::EQUAL); $stmt = PermissionPeer::doSelectStmt($tmpCriteria); $this->setIdIn($stmt->fetchAll(PDO::FETCH_COLUMN)); $this->unsetByName('_partner_permissions_exist'); } return parent::attachToFinalCriteria($criteria); }
public function attachToFinalCriteria(Criteria $c) { $fromHour = $c->getNewCriterion(DwhHourlyPartnerPeer::HOUR_ID, $this->get('_gte_hour_id'), Criteria::GREATER_EQUAL); $theDate = $c->getNewCriterion(DwhHourlyPartnerPeer::DATE_ID, $this->get('_gte_date_id')); $theDate->addAnd($fromHour); $fromDate = $c->getNewCriterion(DwhHourlyPartnerPeer::DATE_ID, $this->get('_gte_date_id'), Criteria::GREATER_THAN); $fromDate->addOr($theDate); $c->addAnd($fromDate); $this->unsetByName('_gte_hour_id'); $this->unsetByName('_gte_date_id'); $toHour = $c->getNewCriterion(DwhHourlyPartnerPeer::HOUR_ID, $this->get('_lte_hour_id'), Criteria::LESS_EQUAL); $theDate = $c->getNewCriterion(DwhHourlyPartnerPeer::DATE_ID, $this->get('_lte_date_id')); $theDate->addAnd($toHour); $toDate = $c->getNewCriterion(DwhHourlyPartnerPeer::DATE_ID, $this->get('_lte_date_id'), Criteria::LESS_THAN); $toDate->addOr($theDate); $c->addAnd($toDate); $this->unsetByName('_lte_hour_id'); $this->unsetByName('_lte_date_id'); return parent::attachToFinalCriteria($c); }
public function attachToFinalCriteria(Criteria $criteria) { $jobTypeAndSubTypeIn = $this->get("_in_job_type_and_sub_type"); if ($jobTypeAndSubTypeIn !== null) { $finalTypesAndSubTypes = array(); $arr = explode(self::JOB_TYPE_AND_SUB_TYPE_MAIN_DELIMITER, $jobTypeAndSubTypeIn); foreach ($arr as $jobTypeIn) { list($jobType, $jobSubTypes) = explode(self::JOB_TYPE_AND_SUB_TYPE_TYPE_DELIMITER, $jobTypeIn); $finalTypesAndSubTypes[$jobType] = $jobSubTypes; } if (count($finalTypesAndSubTypes)) { $mainCriterion = null; foreach ($finalTypesAndSubTypes as $finalJobType => $finalSubTypes) { if ($mainCriterion) { if (strlen(trim($finalSubTypes))) { $finalSubTypesArr = explode(self::JOB_TYPE_AND_SUB_TYPE_SUB_DELIMITER, $finalSubTypes); $jobTypeCriterion = $criteria->getNewCriterion(BatchJobPeer::JOB_TYPE, $finalJobType); $jobTypeCriterion->addAnd($criteria->getNewCriterion(BatchJobPeer::JOB_SUB_TYPE, $finalSubTypesArr, Criteria::IN)); $mainCriterion->addOr($jobTypeCriterion); } else { $jobTypeCriterion = $criteria->getNewCriterion(BatchJobPeer::JOB_TYPE, $finalJobType); $mainCriterion->addOr($jobTypeCriterion); } } else { if (strlen(trim($finalSubTypes))) { $finalSubTypesArr = explode(self::JOB_TYPE_AND_SUB_TYPE_SUB_DELIMITER, $finalSubTypes); $mainCriterion = $criteria->getNewCriterion(BatchJobPeer::JOB_TYPE, $finalJobType); $mainCriterion->addAnd($criteria->getNewCriterion(BatchJobPeer::JOB_SUB_TYPE, $finalSubTypesArr, Criteria::IN)); } else { $mainCriterion = $criteria->getNewCriterion(BatchJobPeer::JOB_TYPE, $finalJobType); } } } $criteria->addAnd($mainCriterion); } } $this->set("_in_job_type_and_sub_type", null); parent::attachToFinalCriteria($criteria); }
public function calcPageSize() { return max(min($this->pageSize, baseObjectFilter::getMaxInValues()), 0); }
protected function applyFilterFields(baseObjectFilter $filter) { //Role ids and kuser permission names are indexed with the partner ID $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; if ($filter->get('_eq_role_ids')) { $filter->set('_eq_role_ids', kuser::getIndexedFieldValue('kuserPeer::ROLE_IDS', $filter->get('_eq_role_ids'), $partnerId)); } if ($filter->get('_in_role_ids')) { $filter->set('_eq_role_ids', kuser::getIndexedFieldValue('kuserPeer::ROLE_IDS', $filter->get('_eq_role_ids'), $partnerId)); } if ($filter->get('_mlikeand_permission_names')) { $permissionNames = kuser::getIndexedFieldValue('kuserPeer::PERMISSION_NAMES', $filter->get('_mlikeand_permission_names'), $partnerId); $permissionNames = implode(' ', explode(',', $permissionNames)); $universalPermissionName = kuser::getIndexedFieldValue('kuserPeer::PERMISSION_NAMES', kuser::UNIVERSAL_PERMISSION, $partnerId); $value = "({$universalPermissionName} | ({$permissionNames}))"; $this->addMatch("@permission_names {$value}"); $filter->unsetByName('_mlikeand_permission_names'); } if ($filter->get('_mlikeor_permission_names')) { $filter->set('_mlikeor_permission_names', kuser::getIndexedFieldValue('kuserPeer::PERMISSION_NAMES', $filter->get('_mlikeor_permission_names') . ',' . kuser::UNIVERSAL_PERMISSION, $partnerId)); } if ($filter->get('_likex_puser_id_or_screen_name')) { $freeTexts = $filter->get('_likex_puser_id_or_screen_name'); KalturaLog::debug("Attach free text [{$freeTexts}]"); $additionalConditions = array(); $advancedSearch = $filter->getAdvancedSearch(); if ($advancedSearch) { $additionalConditions = $advancedSearch->getFreeTextConditions($freeTexts); } if (preg_match('/^"[^"]+"$/', $freeTexts)) { $freeText = str_replace('"', '', $freeTexts); $freeText = SphinxUtils::escapeString($freeText); $freeText = "^{$freeText}\$"; $additionalConditions[] = "@(" . kuserFilter::PUSER_ID_OR_SCREEN_NAME . ") {$freeText}\\\\*"; } else { if (strpos($freeTexts, baseObjectFilter::IN_SEPARATOR) > 0) { str_replace(baseObjectFilter::AND_SEPARATOR, baseObjectFilter::IN_SEPARATOR, $freeTexts); $freeTextsArr = explode(baseObjectFilter::IN_SEPARATOR, $freeTexts); foreach ($freeTextsArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($freeTextsArr[$valIndex]); } else { $freeTextsArr[$valIndex] = SphinxUtils::escapeString($valValue); } } foreach ($freeTextsArr as $freeText) { $additionalConditions[] = "@(" . kuserFilter::PUSER_ID_OR_SCREEN_NAME . ") {$freeText}\\\\*"; } } else { $freeTextsArr = explode(baseObjectFilter::AND_SEPARATOR, $freeTexts); foreach ($freeTextsArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($freeTextsArr[$valIndex]); } else { $freeTextsArr[$valIndex] = SphinxUtils::escapeString($valValue); } } $freeTextsArr = array_unique($freeTextsArr); $freeTextExpr = implode(baseObjectFilter::AND_SEPARATOR, $freeTextsArr); $additionalConditions[] = "@(" . kuserFilter::PUSER_ID_OR_SCREEN_NAME . ") {$freeTextExpr}\\\\*"; } } if (count($additionalConditions)) { $additionalConditions = array_unique($additionalConditions); $matches = reset($additionalConditions); if (count($additionalConditions) > 1) { $matches = '( ' . implode(' ) | ( ', $additionalConditions) . ' )'; } $this->matchClause[] = $matches; } } $filter->unsetByName('_likex_puser_id_or_screen_name'); if ($filter->get('_likex_first_name_or_last_name')) { $names = $filter->get('_likex_first_name_or_last_name'); KalturaLog::debug("Attach free text [{$names}]"); $additionalConditions = array(); if (preg_match('/^"[^"]+"$/', $names)) { $name = str_replace('"', '', $names); $name = SphinxUtils::escapeString($name); $name = "^{$name}\$"; $additionalConditions[] = "@(" . kuserFilter::FIRST_NAME_OR_LAST_NAME . ") {$name}\\\\*"; } else { if (strpos($names, baseObjectFilter::IN_SEPARATOR) > 0) { str_replace(baseObjectFilter::AND_SEPARATOR, baseObjectFilter::IN_SEPARATOR, $names); $namesArr = explode(baseObjectFilter::IN_SEPARATOR, $names); foreach ($namesArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($namesArr[$valIndex]); } else { $namesArr[$valIndex] = SphinxUtils::escapeString($valValue); } } foreach ($namesArr as $name) { $additionalConditions[] = "@(" . kuserFilter::FIRST_NAME_OR_LAST_NAME . ") {$name}\\\\*"; } } else { $namesArr = explode(baseObjectFilter::AND_SEPARATOR, $names); foreach ($namesArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($namesArr[$valIndex]); } else { $namesArr[$valIndex] = SphinxUtils::escapeString($valValue); } } $namesArr = array_unique($namesArr); $nameExpr = implode(baseObjectFilter::AND_SEPARATOR, $namesArr); $additionalConditions[] = "@(" . kuserFilter::FIRST_NAME_OR_LAST_NAME . ") {$nameExpr}\\\\*"; } } if (count($additionalConditions)) { $additionalConditions = array_unique($additionalConditions); $matches = reset($additionalConditions); if (count($additionalConditions) > 1) { $matches = '( ' . implode(' ) | ( ', $additionalConditions) . ' )'; } $this->matchClause[] = $matches; } } $filter->unsetByName('_likex_first_name_or_last_name'); return parent::applyFilterFields($filter); }
private function attachCriterionToCriteria($criteria, $criterion, $add_or_to_criterion, $operator_str, $value, $colname) { //echo ( " operator_str " . $operator_str ); list($criteria_operator, $value_to_set, $query_append_method) = $criteria_operator = baseObjectFilter::getCriteriaOperatorFromStr($operator_str, $value, $colname); // echo ( "<br>Adding to criteria [" . $colname . "] = [" . $value . "] , " . $criteria_operator . "<br>"); // TODO - is this huristics OK ? can we really say for sure that fields that end with _date are time objects ? if (kString::endsWith($colname, "_date")) { $value_to_set = strtotime($value); } // special case where match can be used if ($criteria_operator == self::MATCH_AND) { self::addMatchToCriteria($criteria, null, $value_to_set, $colname, $criteria_operator, true); } elseif ($criteria_operator == self::MATCH_OR) { self::addMatchToCriteria($criteria, null, $value_to_set, $colname, $criteria_operator, true); } elseif ($criteria_operator == Criteria::IN || $criteria_operator == Criteria::NOT_IN || !is_array($value_to_set)) { if ($add_or_to_criterion) { $new_crit = $criteria->getNewCriterion($colname, $value_to_set, $criteria_operator); if ($criterion == null) { // need to create a new criterion for the colname $criterion = $new_crit; } else { $criterion->addOr($new_crit); } } else { // add or null if (in_array($operator_str, array(self::LT_OR_NULL, self::GT_OR_NULL, self::LTE_OR_NULL, self::GTE_OR_NULL))) { $accumulated_criterion = $criteria->getNewCriterion($colname, $value_to_set, $criteria_operator); $or_null_criterion = $criteria->getNewCriterion($colname, null); $accumulated_criterion->addOr($or_null_criterion); $criteria->addAnd($accumulated_criterion); } else { // simply addAnd to the criteria $criteria->addAnd($colname, $value_to_set, $criteria_operator); } } } else { $accumulated_criterion = null; foreach ($value_to_set as $single_value) { // here use the $criteria object $single_crit = $criteria->getNewCriterion($colname, $single_value, $criteria_operator); if ($accumulated_criterion == NULL) { $accumulated_criterion = $single_crit; } else { if ($query_append_method == self::QUERY_OR) { $accumulated_criterion->addOr($single_crit); } else { $accumulated_criterion->addAnd($single_crit); } } } if ($add_or_to_criterion) { if ($criterion == null) { // need to create a new criterion for the colname - use the one just created $criterion = $accumulated_criterion; } else { $criterion->addOr($accumulated_criterion); } } else { // simply addAnd to the criteria $criteria->addAnd($accumulated_criterion); } } return $criterion; }
/** * Applies all filter fields and unset the handled fields * * @param baseObjectFilter $filter */ protected function applyFilterFields(baseObjectFilter $filter) { if ($filter->get("_matchand_categories") !== null) { $filter->set("_matchand_categories_ids", $filter->categoryNamesToIds($filter->get("_matchand_categories"))); $filter->unsetByName('_matchand_categories'); } if ($filter->get("_matchor_categories") !== null) { $filter->set("_matchor_categories_ids", $filter->categoryNamesToIds($filter->get("_matchor_categories"))); $filter->unsetByName('_matchor_categories'); } // if ($filter->get("_matchor_duration_type") !== null) // $filter->set("_matchor_duration_type", $filter->durationTypesToIndexedStrings($filter->get("_matchor_duration_type"))); if ($filter->get(baseObjectFilter::ORDER) === "recent") { $filter->set("_lte_available_from", time()); $filter->set("_gteornull_end_date", time()); // schedule not finished $filter->set(baseObjectFilter::ORDER, "-available_from"); } if ($filter->get('_free_text')) { $freeTexts = $filter->get('_free_text'); KalturaLog::debug("Attach free text [{$freeTexts}]"); $additionalConditions = array(); $advancedSearch = $filter->getAdvancedSearch(); if ($advancedSearch) { $additionalConditions = $advancedSearch->getFreeTextConditions($freeTexts); } if (preg_match('/^"[^"]+"$/', $freeTexts)) { $freeText = str_replace('"', '', $freeTexts); $freeText = "^{$freeText}\$"; $additionalConditions[] = "@(" . entryFilter::FREE_TEXT_FIELDS . ") {$freeText}"; } else { if (strpos($freeTexts, baseObjectFilter::IN_SEPARATOR) > 0) { str_replace(baseObjectFilter::AND_SEPARATOR, baseObjectFilter::IN_SEPARATOR, $freeTexts); $freeTextsArr = explode(baseObjectFilter::IN_SEPARATOR, $freeTexts); foreach ($freeTextsArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 1) { unset($freeTextsArr[$valIndex]); } else { $freeTextsArr[$valIndex] = $valValue; } } foreach ($freeTextsArr as $freeText) { $additionalConditions[] = "@(" . entryFilter::FREE_TEXT_FIELDS . ") {$freeText}"; } } else { $freeTextsArr = explode(baseObjectFilter::AND_SEPARATOR, $freeTexts); foreach ($freeTextsArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 1) { unset($freeTextsArr[$valIndex]); } else { $freeTextsArr[$valIndex] = $valValue; } } $freeTextExpr = implode(baseObjectFilter::AND_SEPARATOR, $freeTextsArr); $additionalConditions[] = "@(" . entryFilter::FREE_TEXT_FIELDS . ") {$freeTextExpr}"; } } if (count($additionalConditions)) { $this->matchClause[] = implode(' | ', $additionalConditions); } } $filter->unsetByName('_free_text'); return parent::applyFilterFields($filter); }
/** * Applies a single filter * * @param baseObjectFilter $filter */ protected function applyFilter(baseObjectFilter $filter) { $advancedSearch = $filter->getAdvancedSearch(); if (is_object($advancedSearch)) { KalturaLog::debug('Apply advanced filter [' . get_class($advancedSearch) . ']'); if ($advancedSearch instanceof AdvancedSearchFilterItem) { $advancedSearch->apply($filter, $this); } $this->hasAdvancedSearchFilter = true; } else { KalturaLog::debug('No advanced filter found'); } // attach all unhandled fields $filter->attachToFinalCriteria($this); }
protected function applyFilterFields(baseObjectFilter $filter) { $partnerId = kCurrentContext::getCurrentPartnerId(); $categories = $filter->get("_matchor_likex_full_name"); if ($categories !== null) { $categories = explode(',', $categories); $parsedCategories = array(); foreach ($categories as $category) { if (trim($category) == '') { continue; } $parsedCategories[] = $category . '\\*'; } $fullNameMatchOr = ''; if (count($parsedCategories)) { $fullNameMatchOr = implode(',', $parsedCategories); } if ($fullNameMatchOr != '') { $filter->set("_matchor_full_name", $fullNameMatchOr); } } $filter->unsetByName('_matchor_likex_full_name'); if ($filter->get('_free_text')) { $freeTexts = $filter->get('_free_text'); $additionalConditions = array(); $advancedSearch = $filter->getAdvancedSearch(); if ($advancedSearch) { $additionalConditions = $advancedSearch->getFreeTextConditions($filter->getPartnerSearchScope(), $freeTexts); } $this->addFreeTextToMatchClauseByMatchFields($freeTexts, categoryFilter::FREE_TEXT_FIELDS, $additionalConditions); } $filter->unsetByName('_free_text'); if ($filter->get('_eq_privacy_context') && $filter->get('_eq_privacy_context') == '*') { $filter->set('_matchor_privacy_context', kEntitlementUtils::NOT_DEFAULT_CONTEXT); $filter->unsetByName('_eq_privacy_context'); } if ($filter->get('_eq_manager')) { $puserId = $filter->get('_eq_manager'); $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $puserId); if ($kuser) { $manager = category::getPermissionLevelName(CategoryKuserPermissionLevel::MANAGER); $this->matchClause[] = '(@(' . categoryFilter::MEMBERS . ') ' . $manager . '_' . $kuser->getid() . ')'; } } $filter->unsetByName('_eq_manager'); if ($filter->get('_eq_member')) { $puserId = $filter->get('_eq_member'); $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $puserId); if ($kuser) { $manager = category::getPermissionLevelName(CategoryKuserPermissionLevel::MANAGER); $member = category::getPermissionLevelName(CategoryKuserPermissionLevel::MEMBER); $moderator = category::getPermissionLevelName(CategoryKuserPermissionLevel::MODERATOR); $contributor = category::getPermissionLevelName(CategoryKuserPermissionLevel::CONTRIBUTOR); $kuserId = $kuser->getid(); $this->matchClause[] = '(@(' . categoryFilter::MEMBERS . ') ' . "({$member}_{$kuserId} | {$moderator}_{$kuserId} | {$contributor}_{$kuserId} ) !({$manager}_{$kuserId}))"; } } $filter->unsetByName('_eq_member'); if ($filter->get('_eq_full_name')) { $filter->set('_matchor_full_name', $filter->get('_eq_full_name') . category::FULL_NAME_EQUAL_MATCH_STRING); } $filter->unsetByName('_eq_full_name'); if ($filter->get('_in_full_name')) { $fullnames = explode(',', $filter->get('_in_full_name')); $fullnameIn = ''; foreach ($fullnames as $fullname) { $fullnameIn .= $fullname . category::FULL_NAME_EQUAL_MATCH_STRING . ','; } $filter->set('_matchor_full_name', $fullnameIn); $filter->unsetByName('_in_full_name'); } $categories = $filter->get("_in_ancestor_id"); if ($categories !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryIdsToAllSubCategoriesIdsParsed($categories); if ($categoriesParsed !== '' || $categories == '') { $filter->set("_matchor_full_ids", $categoriesParsed); } else { $filter->set("_matchor_full_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } $filter->unsetByName('_in_ancestor_id'); if ($filter->get('_likex_full_ids')) { $fullids = explode(',', $filter->get('_likex_full_ids')); $fullIdsIn = ''; foreach ($fullids as $fullid) { $fullIdsIn .= $fullid . '\\*,'; } $filter->set('_matchor_full_ids', $fullIdsIn); $filter->unsetByName('_likex_full_ids'); } if ($filter->get('_eq_full_ids')) { $filter->set('_matchor_full_ids', $filter->get('_eq_full_ids') . category::FULL_IDS_EQUAL_MATCH_STRING); } $filter->unsetByName('_eq_full_ids'); if ($filter->get('_likex_name_or_reference_id')) { $names = $filter->get('_likex_name_or_reference_id'); $this->addFreeTextToMatchClauseByMatchFields($names, categoryFilter::NAME_REFERNCE_ID, null, true); } $filter->unsetByName('_likex_name_or_reference_id'); if ($filter->get('_eq_privacy')) { $filter->set('_eq_privacy', $filter->get('_eq_privacy') . "P" . $partnerId); } if ($filter->get('_in_privacy')) { $privacyIn = explode(',', $filter->get('_in_privacy')); $newPrivacyIn = array(); foreach ($privacyIn as $privacy) { $newPrivacyIn[] = $privacy . "P" . $partnerId; } $filter->set('_in_privacy', implode(",", $newPrivacyIn)); } if ($filter->get('_eq_display_in_search')) { $filter->set('_eq_display_in_search', $filter->get('_eq_display_in_search')); } return parent::applyFilterFields($filter); }
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; }
/** * List all categories * * @action list * @param KalturaCategoryFilter $filter * @param KalturaFilterPager $pager * @return KalturaCategoryListResponse */ function listAction(KalturaCategoryFilter $filter = null, KalturaFilterPager $pager = null) { if ($filter === null) { $filter = new KalturaCategoryFilter(); } if ($pager == null) { $pager = new KalturaFilterPager(); //before falcon we didn't have a pager for action category->list, //and since we added a pager - and remove the limit for partners categories, //for backward compatibility this will be the page size. $pager->pageIndex = 1; $pager->pageSize = Partner::MAX_NUMBER_OF_CATEGORIES; KalturaCriteria::setMaxRecords(Partner::MAX_NUMBER_OF_CATEGORIES); baseObjectFilter::setMaxInValues(Partner::MAX_NUMBER_OF_CATEGORIES); } return $filter->getListResponse($pager, $this->getResponseProfile()); }
protected function applyFilterFields(baseObjectFilter $filter) { /* @var $filter entryFilter */ if ($filter->is_set('_eq_redirect_from_entry_id')) { $partnerGroup = array(kCurrentContext::getCurrentPartnerId(), PartnerPeer::GLOBAL_PARTNER); $criteriaFilter = entryPeer::getCriteriaFilter(); $defaultCriteria = $criteriaFilter->getFilter(); $defaultCriteria->remove(entryPeer::PARTNER_ID); $defaultCriteria->add(entryPeer::PARTNER_ID, $partnerGroup, Criteria::IN); $origEntryId = $filter->get('_eq_redirect_from_entry_id'); $origEntry = entryPeer::retrieveByPK($origEntryId); if (!empty($origEntry)) { if ($origEntry->getType() == entryType::LIVE_STREAM) { // Set a relatively short expiry value in order to reduce the wait-time // until the cache is refreshed and a redirection kicks-in. kApiCache::setExpiry(kApiCache::REDIRECT_ENTRY_CACHE_EXPIRY); } // Get the id of the entry id that is being redirected from the original entry $redirectEntryId = $origEntry->getRedirectEntryId(); if (is_null($redirectEntryId)) { $filter->set('_eq_id', $origEntryId); // Continue with original entry id } else { // Get the redirected entry and check if it exists and is ready $redirectedEntry = entryPeer::retrieveByPK($redirectEntryId); if (!empty($redirectedEntry) && $redirectedEntry->getStatus() == entryStatus::READY) { // Redirected entry is ready. // Set it as the replacement of the original one $filter->set('_eq_id', $redirectEntryId); } else { // Can't redirect? --> Fallback to the original entry $filter->set('_eq_id', $origEntryId); } } } else { throw new kCoreException("Invalid entry id [\"{$origEntryId}\"]", kCoreException::INVALID_ENTRY_ID, $origEntryId); } $filter->unsetByName('_eq_redirect_from_entry_id'); } $categoriesAncestorParsed = null; $categories = $filter->get("_in_category_ancestor_id"); if ($categories !== null) { //if the category exist or the category name is an empty string $categoriesAncestorParsed = $filter->categoryIdsToAllSubCategoriesIdsParsed($categories); if (!($categoriesAncestorParsed !== '' || $categories == '')) { $categoriesAncestorParsed = category::CATEGORY_ID_THAT_DOES_NOT_EXIST; } } $filter->unsetByName('_in_category_ancestor_id'); $categories = $filter->get("_matchor_categories_ids"); if ($categories !== null) { //if the category exist or the category name is an empty string if (is_null($categoriesAncestorParsed)) { $categoriesParsed = $filter->categoryIdsToIdsParsed($categories); } else { $categoriesParsed = $categoriesAncestorParsed; } if ($categoriesParsed !== '' || $categories == '') { $filter->set("_matchor_categories_ids", $categoriesParsed); } else { $filter->set("_matchor_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } else { $filter->set("_matchor_categories_ids", $categoriesAncestorParsed); } $categories = $filter->get("_matchand_categories_ids"); if ($categories !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryIdsToIdsParsed($categories); if ($categoriesParsed !== '' || $categories == '') { $filter->set("_matchand_categories_ids", $categoriesParsed); } else { $filter->set("_matchand_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } $categoriesIds = $filter->get("_notcontains_categories_ids"); if ($categoriesIds !== null) { $categoriesParsed = $filter->categoryIdsToAllSubCategoriesIdsParsed($categoriesIds, CategoryEntryStatus::ACTIVE . ',' . CategoryEntryStatus::PENDING . ',' . CategoryEntryStatus::REJECTED); if ($categoriesParsed !== '' || $categoriesIds == '') { $filter->set("_notcontains_categories_ids", $categoriesParsed); } else { $filter->set("_notcontains_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } $matchAndCats = $filter->get("_matchand_categories"); if ($matchAndCats !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($matchAndCats, CategoryEntryStatus::ACTIVE); if ($categoriesParsed !== '' || $matchAndCats == '') { $filter->set("_matchand_categories_ids", $categoriesParsed); } else { $filter->set("_matchand_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_matchand_categories'); } $matchOrCats = $filter->get("_matchor_categories"); if ($matchOrCats !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($matchOrCats, CategoryEntryStatus::ACTIVE); if ($categoriesParsed !== '' || $matchOrCats == '') { $filter->set("_matchor_categories_ids", $categoriesParsed); } else { $filter->set("_matchor_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_matchor_categories'); } $notContainsCats = $filter->get("_notcontains_categories"); if ($notContainsCats !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($notContainsCats, CategoryEntryStatus::ACTIVE . ',' . CategoryEntryStatus::PENDING . ',' . CategoryEntryStatus::REJECTED); if ($categoriesParsed !== '' || $notContainsCats == '') { $filter->set("_notcontains_categories_ids", $categoriesParsed); } else { $filter->set("_notcontains_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_notcontains_categories'); } // match categories by full name $CatFullNameIn = $filter->get("_in_categories_full_name"); if ($CatFullNameIn !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($CatFullNameIn, CategoryEntryStatus::ACTIVE); if ($categoriesParsed !== '' || $CatFullNameIn == '') { $filter->set("_matchor_categories_ids", $categoriesParsed); } else { $filter->set("_matchor_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_in_categories_full_name'); } if ($filter->is_set('_is_live')) { $this->addCondition(entryIndex::DYNAMIC_ATTRIBUTES . '.' . LiveEntry::IS_LIVE . ' = ' . ($filter->get('_is_live') == '1' ? '1' : '0')); $filter->unsetByName('_is_live'); } if ($filter->is_set('_is_recorded_entry_id_empty')) { $fieldName = entryIndex::DYNAMIC_ATTRIBUTES . '.' . LiveEntry::RECORDED_ENTRY_ID; $this->addWhere("{$fieldName} " . ($filter->get('_is_recorded_entry_id_empty') ? "IS" : "IS NOT") . " NULL"); $filter->unsetByName('_is_recorded_entry_id_empty'); } $matchOrRoots = array(); if ($filter->is_set('_eq_root_entry_id')) { $matchOrRoots[] = entry::ROOTS_FIELD_ENTRY_PREFIX . ' ' . $filter->get('_eq_root_entry_id'); $filter->unsetByName('_eq_root_entry_id'); } if ($filter->is_set('_in_root_entry_id')) { $roots = explode(baseObjectFilter::IN_SEPARATOR, $filter->get('_in_root_entry_id')); foreach ($roots as $root) { $matchOrRoots[] = entry::ROOTS_FIELD_ENTRY_PREFIX . " {$root}"; } $filter->unsetByName('_in_root_entry_id'); } //When setting parent entry ID we also set the root entry id so the entry should be indexed with the root entry prefix if ($filter->is_set('_eq_parent_entry_id')) { $matchOrRoots[] = entry::ROOTS_FIELD_PARENT_ENTRY_PREFIX . '_' . $filter->get('_eq_parent_entry_id'); $filter->unsetByName('_eq_parent_entry_id'); } if ($filter->is_set('_is_root')) { if ($filter->get('_is_root')) { $filter->set('_notin_roots', entry::ROOTS_FIELD_ENTRY_PREFIX); } else { $matchOrRoots[] = entry::ROOTS_FIELD_ENTRY_PREFIX; } $filter->unsetByName('_is_root'); } if (count($matchOrRoots)) { $filter->set('_matchand_roots', $matchOrRoots); } // if ($filter->get("_matchor_duration_type") !== null) // $filter->set("_matchor_duration_type", $filter->durationTypesToIndexedStrings($filter->get("_matchor_duration_type"))); if ($filter->get(baseObjectFilter::ORDER) === "recent" || $filter->get(baseObjectFilter::ORDER) === "-recent") { $filter->set("_lte_available_from", time()); //$filter->set("_gteornull_end_date", time()); // schedule not finished $filter->set(baseObjectFilter::ORDER, "-available_from"); } if ($filter->get(baseObjectFilter::ORDER) === "+recent") { $filter->set(baseObjectFilter::ORDER, "+available_from"); } if ($filter->get(baseObjectFilter::ORDER) === "-first_broadcast") { $this->addOrderBy(entryIndex::DYNAMIC_ATTRIBUTES . '.' . LiveEntry::FIRST_BROADCAST, Criteria::DESC); $filter->set(baseObjectFilter::ORDER, null); } if ($filter->get(baseObjectFilter::ORDER) === "+first_broadcast") { $this->addOrderBy(entryIndex::DYNAMIC_ATTRIBUTES . '.' . LiveEntry::FIRST_BROADCAST, Criteria::ASC); $filter->set(baseObjectFilter::ORDER, null); } if ($filter->get('_free_text')) { $freeTexts = $filter->get('_free_text'); KalturaLog::debug("Attach free text [{$freeTexts}]"); $additionalConditions = array(); $advancedSearch = $filter->getAdvancedSearch(); if ($advancedSearch) { $additionalConditions = $advancedSearch->getFreeTextConditions($filter->getPartnerSearchScope(), $freeTexts); } $this->addFreeTextToMatchClauseByMatchFields($freeTexts, entryFilter::FREE_TEXT_FIELDS, $additionalConditions); } $filter->unsetByName('_free_text'); return parent::applyFilterFields($filter); }
protected function applyFilterFields(baseObjectFilter $filter) { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; if ($filter->get('_in_status')) { $statusList = explode(',', $filter->get('_in_status')); foreach ($statusList as &$status) { $status = categoryKuser::getSearchIndexFieldValue(categoryKuserPeer::STATUS, $status, $partnerId); } $filter->set('_in_status', implode(',', $statusList)); } if ($filter->get('_eq_status')) { $filter->set('_eq_status', categoryKuser::getSearchIndexFieldValue(categoryKuserPeer::STATUS, $filter->get('_eq_status'), $partnerId)); } if ($filter->get('_in_update_method')) { $updateMethodList = explode(',', $filter->get('_in_update_method')); foreach ($updateMethodList as &$updateMethod) { $updateMethod = categoryKuser::getSearchIndexFieldValue(categoryKuserPeer::UPDATE_METHOD, $updateMethod, $partnerId); } $filter->set('_in_update_method', implode(',', $updateMethodList)); } if ($filter->get('_eq_update_method')) { $filter->set('_eq_update_method', categoryKuser::getSearchIndexFieldValue(categoryKuserPeer::UPDATE_METHOD, $filter->get('_eq_update_method'), $partnerId)); } if ($filter->get('_matchor_permission_names')) { $permissionNamesList = explode(',', $filter->get('_matchor_permission_names')); foreach ($permissionNamesList as &$permissionName) { $permissionName = categoryKuser::getSearchIndexFieldValue(categoryKuserPeer::PERMISSION_NAMES, $permissionName, $partnerId); } $filter->set('_matchor_permission_names', implode(',', $permissionNamesList)); } if ($filter->get('_matchand_permission_names')) { $permissionNamesList = explode(',', $filter->get('_matchand_permission_names')); foreach ($permissionNamesList as &$permissionName) { $permissionName = categoryKuser::getSearchIndexFieldValue(categoryKuserPeer::PERMISSION_NAMES, $permissionName, $partnerId); } $filter->set('_matchand_permission_names', implode(',', $permissionNamesList)); } if ($filter->get('_notcontains_permission_names')) { $permissionNamesList = explode(',', $filter->get('_notcontains_permission_names')); foreach ($permissionNamesList as &$permissionName) { $permissionName = categoryKuser::getSearchIndexFieldValue(categoryKuserPeer::PERMISSION_NAMES, $permissionName, $partnerId); } $filter->set('_notcontains_permission_names', $permissionNamesList); } if ($filter->get('_eq_category_full_ids')) { $filter->set('_eq_category_full_ids', $filter->get('_eq_category_full_ids') . category::FULL_IDS_EQUAL_MATCH_STRING); } return parent::applyFilterFields($filter); }
/** * 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; }
protected function applyFilterFields(baseObjectFilter $filter) { if ($filter->get('_in_status')) { $statusList = explode(',', $filter->get('_in_status')); $statusList = $this->translateToSearchIndexFieldValue(categoryKuserPeer::STATUS, $statusList); $filter->set('_in_status', implode(',', $statusList)); } if ($filter->get('_eq_status')) { $filter->set('_eq_status', categoryKuser::getSearchIndexFieldValue(categoryKuserPeer::STATUS, $filter->get('_eq_status'), kCurrentContext::getCurrentPartnerId())); } if ($filter->get('_in_update_method')) { $updateMethodList = explode(',', $filter->get('_in_update_method')); $updateMethodList = $this->translateToSearchIndexFieldValue(categoryKuserPeer::UPDATE_METHOD, $updateMethodList); $filter->set('_in_update_method', implode(',', $updateMethodList)); } if ($filter->get('_eq_update_method')) { $filter->set('_eq_update_method', categoryKuser::getSearchIndexFieldValue(categoryKuserPeer::UPDATE_METHOD, $filter->get('_eq_update_method'), kCurrentContext::getCurrentPartnerId())); } if (!is_null($filter->get('_eq_permission_level'))) { $permissionLevel = $filter->get('_eq_permission_level'); $permissionNamesList = categoryKuser::getPermissionNamesByPermissionLevel($permissionLevel); $negativePermissionNamesList = $this->fixPermissionNamesListForSphinx($permissionLevel); if ($negativePermissionNamesList) { $filter->set('_notcontains_permission_names', implode(',', $negativePermissionNamesList)); } if ($filter->get('_matchand_permission_names')) { $permissionNamesList = $this->translateToSearchIndexFieldValue(categoryKuserPeer::PERMISSION_NAMES, $permissionNamesList); $criterion = $this->getNewCriterion(categoryKuserPeer::PERMISSION_NAMES, $permissionNamesList, baseObjectFilter::MATCH_AND); $this->addAnd($criterion); } else { $filter->set('_matchand_permission_names', $permissionNamesList); } $filter->unsetByName('_eq_permission_level'); } if ($filter->get('_in_permission_level')) { $permissionLevels = $filter->get('_in_permission_level'); $permissionLevels = explode(',', $permissionLevels); foreach ($permissionLevels as $permissionLevel) { $permissionNamesList = categoryKuser::getPermissionNamesByPermissionLevel($permissionLevel); $permissionNamesList = $this->translateToSearchIndexFieldValue(categoryKuserPeer::PERMISSION_NAMES, $permissionNamesList); $criterion = $this->getNewCriterion(categoryKuserPeer::PERMISSION_NAMES, $permissionNamesList, baseObjectFilter::MATCH_AND); $this->addOr($criterion); } $filter->unsetByName('_in_permission_level'); } if ($filter->get('_matchor_permission_names')) { $permissionNamesList = explode(',', $filter->get('_matchor_permission_names')); $permissionNamesList = $this->translateToSearchIndexFieldValue(categoryKuserPeer::PERMISSION_NAMES, $permissionNamesList); $filter->set('_matchor_permission_names', implode(',', $permissionNamesList)); } if ($filter->get('_matchand_permission_names')) { $permissionNamesList = explode(',', $filter->get('_matchand_permission_names')); $permissionNamesList = $this->translateToSearchIndexFieldValue(categoryKuserPeer::PERMISSION_NAMES, $permissionNamesList); $filter->set('_matchand_permission_names', implode(',', $permissionNamesList)); } if ($filter->get('_notcontains_permission_names')) { $permissionNamesList = explode(',', $filter->get('_notcontains_permission_names')); $permissionNamesList = $this->translateToSearchIndexFieldValue(categoryKuserPeer::PERMISSION_NAMES, $permissionNamesList); $filter->set('_notcontains_permission_names', $permissionNamesList); } if ($filter->get('_eq_category_full_ids')) { $filter->set('_eq_category_full_ids', $filter->get('_eq_category_full_ids') . category::FULL_IDS_EQUAL_MATCH_STRING); } return parent::applyFilterFields($filter); }
protected function applyFilterFields(baseObjectFilter $filter) { $categories = $filter->get("_matchor_likex_full_name"); if ($categories !== null) { $categories = explode(',', $categories); $parsedCategories = array(); foreach ($categories as $category) { if (trim($category) == '') { continue; } $parsedCategories[] = $category . '\\*'; } $fullNameMatchOr = ''; if (count($parsedCategories)) { $fullNameMatchOr = implode(',', $parsedCategories); } if ($fullNameMatchOr != '') { $filter->set("_matchor_full_name", $fullNameMatchOr); } } $filter->unsetByName('_matchor_likex_full_name'); if ($filter->get('_free_text')) { $freeTexts = $filter->get('_free_text'); KalturaLog::debug("Attach free text [{$freeTexts}]"); $additionalConditions = array(); $advancedSearch = $filter->getAdvancedSearch(); if ($advancedSearch) { $additionalConditions = $advancedSearch->getFreeTextConditions($freeTexts); } if (preg_match('/^"[^"]+"$/', $freeTexts)) { $freeText = str_replace('"', '', $freeTexts); $freeText = SphinxUtils::escapeString($freeText); $freeText = "^{$freeText}\$"; $additionalConditions[] = "@(" . categoryFilter::FREE_TEXT_FIELDS . ") {$freeText}"; } else { if (strpos($freeTexts, baseObjectFilter::IN_SEPARATOR) > 0) { str_replace(baseObjectFilter::AND_SEPARATOR, baseObjectFilter::IN_SEPARATOR, $freeTexts); $freeTextsArr = explode(baseObjectFilter::IN_SEPARATOR, $freeTexts); foreach ($freeTextsArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($freeTextsArr[$valIndex]); } else { $freeTextsArr[$valIndex] = SphinxUtils::escapeString($valValue); } } foreach ($freeTextsArr as $freeText) { $additionalConditions[] = "@(" . categoryFilter::FREE_TEXT_FIELDS . ") {$freeText}"; } } else { $freeTextsArr = explode(baseObjectFilter::AND_SEPARATOR, $freeTexts); foreach ($freeTextsArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($freeTextsArr[$valIndex]); } else { $freeTextsArr[$valIndex] = SphinxUtils::escapeString($valValue); } } $freeTextsArr = array_unique($freeTextsArr); $freeTextExpr = implode(baseObjectFilter::AND_SEPARATOR, $freeTextsArr); $additionalConditions[] = "@(" . categoryFilter::FREE_TEXT_FIELDS . ") {$freeTextExpr}"; } } if (count($additionalConditions)) { $additionalConditions = array_unique($additionalConditions); $matches = reset($additionalConditions); if (count($additionalConditions) > 1) { $matches = '( ' . implode(' ) | ( ', $additionalConditions) . ' )'; } $this->matchClause[] = $matches; } } $filter->unsetByName('_free_text'); if ($filter->get('_eq_privacy_context') && $filter->get('_eq_privacy_context') == '*') { $filter->set('_matchor_privacy_context', kEntitlementUtils::NOT_DEFAULT_CONTEXT); $filter->unsetByName('_eq_privacy_context'); } if ($filter->get('_eq_manager')) { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $puserId = $filter->get('_eq_manager'); $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $puserId); if ($kuser) { $manager = category::getPermissionLevelName(CategoryKuserPermissionLevel::MANAGER); $this->matchClause[] = '(@(' . categoryFilter::MEMBERS . ') ' . $manager . '_' . $kuser->getid() . ')'; } } $filter->unsetByName('_eq_manager'); if ($filter->get('_eq_member')) { //memeber but not a menager $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $puserId = $filter->get('_eq_member'); $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $puserId); if ($kuser) { $manager = category::getPermissionLevelName(CategoryKuserPermissionLevel::MANAGER); $member = category::getPermissionLevelName(CategoryKuserPermissionLevel::MEMBER); $moderator = category::getPermissionLevelName(CategoryKuserPermissionLevel::MODERATOR); $contributor = category::getPermissionLevelName(CategoryKuserPermissionLevel::CONTRIBUTOR); $kuserId = $kuser->getid(); $this->matchClause[] = '(@(' . categoryFilter::MEMBERS . ') ' . "({$member}_{$kuserId} | {$moderator}_{$kuserId} | {$contributor}_{$kuserId} ) !({$manager}_{$kuserId}))"; } } $filter->unsetByName('_eq_member'); if ($filter->get('_eq_full_name')) { $filter->set('_matchor_full_name', $filter->get('_eq_full_name') . category::FULL_NAME_EQUAL_MATCH_STRING); } $filter->unsetByName('_eq_full_name'); if ($filter->get('_in_full_name')) { $fullnames = explode(',', $filter->get('_in_full_name')); $fullnameIn = ''; foreach ($fullnames as $fullname) { $fullnameIn .= $fullname . category::FULL_NAME_EQUAL_MATCH_STRING . ','; } $filter->set('_matchor_full_name', $fullnameIn); $filter->unsetByName('_in_full_name'); } $categories = $filter->get("_in_ancestor_id"); if ($categories !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryIdsToAllSubCategoriesIdsParsed($categories); if ($categoriesParsed !== '' || $categories == '') { $filter->set("_likex_full_ids", $categoriesParsed); } else { $filter->set("_likex_full_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } $filter->unsetByName('_in_ancestor_id'); if ($filter->get('_likex_full_ids')) { $fullids = explode(',', $filter->get('_likex_full_ids')); $fullIdsIn = ''; foreach ($fullids as $fullid) { $fullIdsIn .= $fullid . '\\*,'; } $filter->set('_matchor_full_ids', $fullIdsIn); $filter->unsetByName('_likex_full_ids'); } if ($filter->get('_eq_full_ids')) { $filter->set('_matchor_full_ids', $filter->get('_eq_full_ids') . category::FULL_IDS_EQUAL_MATCH_STRING); } $filter->unsetByName('_eq_full_ids'); if ($filter->get('_likex_name_or_reference_id')) { $names = $filter->get('_likex_name_or_reference_id'); KalturaLog::debug("Attach free text [{$names}]"); $additionalConditions = array(); if (preg_match('/^"[^"]+"$/', $names)) { $name = str_replace('"', '', $names); $name = SphinxUtils::escapeString($name); $name = "^{$name}\$"; $additionalConditions[] = "@(" . categoryFilter::NAME_REFERNCE_ID . ") {$name}\\\\*"; } else { if (strpos($names, baseObjectFilter::IN_SEPARATOR) > 0) { str_replace(baseObjectFilter::AND_SEPARATOR, baseObjectFilter::IN_SEPARATOR, $names); $namesArr = explode(baseObjectFilter::IN_SEPARATOR, $names); foreach ($namesArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($namesArr[$valIndex]); } else { $namesArr[$valIndex] = SphinxUtils::escapeString($valValue); } } foreach ($namesArr as $name) { $additionalConditions[] = "@(" . categoryFilter::NAME_REFERNCE_ID . ") {$name}\\\\*"; } } else { $namesArr = explode(baseObjectFilter::AND_SEPARATOR, $names); foreach ($namesArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($namesArr[$valIndex]); } else { $namesArr[$valIndex] = SphinxUtils::escapeString($valValue); } } $namesArr = array_unique($namesArr); $nameExpr = implode(baseObjectFilter::AND_SEPARATOR, $namesArr); $additionalConditions[] = "@(" . categoryFilter::NAME_REFERNCE_ID . ") {$nameExpr}\\\\*"; } } if (count($additionalConditions)) { $additionalConditions = array_unique($additionalConditions); $matches = reset($additionalConditions); if (count($additionalConditions) > 1) { $matches = '( ' . implode(' ) | ( ', $additionalConditions) . ' )'; } $this->matchClause[] = $matches; } } $filter->unsetByName('_likex_name_or_reference_id'); return parent::applyFilterFields($filter); }
protected function getRelativeTimeFields() { return array_merge(parent::getRelativeTimeFields(), self::$relative_time_fields); }
protected function applyFilterFields(baseObjectFilter $filter) { //Role ids and kuser permission names are indexed with the partner ID if ($filter->get('_eq_role_ids')) { $filter->set('_eq_role_ids', kuser::getIndexedFieldValue('kuserPeer::ROLE_IDS', $filter->get('_eq_role_ids'), kCurrentContext::getCurrentPartnerId())); } if ($filter->get('_in_role_ids')) { $filter->set('_eq_role_ids', kuser::getIndexedFieldValue('kuserPeer::ROLE_IDS', $filter->get('_eq_role_ids'), kCurrentContext::getCurrentPartnerId())); } if ($filter->get('_mlikeand_permission_names')) { $permissionNames = kuser::getIndexedFieldValue('kuserPeer::PERMISSION_NAMES', $filter->get('_mlikeand_permission_names'), kCurrentContext::getCurrentPartnerId()); $permissionNames = implode(' ', explode(',', $permissionNames)); $universalPermissionName = kuser::getIndexedFieldValue('kuserPeer::PERMISSION_NAMES', kuser::UNIVERSAL_PERMISSION, kCurrentContext::getCurrentPartnerId()); $value = "({$universalPermissionName} | ({$permissionNames}))"; $this->addMatch("@permission_names {$value}"); $filter->unsetByName('_mlikeand_permission_names'); } if ($filter->get('_mlikeor_permission_names')) { $filter->set('_mlikeor_permission_names', kuser::getIndexedFieldValue('kuserPeer::PERMISSION_NAMES', $filter->get('_mlikeor_permission_names') . ',' . kuser::UNIVERSAL_PERMISSION, kCurrentContext::getCurrentPartnerId())); } if ($filter->get('_likex_puser_id_or_screen_name')) { $freeTexts = $filter->get('_likex_puser_id_or_screen_name'); KalturaLog::debug("Attach free text [{$freeTexts}]"); $additionalConditions = array(); $advancedSearch = $filter->getAdvancedSearch(); if ($advancedSearch) { $additionalConditions = $advancedSearch->getFreeTextConditions($filter->getPartnerSearchScope(), $freeTexts); } $this->addFreeTextToMatchClauseByMatchFields($freeTexts, kuserFilter::PUSER_ID_OR_SCREEN_NAME, $additionalConditions, true); } $filter->unsetByName('_likex_puser_id_or_screen_name'); if ($filter->get('_likex_first_name_or_last_name')) { $names = $filter->get('_likex_first_name_or_last_name'); KalturaLog::debug("Attach free text [{$names}]"); $this->addFreeTextToMatchClauseByMatchFields($names, kuserFilter::FIRST_NAME_OR_LAST_NAME, null, true); } $filter->unsetByName('_likex_first_name_or_last_name'); return parent::applyFilterFields($filter); }
protected function applyFilterFields(baseObjectFilter $filter) { $categoriesAncestorParsed = null; $categories = $filter->get("_in_category_ancestor_id"); if ($categories !== null) { //if the category exist or the category name is an empty string $categoriesAncestorParsed = $filter->categoryIdsToAllSubCategoriesIdsParsed($categories); if (!($categoriesAncestorParsed !== '' || $categories == '')) { $categoriesAncestorParsed = category::CATEGORY_ID_THAT_DOES_NOT_EXIST; } } $filter->unsetByName('_in_category_ancestor_id'); $categories = $filter->get("_matchor_categories_ids"); if ($categories !== null) { //if the category exist or the category name is an empty string if (is_null($categoriesAncestorParsed)) { $categoriesParsed = $filter->categoryIdsToIdsParsed($categories); } else { $categoriesParsed = $categoriesAncestorParsed; } if ($categoriesParsed !== '' || $categories == '') { $filter->set("_matchor_categories_ids", $categoriesParsed); } else { $filter->set("_matchor_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } else { $filter->set("_matchor_categories_ids", $categoriesAncestorParsed); } $categories = $filter->get("_matchand_categories_ids"); if ($categories !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryIdsToIdsParsed($categories); if ($categoriesParsed !== '' || $categories == '') { $filter->set("_matchand_categories_ids", $categoriesParsed); } else { $filter->set("_matchand_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } $matchAndCats = $filter->get("_matchand_categories"); if ($matchAndCats !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($matchAndCats); if ($categoriesParsed !== '' || $matchAndCats == '') { $filter->set("_matchand_categories_ids", $categoriesParsed); } else { $filter->set("_matchand_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_matchand_categories'); } $matchOrCats = $filter->get("_matchor_categories"); if ($matchOrCats !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($matchOrCats); if ($categoriesParsed !== '' || $matchOrCats == '') { $filter->set("_matchor_categories_ids", $categoriesParsed); } else { $filter->set("_matchor_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_matchor_categories'); } // match categories by full name $CatFullNameIn = $filter->get("_in_categories_full_name"); if ($CatFullNameIn !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($CatFullNameIn); if ($categoriesParsed !== '' || $CatFullNameIn == '') { $filter->set("_matchor_categories_ids", $categoriesParsed); } else { $filter->set("_matchor_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_in_categories_full_name'); } $matchOrRoots = array(); if ($filter->is_set('_eq_root_entry_id')) { $matchOrRoots[] = entry::ROOTS_FIELD_ENTRY_PREFIX . ' ' . $filter->get('_eq_root_entry_id'); $filter->unsetByName('_eq_root_entry_id'); } if ($filter->is_set('_in_root_entry_id')) { $roots = explode(baseObjectFilter::IN_SEPARATOR, $filter->get('_in_root_entry_id')); foreach ($roots as $root) { $matchOrRoots[] = entry::ROOTS_FIELD_ENTRY_PREFIX . " {$root}"; } $filter->unsetByName('_in_root_entry_id'); } if ($filter->is_set('_is_root')) { if ($filter->get('_is_root')) { $filter->set('_notin_roots', entry::ROOTS_FIELD_ENTRY_PREFIX); } else { $matchOrRoots[] = entry::ROOTS_FIELD_ENTRY_PREFIX; } $filter->unsetByName('_is_root'); } if (count($matchOrRoots)) { $filter->set('_matchand_roots', $matchOrRoots); } // if ($filter->get("_matchor_duration_type") !== null) // $filter->set("_matchor_duration_type", $filter->durationTypesToIndexedStrings($filter->get("_matchor_duration_type"))); if ($filter->get(baseObjectFilter::ORDER) === "recent" || $filter->get(baseObjectFilter::ORDER) === "-recent") { $filter->set("_lte_available_from", time()); //$filter->set("_gteornull_end_date", time()); // schedule not finished $filter->set(baseObjectFilter::ORDER, "-available_from"); } if ($filter->get(baseObjectFilter::ORDER) === "+recent") { $filter->set(baseObjectFilter::ORDER, "+available_from"); } if ($filter->get('_free_text')) { $freeTexts = $filter->get('_free_text'); KalturaLog::debug("Attach free text [{$freeTexts}]"); $additionalConditions = array(); $advancedSearch = $filter->getAdvancedSearch(); if ($advancedSearch) { $additionalConditions = $advancedSearch->getFreeTextConditions($freeTexts); } if (preg_match('/^"[^"]+"$/', $freeTexts)) { $freeText = str_replace('"', '', $freeTexts); $freeText = SphinxUtils::escapeString($freeText); $freeText = "^{$freeText}\$"; $additionalConditions[] = "@(" . entryFilter::FREE_TEXT_FIELDS . ") {$freeText}"; } else { if (strpos($freeTexts, baseObjectFilter::IN_SEPARATOR) > 0) { str_replace(baseObjectFilter::AND_SEPARATOR, baseObjectFilter::IN_SEPARATOR, $freeTexts); $freeTextsArr = explode(baseObjectFilter::IN_SEPARATOR, $freeTexts); foreach ($freeTextsArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($freeTextsArr[$valIndex]); } else { $freeTextsArr[$valIndex] = SphinxUtils::escapeString($valValue); } } foreach ($freeTextsArr as $freeText) { $additionalConditions[] = "@(" . entryFilter::FREE_TEXT_FIELDS . ") {$freeText}"; } } else { $freeTextsArr = explode(baseObjectFilter::AND_SEPARATOR, $freeTexts); foreach ($freeTextsArr as $valIndex => $valValue) { if (!is_numeric($valValue) && strlen($valValue) <= 0) { unset($freeTextsArr[$valIndex]); } else { $freeTextsArr[$valIndex] = SphinxUtils::escapeString($valValue); } } $freeTextsArr = array_unique($freeTextsArr); $freeTextExpr = implode(baseObjectFilter::AND_SEPARATOR, $freeTextsArr); $additionalConditions[] = "@(" . entryFilter::FREE_TEXT_FIELDS . ") {$freeTextExpr}"; } } if (count($additionalConditions)) { $additionalConditions = array_unique($additionalConditions); $matches = reset($additionalConditions); if (count($additionalConditions) > 1) { $matches = '( ' . implode(' ) | ( ', $additionalConditions) . ' )'; } $this->matchClause[] = $matches; } } $filter->unsetByName('_free_text'); return parent::applyFilterFields($filter); }
/** * 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()); }
/** * List all categories * * @action list * @param KalturaCategoryFilter $filter * @param KalturaFilterPager $pager * @return KalturaCategoryListResponse */ function listAction(KalturaCategoryFilter $filter = null, KalturaFilterPager $pager = null) { if ($filter === null) { $filter = new KalturaCategoryFilter(); } if ($pager == null) { $pager = new KalturaFilterPager(); //before falcon we didn’t have a pager for action category->list, //and since we added a pager – and remove the limit for partners categories, //for backward compatibility this will be the page size. $pager->pageIndex = 1; $pager->pageSize = partner::MAX_NUMBER_OF_CATEGORIES; KalturaCriteria::setMaxRecords(partner::MAX_NUMBER_OF_CATEGORIES); baseObjectFilter::setMaxInValues(partner::MAX_NUMBER_OF_CATEGORIES); } if ($filter->orderBy === null) { $filter->orderBy = KalturaCategoryOrderBy::DEPTH_ASC; } $categoryFilter = new categoryFilter(); $filter->toObject($categoryFilter); $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $categoryFilter->attachToCriteria($c); $pager->attachToCriteria($c); $dbList = categoryPeer::doSelect($c); $totalCount = $c->getRecordsCount(); $list = KalturaCategoryArray::fromCategoryArray($dbList); $response = new KalturaCategoryListResponse(); $response->objects = $list; $response->totalCount = $totalCount; return $response; }