List:Eventum Development« Previous MessageNext Message »
From:<lindleysmith Date:July 8 2005 3:29pm
Subject:Bug Fix - Add / Edit Priorities
View as plain text  
All

I've just started using PHP and eventum 1.5.4 this week, and I think I've found a 
bug. Using the increase/decrease priority feature within Add / Edit Priorities 
doesn't work correctly when there are multiple projects with the same priorities. 
Here's my solution to it. I hope it's an an understandable form.

Regards
Lindley

manage\priorities.php
-        Priority::changeRank($HTTP_GET_VARS['id'], $HTTP_GET_VARS['rank']);
+        Priority::changeRank($HTTP_GET_VARS['prj_id'], $HTTP_GET_VARS['id'], 
$HTTP_GET_VARS['rank']);

include\class.priority.php
    /**
     * Method used to quickly change the ranking of a reminder entry
     * from the administration screen.
     *
     * @access  public
+     * @param   integer $prj_id The project ID
     * @param   integer $pri_id The reminder entry ID
     * @param   string $rank_type Whether we should change the reminder ID down or 
up (options are 'asc' or 'desc')
     * @return  boolean
     */
-    function changeRank($pri_id, $rank_type)
+    function changeRank($prj_id, $pri_id, $rank_type)
    {
        // check if the current rank is not already the first or last one
-        $ranking = Priority::_getRanking();
+        $ranking = Priority::_getRanking($prj_id);
        $ranks = array_values($ranking);
        $ids = array_keys($ranking);
        $last = end($ids);
        $first = reset($ids);
        if ((($rank_type == 'asc') && ($pri_id == $first)) ||
                (($rank_type == 'desc') && ($pri_id == $last))) {
            return false;
        }

        if ($rank_type == 'asc') {
            $diff = -1;
        } else {
            $diff = 1;
        }
        $new_rank = $ranking[$pri_id] + $diff;
        if (in_array($new_rank, $ranks)) {
            // switch the rankings here...
            $index = array_search($new_rank, $ranks);
            $replaced_pri_id = $ids[$index];
            $stmt = "UPDATE
                        " . APP_DEFAULT_DB . "." . 
APP_TABLE_PREFIX . "project_priority
                     SET
                        pri_rank=" . Misc::escapeInteger($ranking[$pri_id]) . "
                     WHERE
+                        pri_prj_id=" . Misc::escapeInteger($prj_id) . "
+                     AND
                        pri_id=" . Misc::escapeInteger($replaced_pri_id);
            $GLOBALS["db_api"]->dbh->query($stmt);
        }
        $stmt = "UPDATE
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority
                 SET
                    pri_rank=" . Misc::escapeInteger($new_rank) . "
                 WHERE
+                        pri_prj_id=" . Misc::escapeInteger($prj_id) . "
+                     AND
                    pri_id=" . Misc::escapeInteger($pri_id);
        $GLOBALS["db_api"]->dbh->query($stmt);
        return true;
    }


    /**
     * Returns an associative array with the list of reminder IDs and
     * their respective ranking.
     *
     * @access  private
+     * @param   integer $prj_id The project ID
     * @return  array The list of reminders
     */
    function _getRanking($prj_id)
    {
        $stmt = "SELECT
                    pri_id,
                    pri_rank
                 FROM
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority
+                 WHERE
+                    pri_prj_id=" . Misc::escapeInteger($prj_id) . " 
                 ORDER BY
                    pri_rank ASC";
        $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
        if (PEAR::isError($res)) {
            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo
()), __FILE__, __LINE__);
            return array();
        } else {
            return $res;
        }
    }


Thread
Bug Fix - Add / Edit Prioritieslindleysmith11 Jul