public function save(PropelPDO $con = null) { if ($this->isNew()) { $numOfCatsForPartner = categoryPeer::doCount(new Criteria()); if ($numOfCatsForPartner >= Partner::MAX_NUMBER_OF_CATEGORIES) { throw new kCoreException("Max number of categories was reached", kCoreException::MAX_NUMBER_OF_CATEGORIES_REACHED); } } // set the depth of the parent category + 1 if ($this->isNew() || $this->isColumnModified(categoryPeer::PARENT_ID)) { $parentCat = $this->getParentCategory(); if ($this->getParentId() !== 0) { $this->setDepth($parentCat->getDepth() + 1); } else { $this->setDepth(0); } $this->setChildsDepth(); } if ($this->getDepth() >= self::MAX_CATEGORY_DEPTH) { throw new kCoreException("Max depth was reached", kCoreException::MAX_CATEGORY_DEPTH_REACHED); } if ($this->isColumnModified(categoryPeer::NAME) || $this->isColumnModified(categoryPeer::PARENT_ID)) { $this->updateFullName(); $this->renameOnEntries(); } // happens in 3 cases: // 1. name of the current category was updated // 2. full name of the parent category was updated and it was set here as child // 3. parent id was changed if ($this->isColumnModified(categoryPeer::FULL_NAME)) { $this->setChildsFullNames(); } // save the childs foreach ($this->childs_for_save as $child) { $child->save(); } $this->childs_for_save = array(); if ($this->isColumnModified(categoryPeer::DELETED_AT) && $this->getDeletedAt() !== null) { $this->moveEntriesToParent(); } if ($this->isColumnModified(categoryPeer::PARENT_ID) && !$this->isNew()) { // decrease for the old parent category if ($this->old_parent_id) { $oldParentCat = categoryPeer::retrieveByPK($this->old_parent_id); } if ($oldParentCat) { $oldParentCat->decrementEntriesCount($this->entries_count); } // increase for the new parent category $newParentCat = categoryPeer::retrieveByPK($this->parent_id); if ($newParentCat) { $newParentCat->incrementEntriesCount($this->entries_count); } $this->old_parent_id = null; } parent::save($con); }
public function retrieveByIdentifier($value) { switch ($this->identifier) { case CategoryIdentifierField::FULL_NAME: return categoryPeer::getByFullNameExactMatch($value); case CategoryIdentifierField::ID: return categoryPeer::retrieveByPK($value); case CategoryIdentifierField::REFERENCE_ID: $objects = categoryPeer::getByReferenceId($value); return $objects[0]; } }
public function validateParentId(KalturaCategory $category) { if ($category->parentId === null) { $category->parentId = 0; } if ($category->parentId !== 0) { $parentCategoryDb = categoryPeer::retrieveByPK($category->parentId); if (!$parentCategoryDb) { throw new KalturaAPIException(KalturaErrors::PARENT_CATEGORY_NOT_FOUND, $category->parentId); } } }
/** * Convert the categories to categories ids - not includes the category itself (only sub categories) * * @param string $cats Categories full names * @param string $statuses comma seperated * @return string Comma seperated fullIds */ public static function categoryIdsToAllSubCategoriesIdsParsed($cats) { if ($cats === "") { $cats = array(); } else { $cats = explode(",", $cats); } kArray::trim($cats); $categoryFullIdsToIds = array(); foreach ($cats as $cat) { $category = categoryPeer::retrieveByPK($cat); //all sub categories and not the category itself if (!$category) { continue; } $categoryFullIdsToIds[] = $category->getFullIds() . '>'; } return implode(",", $categoryFullIdsToIds); }
/** * this function return categoryUser if the user has explicit or implicit (by group) required permissions on the category * * @param int $categoryId * @param int $kuserId * @param array $requiredPermissions * @param bool $supportGroups * @param null $con * @return categoryKuser|null */ public static function retrievePermittedKuserInCategory($categoryId, $kuserId = null, $requiredPermissions = null, $supportGroups = true, $con = null) { $category = categoryPeer::retrieveByPK($categoryId); if (!$category) { return null; } if ($category->getInheritedParentId()) { $categoryId = $category->getInheritedParentId(); } if (is_null($kuserId)) { $kuserId = kCurrentContext::getCurrentKsKuserId(); } if (is_null($requiredPermissions)) { $requiredPermissions = array(PermissionName::CATEGORY_VIEW); } $categoryKuser = self::retrieveByCategoryIdAndActiveKuserId($categoryId, $kuserId, $requiredPermissions, $con); if (!is_null($categoryKuser)) { return $categoryKuser; } //check if kuserId has permission in category by a junction group if ($supportGroups) { $kgroupIds = KuserKgroupPeer::retrieveKgroupIdsByKuserId($kuserId); if (count($kgroupIds) == 0) { return null; } $criteria = new Criteria(); $criteria->add(categoryKuserPeer::CATEGORY_ID, $categoryId); $criteria->add(categoryKuserPeer::KUSER_ID, $kgroupIds, Criteria::IN); $criteria->add(categoryKuserPeer::STATUS, CategoryKuserStatus::ACTIVE); $categoryKusers = categoryKuserPeer::doSelect($criteria, $con); if (!$categoryKusers) { return null; } foreach ($categoryKusers as $categoryKuser) { foreach ($requiredPermissions as $requiredPermission) { if ($categoryKuser->hasPermission($requiredPermission)) { return $categoryKuser; } } } } return null; }
public function getRootObjects(IRelatedObject $object) { /* @var $object categoryEntry */ $roots = array(); $category = categoryPeer::retrieveByPK($object->getCategoryId()); if ($category) { $roots = categoryPeer::getRootObjects($category); $roots[] = $category; } $entry = entryPeer::retrieveByPK($object->getEntryId()); if ($entry) { $roots[] = $entry; } return $roots; }
public function reSetCategoryFullIds() { $category = categoryPeer::retrieveByPK($this->getCategoryId()); if (!$category) { throw new kCoreException('category id [' . $this->getCategoryId() . 'was not found', kCoreException::ID_NOT_FOUND); } $this->setCategoryFullIds($category->getFullIds()); }
/** * @return BaseObject */ public function getObject() { switch ($this->getObjectType()) { case BatchJobObjectType::ENTRY: entryPeer::setUseCriteriaFilter(false); $object = entryPeer::retrieveByPK($this->getObjectId()); entryPeer::setUseCriteriaFilter(true); return $object; case BatchJobObjectType::ASSET: assetPeer::setUseCriteriaFilter(false); $object = assetPeer::retrieveById($this->getObjectId()); assetPeer::setUseCriteriaFilter(true); return $object; case BatchJobObjectType::CATEGORY: categoryPeer::setUseCriteriaFilter(false); $object = categoryPeer::retrieveByPK($this->getObjectId()); categoryPeer::setUseCriteriaFilter(true); return $object; case BatchJobObjectType::FILE_SYNC: FileSyncPeer::setUseCriteriaFilter(false); $object = FileSyncPeer::retrieveByPK($this->getObjectId()); FileSyncPeer::setUseCriteriaFilter(true); return $object; default: // TODO implement IBatchable in relevant plugins return KalturaPluginManager::loadObject('IBatchable', $this->getObjectId()); } return $this->aRootJob; }
/** * 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); } } } }
/** * Get categories by id using full ids wildcard match (returns an array) * * @param $id * @param $con * @return array */ public static function getByFullIdsWildcardMatchForCategoryId($id, $con = null) { if (trim($id) == '') { return null; } $category = categoryPeer::retrieveByPK($id); if (!$category) { return null; } $fullIds = $category->getFullIds(); $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $c->add(categoryPeer::FULL_IDS, "{$fullIds}\\*", Criteria::LIKE); return categoryPeer::doSelect($c, $con); }
/** * Delete a Category * * @action delete * @param int $id */ function deleteAction($id) { $categoryDb = categoryPeer::retrieveByPK($id); if (!$categoryDb) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $id); } $categoryDb->setDeletedAt(time()); }
/** * Move categories that belong to the same parent category to a target categroy - enabled only for ks with disable entitlement * * @action move * @param string $categoryIds * @param int $targetCategoryParentId * @return KalturaCategoryListResponse */ function moveAction($categoryIds, $targetCategoryParentId) { if (kEntitlementUtils::getEntitlementEnforcement()) { throw new KalturaAPIException(KalturaErrors::CANNOT_MOVE_CATEGORIES_FROM_DIFFERENT_PARENT_CATEGORY); } if ($this->getPartner()->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) { throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED); } $categories = explode(',', $categoryIds); $dbCategories = array(); $parentId = category::CATEGORY_ID_THAT_DOES_NOT_EXIST; foreach ($categories as $categoryId) { if ($categoryId == '') { continue; } $dbCategory = categoryPeer::retrieveByPK($categoryId); if (!$dbCategory) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryId); } if ($parentId == category::CATEGORY_ID_THAT_DOES_NOT_EXIST) { $parentId = $dbCategory->getParentId(); } if ($parentId != $dbCategory->getParentId()) { throw new KalturaAPIException(KalturaErrors::CANNOT_MOVE_CATEGORIES_FROM_DIFFERENT_PARENT_CATEGORY); } $dbCategories[] = $dbCategory; } // if $targetCategoryParentId = 0 - it means that categories should be with no parent category if ($targetCategoryParentId != 0) { $dbTargetCategory = categoryPeer::retrieveByPK($targetCategoryParentId); if (!$dbTargetCategory) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $targetCategoryParentId); } } foreach ($dbCategories as $dbCategory) { $dbCategory->setParentId($targetCategoryParentId); $dbCategory->save(); } }
public function toInsertableObject($dbObject = null, $skip = array()) { if (is_null($this->permissionLevel)) { $category = categoryPeer::retrieveByPK($this->categoryId); if (!$category) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryId); } $this->permissionLevel = $category->getDefaultPermissionLevel(); } return parent::toInsertableObject($dbObject, $skip); }
public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null) { if ($this->userIdIn) { $usersIds = explode(',', $this->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) { /* @var $kuser kuser */ $usersIds[] = $kuser->getId(); } $this->userIdIn = implode(',', $usersIds); } if ($this->relatedGroupsByUserId) { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $userIds = array(); $c = new Criteria(); $c->add(kuserPeer::PARTNER_ID, $partnerId); $c->add(kuserPeer::PUSER_ID, $this->relatedGroupsByUserId); $c->add(kuserPeer::TYPE, KuserType::USER); $kuser = kuserPeer::doSelectOne($c); if (!$kuser) { $response = new KalturaCategoryUserListResponse(); $response->objects = new KalturaCategoryUserArray(); $response->totalCount = 0; return $response; } $kgroupIds = KuserKgroupPeer::retrieveKgroupIdsByKuserId($kuser->getId()); if (!is_null($kgroupIds) && is_array($kgroupIds)) { $userIds = $kgroupIds; } $userIds[] = $kuser->getId(); // if userIdIn is also set in the filter need to intersect the two arrays. if (isset($this->userIdIn)) { $curUserIds = explode(',', $this->userIdIn); $userIds = array_intersect($curUserIds, $userIds); } $this->userIdIn = implode(',', $userIds); } if ($this->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, $this->userIdEqual); if (kCurrentContext::$ks_partner_id == Partner::BATCH_PARTNER_ID) { //batch should be able to get categoryUser of deleted users. kuserPeer::setUseCriteriaFilter(false); } // in case of more than one deleted kusers - get the last one $c->addDescendingOrderByColumn(kuserPeer::UPDATED_AT); $kuser = kuserPeer::doSelectOne($c); kuserPeer::setUseCriteriaFilter(true); if (!$kuser) { KalturaLog::debug('User not found'); $response = new KalturaCategoryUserListResponse(); $response->objects = new KalturaCategoryUserArray(); $response->totalCount = 0; return $response; } $this->userIdEqual = $kuser->getId(); } $categories = array(); if ($this->categoryIdEqual) { $categories[] = categoryPeer::retrieveByPK($this->categoryIdEqual); } elseif ($this->categoryIdIn) { $categories = categoryPeer::retrieveByPKs(explode(',', $this->categoryIdIn)); } $categoriesInheritanceRoot = array(); foreach ($categories as $category) { /* @var $category category */ if (is_null($category)) { continue; } if ($category->getInheritanceType() == InheritanceType::INHERIT) { if ($this->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(); } } $this->categoryDirectMembers = null; $this->categoryIdEqual = null; $this->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 = $this->toObject(); $c = KalturaCriteria::create(categoryKuserPeer::OM_CLASS); $categoryKuserFilter->attachToCriteria($c); $pager->attachToCriteria($c); $c->applyFilters(); $list = categoryKuserPeer::doSelect($c); $totalCount = $c->getRecordsCount(); $newList = KalturaCategoryUserArray::fromDbArray($list, $responseProfile); $response = new KalturaCategoryUserListResponse(); $response->objects = $newList; $response->totalCount = $totalCount; return $response; }
public function validateForUpdate($sourceObject, $propertiesToSkip = null) { /* @var $sourceObject categoryKuser */ $category = categoryPeer::retrieveByPK($sourceObject->getCategoryId()); if (!$category) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $sourceObject->getCategoryId()); } if ($this->permissionNames && $this->permissionNames != $sourceObject->getPermissionNames()) { if ($sourceObject->getKuserId() == $category->getKuserId()) { if (strpos($this->permissionNames, PermissionName::CATEGORY_EDIT) === false) { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_USER_OWNER); } } } $currentKuserCategoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($sourceObject->getCategoryId(), kCurrentContext::getCurrentKsKuserId()); if (kEntitlementUtils::getEntitlementEnforcement() && (!$currentKuserCategoryKuser || !$currentKuserCategoryKuser->hasPermission(PermissionName::CATEGORY_EDIT))) { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_USER, $sourceObject->getCategoryId()); } return parent::validateForUpdate($sourceObject, $propertiesToSkip); }
/** * update privacy context from the category * * @action syncPrivacyContext * @param string $entryId * @param int $categoryId * @throws KalturaErrors::INVALID_ENTRY_ID * @throws KalturaErrors::CATEGORY_NOT_FOUND * @throws KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY */ function syncPrivacyContextAction($entryId, $categoryId) { $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $entryId); } $category = categoryPeer::retrieveByPK($categoryId); if (!$category) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryId); } $dbCategoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryId, $entryId); if (!$dbCategoryEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY); } $dbCategoryEntry->setPrivacyContext($category->getPrivacyContexts()); $dbCategoryEntry->save(); }
/** * Returns true if kuser or current kuser is entitled to assign entry to categoryId * @param int $categoryId * @param int $kuser * @return bool */ public static function validateEntryAssignToCategory($categoryId, $kuserId = null) { if (!self::getEntitlementEnforcement()) { return true; } $category = categoryPeer::retrieveByPK($categoryUser->categoryId); if (!$category) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryUser->categoryId); } if ($category->getContributionPolicy() == ContributionPolicyType::ALL) { return true; } if ($kuserId) { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, kCurrentContext::$ks_uid); $kuserId = $kuser->getId(); } $currentKuserCategoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryUser->categoryId, $kuserId); if ($currentKuserCategoryKuser && ($currentKuserCategoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MANAGER || $currentKuserCategoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MODERATOR || $currentKuserCategoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::CONTRIBUTOR)) { return true; } return false; }
public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null) { if ($this->entryIdEqual == null && $this->categoryIdIn == null && $this->categoryIdEqual == null && (kEntitlementUtils::getEntitlementEnforcement() || !kCurrentContext::$is_admin_session)) { throw new KalturaAPIException(KalturaErrors::MUST_FILTER_ON_ENTRY_OR_CATEGORY); } if (kEntitlementUtils::getEntitlementEnforcement()) { //validate entitl for entry if ($this->entryIdEqual != null) { $entry = entryPeer::retrieveByPK($this->entryIdEqual); if (!$entry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryIdEqual); } } //validate entitl for entryIn if ($this->entryIdIn != null) { $entry = entryPeer::retrieveByPKs($this->entryIdIn); if (!$entry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryIdIn); } } //validate entitl categories if ($this->categoryIdIn != null) { $categoryIdInArr = explode(',', $this->categoryIdIn); if (!categoryKuserPeer::areCategoriesAllowed($categoryIdInArr)) { $categoryIdInArr = array_unique($categoryIdInArr); } $entitledCategories = categoryPeer::retrieveByPKs($categoryIdInArr); if (!count($entitledCategories) || count($entitledCategories) != count($categoryIdInArr)) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdIn); } $categoriesIdsUnlisted = array(); foreach ($entitledCategories as $category) { if ($category->getDisplayInSearch() == DisplayInSearchType::CATEGORY_MEMBERS_ONLY) { $categoriesIdsUnlisted[] = $category->getId(); } } if (count($categoriesIdsUnlisted)) { if (!categoryKuserPeer::areCategoriesAllowed($categoriesIdsUnlisted)) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdIn); } } } //validate entitl category if ($this->categoryIdEqual != null) { $category = categoryPeer::retrieveByPK($this->categoryIdEqual); if (!$category && kCurrentContext::$master_partner_id != Partner::BATCH_PARTNER_ID) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdEqual); } if ($category->getDisplayInSearch() == DisplayInSearchType::CATEGORY_MEMBERS_ONLY && !categoryKuserPeer::retrievePermittedKuserInCategory($category->getId(), kCurrentContext::getCurrentKsKuserId())) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdEqual); } } } $categoryEntryFilter = $this->toObject(); $c = KalturaCriteria::create(categoryEntryPeer::OM_CLASS); $categoryEntryFilter->attachToCriteria($c); if (!kEntitlementUtils::getEntitlementEnforcement() || $this->entryIdEqual == null) { $pager->attachToCriteria($c); } $dbCategoriesEntry = categoryEntryPeer::doSelect($c); if (kEntitlementUtils::getEntitlementEnforcement() && count($dbCategoriesEntry) && $this->entryIdEqual != null) { //remove unlisted categories: display in search is set to members only $categoriesIds = array(); foreach ($dbCategoriesEntry as $dbCategoryEntry) { $categoriesIds[] = $dbCategoryEntry->getCategoryId(); } $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $c->add(categoryPeer::ID, $categoriesIds, Criteria::IN); $pager->attachToCriteria($c); $c->applyFilters(); $categoryIds = $c->getFetchedIds(); foreach ($dbCategoriesEntry as $key => $dbCategoryEntry) { if (!in_array($dbCategoryEntry->getCategoryId(), $categoryIds)) { KalturaLog::info('Category [' . print_r($dbCategoryEntry->getCategoryId(), true) . '] is not listed to user'); unset($dbCategoriesEntry[$key]); } } $totalCount = $c->getRecordsCount(); } else { $resultCount = count($dbCategoriesEntry); if ($resultCount && $resultCount < $pager->pageSize) { $totalCount = ($pager->pageIndex - 1) * $pager->pageSize + $resultCount; } else { KalturaFilterPager::detachFromCriteria($c); $totalCount = categoryEntryPeer::doCount($c); } } $categoryEntrylist = KalturaCategoryEntryArray::fromDbArray($dbCategoriesEntry, $responseProfile); $response = new KalturaCategoryEntryListResponse(); $response->objects = $categoryEntrylist; $response->totalCount = $totalCount; // no pager since category entry is limited to ENTRY::MAX_CATEGORIES_PER_ENTRY return $response; }
/** * validate category fields * 1. category that inherit memebers canno set values to inherited fields. * 2. validate the owner id exists as kuser * * @param category $sourceObject */ private function validateCategory(category $sourceObject = null) { if ($this->privacyContext != null && kEntitlementUtils::getEntitlementEnforcement()) { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_PRIVACY_CONTEXT); } if (!$this->privacyContext && (!$sourceObject || !$sourceObject->getPrivacyContexts())) { if ($this->appearInList != KalturaAppearInListType::PARTNER_ONLY && $this->appearInList != null || $this->moderation != KalturaNullableBoolean::FALSE_VALUE && $this->moderation != null || $this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->privacy != KalturaPrivacyType::ALL && $this->privacy != null || $this->owner != null || $this->userJoinPolicy != KalturaUserJoinPolicyType::NOT_ALLOWED && $this->userJoinPolicy != null || $this->contributionPolicy != KalturaContributionPolicyType::ALL && $this->contributionPolicy != null || $this->defaultPermissionLevel != KalturaCategoryUserPermissionLevel::MEMBER && $this->defaultPermissionLevel !== null) { if ($this->parentId != null) { $parentCategory = categoryPeer::retrieveByPK($this->parentId); if (!$parentCategory) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->parentId); } if ($parentCategory->getPrivacyContexts() == '') { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_ENTITLEMENT_FIELDS_WITH_NO_PRIVACY_CONTEXT); } } else { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_ENTITLEMENT_FIELDS_WITH_NO_PRIVACY_CONTEXT); } } } if ($this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->inheritanceType == null && $sourceObject && $sourceObject->getInheritanceType() != KalturaInheritanceType::MANUAL) { if (!$sourceObject && $this->owner != null || $sourceObject && $this->owner != null && $this->owner != $sourceObject->getKuserId() || !$sourceObject && $this->userJoinPolicy != null || $sourceObject && $this->userJoinPolicy != null && $this->userJoinPolicy != $sourceObject->getUserJoinPolicy() || !$sourceObject && $this->defaultPermissionLevel != null || $sourceObject && $this->defaultPermissionLevel != null && $this->defaultPermissionLevel != $sourceObject->getDefaultPermissionLevel()) { throw new KalturaAPIException(KalturaErrors::CATEGORY_INHERIT_MEMBERS_CANNOT_UPDATE_INHERITED_ATTRIBUTES); } } if (!is_null($sourceObject)) { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner || $partner->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) { throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED); } } if ($this->owner && $this->owner != '' && !$this->owner instanceof KalturaNullField) { if (!preg_match(kuser::PUSER_ID_REGEXP, $this->owner)) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'owner'); } $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; kuserPeer::createKuserForPartner($partnerId, $this->owner); } }
/** * Convert the categories to categories ids * * @param string $cats Categories full names * @param string $statuses comma seperated * @return string Categogories indexes ids */ public static function categoryIdsToIdsParsed($cats, $statuses = null) { if ($cats === "") { $cats = array(); } else { $cats = explode(",", $cats); } kArray::trim($cats); if ($statuses == null || trim($statuses) == '') { $statuses = CategoryEntryStatus::ACTIVE; } $statuses = explode(',', trim($statuses)); $categoryFullIdsToIds = array(); foreach ($cats as $cat) { $category = categoryPeer::retrieveByPK($cat); if (!$category) { continue; } foreach ($statuses as $status) { $categoryFullIdsToIds[] = entry::CATEGORY_SEARCH_PERFIX . $category->getId() . entry::CATEGORY_SEARCH_STATUS . $status; } } return implode(",", $categoryFullIdsToIds); }
private function getInheritParent() { if ($this->getInheritanceType() != InheritanceType::INHERIT || is_null($this->getInheritedParentId())) { return $this; } KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $inheritCategory = categoryPeer::retrieveByPK($this->getInheritedParentId()); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if (!$inheritCategory) { return $this; } return $inheritCategory; }
/** * Copy all memeber from parent category * * @action copyFromCategory * @param int $categoryId */ public function copyFromCategoryAction($categoryId) { if (kEntitlementUtils::getEntitlementEnforcement()) { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_USER); } $categoryDb = categoryPeer::retrieveByPK($categoryId); if (!$categoryDb) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryId); } if ($categoryDb->getParentId() == null) { throw new KalturaAPIException(KalturaErrors::CATEGORY_DOES_NOT_HAVE_PARENT_CATEGORY); } $categoryDb->copyCategoryUsersFromParent($categoryDb->getParentId()); }
public function toInsertableObject($object_to_fill = null, $props_to_skip = array()) { $hasPrivacyContext = false; if ($this->privacyContext) { $hasPrivacyContext = true; } elseif ($this->parentId != null) { $parentCategory = categoryPeer::retrieveByPK($this->parentId); if (!$parentCategory) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->parentId); } if ($parentCategory->getPrivacyContexts()) { $hasPrivacyContext = true; } } if ($hasPrivacyContext) { if (!$this->owner && $this->inheritanceType != KalturaInheritanceType::INHERIT) { if (kCurrentContext::getCurrentKsKuser()) { $this->owner = kCurrentContext::getCurrentKsKuser()->getPuserId(); } } } return parent::toInsertableObject($object_to_fill, $props_to_skip); }
public function getCategoriesWithNoPrivacyContext() { $allCategoriesEntry = categoryEntryPeer::retrieveActiveAndPendingByEntryId($this->getId()); $categoriesWithNoPrivacyContext = array(); foreach ($allCategoriesEntry as $categoryEntry) { $category = categoryPeer::retrieveByPK($categoryEntry->getCategoryId()); if ($category && $category->getPrivacyContexts() == null) { $categoriesWithNoPrivacyContext[] = $category; } } return $categoriesWithNoPrivacyContext; }
/** * activate CategoryEntry when it is pending moderation * * @action reject * @param string $entryId * @param int $categoryId * @throws KalturaErrors::INVALID_ENTRY_ID * @throws KalturaErrors::CATEGORY_NOT_FOUND * @throws KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY * @throws KalturaErrors::CANNOT_ACTIVATE_CATEGORY_ENTRY */ function rejectAction($entryId, $categoryId) { $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $entryId); } $category = categoryPeer::retrieveByPK($categoryId); if (!$category) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryId); } $dbCategoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryId, $entryId); if (!$dbCategoryEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY); } //validate user is entiteld to reject entry from category if (kEntitlementUtils::getEntitlementEnforcement()) { $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryId, kCurrentContext::$ks_kuser_id); if (!$categoryKuser || $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MODERATOR) { throw new KalturaAPIException(KalturaErrors::CANNOT_REJECT_CATEGORY_ENTRY); } } if ($dbCategoryEntry->getStatus() != CategoryEntryStatus::PENDING) { throw new KalturaAPIException(KalturaErrors::CANNOT_REJECT_CATEGORY_ENTRY_SINCE_IT_IS_NOT_PENDING); } $dbCategoryEntry->setStatus(CategoryEntryStatus::REJECTED); $dbCategoryEntry->save(); }