Changeset 1143


Ignore:
Timestamp:
04/27/10 00:06:59 (2 years ago)
Author:
wefgef
Message:

Adds two new params to TaskParams? macro.

Location:
trunk
Files:
2 edited

Legend:

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

    r1142 r1143  
    347347} 
    348348 
     349// Returns the score a user got on a task in the archive. 
     350// Optionally, a different round parameter can be specified. 
     351function task_get_user_score($task_id, $user_id, $round_id = 'arhiva') { 
     352    // Validate 
     353    if (!is_round_id($round_id)) { 
     354        log_error("Invalid round id"); 
     355    } 
     356    if (!is_task_id($task_id)) { 
     357        log_error("Invalid task id"); 
     358    } 
     359    if (!is_user_id($user_id)) { 
     360        log_error("Invalid user id"); 
     361    } 
     362 
     363    $query = sprintf( 
     364        "SELECT `score` FROM ia_score_user_round_task 
     365         WHERE round_id = %s AND task_id = %s AND user_id = %s", 
     366         db_quote($round_id), db_quote($task_id), db_quote($user_id)); 
     367    $res = db_fetch($query); 
     368 
     369    return getattr($res, "score", null); 
     370} 
     371 
    349372?> 
  • trunk/www/macros/macro_taskparam.php

    r1095 r1143  
    66require_once(IA_ROOT_DIR . "common/cache.php"); 
    77require_once(IA_ROOT_DIR . "www/format/format.php"); 
     8require_once(IA_ROOT_DIR . "www/macros/macro_stars.php"); 
    89 
    910// Displays a task field, be it a hard-coded field such as task author or a grader parameter such as `timelimit`. 
     
    8384                                    $user['rating_cache']); 
    8485 
     86        case 'difficulty': 
     87            if (is_null($task['rating'])) { 
     88                return 'N/A'; 
     89            } 
     90            $star_args = array('rating' => $task['rating'], 
     91                               'scale' => 5, 
     92                               'type' => 'normal'); 
     93            return macro_stars($star_args); 
     94 
     95        case 'archivescore': 
     96            $user = identity_get_user(); 
     97            if (is_null($user)) { 
     98                return 'N/A'; 
     99            } else { 
     100                $score = task_get_user_score($task['id'], $user['id']); 
     101                if (is_null($score)) { 
     102                    return 'N/A'; 
     103                } else { 
     104                    return intval($score) . " puncte"; 
     105                } 
     106            } 
     107 
    85108        default: 
    86109            $params = task_get_parameters($task_id); 
Note: See TracChangeset for help on using the changeset viewer.