public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null) { if (kEntitlementUtils::getEntitlementEnforcement() && (is_null($this->objectIdIn) && is_null($this->objectIdEqual))) { throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_ID); } if (!$this->metadataObjectTypeEqual) { throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_TYPE); } if ($this->metadataObjectTypeEqual == MetadataObjectType::CATEGORY) { if ($this->objectIdEqual) { $categoryIds = array($this->objectIdEqual); } else { if ($this->objectIdIn) { $categoryIds = explode(',', $this->objectIdIn); } } if ($categoryIds) { $categories = categoryPeer::retrieveByPKs($categoryIds); if (!count($categories)) { KalturaLog::debug("No categories found"); $response = new KalturaMetadataListResponse(); $response->objects = new KalturaMetadataArray(); $response->totalCount = 0; return $response; } $categoryIds = array(); foreach ($categories as $category) { $categoryIds[] = $category->getId(); } $this->objectIdEqual = null; $this->objectIdIn = implode(',', $categoryIds); } } $metadataFilter = $this->toObject(); $c = KalturaCriteria::create(MetadataPeer::OM_CLASS); $metadataFilter->attachToCriteria($c); $pager->attachToCriteria($c); $list = MetadataPeer::doSelect($c); $response = new KalturaMetadataListResponse(); $response->objects = KalturaMetadataArray::fromDbArray($list, $responseProfile); if ($c instanceof SphinxMetadataCriteria) { $response->totalCount = $c->getRecordsCount(); } elseif ($pager->pageIndex == 1 && count($response->objects) < $pager->pageSize) { $response->totalCount = count($response->objects); } else { $pager->detachFromCriteria($c); $response->totalCount = MetadataPeer::doCount($c); } return $response; }
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; }
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)); }
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; }
/** * Index CategoryEntry by Id * * @action index * @param string $entryId * @param int $categoryId * @param bool $shouldUpdate * @throws KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY * @return int */ function indexAction($entryId, $categoryId, $shouldUpdate = true) { if (kEntitlementUtils::getEntitlementEnforcement()) { throw new KalturaAPIException(KalturaErrors::CANNOT_INDEX_OBJECT_WHEN_ENTITLEMENT_IS_ENABLE); } $dbCategoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryId, $entryId); if (!$dbCategoryEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY); } if (!$shouldUpdate) { $dbCategoryEntry->setUpdatedAt(time()); $dbCategoryEntry->save(); return $dbCategoryEntry->getIntId(); } $dbCategoryEntry->reSetCategoryFullIds(); $dbCategoryEntry->save(); $entry = entryPeer::retrieveByPK($dbCategoryEntry->getEntryId()); if ($entry) { $categoryEntries = categoryEntryPeer::retrieveActiveByEntryId($entryId); $categoriesIds = array(); foreach ($categoryEntries as $categoryEntry) { $categoriesIds[] = $categoryEntry->getCategoryId(); } $categories = categoryPeer::retrieveByPKs($categoriesIds); $isCategoriesModified = false; $categoriesFullName = array(); foreach ($categories as $category) { if ($category->getPrivacyContexts() == null) { $categoriesFullName[] = $category->getFullName(); $isCategoriesModified = true; } } $entry->setCategories(implode(',', $categoriesFullName)); categoryEntryPeer::syncEntriesCategories($entry, $isCategoriesModified); $entry->save(); } return $dbCategoryEntry->getId(); }
private function setEntryOnCategory(category $category, $entry = null) { if (is_null($this->entryCategoriesAddedIds)) { $categoriesEntries = categoryEntryPeer::retrieveActiveByEntryId($this->getEntryId()); $categoriesIds = array(); foreach ($categoriesEntries as $categroyEntry) { //cannot get directly the full ids - since it might not be updated. if ($categroyEntry->getCategoryId() != $this->getCategoryId()) { $categoriesIds[] = $categroyEntry->getCategoryId(); } } $categoriesAdded = categoryPeer::retrieveByPKs($categoriesIds); $entryCategoriesAddedIds = array(); foreach ($categoriesAdded as $categoryAdded) { $fullIds = explode(categoryPeer::CATEGORY_SEPARATOR, $categoryAdded->getFullIds()); $entryCategoriesAddedIds = array_merge($entryCategoriesAddedIds, $fullIds); } $this->entryCategoriesAddedIds = $entryCategoriesAddedIds; } $category->incrementEntriesCount(1, $this->entryCategoriesAddedIds); $category->incrementDirectEntriesCount(); //if was pending - decrease pending entries count! if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) { $category->decrementPendingEntriesCount(); } $category->save(); //only categories with no context are saved on entry - this is only for Backward compatible if ($entry && !categoryEntryPeer::getSkipSave() && (trim($category->getPrivacyContexts()) == '' || $category->getPrivacyContexts() == null)) { $categories = array(); if (trim($entry->getCategories()) != '') { $categories = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategories()); } $categories[] = $category->getFullName(); $categoriesIds = array(); if (trim($entry->getCategoriesIds()) != '') { $categoriesIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategoriesIds()); } $categoriesIds[] = $category->getId(); $entry->parentSetCategories(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categories)); $entry->parentSetCategoriesIds(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categoriesIds)); $entry->justSave(); } return $entry; }
/** * Function calculates and returns the MRSS XML of a category * @param category $category * @param SimpleXMLElement $mrss * @param kMrssParameters $mrssParams * @param string $features * @return SimpleXMLElement */ public static function getCategoryMrssXml(category $category, SimpleXMLElement $mrss = null, kMrssParameters $mrssParams = null, $features = null) { $instanceKey = self::generateInstanceKey($category->getId(), $mrssParams, $features); if (is_null($mrss)) { $mrss = self::getInstanceFromPool($instanceKey); if ($mrss) { return $mrss; } $mrss = new SimpleXMLElement('<item/>'); } if (!$features || in_array(ObjectFeatureType::METADATA, $features)) { $mrss->addChild("id", $category->getId()); $mrss->addChild("name", $category->getName()); $mrss->addChild("referenceId", $category->getReferenceId()); $mrss->addChild("fullName", $category->getFullName()); } $mrssContributors = self::getMrssContributors(); if (count($mrssContributors)) { foreach ($mrssContributors as $mrssContributor) { /* @var $mrssContributor IKalturaMrssContributor */ try { if (!$features || in_array($mrssContributor->getObjectFeatureType(), $features)) { $mrssContributor->contribute($category, $mrss, $mrssParams); } } catch (kCoreException $ex) { KalturaLog::err("Unable to add MRSS element for contributor [" . get_class($mrssContributor) . "] message [" . $ex->getMessage() . "]"); } } } if ($features && in_array(ObjectFeatureType::ANCESTOR_RECURSIVE, $features)) { $ancestorIds = explode(">", $category->getFullIds()); $ancestorCategories = categoryPeer::retrieveByPKs($ancestorIds); array_pop($ancestorCategories); //find and delete the ANCESTOR_RECURSIVE from the features array for ($i = 0; $i < count($features); $i++) { if ($features[$i] == ObjectFeatureType::ANCESTOR_RECURSIVE) { unset($features[$i]); } } //retrieve mrss for each ancestor category $parentCategories = $mrss->addChild('parent_categories'); foreach ($ancestorCategories as $ancestorCategory) { $ancestorMrss = $parentCategories->addChild('category_item'); $ancestorMrss = self::getCategoryMrssXml($ancestorCategory, $ancestorMrss, $mrssParams, $features); } } if ($mrssParams && $mrssParams->getItemXpathsToExtend()) { self::addExtendingItemsToMrss($mrss, $mrssParams); } self::addInstanceToPool($instanceKey, $mrss); return $mrss; }
public function objectCopied(BaseObject $fromObject, BaseObject $toObject) { if ($fromObject instanceof asset) { self::mapIds('asset', $fromObject->getId(), $toObject->getId()); $flavorParamsId = self::getMappedId('assetParams', $fromObject->getFlavorParamsId()); if ($flavorParamsId) { $toObject->setFlavorParamsId($flavorParamsId); $toObject->save(); } } elseif ($fromObject instanceof assetParams) { self::mapIds('assetParams', $fromObject->getId(), $toObject->getId()); } elseif ($fromObject instanceof assetParamsOutput) { self::mapIds('assetParamsOutput', $fromObject->getId(), $toObject->getId()); $flavorParamsId = self::getMappedId('assetParams', $fromObject->getFlavorParamsId()); if ($flavorParamsId) { $toObject->setFlavorParamsId($flavorParamsId); $toObject->save(); } } else { self::mapIds(get_class($fromObject), $fromObject->getId(), $toObject->getId()); } if ($fromObject instanceof uiConf) { $this->uiConfCopied($fromObject, $toObject); } if ($fromObject instanceof category && $fromObject->getParentId()) { $parentId = self::getMappedId('category', $fromObject->getParentId()); if ($parentId) { $toObject->setParentId($parentId); $toObject->save(); } } if ($fromObject instanceof entry) { $conversionProfileId = self::getMappedId('conversionProfile2', $fromObject->getConversionProfileId()); if ($conversionProfileId) { $toObject->setConversionProfileId($conversionProfileId); $toObject->save(); } $accessControlId = self::getMappedId('accessControl', $fromObject->getAccessControlId()); if ($accessControlId) { $toObject->setAccessControlId($accessControlId); $toObject->save(); } if ($toObject->getPartnerId() == $fromObject->getPartnerId()) { $categoryEntriesObjects = categoryEntryPeer::retrieveActiveByEntryId($fromObject->getId()); $categoryIds = array(); foreach ($categoryEntriesObjects as $categoryEntryObject) { /* @var $categoryEntry categoryEntry */ $categoryIds[] = $categoryEntryObject->getCategoryId(); } if (count($categoryIds)) { $categories = categoryPeer::retrieveByPKs($categoryIds); //which will return only the entiteled ones foreach ($categories as $category) { /* @var $category category */ $categoryEntry = new categoryEntry(); $categoryEntry->setEntryId($toObject->getId()); $categoryEntry->setCategoryId($category->getId()); $categoryEntry->setStatus(CategoryEntryStatus::ACTIVE); $categoryEntry->setPartnerId($toObject->getPartnerId()); $categoryEntry->save(); } } } } return true; }
/** * * @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; }
/** * 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; }