Changeset 1114


Ignore:
Timestamp:
03/20/10 16:19:40 (2 years ago)
Author:
wefgef
Message:

Added new rating count column in round tasks table.

  • Added a new security action.
  • Added a new select statement to get the tasks rating count.
  • Added a new column in the Tasks macro.

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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/db/round.php

    r1110 r1114  
    104104// 
    105105// if user_id is non-null a join is done on $score 
    106 function round_get_tasks($round_id, $first = 0, $count = null, $user_id = null, $fetch_scores = false, $filter = null) { 
     106function round_get_tasks($round_id, $first = 0, $count = null, 
     107                         $user_id = null, $fetch_scores = false, 
     108                         $filter = null, $progress = false) { 
    107109    if ($count === null) { 
    108110        $count = 666013; 
     
    141143                         db_escape($first), db_escape($count)); 
    142144    } 
    143     return db_fetch_all($query); 
     145 
     146    $res = db_fetch_all($query); 
     147 
     148    if ($progress) { 
     149        $task_ids = array(); 
     150        foreach ($res as $row) { 
     151            $task_ids[] = $row['id']; 
     152        } 
     153 
     154        $query_ratings = sprintf( 
     155              "SELECT task_ratings.task_id AS id, count(*) AS rating_count 
     156               FROM ia_task_ratings AS task_ratings 
     157               WHERE task_ratings.task_id IN (%s) 
     158               GROUP BY id", 
     159               implode(',', array_map('db_quote', $task_ids)) 
     160        ); 
     161 
     162        $res_ratings = db_fetch_all($query_ratings); 
     163 
     164        $rating_count = array(); 
     165        foreach ($res_ratings as $res_rating) { 
     166            $rating_count[$res_rating['id']] = $res_rating['rating_count']; 
     167        } 
     168 
     169        foreach ($res as &$row) { 
     170            $row['progress'] = getattr($rating_count, $row['id']); 
     171        } 
     172    } 
     173 
     174    return $res; 
    144175} 
    145176 
  • trunk/common/security.php

    r1111 r1114  
    147147        case 'task-edit-ratings': 
    148148        case 'round-tag': 
     149        case 'round-view-progress': 
    149150        case 'textblock-tag': 
    150151        case 'job-reeval': 
  • trunk/www/macros/macro_tasks.php

    r1110 r1114  
    1313    } else { 
    1414        return round($val); 
     15    } 
     16} 
     17 
     18function format_progress_column($val) { 
     19    if (is_null($val)) { 
     20        return 'N/A'; 
     21    } else { 
     22        return $val; 
    1523    } 
    1624} 
     
    127135    $show_sources = getattr($args, 'show_sources', true); 
    128136 
     137    $show_progress = getattr($args, 'show_progress', false) && 
     138                     identity_can("round-view-progress", $round); 
     139 
    129140    // get round tasks 
    130141    $tasks = round_get_tasks($round_id, 
     
    132143             $options['display_entries'], 
    133144             $user_id, $scores, 
    134              $filter); 
     145             $filter, $show_progress); 
    135146    $options['total_entries'] = round_get_task_count( 
    136147             $round_id, $user_id, $filter); 
     
    174185        ); 
    175186    } 
     187    if ($show_progress) { 
     188        $column_infos[] = array ( 
     189                'title' => 'Note', 
     190                'css_class' => 'number', 
     191                'key' => 'progress', 
     192                'valform' => 'format_progress_column', 
     193        ); 
     194    } 
    176195 
    177196    return $tabs.format_table($tasks, $column_infos, $options); 
Note: See TracChangeset for help on using the changeset viewer.