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