Пример #1
0
 public function syncCategories()
 {
     if (!$this->is_categories_modified) {
         return;
     }
     if (!kEntitlementUtils::getEntitlementEnforcement() || !kEntitlementUtils::isKsPrivacyContextSet()) {
         categoryEntryPeer::syncEntriesCategories($this, $this->is_categories_names_modified);
     }
     parent::save();
     $this->is_categories_modified = false;
 }
Пример #2
0
 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;
 }