public function getLinksForUser(TagRepositoryInterface $tagRepo, TagHandlerInterface $tagHandler, CacheHandlerInterface $cacheHandler, $tags = []) { if (empty($tags)) { // Get user's tags $tags = $tagHandler->getTagsForUser($cacheHandler, $tagRepo); } // Find Discover Cache items for the user's Tags $items = []; foreach ($tags as $tag) { $items[$tag] = $cacheHandler->get(CacheHandlerInterface::DISCOVER_TAG, $tag); } // Filter out their own links $itemIds = []; foreach ($items as $tag => $itemArray) { if (isset($itemArray) && is_array($itemArray)) { foreach ($itemArray as $key => $item) { if ($item->user_id == Auth::user()->id || isset($itemIds[$item->id])) { unset($items[$tag][$key]); } else { // Track item id's so we can remove dups $itemIds[$item->id] = $item->id; } } // If all items are filtered out, remove them from the list if (count($items[$tag]) == 0) { unset($items[$tag]); } } else { // If there are no items found for the tag at all, remove it from the list unset($items[$tag]); } } return $items; }
public function getTagsPane(TagHandlerInterface $tagHandler, CacheHandlerInterface $cacheHandler, TagRepositoryInterface $tagRepo) { $tags = $tagHandler->getTagsForUser($cacheHandler, $tagRepo); sort($tags, SORT_STRING); // Create an array to denote the starting letter of the tags $tagsDisplayArray = []; foreach ($tags as $tag) { // Get first letter of tag and add to the array if it doesn't exist $letter = strtoupper(substr($tag, 0, 1)); if (!array_key_exists($letter, $tagsDisplayArray)) { $tagsDisplayArray[$letter] = []; } // Add tag to array for letter $tagsDisplayArray[$letter][] = $tag; } return \Response::view('panes.tagsPane', ['tags' => $tagsDisplayArray]); }