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