示例#1
0
 public static function doCountOnPeer(Criteria $c)
 {
     return categoryKuserPeer::doCount($c);
 }
示例#2
0
 /**
  * Returns the number of related categoryKuser objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related categoryKuser objects.
  * @throws     PropelException
  */
 public function countcategoryKusers(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(kuserPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collcategoryKusers === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(categoryKuserPeer::KUSER_ID, $this->id);
             $count = categoryKuserPeer::doCount($criteria, false, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(categoryKuserPeer::KUSER_ID, $this->id);
             if (!isset($this->lastcategoryKuserCriteria) || !$this->lastcategoryKuserCriteria->equals($criteria)) {
                 $count = categoryKuserPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collcategoryKusers);
             }
         } else {
             $count = count($this->collcategoryKusers);
         }
     }
     return $count;
 }
 /**
  * List all categories
  * 
  * @action list
  * @param KalturaCategoryUserFilter $filter
  * @param KalturaFilterPager $pager
  * @return KalturaCategoryUserListResponse
  * @throws KalturaErrors::MUST_FILTER_USERS_OR_CATEGORY
  */
 function listAction(KalturaCategoryUserFilter $filter = null, KalturaFilterPager $pager = null)
 {
     if (!($filter->categoryIdEqual || $filter->categoryIdIn || $filter->userIdIn || $filter->userIdEqual)) {
         throw new KalturaAPIException(KalturaErrors::MUST_FILTER_USERS_OR_CATEGORY);
     }
     if (!$filter) {
         $filter = new KalturaCategoryUserFilter();
     }
     if (!$pager) {
         $pager = new kalturaFilterPager();
     }
     if ($filter->userIdIn) {
         $usersIds = explode(',', $filter->userIdIn);
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
         $c->add(kuserPeer::PUSER_ID, $usersIds, Criteria::IN);
         $kusers = kuserPeer::doSelect($c);
         $usersIds = array();
         foreach ($kusers as $kuser) {
             $usersIds[] = $kuser->getId();
         }
         $filter->userIdIn = implode(',', $usersIds);
     }
     if ($filter->userIdEqual) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId);
         $c->add(kuserPeer::PUSER_ID, $filter->userIdEqual);
         $c->add(kuserPeer::STATUS, KuserStatus::ACTIVE);
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = kuserPeer::doSelectOne($c);
         kuserPeer::setUseCriteriaFilter(true);
         //batch should be abke to get categoryUser of deleted users.
         if (!$kuser || $kuser->getStatus() != KuserStatus::ACTIVE && kCurrentContext::$ks_partner_id != Partner::BATCH_PARTNER_ID) {
             KalturaLog::debug('User not found');
             $response = new KalturaCategoryUserListResponse();
             $response->objects = new KalturaCategoryUserArray();
             $response->totalCount = 0;
             return $response;
         }
         $filter->userIdEqual = $kuser->getId();
     }
     $categories = array();
     if ($filter->categoryIdEqual) {
         $categories[] = categoryPeer::retrieveByPK($filter->categoryIdEqual);
     } elseif ($filter->categoryIdIn) {
         $categories = categoryPeer::retrieveByPKs(explode(',', $filter->categoryIdIn));
     }
     $categoriesInheritanceRoot = array();
     foreach ($categories as $category) {
         if (is_null($category)) {
             continue;
         }
         if ($category->getInheritanceType() == InheritanceType::INHERIT) {
             if ($filter->categoryDirectMembers && kCurrentContext::$master_partner_id == Partner::BATCH_PARTNER_ID) {
                 $categoriesInheritanceRoot[$category->getId()] = $category->getId();
             } else {
                 //if category inheris members - change filter to -> inherited from parent id = category->getIheritedParent
                 $categoriesInheritanceRoot[$category->getInheritedParentId()] = $category->getInheritedParentId();
             }
         } else {
             $categoriesInheritanceRoot[$category->getId()] = $category->getId();
         }
     }
     $filter->categoryDirectMembers = null;
     $filter->categoryIdEqual = null;
     $filter->categoryIdIn = implode(',', $categoriesInheritanceRoot);
     //if filter had categories that doesn't exists or not entitled - should return 0 objects.
     if (count($categories) && !count($categoriesInheritanceRoot)) {
         $response = new KalturaCategoryUserListResponse();
         $response->totalCount = 0;
         return $response;
     }
     $categoryKuserFilter = new categoryKuserFilter();
     $filter->toObject($categoryKuserFilter);
     $c = KalturaCriteria::create(categoryKuserPeer::OM_CLASS);
     $categoryKuserFilter->attachToCriteria($c);
     $c->applyFilters();
     $totalCount = categoryKuserPeer::doCount($c);
     $pager->attachToCriteria($c);
     $list = categoryKuserPeer::doSelect($c);
     $newList = KalturaCategoryUserArray::fromDbArray($list);
     $response = new KalturaCategoryUserListResponse();
     $response->objects = $newList;
     $response->totalCount = $totalCount;
     return $response;
 }
示例#4
0
 /**
  * reset category's pendingMembersCount by calculate it.
  */
 public function reSetPendingMembersCount()
 {
     if ($this->getInheritanceType() == InheritanceType::INHERIT) {
         $this->setPendingMembersCount($this->getInheritParent()->getPendingMembersCount());
     } else {
         $criteria = KalturaCriteria::create(categoryKuserPeer::OM_CLASS);
         $criteria->addAnd(categoryKuserPeer::CATEGORY_ID, $this->getId(), Criteria::EQUAL);
         $criteria->addAnd(categoryKuserPeer::STATUS, CategoryKuserStatus::PENDING, Criteria::EQUAL);
         $this->setPendingMembersCount(categoryKuserPeer::doCount($criteria));
     }
 }
 protected function doCountOnPeer(Criteria $c)
 {
     return categoryKuserPeer::doCount($c);
 }