Changeset 1095


Ignore:
Timestamp:
12/24/09 01:10:43 (2 years ago)
Author:
savin.tiberiu@…
Message:

Filter tasks by tag

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

Location:
trunk
Files:
1 added
8 edited

Legend:

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

    r1036 r1095  
    173173} 
    174174 
     175function task_get_authors($task_id, $no_cache = false) { 
     176    log_assert(is_task_id($task_id), 'Invalid task_id'); 
     177 
     178    $authors = false; 
     179    if (!$no_cache) { 
     180        $authors = mem_cache_get("task-authors-by-id:".$task_id); 
     181    } 
     182 
     183    if ($authors === false) { 
     184        $authors = tag_get("task", $task_id, "author"); 
     185        mem_cache_set("task-authors-by-id:".$task_id, $authors); 
     186    } 
     187 
     188    return $authors; 
     189} 
     190 
     191// Task filter 
     192// Returns only tasks that contain all the tags 
     193// and are in 'arhiva' or in 'arhiva-educationala' 
     194// Task from 'arhiva-educationala' are shown first 
     195function task_filter_by_tags($tag_ids, $scores = true, $user_id = null) { 
     196    log_assert(is_array($tag_ids), "tag_ids must be an array"); 
     197    foreach ($tag_ids as $tag_id) { 
     198        log_assert(is_tag_id($tag_id), "invalid tag id"); 
     199    } 
     200 
     201    if (count($tag_ids) > 0) { 
     202        $tag_filter = "AND ".tag_build_where('task', $tag_ids); 
     203    } else { 
     204        $tag_filter = ""; 
     205    } 
     206 
     207    if ($user_id == null || $scores == false) { 
     208        $join_score = ""; 
     209        $score_fields = ""; 
     210    } else { 
     211        $join_score = "LEFT JOIN ia_score ON ia_score.user_id = ".db_quote($user_id)." AND 
     212                            ia_score.round_id = round.id AND 
     213                            ia_score.task_id = ia_task.id AND 
     214                            ia_score.name = 'score'"; 
     215        $score_fields = "ia_score.score,"; 
     216    } 
     217 
     218    $query = "SELECT ia_task.id AS task_id, 
     219                ia_task.title AS task_title, 
     220                ia_task.order AS 'order', 
     221                ia_task.page_name AS page_name, 
     222                ia_task.open_source AS open_source, 
     223                ia_task.open_tests AS open_tests, 
     224                round.id AS round_id, 
     225                $score_fields 
     226                round.title AS round_title 
     227    FROM ia_task 
     228    LEFT JOIN ia_round_task AS round_task ON round_task.task_id = ia_task.id 
     229    LEFT JOIN ia_round AS round ON round.id = round_task.round_id 
     230    $join_score 
     231    WHERE (round.id = 'arhiva' OR round.id = 'arhiva-educationala') 
     232        AND ia_task.hidden = '0' $tag_filter 
     233    ORDER BY round.id DESC, ia_task.order"; 
     234    $tasks = db_fetch_all($query); 
     235 
     236    return $tasks; 
     237} 
    175238?> 
  • trunk/www/controllers/task.php

    r1094 r1095  
    330330} 
    331331 
     332// Gets a list of tags from request 
     333// Prints a list of tasks that contain all those tags 
     334// Tasks must be in 'arhiva' or in 'arhiva educationala' 
     335function controller_task_search() { 
     336    $tags = request('tag_id', null); 
     337    if (is_null($tags)) { 
     338        $tags = Array(); 
     339    } 
     340 
     341    if (!is_array($tags)) { 
     342        flash_error("Url invalid"); 
     343        redirect(url_home()); 
     344    } 
     345 
     346    foreach ($tags as $tag) { 
     347        if (!is_tag_id($tag)) { 
     348            flash_error("Url invalid"); 
     349            redirect(url_home()); 
     350        } 
     351    } 
     352 
     353    if (identity_is_anonymous()) { 
     354        $user_id = null; 
     355    } else { 
     356        $user_id = identity_get_user_id(); 
     357    } 
     358    $tasks = task_filter_by_tags($tags, true, $user_id); 
     359    foreach ($tasks as &$task) { 
     360        $task['authors'] = task_get_authors($task['task_id']); 
     361    } 
     362 
     363    $view['title'] = "Rezultatele filtrării"; 
     364    $view['tasks'] = $tasks; 
     365    execute_view_die('views/task_filter_results.php', $view); 
     366} 
     367 
    332368?> 
  • trunk/www/index.php

    r1086 r1095  
    8383} 
    8484 
     85// Task search 
     86else if ($page == 'cauta-probleme') { 
     87    require_once(IA_ROOT_DIR.'www/controllers/task.php'); 
     88    controller_task_search(); 
     89} 
     90 
    8591// Task detail editor 
    8692else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'problema') { 
  • trunk/www/macros/macro_algorithmtags.php

    r1093 r1095  
    5151        $subtags_html = Array(); 
    5252        foreach ($tag['sub_tags'] as $subtag) { 
    53             $subtags_html[] = '<div class="sub_tag_name">'.$subtag['name'].'</div>'; 
     53            $tag_link = format_link(url_task_search(array($tag_id)), $subtag['name'], true, 
     54                            array('class' => "sub_tag_search_anchor")); 
     55            $subtags_html[] = '<div class="sub_tag_name">'.$tag_link.'</div>'; 
    5456        } 
    5557 
    5658        $color_scheme = $tag_id % 6; 
     59        $tag_link = format_link(url_task_search(array($tag_id)), $tag_name, true, array('class' => 'tag_search_anchor')); 
    5760        $html_code .= ' 
    5861        <li style="display: none;" class="tags_list_item"> 
    59             <span class="tag_name color_scheme_'.$color_scheme.'">'.html_escape($tag_name).'</span> 
     62            <span class="tag_name color_scheme_'.$color_scheme.'">'.$tag_link.'</span> 
    6063            <a href="javascript:show_tag_list('.html_escape($tag_id).')" 
    6164                    id="tag_anchor_'.html_escape($tag_id).'" 
     
    6669            <div style="display: none;" 
    6770                id="tag_list_'.html_escape($tag_id).'" 
    68             >: 
    69                 '.implode(' ', $subtags_html).' 
     71            >&nbsp; 
     72                '.implode('&nbsp;', $subtags_html).' 
    7073            </div> 
    7174        </li>'; 
  • trunk/www/macros/macro_taskparam.php

    r1094 r1095  
    5252 
    5353        case '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             } 
     54            $authors = task_get_authors($task['id']); 
    5955            function format_author($tag) { 
    6056                return format_link(url_task_search(array($tag["id"])), $tag["name"]); 
  • trunk/www/macros/macro_tasks.php

    r1094 r1095  
    55require_once(IA_ROOT_DIR . "www/format/pager.php"); 
    66require_once(IA_ROOT_DIR . "common/db/round.php"); 
     7require_once(IA_ROOT_DIR . "common/db/task.php"); 
    78require_once(IA_ROOT_DIR . "common/round.php"); 
    89 
     
    2829    return format_link(url_task_search(array($tag["id"])), $tag["name"]); 
    2930} 
     31 
    3032function 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     } 
     33    $authors = task_get_authors($row['id']); 
    3634    return implode(", ", array_map('format_single_author', $authors)); 
    3735} 
  • trunk/www/static/css/sitewide.css

    r1089 r1095  
    310310} 
    311311 
     312a.sub_tag_search_anchor { 
     313    color: #000000; 
     314    outline-style: none; 
     315} 
     316 
     317a.sub_tag_search_anchor:hover { 
     318    text-decoration: none; 
     319} 
     320 
     321a.tag_search_anchor { 
     322    color: #FFF0E1; 
     323    outline-style: none; 
     324} 
     325 
     326a.tag_search_anchor:hover { 
     327    text-decoration: none; 
     328} 
     329 
    312330.tag_name.color_scheme_0 { 
    313331    background-color: rgb(204, 0, 0); 
     
    337355    font-size: 10px; 
    338356} 
     357 
     358table.filter_results { 
     359    width: 99%; 
     360} 
  • trunk/www/url.php

    r1094 r1095  
    5252        } 
    5353        if ($k != 'page') { 
    54             $url .= ($first ? "?" : "&"); 
    55             $first = false; 
    56             $url .= $k . '=' . urlencode($v); 
     54            if (is_array($v)) { 
     55                foreach ($v as $sv) { 
     56                    $url .= ($first ? "?" : "&"); 
     57                    $first = false; 
     58                    $url .= $k. '[]=' . urlencode($sv); 
     59                } 
     60            } else { 
     61                $url .= ($first ? "?" : "&"); 
     62                $first = false; 
     63                $url .= $k . '=' . urlencode($v); 
     64            } 
    5765        } 
    5866    } 
    59  
    6067    return $url; 
    6168} 
     
    267274 
    268275function url_task_search($tag_ids) { 
    269     // STUB 
    270     return "#" . implode("#", array_map('html_escape', $tag_ids)); 
     276    log_assert(is_array($tag_ids), "Tag ids must be an array"); 
     277    return url_complex("cauta-probleme", array("tag_id" => $tag_ids)); 
    271278} 
    272279 
Note: See TracChangeset for help on using the changeset viewer.