/** * Action for AJAX request * * @return void */ public function execute() { $bookmark = $this->bookmarkFactory->create(); $jsonData = $this->_request->getParam('data'); if (!$jsonData) { throw new \InvalidArgumentException('Invalid parameter "data"'); } $data = $this->jsonDecoder->decode($jsonData); $action = key($data); switch ($action) { case self::ACTIVE_IDENTIFIER: $this->updateCurrentBookmark($data[$action]); break; case self::CURRENT_IDENTIFIER: $this->updateBookmark($bookmark, $action, $bookmark->getTitle(), $jsonData); break; case self::VIEWS_IDENTIFIER: foreach ($data[$action] as $identifier => $data) { $this->updateBookmark($bookmark, $identifier, isset($data['label']) ? $data['label'] : '', $jsonData); $this->updateCurrentBookmark($identifier); } break; default: throw new \LogicException(__('Unsupported bookmark action.')); } }
/** * Retrieve bookmarks matching the specified criteria. * * @param SearchCriteriaInterface $searchCriteria * @return \Magento\Framework\Api\SearchResultsInterface * @throws \Magento\Framework\Exception\LocalizedException */ public function getList(SearchCriteriaInterface $searchCriteria) { $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($searchCriteria); /** @var \Magento\Ui\Model\ResourceModel\Bookmark\Collection $collection */ $collection = $this->bookmarkFactory->create()->getCollection(); // Add filters from root filter group to the collection foreach ($searchCriteria->getFilterGroups() as $group) { $this->addFilterGroupToCollection($group, $collection); } $searchResults->setTotalCount($collection->getSize()); $sortOrders = $searchCriteria->getSortOrders(); if ($sortOrders) { /** @var SortOrder $sortOrder */ foreach ($sortOrders as $sortOrder) { $field = $sortOrder->getField(); $collection->addOrder($field, $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC'); } } $collection->setCurPage($searchCriteria->getCurrentPage()); $collection->setPageSize($searchCriteria->getPageSize()); $bookmarks = []; /** @var BookmarkInterface $bookmark */ foreach ($collection->getItems() as $bookmark) { $bookmarks[] = $this->getById($bookmark->getId()); } $searchResults->setItems($bookmarks); return $searchResults; }
/** * Action for AJAX request * * @return void */ public function execute() { $bookmark = $this->bookmarkFactory->create(); $data = $this->_request->getParam('data'); if (isset($data['views'])) { foreach ($data['views'] as $identifier => $data) { $updateBookmark = $this->checkBookmark($identifier); if ($updateBookmark !== false) { $bookmark = $updateBookmark; } $this->updateBookmark($bookmark, $identifier, isset($data['label']) ? $data['label'] : '', $data); } } else { $identifier = isset($data['activeIndex']) ? $data['activeIndex'] : (isset($data[self::CURRENT_IDENTIFIER]) ? self::CURRENT_IDENTIFIER : ''); $updateBookmark = $this->checkBookmark($identifier); if ($updateBookmark !== false) { $bookmark = $updateBookmark; } $this->updateBookmark($bookmark, $identifier, '', $data[$identifier]); } }