public function test_count_topics_by_tags() { $count = $this->tags_manager->count_topics_by_tags(array()); $this->assertEquals(0, $count); // uses auth, so we set up the mock/stub // to allow reading first forum $this->auth->expects($this->exactly(4))->method('acl_getf')->with($this->equalTo('f_read'))->willReturn(array(1 => array('f_read' => true))); $tags = array("tag1"); $count = $this->tags_manager->count_topics_by_tags($tags); $this->assertEquals(1, $count); // case sensitive $tags = array("tAg1"); $mode = 'AND'; $casesensitive = true; $count = $this->tags_manager->count_topics_by_tags($tags, $mode, $casesensitive); $this->assertEquals(0, $count); $tags = array("tag1", "noneExistingTag"); $count = $this->tags_manager->count_topics_by_tags($tags); $this->assertEquals(0, $count); // search with OR $tags = array("tag1", "noneExistingTag"); $mode = 'OR'; $count = $this->tags_manager->count_topics_by_tags($tags, $mode); $this->assertEquals(1, $count); }
/** * Shows a list of topics that have the given $tags assigned * * @param $tags tags seperated by comma (",") * @param $mode the mode indicates whether all tags (AND, default) or any tag (OR) should be assigned to the resulting topics * @param casesensitive wether to search case-sensitive (true) or -insensitive (false, default) */ public function show_tag($tags, $mode, $casesensitive) { // validate mode // default == AND $mode = $mode == 'OR' ? 'OR' : 'AND'; $tags = explode(',', urldecode($tags)); // remove possible duplicates $tags = array_unique($tags); $all_tags = $this->tags_manager->split_valid_tags($tags); if (sizeof($all_tags['invalid']) > 0) { $this->template->assign_var('RH_TOPICTAGS_SEARCH_IGNORED_TAGS', $this->user->lang('RH_TOPICTAGS_SEARCH_IGNORED_TAGS', join(', ', $all_tags['invalid']))); } $tags = $all_tags['valid']; $tags_string = join(', ', $tags); $this->template->assign_var('RH_TOPICTAGS_SEARCH_HEADER', $this->user->lang('RH_TOPICTAGS_SEARCH_HEADER_' . $mode, $tags_string)); if (empty($tags)) { // no valid tags $this->template->assign_var('NO_TOPICS_FOR_TAG', $this->user->lang('RH_TOPICTAGS_NO_TOPICS_FOR_NO_TAG')); return $this->helper->render('show_tag.html', $this->user->lang('RH_TOPICTAGS_TAG_SEARCH')); } $topics_count = $this->tags_manager->count_topics_by_tags($tags, $mode, $casesensitive); if ($topics_count <= 0) { $this->template->assign_var('NO_TOPICS_FOR_TAG', $this->user->lang('RH_TOPICTAGS_NO_TOPICS_FOR_TAG_' . $mode, $tags_string)); } else { $pagination = $this->pagination; $start = $this->request->variable('start', 0); $limit = $this->config['topics_per_page']; $start = $pagination->validate_start($start, $limit, $topics_count); $topics = $this->tags_manager->get_topics_by_tags($tags, $start, $limit, $mode, $casesensitive); $base_url = $this->helper->route('robertheim_topictags_show_tag_controller', array('tags' => urlencode($tags_string))); $base_url = append_sid($base_url); $pagination->generate_template_pagination($base_url, 'pagination', 'start', $topics_count, $limit, $start); $this->user->add_lang('viewforum'); $this->template->assign_vars(array('TOTAL_TOPICS' => $this->user->lang('VIEW_FORUM_TOPICS', $topics_count), 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'REPORTED_IMG' => $this->user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'UNAPPROVED_IMG' => $this->user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'), 'DELETED_IMG' => $this->user->img('icon_topic_deleted', 'TOPIC_DELETED'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL'), 'S_TOPIC_ICONS' => true)); $this->display_topics($topics); } // else return $this->helper->render('show_tag.html', $this->user->lang('RH_TOPICTAGS_TAG_SEARCH')); }