Changeset 1094


Ignore:
Timestamp:
12/24/09 00:13:34 (2 years ago)
Author:
bogdan2412
Message:

Show author tags to user.

Removes author column from ia_task and shows cached tags insteads. Also adds a stub url_task_search function used for all tags.
Also fixes the bad user caching. :)

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

Location:
trunk
Files:
11 edited

Legend:

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

    r1010 r1094  
    8484              "task.`order` AS `order`, ". 
    8585              "task.`title` AS `title`, ". 
    86               "task.`author` AS `author`, ". 
    8786              "task.`page_name` AS `page_name`, ". 
    8887              "task.`source` AS `source`, ". 
  • trunk/common/db/user.php

    r1091 r1094  
    1616        log_assert_valid(user_validate($user)); 
    1717        mem_cache_set("user-by-name:{$user['username']}", $user); 
    18         mem_cache_set("user-by-id:{$user['username']}", $user); 
     18        mem_cache_set("user-by-id:{$user['id']}", $user); 
    1919    } 
    2020    return $user; 
     
    2525    log_assert_valid(user_validate($user)); 
    2626    mem_cache_delete("user-by-name:{$user['username']}"); 
    27     mem_cache_delete("user-by-id:{$user['username']}"); 
     27    mem_cache_delete("user-by-id:{$user['id']}"); 
    2828} 
    2929 
  • trunk/common/task.php

    r1081 r1094  
    5454    // User stuff. ugly 
    5555    if (is_null($user)) { 
    56         $task['author'] = 'Unknown'; 
    5756        $task['user_id'] = 0; 
    5857    } else { 
    59         $task['author'] = $user['full_name']; 
    6058        $task['user_id'] = $user['id']; 
    6159    } 
  • trunk/scripts/benchmark

    r1001 r1094  
    88// URLs to benchmark 
    99$benchmark_urls = array( 
     10    IA_URL . "arhiva", 
    1011    IA_URL . "utilizator/domino?action=download&file=avatar&resize=L32x32", 
    1112    IA_URL . "template/preoni-2006?action=download&file=hlogo.gif", 
  • trunk/scripts/migrate-authors-to-task-tags

    r1085 r1094  
    109109} 
    110110 
     111db_query("ALTER TABLE ia_task DROP COLUMN author"); 
     112 
    111113?> 
  • trunk/www/controllers/task.php

    r1089 r1094  
    145145        if (!$errors) { 
    146146            // FIXME: error handling? Is that even remotely possible in php? 
     147            task_update($new_task); 
    147148            task_update_parameters($task_id, $new_task_params); 
    148149 
     
    159160                } 
    160161            } 
    161             $new_task["author"] = tag_build_list("task", $new_task["id"], "author"); 
    162             task_update($new_task); 
     162            mem_cache_delete("task-authors-by-id:".$new_task["id"]); 
    163163 
    164164            flash("Task-ul a fost modificat cu succes."); 
  • trunk/www/controllers/task_tags.php

    r1085 r1094  
    114114 
    115115    $tag["name"] = $new_name; 
     116    // Check that the new tag doesn't already exist. 
    116117    if (tag_get_id($tag)) { 
    117118        flash_error("Tagul deja exista."); 
     
    119120    } 
    120121    tag_update_by_id($tag_id, $tag); 
     122    // Clear author cache for all tasks tagged with the tag. 
     123    if ($tag["type"] == "author") { 
     124        $task_ids = tag_get_objects("task", array($tag_id), false); 
     125        foreach ($task_ids as $task_id) { 
     126            mem_cache_delete("task-authors-by-id:".$task_id["id"]); 
     127        } 
     128    } 
     129 
    121130    flash("Tag-ul a fost redenumit."); 
    122131    redirect(url_task_tags()); 
  • trunk/www/macros/macro_taskparam.php

    r996 r1094  
    33require_once(IA_ROOT_DIR . "common/db/task.php"); 
    44require_once(IA_ROOT_DIR . "common/db/user.php"); 
    5 require_once(IA_ROOT_DIR."www/format/format.php"); 
     5require_once(IA_ROOT_DIR . "common/db/tags.php"); 
     6require_once(IA_ROOT_DIR . "common/cache.php"); 
     7require_once(IA_ROOT_DIR . "www/format/format.php"); 
    68 
    79// Displays a task field, be it a hard-coded field such as task author or a grader parameter such as `timelimit`. 
     
    3537 
    3638    $task = task_get($task_id); 
    37     if ($task) { 
    38         $params = task_get_parameters($task_id); 
    39     } 
    4039 
    4140    // validate task id 
     
    5352 
    5453        case 'author': 
    55             return html_escape($task['author']); 
     54            $authors = mem_cache_get("task-authors-by-id:".$task["id"]); 
     55            if ($authors === false) { 
     56                $authors = tag_get("task", $task["id"], "author"); 
     57                mem_cache_set("task-authors-by-id:".$task["id"], $authors); 
     58            } 
     59            function format_author($tag) { 
     60                return format_link(url_task_search(array($tag["id"])), $tag["name"]); 
     61            } 
     62            return implode(", ", array_map('format_author', $authors)); 
    5663 
    5764        case 'source': 
     65            // TODO: This should also be converted into tags. 
    5866            return html_escape($task['source']); 
    5967 
     
    8088 
    8189        default: 
     90            $params = task_get_parameters($task_id); 
    8291            if (!isset($params[$param])) { 
    8392                if (isset($args['default_value'])) { 
  • trunk/www/macros/macro_tasks.php

    r937 r1094  
    2323    } 
    2424    return $title; 
     25} 
     26 
     27function format_single_author($tag) { 
     28    return format_link(url_task_search(array($tag["id"])), $tag["name"]); 
     29} 
     30function format_author($row) { 
     31    $authors = mem_cache_get("task-authors-by-id:".$row["id"]); 
     32    if ($authors === false) { 
     33        $authors = tag_get("task", $row["id"], "author"); 
     34        mem_cache_set("task-authors-by-id:".$row["id"], $authors); 
     35    } 
     36    return implode(", ", array_map('format_single_author', $authors)); 
    2537} 
    2638 
     
    146158                'title' => 'Autor', 
    147159                'css_class' => 'author', 
    148                 'key' => 'author', 
     160                'rowform' => 'format_author', 
    149161        ); 
    150162    } 
  • trunk/www/url.php

    r1086 r1094  
    266266} 
    267267 
     268function url_task_search($tag_ids) { 
     269    // STUB 
     270    return "#" . implode("#", array_map('html_escape', $tag_ids)); 
     271} 
     272 
    268273function url_task_list($page_name, $filter = null) { 
    269274    $args = $filter ? array('filtru' => $filter) : array(); 
  • trunk/www/views/task_tags.php

    r1085 r1094  
    1414        ), 
    1515        $row["name"], "Redenumește"); 
    16     $tag .= ' <a class="algorithm_tag" href="#">' . html_escape($row["name"]) . '</a>'; 
     16    $tag .= ' '.format_link( 
     17        url_task_search(array($row["id"])), $row["name"], true, 
     18        array("class" => "algorithm_tag") 
     19    ); 
    1720    return $tag; 
    1821} 
Note: See TracChangeset for help on using the changeset viewer.