/** * Test the tag_set function. * This function was deprecated in 3.1 */ public function test_tag_set_get() { global $DB; // Create a course to tag. $course = $this->getDataGenerator()->create_course(); // Create the tag and tag instance. tag_set('course', $course->id, array('A random tag'), 'core', context_course::instance($course->id)->id); $this->assertDebuggingCalled(); // Get the tag instance that should have been created. $taginstance = $DB->get_record('tag_instance', array('itemtype' => 'course', 'itemid' => $course->id), '*', MUST_EXIST); $this->assertEquals('core', $taginstance->component); $this->assertEquals(context_course::instance($course->id)->id, $taginstance->contextid); $tagbyname = tag_get('name', 'A random tag'); $this->assertDebuggingCalled(); $this->assertEquals('A random tag', $tagbyname->rawname); $this->assertEmpty(tag_get('name', 'Non existing tag')); $this->assertDebuggingCalled(); $tagbyid = tag_get('id', $tagbyname->id); $this->assertDebuggingCalled(); $this->assertEquals('A random tag', $tagbyid->rawname); $tagid = $tagbyname->id; $this->assertEmpty(tag_get('id', $tagid + 1)); $this->assertDebuggingCalled(); tag_set('tag', $tagid, array('Some related tag')); $this->assertDebuggingCalled(); $relatedtags = tag_get_related_tags($tagid); $this->assertDebuggingCalled(); $this->assertCount(1, $relatedtags); $this->assertEquals('Some related tag', $relatedtags[0]->rawname); $tagids = tag_get_id(array('A random tag', 'Some related tag')); $this->assertDebuggingCalled(); $this->assertCount(2, $tagids); $this->assertEquals($tagid, $tagids['a random tag']); $this->assertEquals($relatedtags[0]->id, $tagids['some related tag']); }
/** * Validates the Attach Tags group action. * Gets called for every bug, but performs the real tag validation only * the first time. Any invalid tags will be skipped, as there is no simple * or clean method of presenting these errors to the user. * @param integer Bug ID * @return boolean True */ function action_attach_tags_validate($p_bug_id) { global $g_action_attach_tags_valid; if (!isset($g_action_attach_tags_valid)) { $f_tag_string = gpc_get_string('tag_string'); $f_tag_select = gpc_get_string('tag_select'); global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; $g_action_attach_tags_attach = array(); $g_action_attach_tags_create = array(); $g_action_attach_tags_failed = array(); $t_tags = tag_parse_string($f_tag_string); $t_can_create = access_has_global_level(config_get('tag_create_threshold')); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { if ($t_can_create) { $g_action_attach_tags_create[] = $t_tag_row; } else { $g_action_attach_tags_failed[] = $t_tag_row; } } elseif (-2 == $t_tag_row['id']) { $g_action_attach_tags_failed[] = $t_tag_row; } else { $g_action_attach_tags_attach[] = $t_tag_row; } } if (0 < $f_tag_select && tag_exists($f_tag_select)) { $g_action_attach_tags_attach[] = tag_get($f_tag_select); } } global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; return true; }
function get_videos_by_tag_and_category() { $tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility $tag = optional_param('tag', '', PARAM_TAG); // tag if ($tag) { $tagobject = tag_get('name', $tag); } else { if ($tagid) { $tagobject = tag_get('id', $tagid); } } if (empty($tagobject)) { print_error('tagnotfound'); } $querytag = urlencode($tagobject->name); if (isset($this->config->overridetag)) { $querytag = $this->config->overridetag; } $numberofvideos = DEFAULT_NUMBER_OF_VIDEOS; if (!empty($this->config->numberofvideos)) { $numberofvideos = $this->config->numberofvideos; } $request = 'http://www.youtube.com/api2_rest?method=youtube.videos.list_by_category_and_tag'; $request .= '&category_id=' . $this->config->category; $request .= '&dev_id=' . YOUTUBE_DEV_KEY; $request .= "&tag={$querytag}"; $request .= "&page=1"; $request .= "&per_page={$numberofvideos}"; return $this->fetch_request($request); }
/** * Get a list of related tags. * Returns a list of tags that are the most related to the given tag, * based on the number of times they have been attached to the same bugs. * Defaults to a list of five tags. * @param integer Tag ID * @param integer List size * @return array Array of tag rows, with share count added */ function tag_stats_related($p_tag_id, $p_limit = 5) { $t_bug_table = db_get_table('bug'); $t_tag_table = db_get_table('tag'); $t_bug_tag_table = db_get_table('bug_tag'); $t_project_user_list_table = db_get_table('project_user_list'); $t_user_table = db_get_table('user'); $c_tag_id = db_prepare_int($p_tag_id); $c_user_id = auth_get_current_user_id(); $subquery = "SELECT b.id FROM {$t_bug_table} AS b\n\t\t\t\t\tLEFT JOIN {$t_project_user_list_table} AS p\n\t\t\t\t\t\tON p.project_id=b.project_id AND p.user_id=" . db_param() . "\n\t\t\t\t\tJOIN {$t_user_table} AS u\n\t\t\t\t\t\tON u.id=" . db_param() . "\n\t\t\t\t\tJOIN {$t_bug_tag_table} AS t\n\t\t\t\t\t\tON t.bug_id=b.id\n\t\t\t\t\tWHERE ( p.access_level>b.view_state OR u.access_level>b.view_state )\n\t\t\t\t\t\tAND t.tag_id=" . db_param(); $query = "SELECT * FROM {$t_bug_tag_table}\n\t\t\t\t\tWHERE tag_id != " . db_param() . "\n\t\t\t\t\t\tAND bug_id IN ( {$subquery} ) "; $result = db_query_bound($query, array($c_tag_id, $c_user_id, $c_user_id, $c_tag_id)); $t_tag_counts = array(); while ($row = db_fetch_array($result)) { if (!isset($t_tag_counts[$row['tag_id']])) { $t_tag_counts[$row['tag_id']] = 1; } else { $t_tag_counts[$row['tag_id']]++; } } arsort($t_tag_counts); $t_tags = array(); $i = 1; foreach ($t_tag_counts as $t_tag_id => $t_count) { $t_tag_row = tag_get($t_tag_id); $t_tag_row['count'] = $t_count; $t_tags[] = $t_tag_row; $i++; if ($i > $p_limit) { break; } } return $t_tags; }
/** * function to attach tags into a post * @param int postid - id of the blog */ function add_tags_info($postid) { $tags = array(); if ($otags = optional_param('otags', '', PARAM_INT)) { foreach ($otags as $tagid) { // TODO : make this use the tag name in the form if ($tag = tag_get('id', $tagid)) { $tags[] = $tag->name; } } } $manual_tags = optional_param('ptags', '', PARAM_NOTAGS); $tags = array_merge($tags, explode(',', $manual_tags)); tag_set('post', $postid, $tags); }
/** * Test for function tag_cleanup() that is part of tag cron */ public function test_cleanup() { global $DB; $user = $this->getDataGenerator()->create_user(); // Setting tags will create non-official tags 'cat', 'dog' and 'fish'. tag_set('user', $user->id, array('cat', 'dog', 'fish'), 'core', context_user::instance($user->id)->id); $this->assertTrue($DB->record_exists('tag', array('name' => 'cat'))); $this->assertTrue($DB->record_exists('tag', array('name' => 'dog'))); $this->assertTrue($DB->record_exists('tag', array('name' => 'fish'))); // Make tag 'dog' official. $dogtag = tag_get('name', 'dog'); $fishtag = tag_get('name', 'fish'); tag_type_set($dogtag->id, 'official'); // Manually remove the instances pointing on tags 'dog' and 'fish'. $DB->execute('DELETE FROM {tag_instance} WHERE tagid in (?,?)', array($dogtag->id, $fishtag->id)); // Call tag_cleanup(). tag_cleanup(); // Tag 'cat' is still present because it's used. Tag 'dog' is present because it's official. // Tag 'fish' was removed because it is not official and it is no longer used by anybody. $this->assertTrue($DB->record_exists('tag', array('name' => 'cat'))); $this->assertTrue($DB->record_exists('tag', array('name' => 'dog'))); $this->assertFalse($DB->record_exists('tag', array('name' => 'fish'))); // Delete user without using API function. $DB->update_record('user', array('id' => $user->id, 'deleted' => 1)); // Call tag_cleanup(). tag_cleanup(); // Tag 'cat' was now deleted too. $this->assertFalse($DB->record_exists('tag', array('name' => 'cat'))); // Assign tag to non-existing record. Make sure tag was created in the DB. tag_set('course', 1231231, array('bird'), 'core', context_system::instance()->id); $this->assertTrue($DB->record_exists('tag', array('name' => 'bird'))); // Call tag_cleanup(). tag_cleanup(); // Tag 'bird' was now deleted because the related record does not exist in the DB. $this->assertFalse($DB->record_exists('tag', array('name' => 'bird'))); // Now we have a tag instance pointing on 'sometag' tag. $user = $this->getDataGenerator()->create_user(); tag_set('user', $user->id, array('sometag'), 'core', context_user::instance($user->id)->id); $sometag = tag_get('name', 'sometag'); $this->assertTrue($DB->record_exists('tag_instance', array('tagid' => $sometag->id))); // Some hacker removes the tag without using API. $DB->delete_records('tag', array('id' => $sometag->id)); // Call tag_cleanup(). tag_cleanup(); // The tag instances were also removed. $this->assertFalse($DB->record_exists('tag_instance', array('tagid' => $sometag->id))); }
function get_content() { global $CFG, $USER; //note: do NOT include files at the top of this file require_once $CFG->dirroot . '/tag/lib.php'; require_once $CFG->libdir . '/filelib.php'; if ($this->content !== NULL) { return $this->content; } $tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility $tag = optional_param('tag', '', PARAM_TAG); // tag if ($tag) { $tagobject = tag_get('name', $tag); } else { if ($tagid) { $tagobject = tag_get('id', $tagid); } } if (empty($tagobject)) { $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; return $this->content; } //include related tags in the photo query ? $tagscsv = $tagobject->name; if (!empty($this->config->includerelatedtags)) { $tagscsv .= ',' . tag_get_related_tags_csv(tag_get_related_tags($tagobject->id), TAG_RETURN_TEXT); } $tagscsv = urlencode($tagscsv); //number of photos to display $numberofphotos = DEFAULT_NUMBER_OF_PHOTOS; if (!empty($this->config->numberofphotos)) { $numberofphotos = $this->config->numberofphotos; } //sort search results by $sortby = 'relevance'; if (!empty($this->config->sortby)) { $sortby = $this->config->sortby; } //pull photos from a specific photoset if (!empty($this->config->photoset)) { $request = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos'; $request .= '&api_key=' . FLICKR_DEV_KEY; $request .= '&photoset_id=' . $this->config->photoset; $request .= '&per_page=' . $numberofphotos; $request .= '&format=php_serial'; $response = $this->fetch_request($request); $search = unserialize($response); foreach ($search['photoset']['photo'] as $p) { $p['owner'] = $search['photoset']['owner']; } $photos = array_values($search['photoset']['photo']); } else { $request = 'http://api.flickr.com/services/rest/?method=flickr.photos.search'; $request .= '&api_key=' . FLICKR_DEV_KEY; $request .= '&tags=' . $tagscsv; $request .= '&per_page=' . $numberofphotos; $request .= '&sort=' . $sortby; $request .= '&format=php_serial'; $response = $this->fetch_request($request); $search = unserialize($response); $photos = array_values($search['photos']['photo']); } if (strcmp($search['stat'], 'ok') != 0) { return; } //if no results were returned, exit... //Accessibility: render the list of photos $text = '<ul class="inline-list">'; foreach ($photos as $photo) { $text .= '<li><a href="http://www.flickr.com/photos/' . $photo['owner'] . '/' . $photo['id'] . '/" title="' . s($photo['title']) . '">'; $text .= '<img alt="' . s($photo['title']) . '" class="flickr-photos" src="' . $this->build_photo_url($photo, 'square') . "\" /></a></li>\n"; } $text .= "</ul>\n"; $this->content = new stdClass(); $this->content->text = $text; $this->content->footer = ''; return $this->content; }
/** * Change the "value" of a tag, and update the associated 'name'. * * @param int $tagid the id of the tag to modify * @param string $newtag the new rawname * @return bool true on success, false otherwise */ function tag_rename($tagid, $newrawname) { if (!($newrawname_clean = array_shift(tag_normalize($newrawname, TAG_CASE_ORIGINAL)))) { return false; } if (!($newname_clean = moodle_strtolower($newrawname_clean))) { return false; } // Prevent the rename if a tag with that name already exists if ($existing = tag_get('name', $newname_clean, 'id, name, rawname')) { if ($existing->id != $tagid) { // Another tag already exists with this name return false; } } if ($tag = tag_get('id', $tagid, 'id, name, rawname')) { $tag->rawname = addslashes($newrawname_clean); $tag->name = addslashes($newname_clean); $tag->timemodified = time(); return update_record('tag', $tag); } return false; }
*/ /** * MantisBT Core API's */ require_once 'core.php'; /** * requires ajax_api */ require_once 'ajax_api.php'; /** * requires tag_api */ require_once 'tag_api.php'; compress_enable(); $f_tag_id = gpc_get_int('tag_id'); $t_tag_row = tag_get($f_tag_id); $t_name = string_display_line($t_tag_row['name']); $t_description = string_display($t_tag_row['description']); if (!(access_has_global_level(config_get('tag_edit_threshold')) || auth_get_current_user_id() == $t_tag_row['user_id'] && access_has_global_level(config_get('tag_edit_own_threshold')))) { access_denied(); } html_page_top(sprintf(lang_get('tag_update'), $t_name)); ?> <br /> <form method="post" action="tag_update.php"> <?php echo form_security_field('tag_update'); ?> <table class="width100" cellspacing="1">
/** * Change the "value" of a tag, and update the associated 'name'. * * @package core_tag * @category tag * @access public * @param int $tagid the id of the tag to modify * @param string $newrawname the new rawname * @return bool true on success, false otherwise */ function tag_rename($tagid, $newrawname) { global $DB; $norm = tag_normalize($newrawname, TAG_CASE_ORIGINAL); if (! $newrawname_clean = array_shift($norm) ) { return false; } if (! $newname_clean = textlib::strtolower($newrawname_clean)) { return false; } // Prevent the rename if a tag with that name already exists if ($existing = tag_get('name', $newname_clean, 'id, name, rawname')) { if ($existing->id != $tagid) { // Another tag already exists with this name return false; } } if ($tag = tag_get('id', $tagid, 'id, name, rawname')) { $tag->rawname = $newrawname_clean; $tag->name = $newname_clean; $tag->timemodified = time(); return $DB->update_record('tag', $tag); } return false; }
/** * Get a list of related tags. * Returns a list of tags that are the most related to the given tag, * based on the number of times they have been attached to the same bugs. * Defaults to a list of five tags. * @param integer $p_tag_id The tag ID to retrieve statistics on. * @param integer $p_limit List size. * @return array Array of tag rows, with share count added */ function tag_stats_related($p_tag_id, $p_limit = 5) { $c_user_id = auth_get_current_user_id(); $t_subquery = 'SELECT b.id FROM {bug} b LEFT JOIN {project_user_list} p ON p.project_id=b.project_id AND p.user_id=' . db_param() . ' JOIN {user} u ON u.id=' . db_param() . ' JOIN {bug_tag} t ON t.bug_id=b.id WHERE ( p.access_level>b.view_state OR u.access_level>b.view_state ) AND t.tag_id=' . db_param(); # 4th Param $t_query = 'SELECT * FROM {bug_tag} WHERE tag_id != ' . db_param() . ' AND bug_id IN ( ' . $t_subquery . ' ) '; $t_result = db_query($t_query, array($p_tag_id, $c_user_id, $c_user_id, $p_tag_id)); $t_tag_counts = array(); while ($t_row = db_fetch_array($t_result)) { if (!isset($t_tag_counts[$t_row['tag_id']])) { $t_tag_counts[$t_row['tag_id']] = 1; } else { $t_tag_counts[$t_row['tag_id']]++; } } arsort($t_tag_counts); $t_tags = array(); $i = 1; foreach ($t_tag_counts as $t_tag_id => $t_count) { $t_tag_row = tag_get($t_tag_id); $t_tag_row['count'] = $t_count; $t_tags[] = $t_tag_row; $i++; if ($i > $p_limit) { break; } } return $t_tags; }
if (-1 == $t_tag_row['id']) { if ($t_can_create) { $t_tags_create[] = $t_tag_row; } else { $t_tags_failed[] = $t_tag_row; } } else { if (-2 == $t_tag_row['id']) { $t_tags_failed[] = $t_tag_row; } else { $t_tags_attach[] = $t_tag_row; } } } if (0 < $f_tag_select && tag_exists($f_tag_select)) { $t_tags_attach[] = tag_get($f_tag_select); } // failed to attach at least one tag if (count($t_tags_failed) > 0) { html_page_top(lang_get('tag_attach_long') . ' ' . bug_format_summary($f_bug_id, SUMMARY_CAPTION)); ?> <br/> <table class="width75"> <tr class="row-category"> <td colspan="2"><?php echo lang_get('tag_attach_failed'); ?> </td> </tr> <tr class="spacer"><td colspan="2"></td></tr> <?php
/** * * */ function bookmarks_untag($itemid, $tagname) { $tag = tag_get('name', $tagname); return tag_delete_instance('bookmark', $itemid, $tag->id); }
/** * @todo Had to make all these parameters required because we can't use * call-time pass by reference anymore. I really preferred not having * to pass all the params in if you didn't want to, but I wanted to get * rid of the errors for now. If we can think of a better way later * (maybe return an object) that would be great. * * @param int $p_page_number the page you want to see (set to the actual page on return) * @param int $p_per_page the number of bugs to see per page (set to actual on return) * -1 indicates you want to see all bugs * null indicates you want to use the value specified in the filter * @param int $p_page_count you don't need to give a value here, the number of pages will be stored here on return * @param int $p_bug_count you don't need to give a value here, the number of bugs will be stored here on return * @param mixed $p_custom_filter Filter to use. * @param int $p_project_id project id to use in filtering. * @param int $p_user_id user id to use as current user when filtering. * @param bool $p_show_sticky get sticky issues only. */ function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null) { log_event(LOG_FILTERING, 'START NEW FILTER QUERY'); $t_bug_table = db_get_table('mantis_bug_table'); $t_bug_text_table = db_get_table('mantis_bug_text_table'); $t_bugnote_table = db_get_table('mantis_bugnote_table'); $t_category_table = db_get_table('mantis_category_table'); $t_custom_field_string_table = db_get_table('mantis_custom_field_string_table'); $t_bugnote_text_table = db_get_table('mantis_bugnote_text_table'); $t_project_table = db_get_table('mantis_project_table'); $t_bug_monitor_table = db_get_table('mantis_bug_monitor_table'); $t_limit_reporters = config_get('limit_reporters'); $t_bug_relationship_table = db_get_table('mantis_bug_relationship_table'); $t_report_bug_threshold = config_get('report_bug_threshold'); $t_where_param_count = 0; $t_current_user_id = auth_get_current_user_id(); if (null === $p_user_id) { $t_user_id = $t_current_user_id; } else { $t_user_id = $p_user_id; } $c_user_id = db_prepare_int($t_user_id); if (null === $p_project_id) { # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project. $t_project_id = helper_get_current_project(); } else { $t_project_id = $p_project_id; } if ($p_custom_filter === null) { # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports # cookies set by previous version of the code. if ($t_user_id == $t_current_user_id) { $t_filter = current_user_get_bug_filter(); } else { $t_filter = user_get_bug_filter($t_user_id, $t_project_id); } } else { $t_filter = $p_custom_filter; } $t_filter = filter_ensure_valid_filter($t_filter); if (false === $t_filter) { return false; # signify a need to create a cookie # @@@ error instead? } $t_view_type = $t_filter['_view_type']; $t_where_clauses = array("{$t_project_table}.enabled = " . db_param(), "{$t_project_table}.id = {$t_bug_table}.project_id"); $t_where_params = array(1); $t_select_clauses = array("{$t_bug_table}.*"); $t_join_clauses = array(); $t_from_clauses = array(); // normalize the project filtering into an array $t_project_ids if ('simple' == $t_view_type) { log_event(LOG_FILTERING, 'Simple Filter'); $t_project_ids = array($t_project_id); $t_include_sub_projects = true; } else { log_event(LOG_FILTERING, 'Advanced Filter'); if (!is_array($t_filter[FILTER_PROPERTY_PROJECT_ID])) { $t_project_ids = array(db_prepare_int($t_filter[FILTER_PROPERTY_PROJECT_ID])); } else { $t_project_ids = array_map('db_prepare_int', $t_filter[FILTER_PROPERTY_PROJECT_ID]); } $t_include_sub_projects = count($t_project_ids) == 1 && ($t_project_ids[0] == META_FILTER_CURRENT || $t_project_ids[0] == ALL_PROJECTS); } log_event(LOG_FILTERING, 'project_ids = @P' . implode(', @P', $t_project_ids)); log_event(LOG_FILTERING, 'include sub-projects = ' . ($t_include_sub_projects ? '1' : '0')); // if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS. // replace META_FILTER_CURRENT with the actualy current project id. $t_all_projects_found = false; $t_new_project_ids = array(); foreach ($t_project_ids as $t_pid) { if ($t_pid == META_FILTER_CURRENT) { $t_pid = $t_project_id; } if ($t_pid == ALL_PROJECTS) { $t_all_projects_found = true; log_event(LOG_FILTERING, 'all projects selected'); break; } // filter out inaccessible projects. if (!access_has_project_level(VIEWER, $t_pid, $t_user_id)) { continue; } $t_new_project_ids[] = $t_pid; } $t_projects_query_required = true; if ($t_all_projects_found) { if (user_is_administrator($t_user_id)) { log_event(LOG_FILTERING, 'all projects + administrator, hence no project filter.'); $t_projects_query_required = false; } else { $t_project_ids = user_get_accessible_projects($t_user_id); } } else { $t_project_ids = $t_new_project_ids; } if ($t_projects_query_required) { // expand project ids to include sub-projects if ($t_include_sub_projects) { $t_top_project_ids = $t_project_ids; foreach ($t_top_project_ids as $t_pid) { log_event(LOG_FILTERING, 'Getting sub-projects for project id @P' . $t_pid); $t_subproject_ids = user_get_all_accessible_subprojects($t_user_id, $t_pid); if (!$t_subproject_ids) { continue; } $t_project_ids = array_merge($t_project_ids, $t_subproject_ids); } $t_project_ids = array_unique($t_project_ids); } // if no projects are accessible, then return an empty array. if (count($t_project_ids) == 0) { log_event(LOG_FILTERING, 'no accessible projects'); return array(); } log_event(LOG_FILTERING, 'project_ids after including sub-projects = @P' . implode(', @P', $t_project_ids)); // this array is to be populated with project ids for which we only want to show public issues. This is due to the limited // access of the current user. $t_public_only_project_ids = array(); // this array is populated with project ids that the current user has full access to. $t_private_and_public_project_ids = array(); foreach ($t_project_ids as $t_pid) { $t_access_required_to_view_private_bugs = config_get('private_bug_threshold', null, null, $t_pid); if (access_has_project_level($t_access_required_to_view_private_bugs, $t_pid, $t_user_id)) { $t_private_and_public_project_ids[] = $t_pid; } else { $t_public_only_project_ids[] = $t_pid; } } log_event(LOG_FILTERING, 'project_ids (with public/private access) = @P' . implode(', @P', $t_private_and_public_project_ids)); log_event(LOG_FILTERING, 'project_ids (with public access) = @P' . implode(', @P', $t_public_only_project_ids)); $t_count_private_and_public_project_ids = count($t_private_and_public_project_ids); if ($t_count_private_and_public_project_ids == 1) { $t_private_and_public_query = "( {$t_bug_table}.project_id = " . $t_private_and_public_project_ids[0] . " )"; } else { if ($t_count_private_and_public_project_ids > 1) { $t_private_and_public_query = "( {$t_bug_table}.project_id in (" . implode(', ', $t_private_and_public_project_ids) . ") )"; } else { $t_private_and_public_query = null; } } $t_count_public_only_project_ids = count($t_public_only_project_ids); $t_public_view_state_check = "( ( {$t_bug_table}.view_state = " . VS_PUBLIC . " ) OR ( {$t_bug_table}.reporter_id = {$t_user_id} ) )"; if ($t_count_public_only_project_ids == 1) { $t_public_only_query = "( ( {$t_bug_table}.project_id = " . $t_public_only_project_ids[0] . " ) AND {$t_public_view_state_check} )"; } else { if ($t_count_public_only_project_ids > 1) { $t_public_only_query = "( ( {$t_bug_table}.project_id in (" . implode(', ', $t_public_only_project_ids) . ") ) AND {$t_public_view_state_check} )"; } else { $t_public_only_query = null; } } // both queries can't be null, so we either have one of them or both. if ($t_private_and_public_query === null) { $t_project_query = $t_public_only_query; } else { if ($t_public_only_query === null) { $t_project_query = $t_private_and_public_query; } else { $t_project_query = "( {$t_public_only_query} OR {$t_private_and_public_query} )"; } } log_event(LOG_FILTERING, 'project query = ' . $t_project_query); array_push($t_where_clauses, $t_project_query); } # view state $t_view_state = db_prepare_int($t_filter[FILTER_PROPERTY_VIEW_STATE_ID]); if (!filter_field_is_any($t_filter[FILTER_PROPERTY_VIEW_STATE_ID])) { $t_view_state_query = "({$t_bug_table}.view_state=" . db_param() . ')'; log_event(LOG_FILTERING, 'view_state query = ' . $t_view_state_query); $t_where_params[] = $t_view_state; array_push($t_where_clauses, $t_view_state_query); } else { log_event(LOG_FILTERING, 'no view_state query'); } # reporter if (!filter_field_is_any($t_filter[FILTER_PROPERTY_REPORTER_ID])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_REPORTER_ID] as $t_filter_member) { if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, "0"); } else { $c_reporter_id = db_prepare_int($t_filter_member); if (filter_field_is_myself($c_reporter_id)) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_reporter_id); } } } if (1 < count($t_clauses)) { $t_reporter_query = "( {$t_bug_table}.reporter_id in (" . implode(', ', $t_clauses) . ") )"; } else { $t_reporter_query = "( {$t_bug_table}.reporter_id={$t_clauses['0']} )"; } log_event(LOG_FILTERING, 'reporter query = ' . $t_reporter_query); array_push($t_where_clauses, $t_reporter_query); } else { log_event(LOG_FILTERING, 'no reporter query'); } # limit reporter # @@@ thraxisp - access_has_project_level checks greater than or equal to, # this assumed that there aren't any holes above REPORTER where the limit would apply # if (ON === $t_limit_reporters && !access_has_project_level(REPORTER + 1, $t_project_id, $t_user_id)) { $c_reporter_id = $c_user_id; $t_where_params[] = $c_reporter_id; array_push($t_where_clauses, "({$t_bug_table}.reporter_id=" . db_param() . ')'); } # handler if (!filter_field_is_any($t_filter[FILTER_PROPERTY_HANDLER_ID])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_HANDLER_ID] as $t_filter_member) { if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, 0); } else { $c_handler_id = db_prepare_int($t_filter_member); if (filter_field_is_myself($c_handler_id)) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_handler_id); } } } if (1 < count($t_clauses)) { $t_handler_query = "( {$t_bug_table}.handler_id in (" . implode(', ', $t_clauses) . ") )"; } else { $t_handler_query = "( {$t_bug_table}.handler_id={$t_clauses['0']} )"; } log_event(LOG_FILTERING, 'handler query = ' . $t_handler_query); array_push($t_where_clauses, $t_handler_query); } else { log_event(LOG_FILTERING, 'no handler query'); } # category if (!filter_field_is_any($t_filter[FILTER_PROPERTY_CATEGORY])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_CATEGORY] as $t_filter_member) { if (!filter_field_is_none($t_filter_member)) { array_push($t_clauses, $t_filter_member); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.category_id in ( SELECT id FROM {$t_category_table} WHERE name in (" . implode(', ', $t_where_tmp) . ") ) )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.category_id in ( SELECT id FROM {$t_category_table} WHERE name=" . db_param() . ") )"); } } # severity if (!filter_field_is_any($t_filter[FILTER_PROPERTY_SEVERITY_ID])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_SEVERITY_ID] as $t_filter_member) { $c_show_severity = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_severity); } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.severity in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.severity=" . db_param() . " )"); } } # show / hide status # take a list of all available statuses then remove the ones that we want hidden, then make sure # the ones we want shown are still available $t_desired_statuses = array(); $t_available_statuses = MantisEnum::getValues(config_get('status_enum_string')); if ('simple' == $t_filter['_view_type']) { # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide $t_any_found = false; $t_this_status = $t_filter[FILTER_PROPERTY_STATUS_ID][0]; $t_this_hide_status = $t_filter[FILTER_PROPERTY_HIDE_STATUS_ID][0]; if (filter_field_is_any($t_this_status)) { foreach ($t_available_statuses as $t_this_available_status) { if ($t_this_hide_status > $t_this_available_status) { $t_desired_statuses[] = $t_this_available_status; } } } else { $t_desired_statuses[] = $t_this_status; } } else { # advanced filtering: ignore the hide if (filter_field_is_any($t_filter[FILTER_PROPERTY_STATUS_ID])) { $t_desired_statuses = array(); } else { foreach ($t_filter[FILTER_PROPERTY_STATUS_ID] as $t_this_status) { $t_desired_statuses[] = $t_this_status; } } } if (count($t_desired_statuses) > 0) { $t_clauses = array(); foreach ($t_desired_statuses as $t_filter_member) { $c_show_status = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_status); } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.status in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.status=" . db_param() . " )"); } } # resolution if (!filter_field_is_any($t_filter[FILTER_PROPERTY_RESOLUTION_ID])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_RESOLUTION_ID] as $t_filter_member) { $c_show_resolution = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_resolution); } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.resolution in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.resolution=" . db_param() . " )"); } } # priority if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PRIORITY_ID])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_PRIORITY_ID] as $t_filter_member) { $c_show_priority = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_priority); } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.priority in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.priority=" . db_param() . " )"); } } # product build if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PRODUCT_BUILD])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_PRODUCT_BUILD] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_show_build = db_prepare_string($t_filter_member); array_push($t_clauses, $c_show_build); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.build in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.build=" . db_param() . " )"); } } # product version if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PRODUCT_VERSION])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_PRODUCT_VERSION] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_show_version = db_prepare_string($t_filter_member); array_push($t_clauses, $c_show_version); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.version in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.version=" . db_param() . " )"); } } # profile if (!filter_field_is_any($t_filter['show_profile'])) { $t_clauses = array(); foreach ($t_filter['show_profile'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, "0"); } else { $c_show_profile = db_prepare_int($t_filter_member); array_push($t_clauses, "{$c_show_profile}"); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.profile_id in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.profile_id=" . db_param() . " )"); } } # platform if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PLATFORM])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_PLATFORM] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_platform = db_prepare_string($t_filter_member); array_push($t_clauses, $c_platform); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.platform in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.platform = " . db_param() . " )"); } } # os if (!filter_field_is_any($t_filter[FILTER_PROPERTY_OS])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_OS] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_os = db_prepare_string($t_filter_member); array_push($t_clauses, $c_os); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.os in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.os = " . db_param() . " )"); } } # os_build if (!filter_field_is_any($t_filter[FILTER_PROPERTY_OS_BUILD])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_OS_BUILD] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_os_build = db_prepare_string($t_filter_member); array_push($t_clauses, $c_os_build); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.os_build in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.os_build = " . db_param() . " )"); } } # date filter if ('on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] && is_numeric($t_filter[FILTER_PROPERTY_START_MONTH]) && is_numeric($t_filter[FILTER_PROPERTY_START_DAY]) && is_numeric($t_filter[FILTER_PROPERTY_START_YEAR]) && is_numeric($t_filter[FILTER_PROPERTY_END_MONTH]) && is_numeric($t_filter[FILTER_PROPERTY_END_DAY]) && is_numeric($t_filter[FILTER_PROPERTY_END_YEAR])) { $t_start_string = $t_filter[FILTER_PROPERTY_START_YEAR] . "-" . $t_filter[FILTER_PROPERTY_START_MONTH] . "-" . $t_filter[FILTER_PROPERTY_START_DAY] . " 00:00:00"; $t_end_string = $t_filter[FILTER_PROPERTY_END_YEAR] . "-" . $t_filter[FILTER_PROPERTY_END_MONTH] . "-" . $t_filter[FILTER_PROPERTY_END_DAY] . " 23:59:59"; $t_where_params[] = strtotime($t_start_string); $t_where_params[] = strtotime($t_end_string); array_push($t_where_clauses, "({$t_bug_table}.date_submitted BETWEEN " . db_param() . " AND " . db_param() . " )"); } # fixed in version if (!filter_field_is_any($t_filter[FILTER_PROPERTY_FIXED_IN_VERSION])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_FIXED_IN_VERSION] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_fixed_in_version = db_prepare_string($t_filter_member); array_push($t_clauses, $c_fixed_in_version); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version=" . db_param() . " )"); } } # target version if (!filter_field_is_any($t_filter[FILTER_PROPERTY_TARGET_VERSION])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_TARGET_VERSION] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_target_version = db_prepare_string($t_filter_member); array_push($t_clauses, $c_target_version); } } # echo var_dump( $t_clauses ); exit; if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bug_table}.target_version in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bug_table}.target_version=" . db_param() . " )"); } } # users monitoring a bug if (!filter_field_is_any($t_filter[FILTER_PROPERTY_MONITOR_USER_ID])) { $t_clauses = array(); $t_table_name = 'user_monitor'; array_push($t_join_clauses, "LEFT JOIN {$t_bug_monitor_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id"); foreach ($t_filter[FILTER_PROPERTY_MONITOR_USER_ID] as $t_filter_member) { $c_user_monitor = db_prepare_int($t_filter_member); if (filter_field_is_myself($c_user_monitor)) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_user_monitor); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_table_name}.user_id in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_table_name}.user_id=" . db_param() . " )"); } } # bug relationship $t_any_found = false; $c_rel_type = $t_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE]; $c_rel_bug = $t_filter[FILTER_PROPERTY_RELATIONSHIP_BUG]; if (-1 == $c_rel_type || 0 == $c_rel_bug) { $t_any_found = true; } if (!$t_any_found) { # use the complementary type $t_comp_type = relationship_get_complementary_type($c_rel_type); $t_clauses = array(); $t_table_name = 'relationship'; array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name} ON {$t_table_name}.destination_bug_id = {$t_bug_table}.id"); array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name}2 ON {$t_table_name}2.source_bug_id = {$t_bug_table}.id"); // get reverse relationships $t_where_params[] = $t_comp_type; $t_where_params[] = $c_rel_bug; $t_where_params[] = $c_rel_type; $t_where_params[] = $c_rel_bug; array_push($t_clauses, "({$t_table_name}.relationship_type=" . db_param() . " AND {$t_table_name}.source_bug_id=" . db_param() . ')'); array_push($t_clauses, "({$t_table_name}" . "2.relationship_type=" . db_param() . " AND {$t_table_name}" . "2.destination_bug_id=" . db_param() . ')'); array_push($t_where_clauses, '(' . implode(' OR ', $t_clauses) . ')'); } # tags $c_tag_string = trim($t_filter[FILTER_PROPERTY_TAG_STRING]); $c_tag_select = trim($t_filter[FILTER_PROPERTY_TAG_SELECT]); if (is_blank($c_tag_string) && !is_blank($c_tag_select) && $c_tag_select != 0) { $t_tag = tag_get($c_tag_select); $c_tag_string = $t_tag['name']; } if (!is_blank($c_tag_string)) { $t_tags = tag_parse_filters($c_tag_string); if (count($t_tags)) { $t_tags_all = array(); $t_tags_any = array(); $t_tags_none = array(); foreach ($t_tags as $t_tag_row) { switch ($t_tag_row['filter']) { case 1: $t_tags_all[] = $t_tag_row; break; case 0: $t_tags_any[] = $t_tag_row; break; case -1: $t_tags_none[] = $t_tag_row; break; } } if (0 < $t_filter[FILTER_PROPERTY_TAG_SELECT] && tag_exists($t_filter[FILTER_PROPERTY_TAG_SELECT])) { $t_tags_any[] = tag_get($t_filter[FILTER_PROPERTY_TAG_SELECT]); } $t_bug_tag_table = db_get_table('mantis_bug_tag_table'); if (count($t_tags_all)) { $t_clauses = array(); foreach ($t_tags_all as $t_tag_row) { array_push($t_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE {$t_bug_tag_table}.tag_id = {$t_tag_row['id']} )"); } array_push($t_where_clauses, '(' . implode(' AND ', $t_clauses) . ')'); } if (count($t_tags_any)) { $t_clauses = array(); foreach ($t_tags_any as $t_tag_row) { array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}"); } array_push($t_where_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )'); } if (count($t_tags_none)) { $t_clauses = array(); foreach ($t_tags_none as $t_tag_row) { array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}"); } array_push($t_where_clauses, "{$t_bug_table}.id NOT IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )'); } } } # note user id if (!filter_field_is_any($t_filter[FILTER_PROPERTY_NOTE_USER_ID])) { $t_bugnote_table_alias = 'mbnt'; $t_clauses = array(); array_push($t_from_clauses, "{$t_bugnote_table} {$t_bugnote_table_alias}"); array_push($t_where_clauses, "( {$t_bug_table}.id = {$t_bugnote_table_alias}.bug_id )"); foreach ($t_filter[FILTER_PROPERTY_NOTE_USER_ID] as $t_filter_member) { $c_note_user_id = db_prepare_int($t_filter_member); if (filter_field_is_myself($c_note_user_id)) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_note_user_id); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, "( {$t_bugnote_table_alias}.reporter_id in (" . implode(', ', $t_where_tmp) . ") )"); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, "( {$t_bugnote_table_alias}.reporter_id=" . db_param() . " )"); } } # plugin filters $t_plugin_filters = filter_get_plugin_filters(); foreach ($t_plugin_filters as $t_field_name => $t_filter_object) { if (!filter_field_is_any($t_filter[$t_field_name]) || $t_filter_object->type == FILTER_TYPE_BOOLEAN) { $t_filter_query = $t_filter_object->query($t_filter[$t_field_name]); if (is_array($t_filter_query)) { if (isset($t_filter_query['join'])) { array_push($t_join_clauses, $t_filter_query['join']); } if (isset($t_filter_query['where'])) { array_push($t_where_clauses, $t_filter_query['where']); } if (isset($t_filter_query['params']) && is_array($t_filter_query['params'])) { $t_where_params = array_merge($t_where_params, $t_filter_query['params']); } } } } # custom field filters if (ON == config_get('filter_by_custom_fields')) { # custom field filtering # @@@ At the moment this gets the linked fields relating to the current project # It should get the ones relating to the project in the filter or all projects # if multiple projects. $t_custom_fields = custom_field_get_linked_ids($t_project_id); foreach ($t_custom_fields as $t_cfid) { $t_field_info = custom_field_cache_row($t_cfid, true); if (!$t_field_info['filter_by']) { continue; # skip this custom field it shouldn't be filterable } $t_custom_where_clause = ''; # Ignore all custom filters that are not set, or that are set to '' or "any" if (!filter_field_is_any($t_filter['custom_fields'][$t_cfid])) { $t_def = custom_field_get_definition($t_cfid); $t_table_name = $t_custom_field_string_table . '_' . $t_cfid; # We need to filter each joined table or the result query will explode in dimensions # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields # and only after this process ends (if it is able to) the result query will be filtered # by the WHERE clause and by the DISTINCT clause $t_cf_join_clause = "LEFT JOIN {$t_custom_field_string_table} {$t_table_name} ON {$t_bug_table}.id = {$t_table_name}.bug_id AND {$t_table_name}.field_id = {$t_cfid}"; if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) { switch ($t_filter['custom_fields'][$t_cfid][0]) { case CUSTOM_FIELD_DATE_ANY: break; case CUSTOM_FIELD_DATE_NONE: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)'; break; case CUSTOM_FIELD_DATE_BEFORE: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . $t_filter['custom_fields'][$t_cfid][2] . ')'; break; case CUSTOM_FIELD_DATE_AFTER: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( (' . $t_table_name . '.value+0) > ' . ($t_filter['custom_fields'][$t_cfid][1] + 1); break; default: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( (' . $t_table_name . '.value+0) BETWEEN ' . $t_filter['custom_fields'][$t_cfid][1] . ' AND ' . $t_filter['custom_fields'][$t_cfid][2]; break; } } else { array_push($t_join_clauses, $t_cf_join_clause); $t_filter_array = array(); foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { # coerce filter value if selecting META_FILTER_NONE so it will match empty fields $t_filter_member = ''; # but also add those _not_ present in the custom field string table array_push($t_filter_array, "{$t_bug_table}.id NOT IN (SELECT bug_id FROM {$t_custom_field_string_table} WHERE field_id={$t_cfid})"); } switch ($t_def['type']) { case CUSTOM_FIELD_TYPE_CHECKBOX: case CUSTOM_FIELD_TYPE_MULTILIST: if ($t_filter_member != '') { $t_filter_member = '%|' . $t_filter_member . '|%'; } $t_where_params[] = $t_filter_member; array_push($t_filter_array, db_helper_like("{$t_table_name}.value")); break; default: $t_where_params[] = $t_filter_member; array_push($t_filter_array, "{$t_table_name}.value = " . db_param()); } } $t_custom_where_clause .= '(' . implode(' OR ', $t_filter_array); } if (!is_blank($t_custom_where_clause)) { array_push($t_where_clauses, $t_custom_where_clause . ')'); } } } } # Text search if (!is_blank($t_filter[FILTER_PROPERTY_FREE_TEXT])) { # break up search terms by spacing or quoting preg_match_all("/-?([^'\"\\s]+|\"[^\"]+\"|'[^']+')/", $t_filter[FILTER_PROPERTY_FREE_TEXT], $t_matches, PREG_SET_ORDER); # organize terms without quoting, paying attention to negation $t_search_terms = array(); foreach ($t_matches as $t_match) { $t_search_terms[trim($t_match[1], "\\'\"")] = $t_match[0][0] == '-'; } # build a big where-clause and param list for all search terms, including negations $t_first = true; $t_textsearch_where_clause = "( "; foreach ($t_search_terms as $t_search_term => $t_negate) { if (!$t_first) { $t_textsearch_where_clause .= ' AND '; } if ($t_negate) { $t_textsearch_where_clause .= 'NOT '; } $c_search = '%' . $t_search_term . '%'; $t_textsearch_where_clause .= '( ' . db_helper_like('summary') . ' OR ' . db_helper_like("{$t_bug_text_table}.description") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information") . ' OR ' . db_helper_like("{$t_bugnote_text_table}.note"); $t_where_params[] = $c_search; $t_where_params[] = $c_search; $t_where_params[] = $c_search; $t_where_params[] = $c_search; $t_where_params[] = $c_search; if (is_numeric($t_search_term)) { // PostgreSQL on 64-bit OS hack (see #14014) if (PHP_INT_MAX > 0x7fffffff && db_is_pgsql()) { $t_search_max = 0x7fffffff; } else { $t_search_max = PHP_INT_MAX; } // Note: no need to test negative values, '-' sign has been removed if ($t_search_term <= $t_search_max) { $c_search_int = (int) $t_search_term; $t_textsearch_where_clause .= " OR {$t_bug_table}.id = " . db_param(); $t_textsearch_where_clause .= " OR {$t_bugnote_table}.id = " . db_param(); $t_where_params[] = $c_search_int; $t_where_params[] = $c_search_int; } } $t_textsearch_where_clause .= ' )'; $t_first = false; } $t_textsearch_where_clause .= ' )'; # add text query elements to arrays if (!$t_first) { $t_from_clauses[] = "{$t_bug_text_table}"; $t_where_clauses[] = "{$t_bug_table}.bug_text_id = {$t_bug_text_table}.id"; $t_where_clauses[] = $t_textsearch_where_clause; $t_join_clauses[] = " LEFT JOIN {$t_bugnote_table} ON {$t_bug_table}.id = {$t_bugnote_table}.bug_id"; $t_join_clauses[] = " LEFT JOIN {$t_bugnote_text_table} ON {$t_bugnote_table}.bugnote_text_id = {$t_bugnote_text_table}.id"; } } # End text search $t_from_clauses[] = $t_project_table; $t_from_clauses[] = $t_bug_table; $t_query_clauses['select'] = $t_select_clauses; $t_query_clauses['from'] = $t_from_clauses; $t_query_clauses['join'] = $t_join_clauses; $t_query_clauses['where'] = $t_where_clauses; $t_query_clauses['where_values'] = $t_where_params; $t_query_clauses = filter_get_query_sort_data($t_filter, $p_show_sticky, $t_query_clauses); # assigning to $p_* for this function writes the values back in case the caller wants to know # Get the total number of bugs that meet the criteria. $p_bug_count = filter_get_bug_count($t_query_clauses); if (0 == $p_bug_count) { return array(); } $p_per_page = filter_per_page($t_filter, $p_bug_count, $p_per_page); $p_page_count = filter_page_count($p_bug_count, $p_per_page); $p_page_number = filter_valid_page_number($p_page_number, $p_page_count); $t_offset = filter_offset($p_page_number, $p_per_page); $t_query_clauses = filter_unique_query_clauses($t_query_clauses); $t_select_string = "SELECT DISTINCT " . implode(', ', $t_query_clauses['select']); $t_from_string = " FROM " . implode(', ', $t_query_clauses['from']); $t_order_string = " ORDER BY " . implode(', ', $t_query_clauses['order']); $t_join_string = count($t_query_clauses['join']) > 0 ? implode(' ', $t_query_clauses['join']) : ''; $t_where_string = count($t_query_clauses['where']) > 0 ? 'WHERE ' . implode(' AND ', $t_query_clauses['where']) : ''; $t_result = db_query_bound("{$t_select_string} {$t_from_string} {$t_join_string} {$t_where_string} {$t_order_string}", $t_query_clauses['where_values'], $p_per_page, $t_offset); $t_row_count = db_num_rows($t_result); $t_id_array_lastmod = array(); for ($i = 0; $i < $t_row_count; $i++) { $t_row = db_fetch_array($t_result); $t_id_array_lastmod[] = (int) $t_row['id']; $t_rows[] = $t_row; } return filter_cache_result($t_rows, $t_id_array_lastmod); }
require_once "../../config.php"; require_once "lib.php"; require_once $CFG->dirroot . '/tag/lib.php'; require_once $CFG->dirroot . '/tag/locallib.php'; $id = required_param('id', PARAM_INT); $tagname = optional_param('tag', '', PARAM_TAG); $url = new moodle_url('/mod/booking/tag.php', array('id' => $id, 'tag' => $tagname)); $PAGE->set_url($url); if (!($cm = get_coursemodule_from_id('booking', $id))) { print_error('invalidcoursemodule'); } if (!($course = $DB->get_record("course", array("id" => $cm->course)))) { print_error('coursemisconf'); } require_course_login($course, false, $cm); $tag = tag_get('name', $tagname, '*'); $PAGE->set_pagelayout('standard'); $tagname = tag_display_name($tag); $title = get_string('tag', 'tag') . ' - ' . $tagname; $PAGE->navbar->add($tagname); $PAGE->set_heading($COURSE->fullname); $PAGE->set_title($title); echo $OUTPUT->header(); echo $OUTPUT->heading($tagname, 2); $records = $DB->get_records('tag_instance', array('tagid' => $tag->id, 'itemtype' => 'booking')); echo $OUTPUT->box_start('generalbox', 'tag-blogs'); //could use an id separate from tag-blogs, but would have to copy the css style to make it look the same echo '<ul>'; foreach ($records as $record) { $booking = $DB->get_record('booking', array('id' => $record->itemid, 'course' => $cm->course)); if ($booking) {
/** * Handle showing/processing the submission from the block editing form. * @return boolean true if the form was submitted and the new config saved. Does not * return if the editing form was displayed. False otherwise. */ public function process_url_edit() { global $CFG, $DB, $PAGE, $OUTPUT; $blockid = optional_param('bui_editid', null, PARAM_INTEGER); if (!$blockid) { return false; } require_sesskey(); require_once($CFG->dirroot . '/blocks/edit_form.php'); $block = $this->find_instance($blockid); if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock')); } $editpage = new moodle_page(); $editpage->set_pagelayout('admin'); $editpage->set_course($this->page->course); //$editpage->set_context($block->context); $editpage->set_context($this->page->context); if ($this->page->cm) { $editpage->set_cm($this->page->cm); } $editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring()); $editurlparams = $this->page->url->params(); $editurlparams['bui_editid'] = $blockid; $editpage->set_url($editurlbase, $editurlparams); $editpage->set_block_actions_done(); // At this point we are either going to redirect, or display the form, so // overwrite global $PAGE ready for this. (Formslib refers to it.) $PAGE = $editpage; //some functions like MoodleQuickForm::addHelpButton use $OUTPUT so we need to replace that to $output = $editpage->get_renderer('core'); $OUTPUT = $output; $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php'; if (is_readable($formfile)) { require_once($formfile); $classname = 'block_' . $block->name() . '_edit_form'; if (!class_exists($classname)) { $classname = 'block_edit_form'; } } else { $classname = 'block_edit_form'; } $mform = new $classname($editpage->url, $block, $this->page); $mform->set_data($block->instance); if ($mform->is_cancelled()) { redirect($this->page->url); } else if ($data = $mform->get_data()) { $bi = new stdClass; $bi->id = $block->instance->id; $bi->pagetypepattern = $data->bui_pagetypepattern; if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') { $bi->subpagepattern = null; } else { $bi->subpagepattern = $data->bui_subpagepattern; } $parentcontext = get_context_instance_by_id($data->bui_parentcontextid); $systemcontext = get_context_instance(CONTEXT_SYSTEM); // Updating stickiness and contexts. See MDL-21375 for details. if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination // Explicitly set the context $bi->parentcontextid = $parentcontext->id; // If the context type is > 0 then we'll explicitly set the block as sticky, otherwise not $bi->showinsubcontexts = (int)(!empty($data->bui_contexts)); // If the block wants to be system-wide, then explicitly set that if ($data->bui_contexts == BUI_CONTEXTS_ENTIRE_SITE) { // Only possible on a frontpage or system page $bi->parentcontextid = $systemcontext->id; $bi->showinsubcontexts = 1; } else { // The block doesn't want to be system-wide, so let's ensure that if ($parentcontext->id == $systemcontext->id) { // We need to move it to the front page $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); $bi->parentcontextid = $frontpagecontext->id; $bi->pagetypepattern = '*'; // Just in case } } } $bits = explode('-', $bi->pagetypepattern); // hacks for some contexts if (($parentcontext->contextlevel == CONTEXT_COURSE) && ($parentcontext->instanceid != SITEID)) { // For course context // is page type pattern is mod-*, change showinsubcontext to 1 if ($bits[0] == 'mod' || $bi->pagetypepattern == '*') { $bi->showinsubcontexts = 1; } else { $bi->showinsubcontexts = 0; } } else if ($parentcontext->contextlevel == CONTEXT_USER) { // for user context // subpagepattern should be null if ($bits[0] == 'user' or $bits[0] == 'my') { // we don't need subpagepattern in usercontext $bi->subpagepattern = null; } } $bi->defaultregion = $data->bui_defaultregion; $bi->defaultweight = $data->bui_defaultweight; $DB->update_record('block_instances', $bi); if (!empty($block->config)) { $config = clone($block->config); } else { $config = new stdClass; } foreach ($data as $configfield => $value) { if (strpos($configfield, 'config_') !== 0) { continue; } $field = substr($configfield, 7); $config->$field = $value; } $block->instance_config_save($config); $bp = new stdClass; $bp->visible = $data->bui_visible; $bp->region = $data->bui_region; $bp->weight = $data->bui_weight; $needbprecord = !$data->bui_visible || $data->bui_region != $data->bui_defaultregion || $data->bui_weight != $data->bui_defaultweight; if ($block->instance->blockpositionid && !$needbprecord) { $DB->delete_records('block_positions', array('id' => $block->instance->blockpositionid)); } else if ($block->instance->blockpositionid && $needbprecord) { $bp->id = $block->instance->blockpositionid; $DB->update_record('block_positions', $bp); } else if ($needbprecord) { $bp->blockinstanceid = $block->instance->id; $bp->contextid = $this->page->context->id; $bp->pagetype = $this->page->pagetype; if ($this->page->subpage) { $bp->subpage = $this->page->subpage; } else { $bp->subpage = ''; } $DB->insert_record('block_positions', $bp); } redirect($this->page->url); } else { $strheading = get_string('blockconfiga', 'moodle', $block->get_title()); $editpage->set_title($strheading); $editpage->set_heading($strheading); $bits = explode('-', $this->page->pagetype); if ($bits[0] == 'tag' && !empty($this->page->subpage)) { // better navbar for tag pages $editpage->navbar->add(get_string('tags'), new moodle_url('/tag/')); $tag = tag_get('id', $this->page->subpage, '*'); // tag search page doesn't have subpageid if ($tag) { $editpage->navbar->add($tag->name, new moodle_url('/tag/index.php', array('id'=>$tag->id))); } } $editpage->navbar->add($block->get_title()); $editpage->navbar->add(get_string('configuration')); echo $output->header(); echo $output->heading($strheading, 2); $mform->display(); echo $output->footer(); exit; } }
require_once 'lib.php'; require_once 'edit_form.php'; $tag_id = optional_param('id', 0, PARAM_INT); $tag_name = optional_param('tag', '', PARAM_TAG); require_login(); if (empty($CFG->usetags)) { print_error('tagsaredisabled', 'tag'); } //Editing a tag requires moodle/tag:edit capability $systemcontext = context_system::instance(); require_capability('moodle/tag:edit', $systemcontext); if ($tag_name) { $tag = tag_get('name', $tag_name, '*'); } else { if ($tag_id) { $tag = tag_get('id', $tag_id, '*'); } } if (empty($tag)) { redirect($CFG->wwwroot . '/tag/search.php'); } $PAGE->set_url('/tag/index.php', array('id' => $tag->id)); $PAGE->set_subpage($tag->id); $PAGE->set_context($systemcontext); $PAGE->set_blocks_editing_capability('moodle/tag:editblocks'); $PAGE->set_pagelayout('base'); $tagname = tag_display_name($tag); // set the relatedtags field of the $tag object that will be passed to the form $tag->relatedtags = tag_get_related_tags_csv(tag_get_related_tags($tag->id, TAG_RELATED_MANUAL), TAG_RETURN_TEXT); $options = new stdClass(); $options->smiley = false;
/** * Change the "value" of a tag, and update the associated 'name'. * * @package core_tag * @category tag * @access public * @param int $tagid the id of the tag to modify * @param string $newrawname the new rawname * @return bool true on success, false otherwise */ function tag_rename($tagid, $newrawname) { global $COURSE, $DB; $norm = tag_normalize($newrawname, TAG_CASE_ORIGINAL); if (!($newrawname_clean = array_shift($norm))) { return false; } if (!($newname_clean = core_text::strtolower($newrawname_clean))) { return false; } // Prevent the rename if a tag with that name already exists if ($existing = tag_get('name', $newname_clean, 'id, name, rawname')) { if ($existing->id != $tagid) { // Another tag already exists with this name return false; } } if ($tag = tag_get('id', $tagid, 'id, userid, name, rawname')) { // Store the name before we change it. $oldname = $tag->name; $tag->rawname = $newrawname_clean; $tag->name = $newname_clean; $tag->timemodified = time(); $DB->update_record('tag', $tag); $event = \core\event\tag_updated::create(array('objectid' => $tag->id, 'relateduserid' => $tag->userid, 'context' => context_system::instance(), 'other' => array('name' => $newname_clean, 'rawname' => $newrawname_clean))); $event->set_legacy_logdata(array($COURSE->id, 'tag', 'update', 'index.php?id=' . $tag->id, $oldname . '->' . $tag->name)); $event->trigger(); return true; } return false; }
/** * Handle showing/processing the submission from the block editing form. * @return boolean true if the form was submitted and the new config saved. Does not * return if the editing form was displayed. False otherwise. */ public function process_url_edit() { global $CFG, $DB, $PAGE, $OUTPUT; $blockid = optional_param('bui_editid', null, PARAM_INT); if (!$blockid) { return false; } require_sesskey(); require_once $CFG->dirroot . '/blocks/edit_form.php'; $block = $this->find_instance($blockid); if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock')); } $editpage = new moodle_page(); $editpage->set_pagelayout('admin'); $editpage->set_course($this->page->course); //$editpage->set_context($block->context); $editpage->set_context($this->page->context); if ($this->page->cm) { $editpage->set_cm($this->page->cm); } $editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring()); $editurlparams = $this->page->url->params(); $editurlparams['bui_editid'] = $blockid; $editpage->set_url($editurlbase, $editurlparams); $editpage->set_block_actions_done(); // At this point we are either going to redirect, or display the form, so // overwrite global $PAGE ready for this. (Formslib refers to it.) $PAGE = $editpage; //some functions like MoodleQuickForm::addHelpButton use $OUTPUT so we need to replace that to $output = $editpage->get_renderer('core'); $OUTPUT = $output; $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php'; if (is_readable($formfile)) { require_once $formfile; $classname = 'block_' . $block->name() . '_edit_form'; if (!class_exists($classname)) { $classname = 'block_edit_form'; } } else { $classname = 'block_edit_form'; } $mform = new $classname($editpage->url, $block, $this->page); $mform->set_data($block->instance); if ($mform->is_cancelled()) { redirect($this->page->url); } else { if ($data = $mform->get_data()) { $bi = new stdClass(); $bi->id = $block->instance->id; // This may get overwritten by the special case handling below. $bi->pagetypepattern = $data->bui_pagetypepattern; $bi->showinsubcontexts = (bool) $data->bui_contexts; if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') { $bi->subpagepattern = null; } else { $bi->subpagepattern = $data->bui_subpagepattern; } $systemcontext = context_system::instance(); $frontpagecontext = context_course::instance(SITEID); $parentcontext = context::instance_by_id($data->bui_parentcontextid); // Updating stickiness and contexts. See MDL-21375 for details. if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination // Explicitly set the default context $bi->parentcontextid = $parentcontext->id; if ($data->bui_editingatfrontpage) { // The block is being edited on the front page // The interface here is a special case because the pagetype pattern is // totally derived from the context menu. Here are the excpetions. MDL-30340 switch ($data->bui_contexts) { case BUI_CONTEXTS_ENTIRE_SITE: // The user wants to show the block across the entire site $bi->parentcontextid = $systemcontext->id; $bi->showinsubcontexts = true; $bi->pagetypepattern = '*'; break; case BUI_CONTEXTS_FRONTPAGE_SUBS: // The user wants the block shown on the front page and all subcontexts $bi->parentcontextid = $frontpagecontext->id; $bi->showinsubcontexts = true; $bi->pagetypepattern = '*'; break; case BUI_CONTEXTS_FRONTPAGE_ONLY: // The user want to show the front page on the frontpage only $bi->parentcontextid = $frontpagecontext->id; $bi->showinsubcontexts = false; $bi->pagetypepattern = 'site-index'; // This is the only relevant page type anyway but we'll set it explicitly just // in case the front page grows site-index-* subpages of its own later break; } } } $bits = explode('-', $bi->pagetypepattern); // hacks for some contexts if ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid != SITEID) { // For course context // is page type pattern is mod-*, change showinsubcontext to 1 if ($bits[0] == 'mod' || $bi->pagetypepattern == '*') { $bi->showinsubcontexts = 1; } else { $bi->showinsubcontexts = 0; } } else { if ($parentcontext->contextlevel == CONTEXT_USER) { // for user context // subpagepattern should be null if ($bits[0] == 'user' or $bits[0] == 'my') { // we don't need subpagepattern in usercontext $bi->subpagepattern = null; } } } $bi->defaultregion = $data->bui_defaultregion; $bi->defaultweight = $data->bui_defaultweight; $DB->update_record('block_instances', $bi); if (!empty($block->config)) { $config = clone $block->config; } else { $config = new stdClass(); } foreach ($data as $configfield => $value) { if (strpos($configfield, 'config_') !== 0) { continue; } $field = substr($configfield, 7); $config->{$field} = $value; } $block->instance_config_save($config); $bp = new stdClass(); $bp->visible = $data->bui_visible; $bp->region = $data->bui_region; $bp->weight = $data->bui_weight; $needbprecord = !$data->bui_visible || $data->bui_region != $data->bui_defaultregion || $data->bui_weight != $data->bui_defaultweight; if ($block->instance->blockpositionid && !$needbprecord) { $DB->delete_records('block_positions', array('id' => $block->instance->blockpositionid)); } else { if ($block->instance->blockpositionid && $needbprecord) { $bp->id = $block->instance->blockpositionid; $DB->update_record('block_positions', $bp); } else { if ($needbprecord) { $bp->blockinstanceid = $block->instance->id; $bp->contextid = $this->page->context->id; $bp->pagetype = $this->page->pagetype; if ($this->page->subpage) { $bp->subpage = $this->page->subpage; } else { $bp->subpage = ''; } $DB->insert_record('block_positions', $bp); } } } redirect($this->page->url); } else { $strheading = get_string('blockconfiga', 'moodle', $block->get_title()); $editpage->set_title($strheading); $editpage->set_heading($strheading); $bits = explode('-', $this->page->pagetype); if ($bits[0] == 'tag' && !empty($this->page->subpage)) { // better navbar for tag pages $editpage->navbar->add(get_string('tags'), new moodle_url('/tag/')); $tag = tag_get('id', $this->page->subpage, '*'); // tag search page doesn't have subpageid if ($tag) { $editpage->navbar->add($tag->name, new moodle_url('/tag/index.php', array('id' => $tag->id))); } } $editpage->navbar->add($block->get_title()); $editpage->navbar->add(get_string('configuration')); echo $output->header(); echo $output->heading($strheading, 2); $mform->display(); echo $output->footer(); exit; } } }
function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null) { log_event(LOG_FILTERING, 'FILTERING: START NEW FILTER QUERY'); $t_bug_table = config_get('mantis_bug_table'); $t_bug_text_table = config_get('mantis_bug_text_table'); $t_bugnote_table = config_get('mantis_bugnote_table'); $t_custom_field_string_table = config_get('mantis_custom_field_string_table'); $t_bugnote_text_table = config_get('mantis_bugnote_text_table'); $t_project_table = config_get('mantis_project_table'); $t_bug_monitor_table = config_get('mantis_bug_monitor_table'); $t_limit_reporters = config_get('limit_reporters'); $t_bug_relationship_table = config_get('mantis_bug_relationship_table'); $t_report_bug_threshold = config_get('report_bug_threshold'); $t_current_user_id = auth_get_current_user_id(); if (null === $p_user_id) { $t_user_id = $t_current_user_id; } else { $t_user_id = $p_user_id; } $c_user_id = db_prepare_int($t_user_id); if (null === $p_project_id) { # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project. $t_project_id = helper_get_current_project(); } else { $t_project_id = $p_project_id; } if ($p_custom_filter === null) { # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports # cookies set by previous version of the code. if ($t_user_id == $t_current_user_id) { $t_filter = current_user_get_bug_filter(); } else { $t_filter = user_get_bug_filter($t_user_id, $t_project_id); } } else { $t_filter = $p_custom_filter; } $t_filter = filter_ensure_valid_filter($t_filter); if (false === $t_filter) { return false; # signify a need to create a cookie #@@@ error instead? } $t_view_type = $t_filter['_view_type']; $t_where_clauses = array("{$t_project_table}.enabled = 1", "{$t_project_table}.id = {$t_bug_table}.project_id"); $t_select_clauses = array("{$t_bug_table}.*"); $t_join_clauses = array(); $t_from_clauses = array(); // normalize the project filtering into an array $t_project_ids if ('simple' == $t_view_type) { log_event(LOG_FILTERING, 'FILTERING: Simple Filter'); $t_project_ids = array($t_project_id); $t_include_sub_projects = true; } else { log_event(LOG_FILTERING, 'FILTERING: Advanced Filter'); if (!is_array($t_filter['project_id'])) { $t_project_ids = array(db_prepare_int($t_filter['project_id'])); } else { $t_project_ids = array_map('db_prepare_int', $t_filter['project_id']); } $t_include_sub_projects = count($t_project_ids) == 1 && $t_project_ids[0] == META_FILTER_CURRENT; } log_event(LOG_FILTERING, 'FILTERING: project_ids = ' . implode(',', $t_project_ids)); log_event(LOG_FILTERING, 'FILTERING: include sub-projects = ' . ($t_include_sub_projects ? '1' : '0')); // if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS. // replace META_FILTER_CURRENT with the actualy current project id. $t_all_projects_found = false; $t_new_project_ids = array(); foreach ($t_project_ids as $t_pid) { if ($t_pid == META_FILTER_CURRENT) { $t_pid = $t_project_id; } if ($t_pid == ALL_PROJECTS) { $t_all_projects_found = true; log_event(LOG_FILTERING, 'FILTERING: all projects selected'); break; } // filter out inaccessible projects. if (!access_has_project_level(VIEWER, $t_pid, $t_user_id)) { continue; } $t_new_project_ids[] = $t_pid; } $t_projects_query_required = true; if ($t_all_projects_found) { if (user_is_administrator($t_user_id)) { log_event(LOG_FILTERING, 'FILTERING: all projects + administrator, hence no project filter.'); $t_projects_query_required = false; } else { $t_project_ids = user_get_accessible_projects($t_user_id); } } else { $t_project_ids = $t_new_project_ids; } if ($t_projects_query_required) { // expand project ids to include sub-projects if ($t_include_sub_projects) { $t_top_project_ids = $t_project_ids; foreach ($t_top_project_ids as $t_pid) { log_event(LOG_FILTERING, 'FILTERING: Getting sub-projects for project id ' . $t_pid); $t_project_ids = array_merge($t_project_ids, user_get_all_accessible_subprojects($t_user_id, $t_pid)); } $t_project_ids = array_unique($t_project_ids); } // if no projects are accessible, then return an empty array. if (count($t_project_ids) == 0) { log_event(LOG_FILTERING, 'FILTERING: no accessible projects'); return array(); } log_event(LOG_FILTERING, 'FILTERING: project_ids after including sub-projects = ' . implode(',', $t_project_ids)); // this array is to be populated with project ids for which we only want to show public issues. This is due to the limited // access of the current user. $t_public_only_project_ids = array(); // this array is populated with project ids that the current user has full access to. $t_private_and_public_project_ids = array(); $t_access_required_to_view_private_bugs = config_get('private_bug_threshold'); foreach ($t_project_ids as $t_pid) { if (access_has_project_level($t_access_required_to_view_private_bugs, $t_pid, $t_user_id)) { $t_private_and_public_project_ids[] = $t_pid; } else { $t_public_only_project_ids[] = $t_pid; } } log_event(LOG_FILTERING, 'FILTERING: project_ids (with public/private access) = ' . implode(',', $t_private_and_public_project_ids)); log_event(LOG_FILTERING, 'FILTERING: project_ids (with public access) = ' . implode(',', $t_public_only_project_ids)); $t_count_private_and_public_project_ids = count($t_private_and_public_project_ids); if ($t_count_private_and_public_project_ids == 1) { $t_private_and_public_query = "( {$t_bug_table}.project_id = " . $t_private_and_public_project_ids[0] . " )"; } else { if ($t_count_private_and_public_project_ids > 1) { $t_private_and_public_query = "( {$t_bug_table}.project_id in (" . implode(', ', $t_private_and_public_project_ids) . ") )"; } else { $t_private_and_public_query = null; } } $t_count_public_only_project_ids = count($t_public_only_project_ids); $t_public_view_state_check = "( ( {$t_bug_table}.view_state = " . VS_PUBLIC . " ) OR ( {$t_bug_table}.reporter_id = {$t_user_id} ) )"; if ($t_count_public_only_project_ids == 1) { $t_public_only_query = "( ( {$t_bug_table}.project_id = " . $t_public_only_project_ids[0] . " ) AND {$t_public_view_state_check} )"; } else { if ($t_count_public_only_project_ids > 1) { $t_public_only_query = "( ( {$t_bug_table}.project_id in (" . implode(', ', $t_public_only_project_ids) . ") ) AND {$t_public_view_state_check} )"; } else { $t_public_only_query = null; } } // both queries can't be null, so we either have one of them or both. if ($t_private_and_public_query === null) { $t_project_query = $t_public_only_query; } else { if ($t_public_only_query === null) { $t_project_query = $t_private_and_public_query; } else { $t_project_query = "( {$t_public_only_query} OR {$t_private_and_public_query} )"; } } log_event(LOG_FILTERING, 'FILTERING: project query = ' . $t_project_query); array_push($t_where_clauses, $t_project_query); } # view state $t_view_state = db_prepare_int($t_filter['view_state']); if ($t_filter['view_state'] !== META_FILTER_ANY && !is_blank($t_filter['view_state'])) { $t_view_state_query = "({$t_bug_table}.view_state='{$t_view_state}')"; log_event(LOG_FILTERING, 'FILTERING: view_state query = ' . $t_view_state_query); array_push($t_where_clauses, $t_view_state_query); } else { log_event(LOG_FILTERING, 'FILTERING: no view_state query'); } # reporter $t_any_found = false; foreach ($t_filter['reporter_id'] as $t_filter_member) { if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['reporter_id']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['reporter_id'] as $t_filter_member) { if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "0"); } else { $c_reporter_id = db_prepare_int($t_filter_member); if (META_FILTER_MYSELF == $c_reporter_id) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_reporter_id); } } } if (1 < count($t_clauses)) { $t_reporter_query = "( {$t_bug_table}.reporter_id in (" . implode(', ', $t_clauses) . ") )"; } else { $t_reporter_query = "( {$t_bug_table}.reporter_id={$t_clauses['0']} )"; } log_event(LOG_FILTERING, 'FILTERING: reporter query = ' . $t_reporter_query); array_push($t_where_clauses, $t_reporter_query); } else { log_event(LOG_FILTERING, 'FILTERING: no reporter query'); } # limit reporter # @@@ thraxisp - access_has_project_level checks greater than or equal to, # this assumed that there aren't any holes above REPORTER where the limit would apply # if (ON === $t_limit_reporters && !access_has_project_level(REPORTER + 1, $t_project_id, $t_user_id)) { $c_reporter_id = $c_user_id; array_push($t_where_clauses, "({$t_bug_table}.reporter_id='{$c_reporter_id}')"); } # handler $t_any_found = false; foreach ($t_filter['handler_id'] as $t_filter_member) { if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['handler_id']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['handler_id'] as $t_filter_member) { if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, 0); } else { $c_handler_id = db_prepare_int($t_filter_member); if (META_FILTER_MYSELF == $c_handler_id) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_handler_id); } } } if (1 < count($t_clauses)) { $t_handler_query = "( {$t_bug_table}.handler_id in (" . implode(', ', $t_clauses) . ") )"; } else { $t_handler_query = "( {$t_bug_table}.handler_id={$t_clauses['0']} )"; } log_event(LOG_FILTERING, 'FILTERING: handler query = ' . $t_handler_query); array_push($t_where_clauses, $t_handler_query); } else { log_event(LOG_FILTERING, 'FILTERING: no handler query'); } # category if (!_filter_is_any($t_filter['show_category'])) { $t_clauses = array(); foreach ($t_filter['show_category'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_show_category = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_show_category}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.category in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.category={$t_clauses['0']} )"); } } # severity $t_any_found = false; foreach ($t_filter['show_severity'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['show_severity']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['show_severity'] as $t_filter_member) { $c_show_severity = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_severity); } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.severity in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.severity={$t_clauses['0']} )"); } } # show / hide status # take a list of all available statuses then remove the ones that we want hidden, then make sure # the ones we want shown are still available $t_status_arr = explode_enum_string(config_get('status_enum_string')); $t_available_statuses = array(); $t_desired_statuses = array(); foreach ($t_status_arr as $t_this_status) { $t_this_status_arr = explode_enum_arr($t_this_status); $t_available_statuses[] = $t_this_status_arr[0]; } if ('simple' == $t_filter['_view_type']) { # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide $t_any_found = false; $t_this_status = $t_filter['show_status'][0]; $t_this_hide_status = $t_filter['hide_status'][0]; if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) { $t_any_found = true; } if ($t_any_found) { foreach ($t_available_statuses as $t_this_available_status) { if ($t_this_hide_status > $t_this_available_status) { $t_desired_statuses[] = $t_this_available_status; } } } else { $t_desired_statuses[] = $t_this_status; } } else { # advanced filtering: ignore the hide $t_any_found = false; foreach ($t_filter['show_status'] as $t_this_status) { $t_desired_statuses[] = $t_this_status; if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) { $t_any_found = true; } } if ($t_any_found) { $t_desired_statuses = array(); } } if (count($t_desired_statuses) > 0) { $t_clauses = array(); foreach ($t_desired_statuses as $t_filter_member) { $c_show_status = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_status); } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.status in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.status={$t_clauses['0']} )"); } } # resolution $t_any_found = false; foreach ($t_filter['show_resolution'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member) { $t_any_found = true; } } if (count($t_filter['show_resolution']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['show_resolution'] as $t_filter_member) { $c_show_resolution = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_resolution); } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.resolution in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.resolution={$t_clauses['0']} )"); } } # priority $t_any_found = false; foreach ($t_filter['show_priority'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['show_priority']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['show_priority'] as $t_filter_member) { $c_show_priority = db_prepare_int($t_filter_member); array_push($t_clauses, $c_show_priority); } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.priority in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.priority={$t_clauses['0']} )"); } } # product build $t_any_found = false; foreach ($t_filter['show_build'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) { $t_any_found = true; } } if (count($t_filter['show_build']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); foreach ($t_filter['show_build'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_show_build = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_show_build}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.build in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.build={$t_clauses['0']} )"); } } # product version if (!_filter_is_any($t_filter['show_version'])) { $t_clauses = array(); foreach ($t_filter['show_version'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_show_version = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_show_version}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.version in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.version={$t_clauses['0']} )"); } } # profile if (!_filter_is_any($t_filter['show_profile'])) { $t_clauses = array(); foreach ($t_filter['show_profile'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "0"); } else { $c_show_profile = db_prepare_int($t_filter_member); array_push($t_clauses, "{$c_show_profile}"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.profile_id in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.profile_id={$t_clauses['0']} )"); } } # platform if (!_filter_is_any($t_filter['platform'])) { $t_clauses = array(); foreach ($t_filter['platform'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, ''); } else { $c_platform = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_platform}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.platform in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.platform = {$t_clauses['0']} )"); } } # os if (!_filter_is_any($t_filter['os'])) { $t_clauses = array(); foreach ($t_filter['os'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, ''); } else { $c_os = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_os}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.os in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.os = {$t_clauses['0']} )"); } } # os_build if (!_filter_is_any($t_filter['os_build'])) { $t_clauses = array(); foreach ($t_filter['os_build'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, ''); } else { $c_os_build = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_os_build}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.os_build in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.os_build = {$t_clauses['0']} )"); } } # date filter if ('on' == $t_filter['do_filter_by_date'] && is_numeric($t_filter['start_month']) && is_numeric($t_filter['start_day']) && is_numeric($t_filter['start_year']) && is_numeric($t_filter['end_month']) && is_numeric($t_filter['end_day']) && is_numeric($t_filter['end_year'])) { $t_start_string = db_prepare_string($t_filter['start_year'] . "-" . $t_filter['start_month'] . "-" . $t_filter['start_day'] . " 00:00:00"); $t_end_string = db_prepare_string($t_filter['end_year'] . "-" . $t_filter['end_month'] . "-" . $t_filter['end_day'] . " 23:59:59"); array_push($t_where_clauses, "({$t_bug_table}.date_submitted BETWEEN '{$t_start_string}' AND '{$t_end_string}' )"); } # fixed in version if (!_filter_is_any($t_filter['fixed_in_version'])) { $t_clauses = array(); foreach ($t_filter['fixed_in_version'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_fixed_in_version = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_fixed_in_version}'"); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version={$t_clauses['0']} )"); } } # target version if (!_filter_is_any($t_filter['target_version'])) { $t_clauses = array(); foreach ($t_filter['target_version'] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { array_push($t_clauses, "''"); } else { $c_target_version = db_prepare_string($t_filter_member); array_push($t_clauses, "'{$c_target_version}'"); } } #echo var_dump( $t_clauses ); exit; if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_bug_table}.target_version in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_bug_table}.target_version={$t_clauses['0']} )"); } } # users monitoring a bug $t_any_found = false; foreach ($t_filter['user_monitor'] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) { $t_any_found = true; } } if (count($t_filter['user_monitor']) == 0) { $t_any_found = true; } if (!$t_any_found) { $t_clauses = array(); $t_table_name = 'user_monitor'; array_push($t_from_clauses, $t_bug_monitor_table); array_push($t_join_clauses, "LEFT JOIN {$t_bug_monitor_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id"); foreach ($t_filter['user_monitor'] as $t_filter_member) { $c_user_monitor = db_prepare_int($t_filter_member); if (META_FILTER_MYSELF == $c_user_monitor) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_user_monitor); } } if (1 < count($t_clauses)) { array_push($t_where_clauses, "( {$t_table_name}.user_id in (" . implode(', ', $t_clauses) . ") )"); } else { array_push($t_where_clauses, "( {$t_table_name}.user_id={$t_clauses['0']} )"); } } # bug relationship $t_any_found = false; $c_rel_type = $t_filter['relationship_type']; $c_rel_bug = $t_filter['relationship_bug']; if (-1 == $c_rel_type || 0 == $c_rel_bug) { $t_any_found = true; } if (!$t_any_found) { # use the complementary type $t_comp_type = relationship_get_complementary_type($c_rel_type); $t_clauses = array(); $t_table_name = 'relationship'; array_push($t_from_clauses, $t_bug_relationship_table); array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name} ON {$t_table_name}.destination_bug_id = {$t_bug_table}.id"); array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name}2 ON {$t_table_name}2.source_bug_id = {$t_bug_table}.id"); // get reverse relationships array_push($t_clauses, "({$t_table_name}.relationship_type='{$t_comp_type}' AND {$t_table_name}.source_bug_id='{$c_rel_bug}')"); array_push($t_clauses, "({$t_table_name}" . "2.relationship_type='{$c_rel_type}' AND {$t_table_name}" . "2.destination_bug_id='{$c_rel_bug}')"); array_push($t_where_clauses, '(' . implode(' OR ', $t_clauses) . ')'); } # tags $c_tag_string = trim($t_filter['tag_string']); if (!is_blank($c_tag_string)) { $t_tags = tag_parse_filters($c_tag_string); if (count($t_tags)) { $t_tags_all = array(); $t_tags_any = array(); $t_tags_none = array(); foreach ($t_tags as $t_tag_row) { switch ($t_tag_row['filter']) { case 1: $t_tags_all[] = $t_tag_row; break; case 0: $t_tags_any[] = $t_tag_row; break; case -1: $t_tags_none[] = $t_tag_row; break; } } if (0 < $t_filter['tag_select'] && tag_exists($t_filter['tag_select'])) { $t_tags_any[] = tag_get($t_filter['tag_select']); } $t_bug_tag_table = config_get('mantis_bug_tag_table'); if (count($t_tags_all)) { $t_clauses = array(); foreach ($t_tags_all as $t_tag_row) { array_push($t_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE {$t_bug_tag_table}.tag_id = {$t_tag_row['id']} )"); } array_push($t_where_clauses, '(' . implode(' AND ', $t_clauses) . ')'); } if (count($t_tags_any)) { $t_clauses = array(); foreach ($t_tags_any as $t_tag_row) { array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}"); } array_push($t_where_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )'); } if (count($t_tags_none)) { $t_clauses = array(); foreach ($t_tags_none as $t_tag_row) { array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}"); } array_push($t_where_clauses, "{$t_bug_table}.id NOT IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )'); } } } # custom field filters if (ON == config_get('filter_by_custom_fields')) { # custom field filtering # @@@ At the moment this gets the linked fields relating to the current project # It should get the ones relating to the project in the filter or all projects # if multiple projects. $t_custom_fields = custom_field_get_linked_ids($t_project_id); foreach ($t_custom_fields as $t_cfid) { $t_custom_where_clause = ''; # Ignore all custom filters that are not set, or that are set to '' or "any" $t_any_found = false; foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) { if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) { $t_any_found = true; } } if (!isset($t_filter['custom_fields'][$t_cfid])) { $t_any_found = true; } if (!$t_any_found) { $t_def = custom_field_get_definition($t_cfid); $t_table_name = $t_custom_field_string_table . '_' . $t_cfid; # We need to filter each joined table or the result query will explode in dimensions # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields # and only after this process ends (if it is able to) the result query will be filtered # by the WHERE clause and by the DISTINCT clause $t_cf_join_clause = "LEFT JOIN {$t_custom_field_string_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id AND {$t_table_name}.field_id = {$t_cfid} "; if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) { switch ($t_filter['custom_fields'][$t_cfid][0]) { case CUSTOM_FIELD_DATE_ANY: break; case CUSTOM_FIELD_DATE_NONE: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)'; break; case CUSTOM_FIELD_DATE_BEFORE: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . $t_filter['custom_fields'][$t_cfid][2] . ')'; break; case CUSTOM_FIELD_DATE_AFTER: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( (' . $t_table_name . '.value+0) > ' . ($t_filter['custom_fields'][$t_cfid][1] + 1); break; default: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( (' . $t_table_name . '.value+0) BETWEEN ' . $t_filter['custom_fields'][$t_cfid][1] . ' AND ' . $t_filter['custom_fields'][$t_cfid][2]; break; } } else { array_push($t_join_clauses, $t_cf_join_clause); $t_filter_array = array(); foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (META_FILTER_NONE == $t_filter_member) { # coerce filter value if selecting META_FILTER_NONE so it will match empty fields $t_filter_member = ''; # but also add those _not_ present in the custom field string table array_push($t_filter_array, "{$t_bug_table}.id NOT IN (SELECT bug_id FROM {$t_custom_field_string_table} WHERE field_id={$t_cfid})"); } switch ($t_def['type']) { case CUSTOM_FIELD_TYPE_MULTILIST: case CUSTOM_FIELD_TYPE_CHECKBOX: array_push($t_filter_array, db_helper_like("{$t_table_name}.value", '%|' . db_prepare_string($t_filter_member) . '|%')); break; default: array_push($t_filter_array, "{$t_table_name}.value = '" . db_prepare_string($t_filter_member) . "'"); } } $t_custom_where_clause .= '(' . implode(' OR ', $t_filter_array); } if (!is_blank($t_custom_where_clause)) { array_push($t_where_clauses, $t_custom_where_clause . ')'); } } } } $t_textsearch_where_clause = ''; $t_textsearch_wherejoin_clause = ''; # Simple Text Search - Thanks to Alan Knowles if (!is_blank($t_filter['search'])) { $c_search = db_prepare_string($t_filter['search']); $c_search_int = db_prepare_int($t_filter['search']); $t_textsearch_where_clause = '(' . db_helper_like('summary', "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.description", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information", "%{$c_search}%") . " OR ( {$t_bug_table}.id = '{$c_search_int}' ) )"; $t_textsearch_wherejoin_clause = '(' . db_helper_like('summary', "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.description", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_table}.id", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bugnote_text_table}.note", "%{$c_search}%") . ' )'; array_push($t_where_clauses, "({$t_bug_text_table}.id = {$t_bug_table}.bug_text_id)"); $t_from_clauses = array($t_bug_text_table, $t_project_table, $t_bug_table); } else { $t_from_clauses = array($t_project_table, $t_bug_table); } $t_select = implode(', ', array_unique($t_select_clauses)); $t_from = 'FROM ' . implode(', ', array_unique($t_from_clauses)); $t_join = implode(' ', $t_join_clauses); if (count($t_where_clauses) > 0) { $t_where = 'WHERE ' . implode(' AND ', $t_where_clauses); } else { $t_where = ''; } # Possibly do two passes. First time, grab the IDs of issues that match the filters. Second time, grab the IDs of issues that # have bugnotes that match the text search if necessary. $t_id_array = array(); for ($i = 0; $i < 2; $i++) { $t_id_where = $t_where; $t_id_join = $t_join; if ($i == 0) { if (!is_blank($t_id_where) && !is_blank($t_textsearch_where_clause)) { $t_id_where = $t_id_where . ' AND ' . $t_textsearch_where_clause; } } else { if (!is_blank($t_textsearch_wherejoin_clause)) { $t_id_where = $t_id_where . ' AND ' . $t_textsearch_wherejoin_clause; $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_table} ON {$t_bugnote_table}.bug_id = {$t_bug_table}.id"; $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_text_table} ON {$t_bugnote_text_table}.id = {$t_bugnote_table}.bugnote_text_id"; } } $query = "SELECT DISTINCT {$t_bug_table}.id AS id\r\n\t\t\t\t\t\t{$t_from}\r\n\t\t\t\t\t\t{$t_id_join}\r\n\t\t\t\t\t\t{$t_id_where}"; if ($i == 0 || !is_blank($t_textsearch_wherejoin_clause)) { $result = db_query($query); $row_count = db_num_rows($result); for ($j = 0; $j < $row_count; $j++) { $row = db_fetch_array($result); $t_id_array[] = db_prepare_int($row['id']); } } } $t_id_array = array_unique($t_id_array); # Get the total number of bugs that meet the criteria. $bug_count = count($t_id_array); $rows = array(); if ($bug_count > 0) { $t_where = "WHERE {$t_bug_table}.id in (" . implode(", ", $t_id_array) . ")"; } else { return $rows; } $t_from = 'FROM ' . $t_bug_table; # write the value back in case the caller wants to know $p_bug_count = $bug_count; if (null === $p_per_page) { $p_per_page = (int) $t_filter['per_page']; } else { if (-1 == $p_per_page) { $p_per_page = $bug_count; } } # Guard against silly values of $f_per_page. if (0 == $p_per_page) { $p_per_page = $bug_count; // 0 - means show all } $p_per_page = (int) abs($p_per_page); # Use $bug_count and $p_per_page to determine how many pages # to split this list up into. # For the sake of consistency have at least one page, even if it # is empty. $t_page_count = ceil($bug_count / $p_per_page); if ($t_page_count < 1) { $t_page_count = 1; } # write the value back in case the caller wants to know $p_page_count = $t_page_count; # Make sure $p_page_number isn't past the last page. if ($p_page_number > $t_page_count) { $p_page_number = $t_page_count; } # Make sure $p_page_number isn't before the first page if ($p_page_number < 1) { $p_page_number = 1; } # Now add the rest of the criteria i.e. sorting, limit. # if sort is blank then default the sort and direction. This is to fix the # symptoms of #3953. Note that even if the main problem is fixed, we may # have to keep this code for a while to handle filters saved with this blank field. if (is_blank($t_filter['sort'])) { $t_filter['sort'] = 'last_updated'; $t_filter['dir'] = 'DESC'; } $t_order_array = array(); $t_sort_fields = split(',', $t_filter['sort']); $t_dir_fields = split(',', $t_filter['dir']); if ('on' == $t_filter['sticky_issues'] && NULL !== $p_show_sticky) { $t_order_array[] = "sticky DESC"; } $t_join = ''; for ($i = 0; $i < count($t_sort_fields); $i++) { $c_sort = db_prepare_string($t_sort_fields[$i]); if (!in_array($t_sort_fields[$i], array_slice($t_sort_fields, $i + 1))) { # if sorting by a custom field if (strpos($c_sort, 'custom_') === 0) { $t_custom_field = substr($c_sort, strlen('custom_')); $t_custom_field_id = custom_field_get_id_from_name($t_custom_field); $t_join .= " LEFT JOIN {$t_custom_field_string_table} ON ( ( {$t_custom_field_string_table}.bug_id = {$t_bug_table}.id ) AND ( {$t_custom_field_string_table}.field_id = {$t_custom_field_id} ) )"; $c_sort = "{$t_custom_field_string_table}.value"; $t_select_clauses[] = "{$t_custom_field_string_table}.value"; } if ('DESC' == $t_dir_fields[$i]) { $c_dir = 'DESC'; } else { $c_dir = 'ASC'; } $t_order_array[] = "{$c_sort} {$c_dir}"; } } # add basic sorting if necessary if (!in_array('last_updated', $t_sort_fields)) { $t_order_array[] = 'last_updated DESC'; } if (!in_array('date_submitted', $t_sort_fields)) { $t_order_array[] = 'date_submitted DESC'; } $t_order = " ORDER BY " . implode(', ', $t_order_array); $t_select = implode(', ', array_unique($t_select_clauses)); $query2 = "SELECT DISTINCT {$t_select}\r\n\t\t\t\t\t{$t_from}\r\n\t\t\t\t\t{$t_join}\r\n\t\t\t\t\t{$t_where}\r\n\t\t\t\t\t{$t_order}"; # Figure out the offset into the db query # # for example page number 1, per page 5: # t_offset = 0 # for example page number 2, per page 5: # t_offset = 5 $c_per_page = db_prepare_int($p_per_page); $c_page_number = db_prepare_int($p_page_number); $t_offset = ($c_page_number - 1) * $c_per_page; # perform query $result2 = db_query($query2, $c_per_page, $t_offset); $row_count = db_num_rows($result2); $t_id_array_lastmod = array(); for ($i = 0; $i < $row_count; $i++) { $row = db_fetch_array($result2); $t_id_array_lastmod[] = db_prepare_int($row['id']); $row['date_submitted'] = db_unixtimestamp($row['date_submitted']); $row['last_updated'] = db_unixtimestamp($row['last_updated']); array_push($rows, $row); } $t_id_array_lastmod = array_unique($t_id_array_lastmod); // paulr: it should be impossible for t_id_array_lastmod to be array(): // that would imply that $t_id_array is null which aborts this function early //if ( count( $t_id_array_lastmod ) > 0 ) { $t_where = "WHERE {$t_bugnote_table}.bug_id in (" . implode(", ", $t_id_array_lastmod) . ")"; $query3 = "SELECT DISTINCT bug_id,MAX(last_modified) as last_modified, COUNT(last_modified) as count FROM {$t_bugnote_table} {$t_where} GROUP BY bug_id"; # perform query $result3 = db_query($query3); $row_count = db_num_rows($result3); for ($i = 0; $i < $row_count; $i++) { $row = db_fetch_array($result3); $t_stats[$row['bug_id']] = $row; } foreach ($rows as $row) { if (!isset($t_stats[$row['id']])) { bug_cache_database_result($row, false); } else { bug_cache_database_result($row, $t_stats[$row['id']]); } } return $rows; }
/** * Get set of bug rows from given filter * @todo Had to make all these parameters required because we can't use call-time pass by reference anymore. * I really preferred not having to pass all the params in if you didn't want to, but I wanted to get * rid of the errors for now. If we can think of a better way later (maybe return an object) that would be great. * * @param integer &$p_page_number Page number of the page you want to see (set to the actual page on return). * @param integer &$p_per_page The number of bugs to see per page (set to actual on return) * -1 indicates you want to see all bugs * null indicates you want to use the value specified in the filter. * @param integer &$p_page_count You don't need to give a value here, the number of pages will be stored here on return. * @param integer &$p_bug_count You don't need to give a value here, the number of bugs will be stored here on return. * @param mixed $p_custom_filter Custom Filter to use. * @param integer $p_project_id Project id to use in filtering. * @param integer $p_user_id User id to use as current user when filtering. * @param boolean $p_show_sticky True/false - get sticky issues only. * @return boolean|array */ function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null) { log_event(LOG_FILTERING, 'START NEW FILTER QUERY'); $t_limit_reporters = config_get('limit_reporters'); $t_report_bug_threshold = config_get('report_bug_threshold'); $t_where_param_count = 0; $t_current_user_id = auth_get_current_user_id(); if ($p_user_id === null || $p_user_id === 0) { $t_user_id = $t_current_user_id; } else { $t_user_id = $p_user_id; } $c_user_id = (int) $t_user_id; if (null === $p_project_id) { # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project. $t_project_id = helper_get_current_project(); } else { $t_project_id = $p_project_id; } if ($p_custom_filter === null) { # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports # cookies set by previous version of the code. if ($t_user_id == $t_current_user_id) { $t_filter = current_user_get_bug_filter(); } else { $t_filter = user_get_bug_filter($t_user_id, $t_project_id); } } else { $t_filter = $p_custom_filter; } # if filter isn't return above, create a new filter from an empty array. if (false === $t_filter) { $t_filter = array(); } $t_filter = filter_ensure_valid_filter($t_filter); $t_view_type = $t_filter['_view_type']; # project query clauses must be AND-ed always, irrespective of how the filter # clauses are requested by the user ( all matching -> AND, any matching -> OR ) $t_where_clauses = array(); $t_project_where_clauses = array('{project}.enabled = ' . db_param()); $t_where_params = array(1); $t_select_clauses = array('{bug}.*'); $t_from_clauses = array('{bug}'); $t_join_clauses = array(' JOIN {project} ON {project}.id = {bug}.project_id'); # normalize the project filtering into an array $t_project_ids if ('simple' == $t_view_type) { log_event(LOG_FILTERING, 'Simple Filter'); $t_project_ids = array($t_project_id); $t_include_sub_projects = true; } else { log_event(LOG_FILTERING, 'Advanced Filter'); if (!is_array($t_filter[FILTER_PROPERTY_PROJECT_ID])) { $t_project_ids = array((int) $t_filter[FILTER_PROPERTY_PROJECT_ID]); } else { $t_project_ids = array_map('intval', $t_filter[FILTER_PROPERTY_PROJECT_ID]); } $t_include_sub_projects = count($t_project_ids) == 1 && ($t_project_ids[0] == META_FILTER_CURRENT || $t_project_ids[0] == ALL_PROJECTS); } log_event(LOG_FILTERING, 'project_ids = @P' . implode(', @P', $t_project_ids)); log_event(LOG_FILTERING, 'include sub-projects = ' . ($t_include_sub_projects ? '1' : '0')); # if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS. # replace META_FILTER_CURRENT with the actualy current project id. $t_all_projects_found = false; $t_new_project_ids = array(); foreach ($t_project_ids as $t_pid) { if ($t_pid == META_FILTER_CURRENT) { $t_pid = $t_project_id; } if ($t_pid == ALL_PROJECTS) { $t_all_projects_found = true; log_event(LOG_FILTERING, 'all projects selected'); break; } # filter out inaccessible projects. if (!project_exists($t_pid) || !access_has_project_level(config_get('view_bug_threshold', null, $t_user_id, $t_pid), $t_pid, $t_user_id)) { log_event(LOG_FILTERING, 'Invalid or inaccessible project: ' . $t_pid); continue; } $t_new_project_ids[] = $t_pid; } $t_projects_query_required = true; if ($t_all_projects_found) { if (user_is_administrator($t_user_id)) { log_event(LOG_FILTERING, 'all projects + administrator, hence no project filter.'); $t_projects_query_required = false; } else { $t_project_ids = user_get_accessible_projects($t_user_id); } } else { $t_project_ids = $t_new_project_ids; } if ($t_projects_query_required) { # expand project ids to include sub-projects if ($t_include_sub_projects) { $t_top_project_ids = $t_project_ids; foreach ($t_top_project_ids as $t_pid) { log_event(LOG_FILTERING, 'Getting sub-projects for project id @P' . $t_pid); $t_subproject_ids = user_get_all_accessible_subprojects($t_user_id, $t_pid); if (!$t_subproject_ids) { continue; } $t_project_ids = array_merge($t_project_ids, $t_subproject_ids); } $t_project_ids = array_unique($t_project_ids); } # if no projects are accessible, then return an empty array. if (count($t_project_ids) == 0) { log_event(LOG_FILTERING, 'no accessible projects'); return array(); } log_event(LOG_FILTERING, 'project_ids after including sub-projects = @P' . implode(', @P', $t_project_ids)); # this array is to be populated with project ids for which we only want to show public issues. This is due to the limited # access of the current user. $t_public_only_project_ids = array(); # this array is populated with project ids that the current user has full access to. $t_private_and_public_project_ids = array(); $t_limited_projects = array(); foreach ($t_project_ids as $t_pid) { # limit reporters to visible projects if (ON === $t_limit_reporters && !access_has_project_level(config_get('report_bug_threshold', null, $t_user_id, $t_pid) + 1, $t_pid, $t_user_id)) { array_push($t_limited_projects, '({bug}.project_id=' . $t_pid . ' AND ({bug}.reporter_id=' . $t_user_id . ') )'); } else { $t_access_required_to_view_private_bugs = config_get('private_bug_threshold', null, null, $t_pid); if (access_has_project_level($t_access_required_to_view_private_bugs, $t_pid, $t_user_id)) { $t_private_and_public_project_ids[] = $t_pid; } else { $t_public_only_project_ids[] = $t_pid; } } } log_event(LOG_FILTERING, 'project_ids (with public/private access) = @P' . implode(', @P', $t_private_and_public_project_ids)); log_event(LOG_FILTERING, 'project_ids (with public access) = @P' . implode(', @P', $t_public_only_project_ids)); $t_count_private_and_public_project_ids = count($t_private_and_public_project_ids); if ($t_count_private_and_public_project_ids == 1) { $t_private_and_public_query = '( {bug}.project_id = ' . $t_private_and_public_project_ids[0] . ' )'; } else { if ($t_count_private_and_public_project_ids > 1) { $t_private_and_public_query = '( {bug}.project_id in (' . implode(', ', $t_private_and_public_project_ids) . ') )'; } else { $t_private_and_public_query = null; } } $t_count_public_only_project_ids = count($t_public_only_project_ids); $t_public_view_state_check = '( ( {bug}.view_state = ' . VS_PUBLIC . ' ) OR ( {bug}.reporter_id = ' . $t_user_id . ') )'; if ($t_count_public_only_project_ids == 1) { $t_public_only_query = '( ( {bug}.project_id = ' . $t_public_only_project_ids[0] . ' ) AND ' . $t_public_view_state_check . ')'; } else { if ($t_count_public_only_project_ids > 1) { $t_public_only_query = '( ( {bug}.project_id in (' . implode(', ', $t_public_only_project_ids) . ') ) AND ' . $t_public_view_state_check . ')'; } else { $t_public_only_query = null; } } # both queries can't be null, so we either have one of them or both. if ($t_private_and_public_query === null) { $t_project_query = $t_public_only_query; } else { if ($t_public_only_query === null) { $t_project_query = $t_private_and_public_query; } else { $t_project_query = '( ' . $t_public_only_query . ' OR ' . $t_private_and_public_query . ' )'; } } if (!empty($t_limited_projects)) { foreach ($t_limited_projects as $t_string) { if ($t_project_query == "") { $t_project_query = " ( {$t_string} ) "; } else { $t_project_query = " ( {$t_project_query} OR ( {$t_string} ) )"; } } } log_event(LOG_FILTERING, 'project query = ' . $t_project_query); array_push($t_project_where_clauses, $t_project_query); } # date filter if ('on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] && is_numeric($t_filter[FILTER_PROPERTY_START_MONTH]) && is_numeric($t_filter[FILTER_PROPERTY_START_DAY]) && is_numeric($t_filter[FILTER_PROPERTY_START_YEAR]) && is_numeric($t_filter[FILTER_PROPERTY_END_MONTH]) && is_numeric($t_filter[FILTER_PROPERTY_END_DAY]) && is_numeric($t_filter[FILTER_PROPERTY_END_YEAR])) { $t_start_string = $t_filter[FILTER_PROPERTY_START_YEAR] . '-' . $t_filter[FILTER_PROPERTY_START_MONTH] . '-' . $t_filter[FILTER_PROPERTY_START_DAY] . ' 00:00:00'; $t_end_string = $t_filter[FILTER_PROPERTY_END_YEAR] . '-' . $t_filter[FILTER_PROPERTY_END_MONTH] . '-' . $t_filter[FILTER_PROPERTY_END_DAY] . ' 23:59:59'; $t_where_params[] = strtotime($t_start_string); $t_where_params[] = strtotime($t_end_string); array_push($t_project_where_clauses, '({bug}.date_submitted BETWEEN ' . db_param() . ' AND ' . db_param() . ' )'); } # view state $t_view_state = (int) $t_filter[FILTER_PROPERTY_VIEW_STATE]; if (!filter_field_is_any($t_filter[FILTER_PROPERTY_VIEW_STATE])) { $t_view_state_query = '({bug}.view_state=' . db_param() . ')'; log_event(LOG_FILTERING, 'view_state query = ' . $t_view_state_query); $t_where_params[] = $t_view_state; array_push($t_where_clauses, $t_view_state_query); } else { log_event(LOG_FILTERING, 'no view_state query'); } # reporter if (!filter_field_is_any($t_filter[FILTER_PROPERTY_REPORTER_ID])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_REPORTER_ID] as $t_filter_member) { if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, '0'); } else { $c_reporter_id = (int) $t_filter_member; if (filter_field_is_myself($c_reporter_id)) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_reporter_id); } } } if (1 < count($t_clauses)) { $t_reporter_query = '( {bug}.reporter_id in (' . implode(', ', $t_clauses) . ') )'; } else { $t_reporter_query = '( {bug}.reporter_id=' . $t_clauses[0] . ' )'; } log_event(LOG_FILTERING, 'reporter query = ' . $t_reporter_query); array_push($t_where_clauses, $t_reporter_query); } else { log_event(LOG_FILTERING, 'no reporter query'); } # handler if (!filter_field_is_any($t_filter[FILTER_PROPERTY_HANDLER_ID])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_HANDLER_ID] as $t_filter_member) { if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, 0); } else { $c_handler_id = (int) $t_filter_member; if (filter_field_is_myself($c_handler_id)) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_handler_id); } } } if (1 < count($t_clauses)) { $t_handler_query = '( {bug}.handler_id in (' . implode(', ', $t_clauses) . ') )'; } else { $t_handler_query = '( {bug}.handler_id=' . $t_clauses[0] . ' )'; } log_event(LOG_FILTERING, 'handler query = ' . $t_handler_query); array_push($t_where_clauses, $t_handler_query); } else { log_event(LOG_FILTERING, 'no handler query'); } # category if (!filter_field_is_any($t_filter[FILTER_PROPERTY_CATEGORY_ID])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_CATEGORY_ID] as $t_filter_member) { if (!filter_field_is_none($t_filter_member)) { array_push($t_clauses, $t_filter_member); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.category_id in ( SELECT id FROM {category} WHERE name in (' . implode(', ', $t_where_tmp) . ') ) )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.category_id in ( SELECT id FROM {category} WHERE name=' . db_param() . ') )'); } } # severity if (!filter_field_is_any($t_filter[FILTER_PROPERTY_SEVERITY])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_SEVERITY] as $t_filter_member) { $c_show_severity = (int) $t_filter_member; array_push($t_clauses, $c_show_severity); } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.severity in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.severity=' . db_param() . ' )'); } } # show / hide status # take a list of all available statuses then remove the ones that we want hidden, then make sure # the ones we want shown are still available $t_desired_statuses = array(); $t_available_statuses = MantisEnum::getValues(config_get('status_enum_string')); if ('simple' == $t_filter['_view_type']) { # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide $t_this_status = $t_filter[FILTER_PROPERTY_STATUS][0]; $t_this_hide_status = isset($t_filter[FILTER_PROPERTY_HIDE_STATUS][0]) ? $t_filter[FILTER_PROPERTY_HIDE_STATUS][0] : null; if (filter_field_is_any($t_this_status)) { foreach ($t_available_statuses as $t_this_available_status) { if ($t_this_hide_status > $t_this_available_status) { $t_desired_statuses[] = $t_this_available_status; } } } else { $t_desired_statuses[] = $t_this_status; } } else { # advanced filtering: ignore the hide if (filter_field_is_any($t_filter[FILTER_PROPERTY_STATUS])) { $t_desired_statuses = array(); } else { foreach ($t_filter[FILTER_PROPERTY_STATUS] as $t_this_status) { $t_desired_statuses[] = $t_this_status; } } } if (count($t_desired_statuses) > 0) { $t_clauses = array(); foreach ($t_desired_statuses as $t_filter_member) { $c_show_status = (int) $t_filter_member; array_push($t_clauses, $c_show_status); } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.status in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.status=' . db_param() . ' )'); } } # resolution if (!filter_field_is_any($t_filter[FILTER_PROPERTY_RESOLUTION])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_RESOLUTION] as $t_filter_member) { $c_show_resolution = (int) $t_filter_member; array_push($t_clauses, $c_show_resolution); } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.resolution in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.resolution=' . db_param() . ' )'); } } # priority if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PRIORITY])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_PRIORITY] as $t_filter_member) { $c_show_priority = (int) $t_filter_member; array_push($t_clauses, $c_show_priority); } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.priority in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.priority=' . db_param() . ' )'); } } # product build if (!filter_field_is_any($t_filter[FILTER_PROPERTY_BUILD])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_BUILD] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_show_build = $t_filter_member; array_push($t_clauses, $c_show_build); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.build in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.build=' . db_param() . ' )'); } } # product version if (!filter_field_is_any($t_filter[FILTER_PROPERTY_VERSION])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_VERSION] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_show_version = $t_filter_member; array_push($t_clauses, $c_show_version); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.version in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.version=' . db_param() . ' )'); } } # profile if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PROFILE_ID])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_PROFILE_ID] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, '0'); } else { $c_show_profile = (int) $t_filter_member; array_push($t_clauses, $c_show_profile); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.profile_id in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.profile_id=' . db_param() . ' )'); } } # platform if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PLATFORM])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_PLATFORM] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_platform = $t_filter_member; array_push($t_clauses, $c_platform); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.platform in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.platform = ' . db_param() . ' )'); } } # Operating System (os) if (!filter_field_is_any($t_filter[FILTER_PROPERTY_OS])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_OS] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_os = $t_filter_member; array_push($t_clauses, $c_os); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.os in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.os = ' . db_param() . ' )'); } } # Operating System Build (os_build) if (!filter_field_is_any($t_filter[FILTER_PROPERTY_OS_BUILD])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_OS_BUILD] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_os_build = $t_filter_member; array_push($t_clauses, $c_os_build); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.os_build in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.os_build = ' . db_param() . ' )'); } } # fixed in version if (!filter_field_is_any($t_filter[FILTER_PROPERTY_FIXED_IN_VERSION])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_FIXED_IN_VERSION] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_fixed_in_version = $t_filter_member; array_push($t_clauses, $c_fixed_in_version); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.fixed_in_version in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.fixed_in_version=' . db_param() . ' )'); } } # target version if (!filter_field_is_any($t_filter[FILTER_PROPERTY_TARGET_VERSION])) { $t_clauses = array(); foreach ($t_filter[FILTER_PROPERTY_TARGET_VERSION] as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { array_push($t_clauses, ''); } else { $c_target_version = $t_filter_member; array_push($t_clauses, $c_target_version); } } # echo var_dump( $t_clauses ); exit; if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( {bug}.target_version in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( {bug}.target_version=' . db_param() . ' )'); } } # users monitoring a bug if (!filter_field_is_any($t_filter[FILTER_PROPERTY_MONITOR_USER_ID])) { $t_clauses = array(); $t_table_name = 'user_monitor'; array_push($t_join_clauses, 'LEFT JOIN {bug_monitor} ' . $t_table_name . ' ON ' . $t_table_name . '.bug_id = {bug}.id'); foreach ($t_filter[FILTER_PROPERTY_MONITOR_USER_ID] as $t_filter_member) { $c_user_monitor = (int) $t_filter_member; if (filter_field_is_myself($c_user_monitor)) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_user_monitor); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( ' . $t_table_name . '.user_id in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( ' . $t_table_name . '.user_id=' . db_param() . ' )'); } } # bug relationship $t_any_found = false; $c_rel_type = $t_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE]; $c_rel_bug = $t_filter[FILTER_PROPERTY_RELATIONSHIP_BUG]; if (-1 == $c_rel_type || 0 == $c_rel_bug) { $t_any_found = true; } if (!$t_any_found) { # use the complementary type $t_comp_type = relationship_get_complementary_type($c_rel_type); $t_clauses = array(); $t_table_dst = 'rel_dst'; $t_table_src = 'rel_src'; array_push($t_join_clauses, 'LEFT JOIN {bug_relationship} ' . $t_table_dst . ' ON ' . $t_table_dst . '.destination_bug_id = {bug}.id'); array_push($t_join_clauses, 'LEFT JOIN {bug_relationship} ' . $t_table_src . ' ON ' . $t_table_src . '.source_bug_id = {bug}.id'); # get reverse relationships $t_where_params[] = $t_comp_type; $t_where_params[] = $c_rel_bug; $t_where_params[] = $c_rel_type; $t_where_params[] = $c_rel_bug; array_push($t_clauses, '(' . $t_table_dst . '.relationship_type=' . db_param() . ' AND ' . $t_table_dst . '.source_bug_id=' . db_param() . ')'); array_push($t_clauses, '(' . $t_table_src . '.relationship_type=' . db_param() . ' AND ' . $t_table_src . '.destination_bug_id=' . db_param() . ')'); array_push($t_where_clauses, '(' . implode(' OR ', $t_clauses) . ')'); } # tags $c_tag_string = trim($t_filter[FILTER_PROPERTY_TAG_STRING]); $c_tag_select = trim($t_filter[FILTER_PROPERTY_TAG_SELECT]); if (is_blank($c_tag_string) && !is_blank($c_tag_select) && $c_tag_select != 0) { $t_tag = tag_get($c_tag_select); $c_tag_string = $t_tag['name']; } if (!is_blank($c_tag_string)) { $t_tags = tag_parse_filters($c_tag_string); if (count($t_tags)) { $t_tags_all = array(); $t_tags_any = array(); $t_tags_none = array(); foreach ($t_tags as $t_tag_row) { switch ($t_tag_row['filter']) { case 1: $t_tags_all[] = $t_tag_row; break; case 0: $t_tags_any[] = $t_tag_row; break; case -1: $t_tags_none[] = $t_tag_row; break; } } if (0 < $t_filter[FILTER_PROPERTY_TAG_SELECT] && tag_exists($t_filter[FILTER_PROPERTY_TAG_SELECT])) { $t_tags_any[] = tag_get($t_filter[FILTER_PROPERTY_TAG_SELECT]); } if (count($t_tags_all)) { $t_clauses = array(); foreach ($t_tags_all as $t_tag_row) { array_push($t_clauses, '{bug}.id IN ( SELECT bug_id FROM {bug_tag} WHERE {bug_tag}.tag_id = ' . $t_tag_row['id'] . ')'); } array_push($t_where_clauses, '(' . implode(' AND ', $t_clauses) . ')'); } if (count($t_tags_any)) { $t_clauses = array(); foreach ($t_tags_any as $t_tag_row) { array_push($t_clauses, '{bug_tag}.tag_id = ' . $t_tag_row['id']); } array_push($t_where_clauses, '{bug}.id IN ( SELECT bug_id FROM {bug_tag} WHERE ( ' . implode(' OR ', $t_clauses) . ') )'); } if (count($t_tags_none)) { $t_clauses = array(); foreach ($t_tags_none as $t_tag_row) { array_push($t_clauses, '{bug_tag}.tag_id = ' . $t_tag_row['id']); } array_push($t_where_clauses, '{bug}.id NOT IN ( SELECT bug_id FROM {bug_tag} WHERE ( ' . implode(' OR ', $t_clauses) . ') )'); } } } # note user id if (!filter_field_is_any($t_filter[FILTER_PROPERTY_NOTE_USER_ID])) { $t_bugnote_table_alias = 'mbnt'; $t_clauses = array(); array_push($t_join_clauses, 'LEFT JOIN {bugnote} ' . $t_bugnote_table_alias . ' ON {bug}.id = ' . $t_bugnote_table_alias . '.bug_id'); foreach ($t_filter[FILTER_PROPERTY_NOTE_USER_ID] as $t_filter_member) { $c_note_user_id = (int) $t_filter_member; if (filter_field_is_myself($c_note_user_id)) { array_push($t_clauses, $c_user_id); } else { array_push($t_clauses, $c_note_user_id); } } if (1 < count($t_clauses)) { $t_where_tmp = array(); foreach ($t_clauses as $t_clause) { $t_where_tmp[] = db_param(); $t_where_params[] = $t_clause; } array_push($t_where_clauses, '( ' . $t_bugnote_table_alias . '.reporter_id in (' . implode(', ', $t_where_tmp) . ') )'); } else { $t_where_params[] = $t_clauses[0]; array_push($t_where_clauses, '( ' . $t_bugnote_table_alias . '.reporter_id=' . db_param() . ' )'); } } # plugin filters $t_plugin_filters = filter_get_plugin_filters(); foreach ($t_plugin_filters as $t_field_name => $t_filter_object) { if (!filter_field_is_any($t_filter[$t_field_name]) || $t_filter_object->type == FILTER_TYPE_BOOLEAN) { $t_filter_query = $t_filter_object->query($t_filter[$t_field_name]); if (is_array($t_filter_query)) { if (isset($t_filter_query['join'])) { array_push($t_join_clauses, $t_filter_query['join']); } if (isset($t_filter_query['where'])) { array_push($t_where_clauses, $t_filter_query['where']); } if (isset($t_filter_query['params']) && is_array($t_filter_query['params'])) { $t_where_params = array_merge($t_where_params, $t_filter_query['params']); } } } } # custom field filters if (ON == config_get('filter_by_custom_fields')) { # custom field filtering # @@@ At the moment this gets the linked fields relating to the current project # It should get the ones relating to the project in the filter or all projects # if multiple projects. $t_custom_fields = custom_field_get_linked_ids($t_project_id); foreach ($t_custom_fields as $t_cfid) { $t_field_info = custom_field_cache_row($t_cfid, true); if (!$t_field_info['filter_by']) { continue; # skip this custom field it shouldn't be filterable } $t_field = $t_filter['custom_fields'][$t_cfid]; $t_custom_where_clause = ''; # Ignore all custom filters that are not set, or that are set to '' or "any" if (!filter_field_is_any($t_field)) { $t_def = custom_field_get_definition($t_cfid); $t_table_name = '{custom_field_string}_' . $t_cfid; # We need to filter each joined table or the result query will explode in dimensions # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields # and only after this process ends (if it is able to) the result query will be filtered # by the WHERE clause and by the DISTINCT clause $t_cf_join_clause = 'LEFT JOIN {custom_field_string} ' . $t_table_name . ' ON {bug}.id = ' . $t_table_name . '.bug_id AND ' . $t_table_name . '.field_id = ' . $t_cfid; if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) { # Define the value field with type cast to integer $t_value_field = 'CAST(COALESCE(NULLIF(' . $t_table_name . '.value, \'\'), \'0\') AS DECIMAL)'; switch ($t_field[0]) { # Closing parenthesis intentionally omitted, will be added later on case CUSTOM_FIELD_DATE_ANY: break; case CUSTOM_FIELD_DATE_NONE: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( ' . $t_table_name . '.bug_id is null OR ' . $t_value_field . ' = 0 '; break; case CUSTOM_FIELD_DATE_BEFORE: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( ' . $t_value_field . ' != 0 AND ' . $t_value_field . ' < ' . $t_field[2]; break; case CUSTOM_FIELD_DATE_AFTER: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( ' . $t_value_field . ' > ' . ($t_field[1] + 1); break; default: array_push($t_join_clauses, $t_cf_join_clause); $t_custom_where_clause = '( ' . $t_value_field . ' BETWEEN ' . $t_field[1] . ' AND ' . $t_field[2]; break; } } else { array_push($t_join_clauses, $t_cf_join_clause); $t_filter_array = array(); foreach ($t_field as $t_filter_member) { $t_filter_member = stripslashes($t_filter_member); if (filter_field_is_none($t_filter_member)) { # coerce filter value if selecting META_FILTER_NONE so it will match empty fields $t_filter_member = ''; # but also add those _not_ present in the custom field string table array_push($t_filter_array, '{bug}.id NOT IN (SELECT bug_id FROM {custom_field_string} WHERE field_id=' . $t_cfid . ')'); } switch ($t_def['type']) { case CUSTOM_FIELD_TYPE_CHECKBOX: case CUSTOM_FIELD_TYPE_MULTILIST: $t_where_params[] = '%|' . $t_filter_member . '|%'; array_push($t_filter_array, db_helper_like($t_table_name . '.value')); break; case CUSTOM_FIELD_TYPE_TEXTAREA: $t_where_params[] = '%' . $t_filter_member . '%'; array_push($t_filter_array, db_helper_like($t_table_name . '.text')); break; default: $t_where_params[] = $t_filter_member; array_push($t_filter_array, $t_table_name . '.value = ' . db_param()); } } $t_custom_where_clause .= '(' . implode(' OR ', $t_filter_array); } if (!is_blank($t_custom_where_clause)) { array_push($t_where_clauses, $t_custom_where_clause . ')'); } } } } # Text search if (!is_blank($t_filter[FILTER_PROPERTY_SEARCH])) { # break up search terms by spacing or quoting preg_match_all("/-?([^'\"\\s]+|\"[^\"]+\"|'[^']+')/", $t_filter[FILTER_PROPERTY_SEARCH], $t_matches, PREG_SET_ORDER); # organize terms without quoting, paying attention to negation $t_search_terms = array(); foreach ($t_matches as $t_match) { $t_search_terms[trim($t_match[1], "\\'\"")] = $t_match[0][0] == '-'; } # build a big where-clause and param list for all search terms, including negations $t_first = true; $t_textsearch_where_clause = '( '; foreach ($t_search_terms as $t_search_term => $t_negate) { if (!$t_first) { $t_textsearch_where_clause .= ' AND '; } if ($t_negate) { $t_textsearch_where_clause .= 'NOT '; } $c_search = '%' . $t_search_term . '%'; $t_textsearch_where_clause .= '( ' . db_helper_like('{bug}.summary') . ' OR ' . db_helper_like('{bug_text}.description') . ' OR ' . db_helper_like('{bug_text}.steps_to_reproduce') . ' OR ' . db_helper_like('{bug_text}.additional_information') . ' OR ' . db_helper_like('{bugnote_text}.note'); $t_where_params[] = $c_search; $t_where_params[] = $c_search; $t_where_params[] = $c_search; $t_where_params[] = $c_search; $t_where_params[] = $c_search; if (is_numeric($t_search_term)) { # PostgreSQL on 64-bit OS hack (see #14014) if (PHP_INT_MAX > 0x7fffffff && db_is_pgsql()) { $t_search_max = 0x7fffffff; } else { $t_search_max = PHP_INT_MAX; } # Note: no need to test negative values, '-' sign has been removed if ($t_search_term <= $t_search_max) { $c_search_int = (int) $t_search_term; $t_textsearch_where_clause .= ' OR {bug}.id = ' . db_param(); $t_textsearch_where_clause .= ' OR {bugnote}.id = ' . db_param(); $t_where_params[] = $c_search_int; $t_where_params[] = $c_search_int; } } $t_textsearch_where_clause .= ' )'; $t_first = false; } $t_textsearch_where_clause .= ' )'; # add text query elements to arrays if (!$t_first) { $t_join_clauses[] = 'JOIN {bug_text} ON {bug}.bug_text_id = {bug_text}.id'; $t_join_clauses[] = 'LEFT JOIN {bugnote} ON {bug}.id = {bugnote}.bug_id'; # Outer join required otherwise we don't retrieve issues without notes $t_join_clauses[] = 'LEFT JOIN {bugnote_text} ON {bugnote}.bugnote_text_id = {bugnote_text}.id'; $t_where_clauses[] = $t_textsearch_where_clause; } } # End text search # Determine join operator if ($t_filter[FILTER_PROPERTY_MATCH_TYPE] == FILTER_MATCH_ANY) { $t_join_operator = ' OR '; } else { $t_join_operator = ' AND '; } log_event(LOG_FILTERING, 'Join operator : ' . $t_join_operator); $t_query_clauses['select'] = $t_select_clauses; $t_query_clauses['from'] = $t_from_clauses; $t_query_clauses['join'] = $t_join_clauses; $t_query_clauses['where'] = $t_where_clauses; $t_query_clauses['where_values'] = $t_where_params; $t_query_clauses['project_where'] = $t_project_where_clauses; $t_query_clauses['operator'] = $t_join_operator; $t_query_clauses = filter_get_query_sort_data($t_filter, $p_show_sticky, $t_query_clauses); # assigning to $p_* for this function writes the values back in case the caller wants to know # Get the total number of bugs that meet the criteria. $p_bug_count = filter_get_bug_count($t_query_clauses); if (0 == $p_bug_count) { return array(); } $p_per_page = filter_per_page($t_filter, $p_bug_count, $p_per_page); $p_page_count = filter_page_count($p_bug_count, $p_per_page); $p_page_number = filter_valid_page_number($p_page_number, $p_page_count); $t_offset = filter_offset($p_page_number, $p_per_page); $t_query_clauses = filter_unique_query_clauses($t_query_clauses); $t_select_string = 'SELECT DISTINCT ' . implode(', ', $t_query_clauses['select']); $t_from_string = ' FROM ' . implode(', ', $t_query_clauses['from']); $t_order_string = ' ORDER BY ' . implode(', ', $t_query_clauses['order']); $t_join_string = count($t_query_clauses['join']) > 0 ? implode(' ', $t_query_clauses['join']) : ' '; $t_where_string = ' WHERE ' . implode(' AND ', $t_query_clauses['project_where']); if (count($t_query_clauses['where']) > 0) { $t_where_string .= ' AND ( '; $t_where_string .= implode($t_join_operator, $t_query_clauses['where']); $t_where_string .= ' ) '; } $t_result = db_query($t_select_string . $t_from_string . $t_join_string . $t_where_string . $t_order_string, $t_query_clauses['where_values'], $p_per_page, $t_offset); $t_id_array_lastmod = array(); while ($t_row = db_fetch_array($t_result)) { $t_id_array_lastmod[] = (int) $t_row['id']; $t_rows[] = $t_row; } return filter_cache_result($t_rows, $t_id_array_lastmod); }
function get_videos_by_tag_and_category() { $tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility $tag = optional_param('tag', '', PARAM_TAG); // tag if ($tag) { $tagobject = tag_get('name', $tag); } else { if ($tagid) { $tagobject = tag_get('id', $tagid); } } if (empty($tagobject)) { return ''; } $querytag = urlencode($tagobject->name); $numberofvideos = DEFAULT_NUMBER_OF_VIDEOS; if (!empty($this->config->numberofvideos)) { $numberofvideos = $this->config->numberofvideos; } $request = 'http://gdata.youtube.com/feeds/api/videos?category=' . $this->config->category . '&vq=' . $querytag . '&start-index=1&max-results=' . $numberofvideos . '&format=5'; return $this->fetch_request($request); }
/** * function to attach tags into an entry * @return void */ public function add_tags_info() { $tags = array(); if ($otags = optional_param('otags', '', PARAM_INT)) { foreach ($otags as $tagid) { // TODO : make this use the tag name in the form if ($tag = tag_get('id', $tagid)) { $tags[] = $tag->name; } } } tag_set('post', $this->id, $tags); }
function get_videos_by_tag_and_category() { if (!($service = $this->get_service())) { return $this->get_error_message(); } $tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility $tag = optional_param('tag', '', PARAM_TAG); // tag if ($tag) { $tagobject = tag_get('name', $tag); } else { if ($tagid) { $tagobject = tag_get('id', $tagid); } } if (empty($tagobject)) { return ''; } $querytag = urlencode($tagobject->name); $numberofvideos = DEFAULT_NUMBER_OF_VIDEOS; if (!empty($this->config->numberofvideos)) { $numberofvideos = $this->config->numberofvideos; } try { $response = $service->search->listSearch('id,snippet', array('q' => $querytag, 'type' => 'video', 'maxResults' => $numberofvideos, 'videoCategoryId' => $this->config->category)); } catch (Google_Service_Exception $e) { debugging('Google service exception: ' . $e->getMessage(), DEBUG_DEVELOPER); return $this->get_error_message(get_string('requesterror', 'block_tag_youtube')); } return $this->render_items($response); }