public function getEntitledKusers() { $entitledKusersPublish = explode(',', $this->getEntitledKusersPublish()); $entitledKusersEdit = explode(',', $this->getEntitledKusersEdit()); $entitledKusersNoPrivacyContext = array_merge($entitledKusersPublish, $entitledKusersEdit); $entitledKusersNoPrivacyContext[] = $this->getKuserId(); foreach ($entitledKusersNoPrivacyContext as $key => $value) { if (!$value) { unset($entitledKusersNoPrivacyContext[$key]); } } $entitledKusers = array(); if (count(array_unique($entitledKusersNoPrivacyContext))) { $entitledKusers[kEntitlementUtils::ENTRY_PRIVACY_CONTEXT] = array_unique($entitledKusersNoPrivacyContext); } $allCategoriesIds = $this->getAllCategoriesIds(true); if (!count($allCategoriesIds)) { return kEntitlementUtils::ENTRY_PRIVACY_CONTEXT . '_' . implode(' ' . kEntitlementUtils::ENTRY_PRIVACY_CONTEXT . '_', $entitledKusersNoPrivacyContext); } $categoryGroupSize = kConf::get('max_number_of_memebrs_to_be_indexed_on_entry'); $partner = $this->getPartner(); if ($partner && $partner->getCategoryGroupSize()) { $categoryGroupSize = $partner->getCategoryGroupSize(); } //get categories for this entry that have small amount of members. $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $c->add(categoryPeer::ID, $allCategoriesIds, Criteria::IN); $c->add(categoryPeer::MEMBERS_COUNT, $categoryGroupSize, Criteria::LESS_EQUAL); $c->add(categoryPeer::ENTRIES_COUNT, kConf::get('category_entries_count_limit_to_be_indexed'), Criteria::LESS_EQUAL); $c->dontCount(); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $categories = categoryPeer::doSelect($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); //get all memebrs foreach ($categories as $category) { if (!count($category->getMembers())) { continue; } $privacyContexts = explode(',', $category->getPrivacyContexts()); if (!count($privacyContexts)) { $privacyContexts = array(kEntitlementUtils::DEFAULT_CONTEXT . $this->getPartnerId()); } foreach ($privacyContexts as $privacyContext) { $privacyContext = trim($privacyContext); if (isset($entitledKusers[$privacyContext])) { $entitledKusers[$privacyContext] = array_merge($entitledKusers[$privacyContext], $category->getMembers()); } else { $entitledKusers[$privacyContext] = $category->getMembers(); } } } $entitledKusersByContexts = array(); foreach ($entitledKusers as $privacyContext => $kusers) { $entitledKusersByContexts[] = $privacyContext . '_' . implode(' ' . $privacyContext . '_', $kusers); } return implode(' ', $entitledKusersByContexts); }
protected function doGetListResponse(KalturaFilterPager $pager) { myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL3; $disableWidgetSessionFilters = false; if ($this && ($this->idEqual != null || $this->idIn != null || $this->referenceIdEqual != null || $this->redirectFromEntryId != null || $this->referenceIdIn != null || $this->parentEntryIdEqual != null)) { $disableWidgetSessionFilters = true; } $c = $this->prepareEntriesCriteriaFilter($pager); if ($disableWidgetSessionFilters) { KalturaCriterion::disableTag(KalturaCriterion::TAG_WIDGET_SESSION); } $list = entryPeer::doSelect($c); $totalCount = $c->getRecordsCount(); if ($disableWidgetSessionFilters) { KalturaCriterion::restoreTag(KalturaCriterion::TAG_WIDGET_SESSION); } myDbHelper::$use_alternative_con = null; return array($list, $totalCount); }
public static function executeDynamicPlaylist($partner_id, $xml, $filter = null, $detailed = true, $pager = null) { list($total_results, $list_of_filters) = self::getPlaylistFilterListStruct($xml); $entry_filters = array(); if (!$list_of_filters) { return null; } // TODO - for now we assume that there are more or equal filters in the XML than the ones from the request $filterLimit = null; if ($filter && $filter->getLimit() > 0) { $filterLimit = $filter->getLimit(); // Get the max results from the limit of the first filter $total_results = min($total_results, $filterLimit); // Clear this limit so it won't overcloud the limits of $entry_filter_xml rules $filter->setLimit(null); } $numFiltersInList = count($list_of_filters); for ($i = 0; $i < $numFiltersInList; $i++) { $entry_filter_xml = $list_of_filters[$i]; /* @var $entry_filter_xml SimpleXMLElement */ // in general this service can fetch entries from kaltura networks. // for each filter we should decide if thie assumption is true... $allow_partner_only = true; self::replaceContextTokens($entry_filter_xml); // compile all the filters - only then execute them if not yet reached the total_results // TODO - optimize - maybe create them only when needed. - For now it's safer to compile all even if not needed. $entry_filter = new entryFilter(); // add the desired prefix "_" because the XML is not expected to have it while the entryFilter class expects it $entry_filter->fillObjectFromXml($entry_filter_xml, "_"); // make sure there is alway a limit for each filter - if not an explicit one - the system limit should be used if ($entry_filter->getLimit() == null || $entry_filter->getLimit() < 1) { $entry_filter->setLimit(self::TOTAL_RESULTS); } // merge the current_filter with the correcponding extra_filter // allow the extra_filter to override properties of the current filter if ($filter) { if ($filterLimit && $i == $numFiltersInList - 1) { // Hack (in order to preserve old behavior): // If the filter contained a limit, we'll add it to the last XML filter on the list // in order to make sure the number of requested ($limit) entries will be supplied. // This handles requests of a $limit which is higher than the total sum of inner XML filter limits. $filter->setLimit($filterLimit); } $entry_filter->fillObjectFromObject($filter, myBaseObject::CLONE_FIELD_POLICY_THIS, myBaseObject::CLONE_POLICY_PREFER_NEW, null, null, false); $entry_filter->setPartnerSearchScope(baseObjectFilter::MATCH_KALTURA_NETWORK_AND_PRIVATE); } self::updateEntryFilter($entry_filter, $partner_id, true); $entry_filters[] = $entry_filter; } if ($pager) { $startOffset = $pager->calcOffset(); $pageSize = $pager->calcPageSize(); if ($startOffset > $total_results) { return array(); } $total_results = min($total_results, $startOffset + $pageSize); } $entry_ids_list = array(); foreach ($entry_filters as $entry_filter) { $current_limit = max(0, $total_results - count($entry_ids_list)); // if the current_limit is < 0 - set it to be 0 // no need to fetch any more results if ($current_limit <= 0) { break; } $c = KalturaCriteria::create(entryPeer::OM_CLASS); // don't fetch the same entries twice - filter out all the entries that were already fetched if ($entry_ids_list) { $c->add(entryPeer::ID, $entry_ids_list, Criteria::NOT_IN); } $filter_limit = $entry_filter->getLimit(); if ($filter_limit > $current_limit) { // set a smaller limit incase the filter's limit is to high $entry_filter->setLimit($current_limit); } // read the _eq_display_in_search field but ignore it because it's part of a more complex criterion $display_in_search = $entry_filter->get("_eq_display_in_search"); if ($display_in_search >= 2) { $entry_filter->set("_eq_display_in_search", null); } $entry_filter->attachToCriteria($c); // add some hard-coded criteria $c->addAnd(entryPeer::TYPE, array(entryType::MEDIA_CLIP, entryType::MIX, entryType::LIVE_STREAM), Criteria::IN); // search only for clips or roughcuts $c->addAnd(entryPeer::STATUS, entryStatus::READY); // search only for READY entries $c->addAnd(entryPeer::DISPLAY_IN_SEARCH, mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM, Criteria::NOT_EQUAL); if ($display_in_search >= 2) { // We don't allow searching in the KalturaNEtwork anymore (mainly for performance reasons) // allow only assets for the partner $c->addAnd(entryPeer::PARTNER_ID, $partner_id); // /* $crit = $c->getNewCriterion ( entryPeer::PARTNER_ID , $partner_id ); $crit->addOr ( $c->getNewCriterion ( entryPeer::DISPLAY_IN_SEARCH , $display_in_search ) ); $c->addAnd ( $crit ); */ } if (!self::$isAdminKs) { self::addSchedulingToCriteria($c); } self::addModerationToCriteria($c); $c = entryPeer::prepareEntitlementCriteriaAndFilters($c); $entry_ids_list_for_filter = $c->getFetchedIds(); // update total count and merge current result with the global list $entry_ids_list = array_merge($entry_ids_list, $entry_ids_list_for_filter); } if ($pager) { // Keep the paged entries only $entry_ids_list = array_slice($entry_ids_list, $startOffset, $pageSize); } // Disable entitlement, which was already applied in entryPeer::prepareEntitlementCriteriaAndFilters() // otherwise we will hit the 150 entries limit from SphinxCriterion KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_ENTRY); $db_entry_list = entryPeer::retrieveByPKs($entry_ids_list); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_ENTRY); // Map the entries to their IDs $entry_map = array(); foreach ($db_entry_list as $entry) { $entry_map[$entry->getId()] = $entry; } // Build entry_list according to the playlist order $entry_list = array(); foreach ($entry_ids_list as $entryId) { $entry_list[] = $entry_map[$entryId]; } return $entry_list; }
/** * Get category by full name using exact match (returns null or category object) * * @param $fullName * @param $ignoreCategoryId * @param $partnerId * @return category */ public static function getByFullNameExactMatch($fullName, $ignoreCategoryId = null, $partnerId = null) { $fullName = self::getParsedFullName($fullName); if (trim($fullName) == '') { return null; } $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $c->add(categoryPeer::FULL_NAME, $fullName); if ($ignoreCategoryId) { $c->add(categoryPeer::ID, $ignoreCategoryId, Criteria::NOT_EQUAL); } $tagDisabled = false; if (!is_null($partnerId)) { $tagDisabled = true; KalturaCriterion::disableTag(KalturaCriterion::TAG_PARTNER_SESSION); $c->add(categoryPeer::PARTNER_ID, $partnerId); } $ret = categoryPeer::doSelectOne($c); if ($tagDisabled) { KalturaCriterion::restoreTag(KalturaCriterion::TAG_PARTNER_SESSION); } return $ret; }
/** * To validate if user is entitled to the category � all needed is to select from the db. * * @throws KalturaErrors::ENTRY_CATEGORY_FIELD_IS_DEPRECATED */ public function validateCategories() { $partnerId = kCurrentContext::$ks_partner_id ? kCurrentContext::$ks_partner_id : kCurrentContext::$partner_id; if (implode(',', kEntitlementUtils::getKsPrivacyContext()) != kEntitlementUtils::DEFAULT_CONTEXT . $partnerId && ($this->categoriesIds != null || $this->categories != null)) { throw new KalturaAPIException(KalturaErrors::ENTRY_CATEGORY_FIELD_IS_DEPRECATED); } if ($this->categoriesIds != null) { $catsNames = array(); $cats = explode(",", $this->categoriesIds); foreach ($cats as $cat) { $catName = categoryPeer::retrieveByPK($cat); if (is_null($catName)) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $cat); } } } if ($this->categories != null) { $catsNames = array(); $cats = explode(",", $this->categories); foreach ($cats as $cat) { $catName = categoryPeer::getByFullNameExactMatch($cat); if (is_null($catName)) { KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $catName = categoryPeer::getByFullNameExactMatch($cat); if ($catName) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_PERMITTED, $cat); } KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); } } } }
public static function syncEntriesCategories(entry $entry, $isCategoriesModified) { self::$skipEntrySave = true; if ($entry->getNewCategories() != null && $entry->getNewCategories() !== "") { $newCats = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategories()); } else { $newCats = array(); } if (!$isCategoriesModified) { if ($entry->getNewCategoriesIds() != null && $entry->getNewCategoriesIds() !== "") { $newCatsIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategoriesIds()); } else { $newCatsIds = array(); } KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $dbCategories = categoryPeer::retrieveByPKs($newCatsIds); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); foreach ($dbCategories as $dbCategory) { //skip categoy with privacy contexts. if ($dbCategory->getPrivacyContexts() != null && $dbCategory->getPrivacyContexts() != '') { continue; } $newCats[] = $dbCategory->getFullName(); } } $newCats = array_unique($newCats); $allIds = array(); $allCats = array(); $allIdsWithParents = array(); $addedCats = array(); $removedCats = array(); $remainingCats = array(); $oldCats = array(); $oldCatsIds = array(); $dbOldCategoriesEntry = categoryEntryPeer::selectByEntryId($entry->getId()); foreach ($dbOldCategoriesEntry as $dbOldCategoryEntry) { $oldCatsIds[] = $dbOldCategoryEntry->getCategoryId(); } $oldCategoris = categoryPeer::retrieveByPKsNoFilter($oldCatsIds); foreach ($oldCategoris as $category) { if ($category->getPrivacyContexts() != '' && $category->getPrivacyContexts() != null) { continue; } $oldCats[] = $category->getFullName(); } foreach ($oldCats as $cat) { if (array_search($cat, $newCats) === false) { $removedCats[] = $cat; } } foreach ($newCats as $cat) { if (array_search($cat, $oldCats) === false) { $addedCats[] = $cat; } else { $remainingCats[] = $cat; } } foreach ($remainingCats as $cat) { KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $category = categoryPeer::getByFullNameExactMatch($cat); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if ($category) { if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) { $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } $allIdsWithParents[] = $category->getId(); $allIdsWithParents = array_merge($allIdsWithParents, $category->getAllParentsIds()); } } $alreadyAddedCatIds = $allIdsWithParents; foreach ($addedCats as $cat) { $category = categoryPeer::getByFullNameExactMatch($cat); if (!$category) { KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $unentitedCategory = categoryPeer::getByFullNameExactMatch($cat); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if (!$unentitedCategory) { $category = category::createByPartnerAndFullName($entry->getPartnerId(), $cat); //it is possible to add on an entry a few new categories on the same new parent - //and we need to sync sphinx once we add so the category will not be duplicated kEventsManager::flushEvents(); } } else { $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($category->getId(), kCurrentContext::$ks_kuser_id); if (kEntitlementUtils::getEntitlementEnforcement() && $category->getContributionPolicy() != ContributionPolicyType::ALL && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) { //user is not entitled to add entry to this category $category = null; } } if (!$category) { continue; } //when use caetgoryEntry->add categoryEntry object was alreay created - and no need to create it. //when using baseEntry->categories = 'my category' will need to add the new category. $categoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId()); if (!$categoryEntry) { $categoryEntry = new categoryEntry(); $categoryEntry->setEntryId($entry->getId()); $categoryEntry->setCategoryId($category->getId()); $categoryEntry->setEntryCategoriesAddedIds($alreadyAddedCatIds); $categoryEntry->setPartnerId($entry->getPartnerId()); $categoryEntry->setStatus(CategoryEntryStatus::ACTIVE); $categoryEntry->save(); } if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) { // only categories with no context should be set on entry->categories and entry->categoriesIds $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } $alreadyAddedCatIds[] = $category->getId(); $alreadyAddedCatIds = array_merge($alreadyAddedCatIds, $category->getAllParentsIds()); } $alreadyRemovedCatIds = $allIdsWithParents; foreach ($removedCats as $cat) { $category = categoryPeer::getByFullNameExactMatch($cat); if ($category) { $categoryEntryToDelete = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId()); if ($categoryEntryToDelete) { $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryEntryToDelete->getCategoryId(), kCurrentContext::$ks_kuser_id); if ($category->getPrivacyContexts() && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) { //not entiteld to delete - should be set back on the entry. $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } else { $categoryEntryToDelete->setEntryCategoriesRemovedIds($alreadyRemovedCatIds); $categoryEntryToDelete->setStatus(CategoryEntryStatus::DELETED); $categoryEntryToDelete->save(); } } $alreadyRemovedCatIds[] = $category->getId(); $alreadyRemovedCatIds = array_merge($alreadyRemovedCatIds, $category->getAllParentsIds()); } else { //category was not found - it could be that user is not entitled to remove it KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $category = categoryPeer::getByFullNameExactMatch($cat); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if ($category) { $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } } } self::$skipEntrySave = false; $entry->parentSetCategories(implode(",", $allCats)); $entry->parentSetCategoriesIds(implode(',', $allIds)); }
protected function listEntriesByFilter(KalturaBaseEntryFilter $filter = null, KalturaFilterPager $pager = null) { myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL3; $disableWidgetSessionFilters = false; if ($filter && ($filter->idEqual != null || $filter->idIn != null || $filter->referenceIdEqual != null || $filter->referenceIdIn != null)) { $disableWidgetSessionFilters = true; } if (!$pager) { $pager = new KalturaFilterPager(); } $c = $this->prepareEntriesCriteriaFilter($filter, $pager); if ($disableWidgetSessionFilters) { KalturaCriterion::disableTag(KalturaCriterion::TAG_WIDGET_SESSION); } $list = entryPeer::doSelect($c); $totalCount = $c->getRecordsCount(); if ($disableWidgetSessionFilters) { KalturaCriterion::restoreTag(KalturaCriterion::TAG_WIDGET_SESSION); } return array($list, $totalCount); }
private static function applyEntitlementCriteria(Criteria &$c) { $skipApplyFilters = false; if (kEntitlementUtils::getEntitlementEnforcement() && KalturaCriterion::isTagEnable(KalturaCriterion::TAG_ENTITLEMENT_ENTRY) && self::$kuserBlongToMoreThanMaxCategoriesForSearch && !$c->getOffset()) { KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_ENTRY); $entitlementCrit = clone $c; $entitlementCrit->applyFilters(); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_ENTRY); if ($entitlementCrit->getRecordsCount() < $entitlementCrit->getLimit()) { $c = $entitlementCrit; $c->setRecordsCount($entitlementCrit->getRecordsCount()); $skipApplyFilters = true; self::$filerResults = true; } else { self::$filerResults = false; //TODO add header that not full search } } return $skipApplyFilters; }
/** * List base entries by filter according to reference id * * @action listByReferenceId * @param string $refId Entry Reference ID * @param KalturaFilterPager $pager Pager * @throws KalturaErrors::MISSING_MANDATORY_PARAMETER */ function listByReferenceId($refId, KalturaFilterPager $pager = null) { if (!$refId) { //if refId wasn't provided return an error of missing parameter throw new KalturaAPIException(KalturaErrors::MISSING_MANDATORY_PARAMETER, $refId); } if (!$pager) { $pager = new KalturaFilterPager(); } $entryFilter = new entryFilter(); $entryFilter->setPartnerSearchScope(baseObjectFilter::MATCH_KALTURA_NETWORK_AND_PRIVATE); //setting reference ID $entryFilter->set('_eq_reference_id', $refId); $c = KalturaCriteria::create(entryPeer::OM_CLASS); $pager->attachToCriteria($c); $entryFilter->attachToCriteria($c); $c->add(entryPeer::DISPLAY_IN_SEARCH, mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM, Criteria::NOT_EQUAL); KalturaCriterion::disableTag(KalturaCriterion::TAG_WIDGET_SESSION); $list = entryPeer::doSelect($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_WIDGET_SESSION); $totalCount = $c->getRecordsCount(); $newList = KalturaBaseEntryArray::fromEntryArray($list, false); $response = new KalturaBaseEntryListResponse(); $response->objects = $newList; $response->totalCount = $totalCount; return $response; }
public function reSetDirectSubCategoriesCount() { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $c->add(categoryPeer::STATUS, array(CategoryStatus::DELETED, CategoryStatus::PURGED), Criteria::NOT_IN); $c->add(categoryPeer::PARENT_ID, $this->getId(), Criteria::EQUAL); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $c->applyFilters(); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $this->setDirectSubCategoriesCount($c->getRecordsCount()); }
public function addIndexCategoryInheritedTreeJob($fullIdsStartsWithCategoryId) { $featureStatusToRemoveIndex = new kFeatureStatus(); $featureStatusToRemoveIndex->setType(IndexObjectType::CATEGORY); $featureStatusesToRemove = array(); $featureStatusesToRemove[] = $featureStatusToRemoveIndex; $filter = new categoryFilter(); $filter->setFullIdsStartsWith($fullIdsStartsWithCategoryId); $filter->setInheritanceTypeEqual(InheritanceType::INHERIT); $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $filter->attachToCriteria($c); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $categories = categoryPeer::doSelect($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if (count($categories)) { kJobsManager::addIndexJob($this->getPartnerId(), IndexObjectType::CATEGORY, $filter, true, $featureStatusesToRemove); } }
public static function getPrivacyContextForEntry(entry $entry) { $privacyContexts = array(); $entryPrivacy = null; $categories = array(); if (count($entry->getAllCategoriesIds(true))) { $c = KalturaCriteria::create(categoryPeer::OM_CLASS); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $c->add(categoryPeer::ID, $entry->getAllCategoriesIds(true), Criteria::IN); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $categories = categoryPeer::doSelect($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); foreach ($categories as $category) { $categoryPrivacy = $category->getPrivacy(); $categoryPrivacyContexts = $category->getPrivacyContexts(); if (!$categoryPrivacyContexts) { $categoryPrivacyContexts = self::DEFAULT_CONTEXT . $entry->getPartnerId(); } $categoryPrivacyContexts = explode(',', $categoryPrivacyContexts); foreach ($categoryPrivacyContexts as $categoryPrivacyContext) { if (trim($categoryPrivacyContext) == '') { $categoryPrivacyContext = self::DEFAULT_CONTEXT . $entry->getPartnerId(); } if (!isset($privacyContexts[$categoryPrivacyContext]) || $privacyContexts[$categoryPrivacyContext] > $categoryPrivacy) { $privacyContexts[trim($categoryPrivacyContext)] = $categoryPrivacy; } } } } //Entry That doesn't assinged to any category is public. if (!count($categories)) { $privacyContexts[self::DEFAULT_CONTEXT . $entry->getPartnerId()] = PrivacyType::ALL; } $entryPrivacyContexts = array(); foreach ($privacyContexts as $categoryPrivacyContext => $Privacy) { $entryPrivacyContexts[] = $categoryPrivacyContext . '_' . $Privacy; } KalturaLog::debug('Privacy by context: ' . print_r($entryPrivacyContexts, true)); return $entryPrivacyContexts; }
public static function executeDynamicPlaylist($partner_id, $xml, $extra_filters = null, $detailed = true) { list($total_results, $list_of_filters) = self::getPlaylistFilterListStruct($xml); $entry_filters = array(); if (!$list_of_filters) { return null; } // TODO - for now we assume that there are more or equal filters in the XML than the ones from the request $i = 1; // the extra_filter is 1-based foreach ($list_of_filters as $entry_filter_xml) { // in general this service can fetch entries from kaltura networks. // for each filter we should decide if thie assumption is true... $allow_partner_only = true; // compile all the filters - only then execute them if not yet reached the total_results // TODO - optimize - maybe create them only when needed. - For now it's safer to compile all even if not needed. $entry_filter = new entryFilter(); // add the desired prefix "_" because the XML is not expected to have it while the entryFilter class expects it $entry_filter->fillObjectFromXml($entry_filter_xml, "_"); // make sure there is alway a limit for each filter - if not an explicit one - the system limit should be used if ($entry_filter->getLimit() == null || $entry_filter->getLimit() < 1) { $entry_filter->setLimit(self::TOTAL_RESULTS); } $extra_filter = @$extra_filters[$i]; // merge the current_filter with the correcponding extra_filter // allow the extra_filter to override properties of the current filter if ($extra_filter) { $entry_filter->fillObjectFromObject($extra_filter, myBaseObject::CLONE_FIELD_POLICY_THIS, myBaseObject::CLONE_POLICY_PREFER_NEW, null, null, false); $entry_filter->setPartnerSearchScope(baseObjectFilter::MATCH_KALTURA_NETWORK_AND_PRIVATE); } self::updateEntryFilter($entry_filter, $partner_id, true); $entry_filters[] = $entry_filter; $i++; } $number_of_entries = 0; $entry_list = array(); $i = 1; foreach ($entry_filters as $entry_filter) { $current_limit = max(0, $total_results - $number_of_entries); // if the current_limit is < 0 - set it to be 0 $exclude_id_list = self::getIds($entry_list); $c = KalturaCriteria::create(entryPeer::OM_CLASS); // don't fetch the same entries twice - filter out all the entries that were already fetched if ($exclude_id_list) { $c->add(entryPeer::ID, $exclude_id_list, Criteria::NOT_IN); } // no need to fetch any more results if ($current_limit <= 0) { break; } $filter_limit = $entry_filter->getLimit(); if ($filter_limit > $current_limit) { // set a smaller limit incase the filter's limit is to high $entry_filter->setLimit($current_limit); } // read the _eq_display_in_search field but ignore it because it's part of a more complex criterion $display_in_search = $entry_filter->get("_eq_display_in_search"); if ($display_in_search >= 2) { $entry_filter->set("_eq_display_in_search", null); } $entry_filter->attachToCriteria($c); // add some hard-coded criteria $c->addAnd(entryPeer::TYPE, array(entryType::MEDIA_CLIP, entryType::MIX, entryType::LIVE_STREAM), Criteria::IN); // search only for clips or roughcuts $c->addAnd(entryPeer::STATUS, entryStatus::READY); // search only for READY entries $c->addAnd(entryPeer::DISPLAY_IN_SEARCH, mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM, Criteria::NOT_EQUAL); if ($display_in_search >= 2) { // We don't allow searching in the KalturaNEtwork anymore (mainly for performance reasons) // allow only assets for the partner $c->addAnd(entryPeer::PARTNER_ID, $partner_id); // /* $crit = $c->getNewCriterion ( entryPeer::PARTNER_ID , $partner_id ); $crit->addOr ( $c->getNewCriterion ( entryPeer::DISPLAY_IN_SEARCH , $display_in_search ) ); $c->addAnd ( $crit ); */ } if (!self::$isAdminKs) { self::addSchedulingToCriteria($c); } self::addModerationToCriteria($c); KalturaCriterion::disableTag(KalturaCriterion::TAG_WIDGET_SESSION); if ($detailed) { $entry_list_for_filter = entryPeer::doSelectJoinkuser($c); } else { $entry_list_for_filter = entryPeer::doSelect($c); } // maybe join with kuser to add some data about the contributor KalturaCriterion::restoreTag(KalturaCriterion::TAG_WIDGET_SESSION); // update total count and merge current result with the global list $number_of_entries += count($entry_list_for_filter); $entry_list = array_merge($entry_list, $entry_list_for_filter); } return $entry_list; }
private static function getCategoriesByIds($categoriesIds) { $c = KalturaCriteria::create(categoryPeer::OM_CLASS); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $c->add(categoryPeer::ID, $categoriesIds, Criteria::IN); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $c->dontCount(); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $categories = categoryPeer::doSelect($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); return $categories; }
/** * Get web playable Flavor Assets for Entry * * @action getWebPlayableByEntryId * @param string $entryId * @return KalturaFlavorAssetArray */ public function getWebPlayableByEntryIdAction($entryId) { // entry could be "display_in_search = 2" - in that case we want to pull it although KN is off in services.ct for this action $c = KalturaCriteria::create(entryPeer::OM_CLASS); $c->addAnd(entryPeer::ID, $entryId); $criterionPartnerOrKn = $c->getNewCriterion(entryPeer::PARTNER_ID, $this->getPartnerId()); $criterionPartnerOrKn->addOr($c->getNewCriterion(entryPeer::DISPLAY_IN_SEARCH, mySearchUtils::DISPLAY_IN_SEARCH_KALTURA_NETWORK)); $c->addAnd($criterionPartnerOrKn); // there could only be one entry because the query is by primary key. // so using doSelectOne is safe. KalturaCriterion::disableTag(KalturaCriterion::TAG_WIDGET_SESSION); $dbEntry = entryPeer::doSelectOne($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_WIDGET_SESSION); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $flavorAssetsDb = assetPeer::retrieveReadyWebByEntryId($entryId); if (count($flavorAssetsDb) == 0) { throw new KalturaAPIException(KalturaErrors::NO_FLAVORS_FOUND); } $flavorAssets = KalturaFlavorAssetArray::fromDbArray($flavorAssetsDb); return $flavorAssets; }
public static function filterEntriesByPartnerOrKalturaNetwork(array $entryIds, $partnerId) { $c = KalturaCriteria::create(entryPeer::OM_CLASS); $c->addAnd(entryPeer::ID, $entryIds, Criteria::IN); $criterionPartnerOrKn = $c->getNewCriterion(entryPeer::PARTNER_ID, $partnerId); $criterionPartnerOrKn->addOr($c->getNewCriterion(entryPeer::DISPLAY_IN_SEARCH, mySearchUtils::DISPLAY_IN_SEARCH_KALTURA_NETWORK)); $c->addAnd($criterionPartnerOrKn); KalturaCriterion::disableTag(KalturaCriterion::TAG_WIDGET_SESSION); $dbEntries = self::doSelect($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_WIDGET_SESSION); $entryIds = array(); foreach ($dbEntries as $dbEntry) { $entryIds[] = $dbEntry->getId(); } return $entryIds; }