source: trunk/common/db/task_rating.php @ 1184

Revision 1111, 1.9 KB checked in by wefgef, 2 years ago (diff)

Added task ratings functionality and changed the task edit related pages UI.

  • Replaced all the edit links in a task page with a single edit link.
  • All the task related edit pages are grouped together using tabs.
  • Created a task ratings page
  • Included a script to create/update necessary database tables.

REVIEW URL http://reviewboard.infoarena.ro/r/140/

Includes changes from http://reviewboard.infoarena.ro/r/137/

Line 
1<?php
2
3require_once(IA_ROOT_DIR."common/db/db.php");
4require_once(IA_ROOT_DIR."common/task_rating.php");
5
6function task_rating_get_all($task_id) {
7    $query = "SELECT user_id, idea, theory, coding FROM ia_task_ratings
8                WHERE task_id = " . db_quote($task_id);
9
10    $res = db_fetch_all($query);
11
12    return $res;
13}
14
15// Returns an array with ratings given by $user_id to $task_id
16function task_rating_get($task_id, $user_id) {
17    log_assert(is_task_id($task_id));
18    log_assert(is_user_id($user_id));
19
20    $query = sprintf("SELECT idea, theory, coding FROM ia_task_ratings
21                      WHERE task_id = %s AND user_id = %s",
22                      db_quote($task_id), db_quote($user_id));
23
24    $result = db_fetch($query);
25
26    if (!$result) {
27        $result = array(
28              'idea' => null,
29              'theory' => null,
30              'coding' => null,
31        );
32    }
33
34    return $result;
35}
36
37// Update the rating for task_id
38function task_rating_update($task_id) {
39    $res = task_rating_get_all($task_id);
40
41    $task_rating = task_rating_compute($res);
42
43    // Update the rating in db
44    $values = array(
45        'rating' => $task_rating
46    );
47    $where = "id = " . db_quote($task_id);
48
49    db_update('ia_task', $values, $where);
50}
51
52// Inserts new ratings for task_id by user user_id
53// ratings are specified in $ratings
54function task_rating_add($task_id, $user_id, $ratings) {
55    $values = array(
56        'task_id' => $task_id,
57        'user_id' => $user_id,
58        'idea' => $ratings['idea'],
59        'theory' => $ratings['theory'],
60        'coding' => $ratings['coding']
61    );
62
63    $where = "task_id = " . db_quote($task_id) . " AND user_id = " .
64                db_quote($user_id);
65
66
67    if (!db_query_value("SELECT COUNT(*) FROM ia_task_ratings WHERE $where")) {
68        db_insert('ia_task_ratings', $values);
69    } else {
70        db_update('ia_task_ratings', $values, $where);
71    }
72
73    task_rating_update($task_id);
74}
75
76?>
Note: See TracBrowser for help on using the repository browser.