/** * * @param array $categoriesIds * @param int $kuserId * @param $con * * @return categoryKuser */ public static function retrieveByCategoriesIdsAndActiveKuserId($categoriesIds, $kuserId, $con = null) { $criteria = new Criteria(); $criteria->add(categoryKuserPeer::CATEGORY_ID, $categoriesIds, Criteria::IN); $criteria->add(categoryKuserPeer::KUSER_ID, $kuserId); $criteria->add(categoryKuserPeer::STATUS, CategoryKuserStatus::ACTIVE); return categoryKuserPeer::doSelectOne($criteria, $con); }
protected function kuserDelete(kuser $kuser) { $filter = new categoryKuserFilter(); $filter->setUserIdEqual($kuser->getPuserId()); $c = new Criteria(); $c->add(categoryKuserPeer::PUSER_ID, $kuser->getPuserId()); if (categoryKuserPeer::doSelectOne($c)) { kJobsManager::addDeleteJob($kuser->getPartnerId(), DeleteObjectType::CATEGORY_USER, $filter); } if ($kuser->getType() == KuserType::USER) { // remove user from groups KuserKgroupPeer::deleteByKuserId($kuser->getId()); } elseif ($kuser->getType() == KuserType::GROUP) { // remove users from group $filter = new KuserKgroupFilter(); $filter->setGroupIdEqual($kuser->getPuserId()); $c = new Criteria(); $c->add(KuserKgroupPeer::PGROUP_ID, $kuser->getPuserId()); if (KuserKgroupPeer::doSelectOne($c)) { kJobsManager::addDeleteJob($kuser->getPartnerId(), DeleteObjectType::GROUP_USER, $filter); } } }
protected function addDeleteCategoryKuserJob($categoryId, $deleteCategoryDirectMembersOnly = false) { $filter = new categoryKuserFilter(); $filter->setCategoryIdEqual($categoryId); $filter->set('_category_direct_members', $deleteCategoryDirectMembersOnly); $c = new Criteria(); $c->add(categoryKuserPeer::CATEGORY_ID, $categoryId); if (!categoryKuserPeer::doSelectOne($c)) { return; } kJobsManager::addDeleteJob($this->getPartnerId(), DeleteObjectType::CATEGORY_USER, $filter); }
/** * * @param array $categoriesIds * @param int $kuserId * @param array $requiredPermissions * @param $con * * @return categoryKuser */ public static function areCategoriesAllowed(array $categoriesIds, $kuserId = null, $requiredPermissions = null, $con = null) { if (is_null($kuserId)) { $kuserId = kCurrentContext::getCurrentKsKuserId(); } if (is_null($requiredPermissions)) { $requiredPermissions = array(PermissionName::CATEGORY_VIEW); } $categories = categoryPeer::retrieveByPKs($categoriesIds); if (count($categories) < count($categoriesIds)) { return false; } $categoriesIds = array(); foreach ($categories as $category) { /* @var $category category */ $categoriesIds[] = $category->getInheritedParentId() ? $category->getInheritedParentId() : $category->getId(); } $categoriesIds = array_unique($categoriesIds); $criteria = new Criteria(); $criteria->add(categoryKuserPeer::CATEGORY_ID, $categoriesIds, Criteria::IN); $criteria->add(categoryKuserPeer::KUSER_ID, $kuserId); $criteria->add(categoryKuserPeer::STATUS, CategoryKuserStatus::ACTIVE); $categoryKusers = categoryKuserPeer::doSelectOne($criteria, $con); if (count($categoryKusers) < count($categoriesIds)) { return false; } foreach ($categoryKusers as $categoryKuser) { $permissions = explode(',', $categoryKuser->getPermissionNames()); foreach ($requiredPermissions as $requiredPermission) { if (!in_array($requiredPermission, $permissions)) { return false; } } } return true; }