本文整理汇总了PHP中category::createByPartnerAndFullName方法的典型用法代码示例。如果您正苦于以下问题:PHP category::createByPartnerAndFullName方法的具体用法?PHP category::createByPartnerAndFullName怎么用?PHP category::createByPartnerAndFullName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类category
的用法示例。
在下文中一共展示了category::createByPartnerAndFullName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: syncEntriesCategories
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());
//.........这里部分代码省略.........
示例2: syncCategories
public function syncCategories()
{
if (!$this->is_categories_modified) {
return;
}
if ($this->categories != null && $this->categories !== "") {
$newCats = explode(self::ENTRY_CATEGORY_SEPARATOR, $this->categories);
} else {
$newCats = array();
}
if ($this->old_categories !== null && $this->old_categories !== "") {
$oldCats = explode(self::ENTRY_CATEGORY_SEPARATOR, $this->old_categories);
} else {
$oldCats = array();
}
$allIds = array();
$allIdsWithParents = array();
$addedCats = array();
$removedCats = array();
$remainingCats = array();
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) {
$category = categoryPeer::getByFullNameExactMatch($cat);
if ($category) {
$allIds[] = $category->getId();
$allIdsWithParents[] = $category->getId();
$allIdsWithParents = array_merge($allIdsWithParents, $category->getAllParentsIds());
}
}
$alreadyAddedCatIds = $allIdsWithParents;
foreach ($addedCats as $cat) {
$category = categoryPeer::getByFullNameExactMatch($cat);
if (!$category) {
$category = category::createByPartnerAndFullName($this->getPartnerId(), $cat);
}
$category->incrementEntriesCount(1, $alreadyAddedCatIds);
$allIds[] = $category->getId();
$alreadyAddedCatIds[] = $category->getId();
$alreadyAddedCatIds = array_merge($alreadyAddedCatIds, $category->getAllParentsIds());
}
$alreadyRemovedCatIds = $allIdsWithParents;
foreach ($removedCats as $cat) {
$category = categoryPeer::getByFullNameExactMatch($cat);
if ($category) {
$category->decrementEntriesCount(1, $alreadyRemovedCatIds);
$alreadyRemovedCatIds[] = $category->getId();
$alreadyRemovedCatIds = array_merge($alreadyRemovedCatIds, $category->getAllParentsIds());
}
}
$this->setCategoriesIds(implode(",", $allIds));
mySearchUtils::setSearchTextDiscreteForEntry($this);
parent::save();
$this->is_categories_modified = false;
}