Exemplo n.º 1
0
 /**
  * Return all categories kuser is entitled to view the content.
  * (User may call category->get to view a category - but not to view its content)
  * 
  * @param int $kuserId
  * @param int $limit
  * @return array<category>
  */
 public static function retrieveEntitledAndNonIndexedByKuser($kuserId, $limit)
 {
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $partner = PartnerPeer::retrieveByPK($partnerId);
     $categoryGroupSize = kConf::get('max_number_of_memebrs_to_be_indexed_on_entry');
     if ($partner && $partner->getCategoryGroupSize()) {
         $categoryGroupSize = $partner->getCategoryGroupSize();
     }
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $filteredCategoriesIds = entryPeer::getFilterdCategoriesIds();
     if (count($filteredCategoriesIds)) {
         $c->addAnd(categoryPeer::ID, $filteredCategoriesIds, Criteria::IN);
     }
     $membersCountCrit = $c->getNewCriterion(categoryPeer::MEMBERS_COUNT, $categoryGroupSize, Criteria::GREATER_THAN);
     $membersCountCrit->addOr($c->getNewCriterion(categoryPeer::ENTRIES_COUNT, kConf::get('category_entries_count_limit_to_be_indexed'), Criteria::GREATER_THAN));
     $c->addAnd($membersCountCrit);
     $c->setLimit($limit);
     $c->addDescendingOrderByColumn(categoryPeer::UPDATED_AT);
     //all fields needed from default criteria
     //here we cannot use the default criteria, as we need to get all categories user is entitled to view the content.
     //not deleted or purged
     $c->add(self::STATUS, array(CategoryStatus::DELETED, CategoryStatus::PURGED), Criteria::NOT_IN);
     $c->add(self::PARTNER_ID, $partnerId, Criteria::EQUAL);
     //add privacy context
     $privacyContextCrit = $c->getNewCriterion(self::PRIVACY_CONTEXTS, kEntitlementUtils::getKsPrivacyContext(), KalturaCriteria::IN_LIKE);
     $privacyContextCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $c->addAnd($privacyContextCrit);
     //set privacy by ks and type
     $crit = $c->getNewCriterion(self::PRIVACY, kEntitlementUtils::getPrivacyForKs($partnerId), Criteria::IN);
     $crit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     //user is entitled to view all cantent that belong to categoires he is a membr of
     $kuser = null;
     $ksString = kCurrentContext::$ks ? kCurrentContext::$ks : '';
     if ($ksString != '') {
         $kuser = kCurrentContext::getCurrentKsKuser();
     }
     if ($kuser) {
         // get the groups that the user belongs to in case she is not associated to the category directly
         $kgroupIds = KuserKgroupPeer::retrieveKgroupIdsByKuserId($kuser->getId());
         $kgroupIds[] = $kuser->getId();
         $membersCrit = $c->getNewCriterion(self::MEMBERS, $kgroupIds, KalturaCriteria::IN_LIKE);
         $membersCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $crit->addOr($membersCrit);
     }
     $c->addAnd($crit);
     $c->applyFilters();
     $categoryIds = $c->getFetchedIds();
     return $categoryIds;
 }
Exemplo n.º 2
0
 /**
  * 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);
             }
         }
     }
 }
 /**
  * Return all categories kuser is entitled to view the content.
  * (User may call category->get to view a category - but not to view its content)
  * 
  * @param int $kuserId
  * @param int $limit
  * @return array<categories>
  */
 public static function retrieveEntitledAndNonIndexedByKuser($kuserId, $limit)
 {
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $partner = PartnerPeer::retrieveByPK($partnerId);
     $categoryGroupSize = category::MAX_NUMBER_OF_MEMBERS_TO_BE_INDEXED_ON_ENTRY;
     if ($partner && $partner->getCategoryGroupSize()) {
         $categoryGroupSize = $partner->getCategoryGroupSize();
     }
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $filteredCategoriesIds = entryPeer::getFilterdCategoriesIds();
     if (count($filteredCategoriesIds)) {
         $c->addAnd(categoryPeer::ID, $filteredCategoriesIds, Criteria::IN);
     }
     $membersCountCrit = $c->getNewCriterion(categoryPeer::MEMBERS_COUNT, $categoryGroupSize, Criteria::GREATER_THAN);
     $membersCountCrit->addOr($c->getNewCriterion(categoryPeer::ENTRIES_COUNT, entry::CATEGORY_ENTRIES_COUNT_LIMIT_TO_BE_INDEXED, Criteria::GREATER_THAN));
     $c->addAnd($membersCountCrit);
     $c->setLimit($limit);
     $c->addDescendingOrderByColumn(categoryPeer::UPDATED_AT);
     //all fields needed from default criteria
     //here we cannot use the default criteria, as we need to get all categories user is entitled to view the content.
     //not deleted or purged
     $c->add(self::STATUS, array(CategoryStatus::DELETED, CategoryStatus::PURGED), Criteria::NOT_IN);
     $c->add(self::PARTNER_ID, $partnerId, Criteria::EQUAL);
     //add privacy context
     $privacyContextCrit = $c->getNewCriterion(self::PRIVACY_CONTEXTS, kEntitlementUtils::getKsPrivacyContext(), KalturaCriteria::IN_LIKE);
     $privacyContextCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $c->addAnd($privacyContextCrit);
     //set privacy by ks and type
     $crit = $c->getNewCriterion(self::PRIVACY, kEntitlementUtils::getPrivacyForKs(), Criteria::IN);
     $crit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     //user is entitled to view all cantent that belong to categoires he is a membr of
     $kuser = null;
     $ksString = kCurrentContext::$ks ? kCurrentContext::$ks : '';
     if ($ksString != '') {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $kuser = kuserPeer::getActiveKuserByPartnerAndUid($partnerId, kCurrentContext::$ks_uid);
     }
     if ($kuser) {
         $membersCrit = $c->getNewCriterion(self::MEMBERS, $kuser->getId(), Criteria::LIKE);
         $membersCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $crit->addOr($membersCrit);
     }
     $c->addAnd($crit);
     categoryPeer::setUseCriteriaFilter(false);
     $categories = self::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     return $categories;
 }