]> git.pld-linux.org Git - packages/eventum.git/blob - eventum-order.patch
- merge to HEAD from iss_sort branch
[packages/eventum.git] / eventum-order.patch
1 --- eventum-1.7.0/include/class.display_column.php      2005-12-29 21:27:24.000000000 +0200
2 +++ eventum/include/class.display_column.php    2006-03-22 18:03:06.000000000 +0200
3 @@ -223,6 +223,9 @@
4                  ),
5                  "iss_expected_resolution_date"  =>  array(
6                      "title" =>  "Expected Resolution Date"
7 +                ),
8 +                "isu_order" => array(
9 +                    "title" => "Order"
10                  )
11              )
12          );
13 --- eventum-1.7.0/include/class.issue.php       2005-12-29 21:27:25.000000000 +0200
14 +++ eventum/include/class.issue.php     2006-03-27 15:33:02.000000000 +0300
15 @@ -421,7 +421,7 @@
16              Reminder_Action::clearLastTriggered($issue_id);
17  
18              // if old status was closed and new status is not, clear closed data from issue.
19 -            if ($old_details['sta_is_closed'] == 1) {
20 +            if (@$old_details['sta_is_closed'] == 1) {
21                  $new_details = Status::getDetails($status_id);
22                  if ($new_details['sta_is_closed'] != 1) {
23                      Issue::clearClosed($issue_id);
24 @@ -1245,6 +1245,7 @@
25              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
26              return -1;
27          } else {
28 +            Issue::moveOrderForAllUsers($issue_id, 1000);
29              $prj_id = Issue::getProjectID($issue_id);
30  
31              // add note with the reason to close the issue
32 @@ -1349,7 +1350,6 @@
33                      $assignment_notifications[] = $assignee;
34                      $assignments_changed = true;
35                  }
36 -                $assignments_changed = true;
37              }
38              if (count($assignment_notifications) > 0) {
39                  Notification::notifyNewAssignment($assignment_notifications, $issue_id);
40 @@ -1596,16 +1596,33 @@
41      {
42          $issue_id = Misc::escapeInteger($issue_id);
43          $assignee_usr_id = Misc::escapeInteger($assignee_usr_id);
44 +        $order = 1;
45 +        // move all orders down to free "order space" for this new association
46 +        $stmt = "UPDATE 
47 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
48 +                 SET
49 +                    isu_order = isu_order + 1
50 +                 WHERE
51 +                    isu_usr_id = $assignee_usr_id AND
52 +                    isu_order >= $order";
53 +        $res = $GLOBALS["db_api"]->dbh->query($stmt);
54 +        if (PEAR::isError($res)) {
55 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
56 +            return -1;
57 +        }
58 +        // insert the new association
59          $stmt = "INSERT INTO
60                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
61                   (
62                      isu_iss_id,
63                      isu_usr_id,
64 -                    isu_assigned_date
65 +                    isu_assigned_date,
66 +                    isu_order
67                   ) VALUES (
68                      $issue_id,
69                      $assignee_usr_id,
70 -                    '" . Date_API::getCurrentDateGMT() . "'
71 +                    '" . Date_API::getCurrentDateGMT() . "',
72 +                    $order
73                   )";
74          $res = $GLOBALS["db_api"]->dbh->query($stmt);
75          if (PEAR::isError($res)) {
76 @@ -1620,6 +1637,78 @@
77          }
78      }
79  
80 +    /**
81 +     * Method used to get the order list to be rearranged
82 +     * 
83 +     * @access  private
84 +     * @param   string $issue_id The issue ID or a comma seperated list of IDs already prepared for giving to mysql
85 +     * @param   string $usr_id The user to remove. When not specified, all users are taken as to be removed for that issue
86 +     * @return  mixed delete order list to be rearranged. Used as a parameter to the method of rearranging the order.
87 +     */
88 +    function getDeleteUserAssociationOrderList($issue_id, $usr_id = "")
89 +    {
90 +        // find all affected associantion orders
91 +        $stmt = "SELECT isu_usr_id, isu_order FROM
92 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
93 +                 WHERE
94 +                 isu_iss_id IN ($issue_id)";
95 +        if ($usr_id !== FALSE) {
96 +            $stmt.= " AND isu_usr_id IN ($usr_id)";
97 +        }
98 +        $stmt.= "ORDER BY isu_order";
99 +        $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
100 +        if (PEAR::isError($res)) {
101 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
102 +            return -1;
103 +        } else {
104 +            $deleted_orders = array();
105 +            foreach ($res as $row) {
106 +                if (empty($deleted_orders[$row['isu_usr_id']])) {
107 +                    $deleted_orders[$row['isu_usr_id']] = array();
108 +                }
109 +                $deleted_orders[$row['isu_usr_id']] [] = $row['isu_order'];
110 +            }
111 +            return $deleted_orders;
112 +        }
113 +    }
114 +
115 +    /**
116 +     *
117 +     * Method used to rearrange order list in the db according to known deleted records
118 +     *
119 +     * @access  private
120 +     * @param   mixed  deleteorder list
121 +     * @return void
122 +     */
123 +    function rearrangeDeleteUserAssociationOrderList($delete_order_list)
124 +    {
125 +        if (empty($delete_order_list) || (!is_array($delete_order_list))) {
126 +            return -1;
127 +        }
128 +        foreach ($delete_order_list as $isu_usr_id => $orders) {
129 +            for ($i = 0; $i < count($orders); $i++) { // traverse all deleted orders
130 +                // move the orders after them up to take the "order space" of the deleted records
131 +                $stmt = "UPDATE
132 +                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
133 +                         SET
134 +                            isu_order = isu_order - " . ($i+1) . "
135 +                         WHERE
136 +                            isu_usr_id = $isu_usr_id AND
137 +                            isu_order > " . $orders[$i];
138 +                if ($i < count($orders) - 1) {
139 +                    $stmt.=  " AND
140 +                            isu_order < " . $orders[$i+1];
141 +                }
142 +                $res = $GLOBALS["db_api"]->dbh->query($stmt);
143 +                if (PEAR::isError($res)) {
144 +                    Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
145 +                    return -1;
146 +                }
147 +            }
148 +        }
149 +        return 1;
150 +    }
151 +
152  
153      /**
154       * Method used to delete all user assignments for a specific issue.
155 @@ -1635,6 +1724,7 @@
156          if (is_array($issue_id)) {
157              $issue_id = implode(", ", $issue_id);
158          }
159 +        $deleted_order_list = Issue::getDeleteUserAssociationOrderList($issue_id);
160          $stmt = "DELETE FROM
161                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
162                   WHERE
163 @@ -1647,6 +1737,7 @@
164              if ($usr_id) {
165                  History::add($issue_id, $usr_id, History::getTypeID('user_all_unassociated'), 'Issue assignments removed by ' . User::getFullName($usr_id));
166              }
167 +            Issue::rearrangeDeleteUserAsssociationOrderList($deleted_order_list);
168              return 1;
169          }
170      }
171 @@ -1665,6 +1756,7 @@
172      {
173          $issue_id = Misc::escapeInteger($issue_id);
174          $usr_id = Misc::escapeInteger($usr_id);
175 +        $delete_order_list = Issue::getDeleteUserAssociationOrderList($issue_id, $usr_id);
176          $stmt = "DELETE FROM
177                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
178                   WHERE
179 @@ -1679,6 +1771,7 @@
180                  History::add($issue_id, Auth::getUserID(), History::getTypeID('user_unassociated'),
181                      User::getFullName($usr_id) . ' removed from issue by ' . User::getFullName(Auth::getUserID()));
182              }
183 +            Issue::rearrangeDeleteUserAssociationOrderList($delete_order_list);
184              return 1;
185          }
186      }
187 @@ -2047,14 +2140,6 @@
188                      }
189                  }
190              }
191 -            if (count($users) > 0) {
192 -                // automatically change the status to 'Assigned'
193 -                Issue::setStatus($new_issue_id, Status::getStatusID('Assigned'), FALSE);
194 -
195 -                // set this special variable to false, to avoid triggering
196 -                // another status update on the workflow class
197 -                $has_assignee = false;
198 -            }
199  
200              // now process any files being uploaded
201              $found = 0;
202 @@ -2161,6 +2246,11 @@
203      {
204          $sort_by = Issue::getParam('sort_by');
205          $sort_order = Issue::getParam('sort_order');
206 +        $users = Issue::getParam('users');
207 +        if (empty($users) && ($sort_by == 'isu_order')) { // Sorting by isu_order is impossible when no user specified
208 +            unset($sort_by);
209 +            unset($sort_order);
210 +        }
211          $rows = Issue::getParam('rows');
212          $hide_closed = Issue::getParam('hide_closed');
213          if ($hide_closed === '') {
214 @@ -2261,7 +2351,8 @@
215              "iss_summary",
216              "last_action_date",
217              "usr_full_name",
218 -            "iss_expected_resolution_date"
219 +            "iss_expected_resolution_date",
220 +            "isu_order"
221          );
222          $items = array(
223              "links"  => array(),
224 @@ -2975,6 +3066,8 @@
225          $ids = implode(", ", $ids);
226          $stmt = "SELECT
227                      isu_iss_id,
228 +                    isu_order,
229 +                    isu_usr_id,
230                      usr_full_name
231                   FROM
232                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,
233 @@ -2986,6 +3079,7 @@
234          if (PEAR::isError($res)) {
235              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
236          } else {
237 +            // gather names of the users assigned to each issue
238              $t = array();
239              for ($i = 0; $i < count($res); $i++) {
240                  if (!empty($t[$res[$i]['isu_iss_id']])) {
241 @@ -2994,9 +3088,18 @@
242                      $t[$res[$i]['isu_iss_id']] = $res[$i]['usr_full_name'];
243                  }
244              }
245 +            // gather orders
246 +            $o = array();
247 +            for ($i = 0; $i < count($res); $i++) {
248 +                if (empty($o[$res[$i]['isu_iss_id']])) {
249 +                    $o[$res[$i]['isu_iss_id']] = array();
250 +                }
251 +                $o[$res[$i]['isu_iss_id']][$res[$i]['isu_usr_id']] = $res[$i]['isu_order'];
252 +            }
253              // now populate the $result variable again
254              for ($i = 0; $i < count($result); $i++) {
255                  @$result[$i]['assigned_users'] = $t[$result[$i]['iss_id']];
256 +                @$result[$i]['assigned_users_order'] = $o[$result[$i]['iss_id']];
257              }
258          }
259      }
260 @@ -3963,6 +4066,7 @@
261              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
262              return -1;
263          }
264 +        Issue::moveOrderForAllUsers($issue_id, 1);
265      }
266  
267  
268 @@ -4021,8 +4125,91 @@
269          }
270          return $returns[$msg_id];
271      }
272 +
273 +    /**
274 +     * Reorders user's issues as requested by user
275 +     * @access public
276 +     * @param $usr_id User to be reordered
277 +     * @param $issue_id Issue or array of issues to be moved
278 +     * @param $neworder The new order of the issues
279 +     * @return void
280 +     */
281 +    function reorderUserIssues($usr_id, $issue_id, $neworder)
282 +    {
283 +        if (!isset($usr_id) || !isset($issue_id) || !isset($neworder)) {
284 +            return false;
285 +        }
286 +        if (!is_numeric($usr_id) || !is_numeric($neworder)) {
287 +            return false;
288 +        }
289 +        $usr_id = Misc::escapeInteger($usr_id);
290 +        $issue_id = Misc::escapeInteger($issue_id);
291 +        $neworder = Misc::escapeInteger($neworder);
292 +        if (is_array($issue_id)) {
293 +            $issue_count = count($issue_id);
294 +            $issue_id_str = implode(", ", $issue_id);
295 +        } else {
296 +            $issue_count = 1;
297 +            $issue_id_str = $issue_id;
298 +            $issue_id = array($issue_id);
299 +        }
300 +        // do a nasty pretending to be deleting stuff so that reordering happens as if these elements were deleted
301 +        $orderlist = Issue::getDeleteUserAssociationOrderList($issue_id_str, $usr_id);
302 +        Issue::rearrangeDeleteUserAssociationOrderList($orderlist);
303 +        // move down the orders to free the "order space" needed
304 +        $stmt = "UPDATE 
305 +                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
306 +                 SET
307 +                    isu_order = isu_order + $issue_count
308 +                 WHERE
309 +                    isu_usr_id = $usr_id AND
310 +                    isu_order >= $neworder";
311 +        $res = $GLOBALS["db_api"]->dbh->query($stmt);
312 +        if (PEAR::isError($res)) {
313 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
314 +            return -1;
315 +        }
316 +        //update the order for the issues being moved
317 +        $i = 0;
318 +        foreach ($issue_id as $iss_id) {
319 +            $stmt = "UPDATE
320 +                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
321 +                     SET
322 +                        isu_order = " . ($neworder + $i) . "
323 +                     WHERE
324 +                        isu_usr_id = $usr_id AND
325 +                        isu_iss_id = $iss_id";
326 +            $res = $GLOBALS["db_api"]->dbh->query($stmt);
327 +            if (PEAR::isError($res)) {
328 +                Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
329 +                return -1;
330 +            }
331 +            $i++;
332 +        }
333 +    }
334 +
335 +    function moveOrderForAllUsers($issue_id, $neworder)
336 +    {
337 +        // Move the issue to the top priority for the ppl it's assigned to
338 +        $stmt = "SELECT isu_usr_id FROM
339 +                    "  . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
340 +                 WHERE
341 +                    isu_iss_id = " . Misc::escapeInteger($issue_id);
342 +        $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
343 +        if (PEAR::isError($res)) {
344 +            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
345 +            return -1;
346 +        }
347 +        foreach ($res as $row) {
348 +            Issue::reorderUserIssues($row["isu_usr_id"], $issue_id, $neworder);
349 +        }
350 +    }
351 +    
352  }
353  
354 +
355 +
356 +
357  // benchmarking the included file (aka setup time)
358  if (APP_BENCHMARK) {
359      $GLOBALS['bench']->setMarker('Included Issue Class');
360 diff -ru eventum-1.7.0/list.php eventum/list.php
361 --- eventum-1.7.0/list.php      2005-12-29 21:27:24.000000000 +0200
362 +++ eventum/list.php    2006-03-30 14:57:06.000000000 +0300
363 @@ -67,6 +67,11 @@
364              $profile['sort_by'] . "&sort_order=" . $profile['sort_order']);
365  }
366  
367 +@$reorder_usr_id = $_REQUEST["reorder_user"];
368 +@$reorder_issue_id = $_REQUEST["reorder_source"];
369 +@$reorder_neworder = $_REQUEST["reorder_neworder"];
370 +Issue::reorderUserIssues($reorder_usr_id, $reorder_issue_id, $reorder_neworder);
371 +
372  $options = Issue::saveSearchParams();
373  $tpl->assign("options", $options);
374  $tpl->assign("sorting", Issue::getSortingInfo($options));
375 @@ -104,6 +109,21 @@
376      }
377  }
378  
379 +// get the isu_order (assignated users) ordering user
380 +if (!empty($options["users"])) {
381 +    if ($options["users"] == -2) {
382 +        $isu_order_user = $usr_id;
383 +    } else
384 +    if ($options["users"] > 0) {
385 +        $isu_order_user = $options["users"];
386 +    } else {
387 +        unset($isu_order_user);
388 +    }
389 +} else {
390 +    unset($isu_order_user);
391 +}
392 +$tpl->assign("isu_order_user", $isu_order_user);
393 +
394  $list = Issue::getListing($prj_id, $options, $pagerRow, $rows);
395  $tpl->assign("list", $list["list"]);
396  $tpl->assign("list_info", $list["info"]);
397 @@ -130,4 +150,4 @@
398  $tpl->assign("refresh_page", "list.php");
399  
400  $tpl->displayTemplate();
401 -?>
402 \ No newline at end of file
403 +?>
404 diff -ru eventum-1.7.0/templates/en/list.tpl.html eventum/templates/en/list.tpl.html
405 --- eventum-1.7.0/templates/en/list.tpl.html    2005-12-29 21:27:24.000000000 +0200
406 +++ eventum/templates/en/list.tpl.html  2006-03-23 16:28:30.000000000 +0200
407 @@ -89,6 +89,28 @@
408      f.target = '_popup';
409      f.submit();
410  }
411 +function reorderBulk(order_user, neworder)
412 +{
413 +    url = page_url + "?";
414 +    url += "reorder_user=" + order_user;
415 +       
416 +    items = document.getElementsByName("item[]");
417 +    checkedcount = 0;
418 +    for (var i = 0; i < items.length; i++) {
419 +       if (items[i].checked) {
420 +           url += "&reorder_source[" + checkedcount + "]=" + items[i].value;
421 +           checkedcount++;
422 +       }
423 +    }
424 +    if (checkedcount == 0) {
425 +        alert('Please choose which issues to move to the new palce.');
426 +        return false;
427 +    }
428 +
429 +    url += "&reorder_neworder=" + neworder;
430 +    
431 +    window.location.href = url;
432 +}
433  function hideClosed(f)
434  {
435      if (f.hide_closed.checked) {
436 @@ -202,8 +224,8 @@
437                  <td align="{$column.align|default:'center'}" class="default_white" nowrap>
438                    {$fld_title|escape:"html"}
439                  </td>
440 -              {/foreach}
441 -          {else}
442 +           {/foreach}
443 +          {elseif $field_name != 'isu_order' || $isu_order_user}
444            <td align="{$column.align|default:'center'}" class="default_white" nowrap {if $column.width != ''}width="{$column.width}"{/if}>
445              {if $field_name == 'iss_summary'}
446              <table cellspacing="0" cellpadding="1" width="100%">
447 @@ -218,8 +240,11 @@
448                </tr>
449              </table>
450              {elseif $sorting.links[$field_name] != ''}
451 -              <a title="sort by {$column.title}" href="{$sorting.links[$field_name]}" class="white_link">{$column.title}</a>
452 -              {if $sorting.images[$field_name] != ""}<a title="sort by {$column.title}" href="{$sorting.links[$field_name]}" class="white_link"><img border="0" src="{$sorting.images[$field_name]}"></a>{/if}
453 +           <a title="sort by {$column.title}" href="{$sorting.links[$field_name]}" class="white_link">{$column.title}</a>
454 +           {if $field_name == 'isu_order'}
455 +             <br>{$users[$isu_order_user]}
456 +           {/if}
457 +            {if $sorting.images[$field_name] != ""}<a title="sort by {$column.title}" href="{$sorting.links[$field_name]}" class="white_link"><img border="0" src="{$sorting.images[$field_name]}"></a>{/if}
458              {else}
459                {$column.title}
460              {/if}
461 @@ -239,7 +264,7 @@
462                    {$fld_value|formatCustomValue:$fld_id:$list[i].iss_id}
463                  </td>
464                {/foreach}
465 -          {else}
466 +          {elseif $field_name != 'isu_order' || $isu_order_user}
467            <td bgcolor="{$list[i].status_color}" align="{$column.align|default:'center'}" class="default">
468              {if $field_name == 'iss_id'}
469                <a href="view.php?id={$list[i].iss_id}" class="link" title="view issue details">{$list[i].iss_id}</a>
470 @@ -278,7 +303,24 @@
471                {/if}
472                {if $list[i].iss_private == 1}
473                    <b>[Private]</b>
474 -              {/if}
475 +             {/if}
476 +           {elseif $field_name == 'isu_order'}
477 +             {if $isu_order_user}
478 +               {assign var="order" value=$list[i].assigned_users_order[$isu_order_user]}
479 +               {if $order}
480 +               <a class="link" title="hide / show reordering options" href="javascript:void(null);" onClick="javascript:toggleVisibility('order{$list[i].iss_id}_');">{$order}</a>
481 +               <div id="order{$list[i].iss_id}_1" style="display: none">
482 +                 <table>
483 +                    <tr>
484 +                     <td class="default">{if $order > 1}<a class="link" title="move up" href="list.php?reorder_user={$isu_order_user}&reorder_source[0]={$list[i].iss_id}&reorder_neworder={math equation="x - 1" x=$order}">Up</a>{/if}</td>
485 +                     <td class="default"><a class="link" title="move up" href="list.php?reorder_user={$isu_order_user}&reorder_source[0]={$list[i].iss_id}&reorder_neworder={math equation="x + 1" x=$order}">Down</a></td>
486 +                   </tr>
487 +                   <tr>
488 +                      <td class="default"><a class="link" title="move here" href="javascript:void(null);" onClick="javascript:reorderBulk({$isu_order_user}, {$order})">Move here</a></td>
489 +                   </tr>
490 +                 </table>
491 +               {/if}
492 +             {/if}
493              {/if}
494            </td>
495            {/if}
496 @@ -348,4 +390,4 @@
497  <br />
498  
499  {include file="app_info.tpl.html"}
500 -{include file="footer.tpl.html"}
501 \ No newline at end of file
502 +{include file="footer.tpl.html"}
503
504
505 --- /dev/null   2006-03-28 14:00:37.000000000 +0300
506 +++ ./order_patch-patch.sql     2008-08-27 17:16:21.444016830 +0300
507 @@ -0,0 +1,3 @@
508 +ALTER TABLE eventum_issue_user
509 +    ADD isu_order int(11) NOT NULL DEFAULT '0' AFTER isu_assigned_date,
510 +    ADD INDEX isu_order (isu_order);
This page took 0.064889 seconds and 4 git commands to generate.