From fe3922729b0cb4e59e838c5be01078b76f18509a Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 4 Aug 2007 17:46:45 +0000 Subject: [PATCH] r1597: Adding custom columns to the bug listing display. Fixes bug://report/73 * includes/definitions.php: Removed * includes/init.php: Do not include definitions.php anymore * includes/class_sort.php: (ListSorter::fetch_by_text): Fetch custom fields when getting the text information (ListSorter::constructColumnHeaders): Use fetch_by_text() instead of $bugsys->columnNames[] (ListSorter::_processColumns): Use fetch_by_text() instead of $bugsys->columnNames[] and make sure that the columns the user has selected actually exist (namely for permissions sanity) (ListSorter::_fetchCustomFields): New method that returns all the custom fields in the system, or just the ones the user can see, based on a parameter --- admin/setting.php | 8 +-- docs/changes.txt | 4 ++ includes/class_sort.php | 93 +++++++++++++++++++++++++++++++++-- includes/definitions.php | 60 ---------------------- includes/init.php | 2 - templates/userctrl_column.tpl | 4 +- userctrl.php | 5 +- 7 files changed, 103 insertions(+), 73 deletions(-) delete mode 100644 includes/definitions.php diff --git a/admin/setting.php b/admin/setting.php index e7b5c08..d22e9b5 100755 --- a/admin/setting.php +++ b/admin/setting.php @@ -188,7 +188,7 @@ if ($_REQUEST['do'] == 'modify') // defaultsortkey $admin->row_span(_('Default Sort Column'), 'thead'); - $admin->row_text(_('Select the column to sort bugs by on listings. This is only a default setting which users can override in their preferences.'), construct_option_select('setting[defaultsortkey]', ListSorter::fetch_by_text(false), $bugsys->options['defaultsortkey'])); + $admin->row_text(_('Select the column to sort bugs by on listings. This is only a default setting which users can override in their preferences.'), construct_option_select('setting[defaultsortkey]', ListSorter::fetch_by_text(false, false), $bugsys->options['defaultsortkey'])); // defaultsortas $admin->row_span(_('Default Sort Direction'), 'thead'); @@ -248,12 +248,14 @@ function ConstructColumnOptionsSetting() { global $bugsys; + require_once('./includes/class_sort.php'); + $array = ($bugsys->options['columnoptions'] == null ? array('bugid' => 1, 'summary' => 2, 'userid' => 2, 'product' => 3, 'version' => 3, 'component' => 0, 'status' => 4, 'resolution' => 4, 'priority' => 5, 'severity' => 5, 'lastpost' => 6, 'votes' => 0) : $bugsys->options['columnoptions']); $return = ''; - foreach ($bugsys->columns AS $column => $mask) + foreach (ListSorter::fetch_by_text(false, false) AS $column => $name) { - $return .= ''; + $return .= ''; } $return .= '
' . $bugsys->columnNames["$column"] . '
' . $name . '
'; return $return; diff --git a/docs/changes.txt b/docs/changes.txt index 79717ba..c5f41eb 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -1,3 +1,7 @@ +2.0.0 Beta 1 +=============================== +- Enhancement: Custom columns can now be displayed on the bug listings (bug://report/73) + 1.2.2 =============================== - Fixed: A "Call-time pass-by-reference has been deprecated" on search.php diff --git a/includes/class_sort.php b/includes/class_sort.php index cc98d01..116d8e6 100644 --- a/includes/class_sort.php +++ b/includes/class_sort.php @@ -180,6 +180,21 @@ class ListSorter ORDER BY vote.votefor " . strtoupper($this->direction) . ", vote.voteagainst " . strtoupper($this->fetch_opposite_sort_direction()) . ", bug.$querykeys[lastpost] " . strtoupper($this->direction) . ($limit ? " LIMIT $limit" : ""); break; + default: + if (substr($this->sortkey, 0, 6) != 'custom') + { + return; + } + + $query = " + SELECT bug.*, vote.votefor, vote.voteagainst FROM " . TABLE_PREFIX . "bug AS bug + LEFT JOIN " . TABLE_PREFIX . "vote AS vote + ON (bug.bugid = vote.bugid) + WHERE $basewhere" . + (is_array($where) ? " + AND " . implode("\nAND ", $where) : "") . " + ORDER BY {$this->sortkey} " . strtoupper($this->direction) . ", " . $querykeys['lastpost'] . " " . strtoupper($this->direction) . ($limit ? " + LIMIT $limit" : ""); } return $query; @@ -192,12 +207,13 @@ class ListSorter * @access public static * * @param string Sort order key, or FALSE for the array + * @param bool Permission check the custom fields? * * @return mixed Display text if param is string, or array of all key=>text if param is NULL */ - function fetch_by_text($key) + function fetch_by_text($key, $doPerm = true) { - global $lang; + global $bugsys; $keys = array( 'lastpost' => _('Last Post Time'), @@ -215,6 +231,12 @@ class ListSorter 'assignedto' => _('Assigned To') ); + $fields = self::_fetchCustomFields($doPerm); + foreach ($fields AS $field) + { + $keys['custom' . $field['fieldid']] = $field['name']; + } + if ($key === false) { return $keys; @@ -360,13 +382,15 @@ class ListSorter { $this->_processColumns(); + $names = self::fetch_by_text(false); + $output = ''; foreach ($this->columns AS $columns) { $build = array(); foreach ($columns AS $column) { - $build[] = ($sortable ? '' . $this->registry->columnNames["$column"] . '' : $this->registry->columnNames["$column"]); + $build[] = ($sortable ? '' . $names[$column] . '' : $names[$column]); } $image = ((in_array($this->sortkey, $columns) AND $sortable) ? $this->fetch_sort_image() : ''); $name = implode(' / ', $build); @@ -455,10 +479,17 @@ class ListSorter return; } + $columns = self::fetch_by_text(false); + $array = (($this->registry->userinfo['userid'] AND is_array($this->registry->userinfo['columnoptions'])) ? $this->registry->userinfo['columnoptions'] : $this->registry->options['columnoptions']); foreach ($array AS $column => $position) { + // the column doesn't exist, or more likely, we don't have permission to view it + if (!isset($columns[$column])) + { + continue; + } if ($position > 0) { $this->columns["$position"][] = $column; @@ -467,6 +498,60 @@ class ListSorter ksort($this->columns); } + + // ################################################################### + /** + * Returns an array of all the custom fields that the current user + * has permission to use + * + * @param boolean Ignore permissions? + * + * @return array + */ + private static function _fetchCustomFields($doPerm = true) + { + global $bugsys; + static $fields = array(), $fieldsPerm = array(); + + if ($doPerm AND !empty($fieldsPerm)) + { + return $fieldsPerm; + } + else if (!$doPerm AND !empty($fields)) + { + return $fields; + } + + if ($doPerm) + { + $fields_fetch = $bugsys->db->query(" + SELECT bugfield.*, MAX(permission.mask) AS mask + FROM " . TABLE_PREFIX . "bugfield AS bugfield + LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission + ON (bugfield.fieldid = permission.fieldid) + WHERE (permission.mask = 2 OR permission.mask = 1) + AND permission.usergroupid IN ({$bugsys->userinfo['usergroupid']}" . (sizeof($bugsys->userinfo['groupids']) != 0 ? ',' . implode(',', $bugsys->userinfo['groupids']) : '') . ") + GROUP BY (bugfield.fieldid) + "); + } + else + { + $fields_fetch = $bugsys->db->query("SELECT * FROM bugfield"); + } + + while ($field = $bugsys->db->fetch_array($fields_fetch)) + { + if ($doPerm) + { + $fieldsPerm[$field['fieldid']] = $field; + } + else + { + $fields[$field['fieldid']] = $field; + } + } + return $fields; + } } /*=====================================================================*\ @@ -475,4 +560,4 @@ class ListSorter || # $Id$ || ################################################################### \*=====================================================================*/ -?> +?> \ No newline at end of file diff --git a/includes/definitions.php b/includes/definitions.php deleted file mode 100644 index 53cd4c8..0000000 --- a/includes/definitions.php +++ /dev/null @@ -1,60 +0,0 @@ -columns = array( - 'bugid' => 1, - 'summary' => 2, - 'reporter' => 4, - 'product' => 8, - 'component' => 16, - 'version' => 32, - 'status' => 64, - 'resolution' => 128, - 'priority' => 256, - 'severity' => 512, - 'lastpost' => 1024, - 'votes' => 2048, - 'assignedto' => 4096 -); - -$bugsys->columnNames = array( - 'bugid' => _('ID'), - 'summary' => _('Summary'), - 'reporter' => _('Reporter'), - 'product' => _('Product'), - 'component' => _('Component'), - 'version' => _('Version'), - 'status' => _('Status'), - 'resolution' => _('Resolution'), - 'priority' => _('Priority'), - 'severity' => _('Severity'), - 'lastpost' => _('Last Post'), - 'votes' => _('Votes'), - 'assignedto' => _('Assigned To') -); - -/*=====================================================================*\ -|| ################################################################### -|| # $HeadURL$ -|| # $Id$ -|| ################################################################### -\*=====================================================================*/ -?> \ No newline at end of file diff --git a/includes/init.php b/includes/init.php index 84a77a6..65e0868 100755 --- a/includes/init.php +++ b/includes/init.php @@ -158,8 +158,6 @@ textdomain('MESSAGES'); bind_textdomain_codeset('MESSAGES', $language['charset']); -require_once('./includes/definitions.php'); - // ################################################################### // initialize the date system $bugsys->load('date', 'datef', true); diff --git a/templates/userctrl_column.tpl b/templates/userctrl_column.tpl index 0c2f96c..e769cf0 100644 --- a/templates/userctrl_column.tpl +++ b/templates/userctrl_column.tpl @@ -1,4 +1,4 @@ - {$bugsys->columnNames[$column]}: - + $name: + \ No newline at end of file diff --git a/userctrl.php b/userctrl.php index 64f5a8a..745cae4 100644 --- a/userctrl.php +++ b/userctrl.php @@ -251,9 +251,10 @@ if ($_REQUEST['do'] == 'modify') $columns = array(); $columnOptions = ''; + require_once('./includes/class_sort.php'); if (!is_array($bugsys->in['columnoptions'])) { - foreach ($bugsys->columns AS $column => $mask) + foreach (ListSorter::fetch_by_text(false) AS $column => $name) { if (is_array($bugsys->userinfo['columnoptions'])) { @@ -269,7 +270,7 @@ if ($_REQUEST['do'] == 'modify') else { $columns = $bugsys->in['columnoptions']; - foreach ($bugsys->columns AS $column => $mask) + foreach (ListSorter::fetch_by_text(false) AS $column => $name) { eval('$columnOptions .= "' . $template->fetch('userctrl_column') . '";'); } -- 2.43.5