Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 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);
 }