| Revision 1132,
1.3 KB
checked in by bogdan2412, 2 years ago
(diff) |
|
Merge branch taskreordering into trunk.
|
| Line | |
|---|
| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | require_once(IA_ROOT_DIR."common/db/db.php"); |
|---|
| 4 | require_once(IA_ROOT_DIR."common/db/task.php"); |
|---|
| 5 | |
|---|
| 6 | // Updates the `order_id` for a (round, task) pair. |
|---|
| 7 | function round_task_update_order_id($round_id, $task_id, $order_id) { |
|---|
| 8 | $query = sprintf( |
|---|
| 9 | "UPDATE ia_round_task |
|---|
| 10 | SET order_id = %s |
|---|
| 11 | WHERE round_id = %s AND task_id = %s", |
|---|
| 12 | db_quote($order_id), db_quote($round_id), db_quote($task_id)); |
|---|
| 13 | |
|---|
| 14 | db_query($query); |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | // Preserve consecutive numbers for `order_id` |
|---|
| 18 | function round_task_recompute_order($round_id) { |
|---|
| 19 | $query = "SELECT task_id, order_id FROM ia_round_task |
|---|
| 20 | WHERE round_id = " . db_quote($round_id) . |
|---|
| 21 | "ORDER BY order_id"; |
|---|
| 22 | $res = db_fetch_all($query); |
|---|
| 23 | |
|---|
| 24 | $order_id = 0; |
|---|
| 25 | foreach ($res as $row) { |
|---|
| 26 | $order_id += 1; |
|---|
| 27 | |
|---|
| 28 | if ($order_id != $row['order_id']) { |
|---|
| 29 | $query = sprintf( |
|---|
| 30 | "UPDATE ia_round_task |
|---|
| 31 | SET order_id = %s |
|---|
| 32 | WHERE round_id = %s AND task_id = %s", |
|---|
| 33 | db_quote($order_id), db_quote($round_id), |
|---|
| 34 | db_quote($row['task_id'])); |
|---|
| 35 | db_query($query); |
|---|
| 36 | |
|---|
| 37 | // update forum if necessary |
|---|
| 38 | if ($round_id == 'arhiva') { |
|---|
| 39 | task_update_forum_topic($row['task_id']); |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.