From b4206400314c916b95b3e0a77a0e92ff940c0b6c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 24 Nov 2006 02:13:04 +0000 Subject: [PATCH] r1318: Created the ProcessBugDataForDisplay() function that removes redundant code that preps display for bug listings --- favorite.php | 15 +-------------- includes/functions.php | 33 +++++++++++++++++++++++++++++++++ index.php | 19 ++----------------- search.php | 12 +----------- 4 files changed, 37 insertions(+), 42 deletions(-) diff --git a/favorite.php b/favorite.php index 194b243..457d058 100644 --- a/favorite.php +++ b/favorite.php @@ -82,20 +82,7 @@ if ($_REQUEST['do'] == 'manage') while ($bug = $db->fetch_array($favorites)) { $funct->exec_swap_bg($stylevar['alt_color'], ''); - $bug['bgcolor'] = ($bugsys->userinfo['showcolors'] ? $bugsys->datastore['status']["$bug[status]"]['color'] : $funct->bgcolour); - $bug['product'] = $bugsys->datastore['product']["$bug[product]"]['title']; - $bug['version'] = $bugsys->datastore['version']["$bug[version]"]['version']; - $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status']; - $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution']; - $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority']; - $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity']; - - $bug['hiddendisplay'] = ((!can_perform('canviewhidden', $bug['product']) AND $bug['hiddenlastposttime']) ? true : false); - - $bug['lastposttime'] = ($bug['hiddendisplay'] ? $bug['hiddenlastposttime'] : $bug['lastposttime']); - $bug['lastpost'] = ($bug['hiddendisplay'] ? $bug['hiddenlastpostbyname'] : $bug['lastpostbyname']); - - $bug['lastposttime'] = $datef->format($bugsys->options['dateformat'], $bug['lastposttime']); + ProcessBugDataForDisplay(&$bug, $funct->bgcolour); eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";'); } diff --git a/includes/functions.php b/includes/functions.php index 26ec30a..7515f3b 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -615,6 +615,39 @@ function check_bug_permissions($bug, $userinfo = null) return true; } +// ################################################################### +/** +* Takes an array of bug information and returns another array with +* information that is suitable for display as all the IDs have been +* replaced by their string equivalents +* +* @param array Unprocessed bug data +* @param string Color to display if the user has opted to not show status colours +* +* @param array Bug array with data fit for display +*/ +function ProcessBugDataForDisplay($bug, $color = '') +{ + global $bugsys; + + $bug['hiddendisplay'] = (can_perform('canviewhidden', $bug['product']) OR (can_perform('canviewownhidden') AND $bug['userid'] == $bugsys->userinfo['userid'])); + + $bug['bgcolor'] = ($bugsys->userinfo['showcolors'] ? $bugsys->datastore['status']["$bug[status]"]['color'] : $color); + $bug['product'] = $bugsys->datastore['product']["$bug[product]"]['title']; + $bug['version'] = $bugsys->datastore['version']["$bug[version]"]['version']; + $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status']; + $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution']; + $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority']; + $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity']; + + $bug['lastposttime'] = ($bug['hiddendisplay'] ? $bug['hiddenlastposttime'] : $bug['lastposttime']); + $bug['lastpost'] = ($bug['hiddendisplay'] ? $bug['hiddenlastpostbyname'] : $bug['lastpostbyname']); + + $bug['lastposttime'] = $bugsys->datef->format($bugsys->options['dateformat'], $bug['lastposttime']); + + return $bug; +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/index.php b/index.php index 6559848..9b8626a 100644 --- a/index.php +++ b/index.php @@ -59,23 +59,8 @@ $bugs_fetch = $db->query($sort->fetch_sql_query(null, $pagination->fetch_limit($ while ($bug = $db->fetch_array($bugs_fetch)) { - $funct->exec_swap_bg($stylevar['alt_color'], ''); - - $bug['hiddendisplay'] = ((can_perform('canviewhidden', $bug['product']) OR (can_perform('canviewownhidden') AND $bug['userid'] == $bugsys->userinfo['userid'])) ? false : true); - - $bug['bgcolor'] = ($bugsys->userinfo['showcolors'] ? $bugsys->datastore['status']["$bug[status]"]['color'] : $funct->bgcolour); - $bug['product'] = $bugsys->datastore['product']["$bug[product]"]['title']; - $bug['version'] = $bugsys->datastore['version']["$bug[version]"]['version']; - $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status']; - $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution']; - $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority']; - $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity']; - - $bug['lastposttime'] = ($bug['hiddendisplay'] ? $bug['hiddenlastposttime'] : $bug['lastposttime']); - $bug['lastpost'] = ($bug['hiddendisplay'] ? $bug['hiddenlastpostbyname'] : $bug['lastpostbyname']); - - $bug['lastposttime'] = $datef->format($bugsys->options['dateformat'], $bug['lastposttime']); - + $funct->exec_swap_bg($stylevar['alt_color'], ''); + ProcessBugDataForDisplay(&$bug, $funct->bgcolour); eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";'); } diff --git a/search.php b/search.php index cc1260f..c90576e 100644 --- a/search.php +++ b/search.php @@ -401,17 +401,7 @@ if ($_REQUEST['do'] == 'results') while ($bug = $db->fetch_array($search)) { $funct->exec_swap_bg($stylevar['alt_color'], ''); - $bug['bgcolor'] = ($bugsys->userinfo['showcolors'] ? $bugsys->datastore['status']["$bug[status]"]['color'] : $funct->bgcolour); - $bug['hiddendisplay'] = ((can_perform('canviewhidden', $bug['product']) OR (can_perform('canviewownhidden') AND $bug['userid'] == $bugsys->userinfo['userid'])) ? false : true); - $bug['product'] = $bugsys->datastore['product']["$bug[product]"]['title']; - $bug['version'] = $bugsys->datastore['version']["$bug[version]"]['version']; - $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status']; - $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution']; - $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority']; - $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity']; - $bug['lastposttime'] = ($bug['hiddendisplay'] ? $bug['hiddenlastposttime'] : $bug['lastposttime']); - $bug['lastpost'] = ($bug['hiddendisplay'] ? $bug['hiddenlastpostbyname'] : $bug['lastpostbyname']); - $bug['lastposttime'] = $datef->format($bugsys->options['dateformat'], $bug['lastposttime']); + ProcessBugDataForDisplay(&$bug, $funct->bgcolour); $bug['urladd'] = "&hilight=$hilight"; eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";'); } -- 2.43.5