Changeset 1099 for trunk


Ignore:
Timestamp:
12/28/09 14:24:37 (2 years ago)
Author:
bogdan2412
Message:

Show tags on filter results page.

Reimplemented tag_build_tree so that it works with more than one level of depth. It now receives all the tags in a single array and returns the tag tree.

Also added some diacritics to some pages.

Location:
trunk
Files:
12 edited

Legend:

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

    r1089 r1099  
    6060// Return an array with id's of their parents 
    6161// Each parent id appears only once 
    62 function tag_get_parents($tags) { 
     62function tag_get_parents($tag_ids) { 
    6363    $query = sprintf("SELECT DISTINCT(`parent`) 
    6464            FROM ia_tags 
    65             WHERE `id` IN (%s)", 
    66             implode(",", array_map('db_quote', $tags)) 
     65            WHERE `id` IN (%s) AND `parent` != 0", 
     66            implode(",", array_map('db_quote', $tag_ids)) 
    6767        ); 
    6868    $result = db_fetch_all($query); 
    69     $ret = Array(); 
     69    $ret = array(); 
    7070    foreach ($result as $row) { 
    7171        $ret[] = $row['parent']; 
  • trunk/common/tags.php

    r1089 r1099  
    5252} 
    5353 
    54 // Receives a list of parent tags and children tags 
    55 // For each parent_tag adds an array 'sub_tags' containing 
    56 // an array with all his children tags 
    57 function build_tags_tree($parent_tags, $sub_tags) { 
    58     log_assert(is_array($parent_tags), "Parent tags is not an array"); 
    59     log_assert(is_array($sub_tags), "Children tags is not an array"); 
     54// Receives a list of tags which will be arranged in a tree-like structure 
     55// according to their respective parents. 
     56function tag_build_tree($tags) { 
     57    log_assert(is_array($tags), "tag_build_tree expects an array of tags"); 
     58    $tags_by_id = array(); 
     59    // Group tags by id 
     60    foreach ($tags as &$tag) { 
     61        log_assert(is_tag($tag), "tag_build_tree expects an array of tags"); 
     62        log_assert(isset($tag["id"]), 
     63            "tag_build_tree expects an array of tags with id"); 
    6064 
    61     $parent_tags_key = Array(); 
    62     foreach ($parent_tags as $key => $tag) { 
    63         $parent_tags[$key]['sub_tags'] = Array(); 
    64         $parent_tags_key[$tag['id']] = $key; 
     65        $tags_by_id[$tag["id"]] =& $tag; 
    6566    } 
    6667 
    67     foreach ($sub_tags as $tag) { 
    68         log_assert(isset($parent_tags_key[$tag['parent']]), "Child tag doesn't have a parent"); 
    69         $parent_tag_key = $parent_tags_key[$tag['parent']]; 
    70         $parent_tags[$parent_tag_key]['sub_tags'][] = $tag; 
     68    // Add 'sub_tags' attribute to all tags which have children. 
     69    $has_parent = array(); 
     70    foreach ($tags as &$tag) { 
     71        if (array_key_exists($tag["parent"], $tags_by_id)) { 
     72            $has_parent[$tag["id"]] = true; 
     73 
     74            if (!isset($tags_by_id[$tag["parent"]]["sub_tags"])) { 
     75                $tags_by_id[$tag["parent"]]["sub_tags"] = array(); 
     76            } 
     77            $tags_by_id[$tag["parent"]]["sub_tags"][] =& $tag; 
     78        } 
    7179    } 
    7280 
    73     return $parent_tags; 
     81    // Return only tree roots (tags which have no parents). 
     82    $roots = array(); 
     83    foreach ($tags_by_id as &$tag) { 
     84        if (!isset($has_parent[$tag["id"]])) { 
     85            $roots[] = $tag; 
     86        } 
     87    } 
     88    return $roots; 
    7489} 
    7590 
  • trunk/www/controllers/task.php

    r1095 r1099  
    315315    } 
    316316 
    317     $tags = tag_get_all( Array('method') ); 
    318     $sub_tags = tag_get_all( Array('algorithm') ); 
    319  
    320     $tags_tree = build_tags_tree($tags, $sub_tags); 
     317    $tags_tree = tag_build_tree(tag_get_all(array("method", "algorithm"))); 
    321318 
    322319    // Get tags for task_id 
     
    336333    $tags = request('tag_id', null); 
    337334    if (is_null($tags)) { 
    338         $tags = Array(); 
     335        $tags = array(); 
    339336    } 
    340337 
    341338    if (!is_array($tags)) { 
    342         flash_error("Url invalid"); 
    343         redirect(url_home()); 
    344     } 
    345  
     339        flash_error("Filtru invalid"); 
     340        redirect(url_home()); 
     341    } 
    346342    foreach ($tags as $tag) { 
    347343        if (!is_tag_id($tag)) { 
    348             flash_error("Url invalid"); 
     344            flash_error("Filtru invalid"); 
    349345            redirect(url_home()); 
    350346        } 
     
    361357    } 
    362358 
     359    // Fetch the tags and all their parents so they can be displayed 
     360    // in a tree-like fashion 
     361    if (count($tags) > 0) { 
     362        while (( 
     363            $new_tags = array_unique(array_merge($tags, tag_get_parents($tags))) 
     364        ) != $tags) { 
     365            $tags = $new_tags; 
     366        } 
     367        $tags = tag_build_tree(tag_get_by_ids($tags)); 
     368    } 
     369 
    363370    $view['title'] = "Rezultatele filtrării"; 
    364371    $view['tasks'] = $tasks; 
     372    $view['tags'] = $tags; 
    365373    execute_view_die('views/task_filter_results.php', $view); 
    366374} 
  • trunk/www/controllers/task_tags.php

    r1094 r1099  
    11<?php 
    2 require_once(IA_ROOT_DIR . "common/db/tags.php"); 
     2require_once(IA_ROOT_DIR . "common/tags.php"); 
    33require_once(IA_ROOT_DIR . "common/string.php"); 
    44 
     
    77    identity_require("task-tag"); 
    88 
    9     $categories = tag_get_all(array("method")); 
     9    $categories = tag_build_tree(tag_get_all(array("method", "algorithm"))); 
    1010    foreach ($categories as &$category) { 
    11         // Get all sub tags for current category 
    12         $category["sub_tags"] = tag_get_all(array("algorithm"), 
    13             $category["id"]); 
    1411        foreach ($category["sub_tags"] as &$tag) { 
    1512            $tag["task_count"] = tag_count_objects("task", array($tag["id"])); 
  • trunk/www/macros/macro_algorithmtags.php

    r1096 r1099  
    1717    $sub_tags = tag_get('task', $task_id, 'algorithm'); 
    1818 
    19     $tags_tree = build_tags_tree($tags, $sub_tags); 
     19    $tags_tree = tag_build_tree(array_merge($tags, $sub_tags)); 
    2020 
    2121    $task = task_get($task_id); 
     
    3434    } 
    3535    $html_code = "<div id=\"task_tags\">"; 
    36     $html_code .= "<h3> Indicii de rezolvare</h3>"; 
     36    $html_code .= "<h3> Indicii de rezolvare</h3>"; 
    3737    $html_code .= '<a id="show_tags" href="javascript:show_tags()"> 
    3838                Arată '.count($tags_tree).' '.$category_word.'</a>'; 
  • trunk/www/macros/macro_tasks.php

    r1095 r1099  
    5757    $tab_names = array(IA_TLF_ALL => 'Toate problemele', 
    5858                       IA_TLF_UNSOLVED => 'Nerezolvate', 
    59                        IA_TLF_TRIED => 'Incercate', 
     59                       IA_TLF_TRIED => 'Încercate', 
    6060                       IA_TLF_SOLVED => 'Rezolvate'); 
    6161 
     
    141141    if ($show_numbers) { 
    142142        $column_infos[] = array( 
    143                 'title' => 'Numar', 
     143                'title' => 'Număr', 
    144144                'css_class' => 'number', 
    145145                'rowform' => create_function_cached('$row', 
     
    161161    if ($show_sources) { 
    162162        $column_infos[] = array( 
    163                 'title' => 'Sursa', 
     163                'title' => 'Sursă', 
    164164                'css_class' => 'source', 
    165165                'key' => 'source', 
     
    168168    if (!is_null($user_id)) { 
    169169        $column_infos[] = array ( 
    170                 'title' => 'Scorul tau', 
     170                'title' => 'Scorul tău', 
    171171                'css_class' => 'number score', 
    172172                'key' => 'score', 
  • trunk/www/static/css/screen.css

    r1090 r1099  
    549549 
    550550input[type='text'], input[type='password'], select { 
    551     width: 250px; 
     551    width: 200px; 
    552552} 
    553553 
     
    15361536    width: 25%; 
    15371537} 
     1538 
     1539/* Task filter by tag page */ 
     1540.filter_results { 
     1541    line-height: 2em; 
     1542} 
     1543 
     1544ul.tag_filters { 
     1545    line-height: 1.5em; 
     1546    margin: 0 .5em .5em 2em; 
     1547} 
  • trunk/www/static/css/sitewide.css

    r1096 r1099  
    355355    font-size: 10px; 
    356356} 
    357  
    358 table.filter_results { 
    359     width: 99%; 
    360 } 
    361  
    362 table.filter_results td, th { 
    363     padding: 3px; 
    364 } 
  • trunk/www/static/css/wick.css

    r1083 r1099  
    2828    color:black; 
    2929    padding: 0; 
    30     width: 257px; 
     30    width: 207px; 
    3131} 
    3232 
  • trunk/www/views/header.php

    r1088 r1099  
    9999        <li><a href="<?= html_escape(url_home()) ?>">Home</a></li> 
    100100        <li><?= format_link_access(url_textblock('arhiva'), "Arhiva de probleme", 'a') ?></li> 
    101         <li><a href="<?= html_escape(url_textblock('arhiva-educationala')) ?>">Arhiva educationala</a></li> 
     101        <li><a href="<?= html_escape(url_textblock('arhiva-educationala')) ?>">Arhiva educatională</a></li> 
    102102        <li><a href="<?= html_escape(url_textblock('concursuri')) ?>">Concursuri</a></li> 
    103103        <li><a href="<?= html_escape(url_textblock('concursuri-virtuale')) ?>">Concursuri virtuale<span style="color: red; font-weight:bold;"><sup>nou!</sup></span></a></li>  
     
    106106        <li><a href="<?= html_escape(url_textblock('downloads')) ?>">Downloads</a></li> 
    107107        <li><a href="<?= html_escape(url_textblock('links')) ?>">Links</a></li> 
    108         <li><a href="<?= html_escape(url_textblock('documentatie')) ?>">Documentatie</a></li> 
     108        <li><a href="<?= html_escape(url_textblock('documentatie')) ?>">Documentaţie</a></li> 
    109109        <li><a href="<?= html_escape(url_textblock('despre-infoarena')) ?>">Despre infoarena</a></li> 
    110110        <li class="separator"><hr/></li> 
    111111        <li><?= format_link_access(url_monitor(array('user' => identity_get_username())), "Monitorul de evaluare", 'm') ?></li> 
    112112        <?php if (!identity_is_anonymous()) { ?> 
    113         <li><a href="<?= html_escape(url_submit()) ?>"><strong>Trimite solutii</strong></a></li> 
     113        <li><a href="<?= html_escape(url_submit()) ?>"><strong>Trimite soluţii</strong></a></li> 
    114114        <li><?= format_link_access(url_account(), "Contul meu", 'c') ?></li> 
    115115        <?php } ?> 
  • trunk/www/views/task_filter_results.php

    r1095 r1099  
    4747} 
    4848 
    49 echo "<h1>Rezultatele Filtrarii</h1>"; 
     49function tag_print($tags) { 
     50    if (count($tags) == 0) { 
     51        return ""; 
     52    } 
     53 
     54    $tag_types = array( 
     55        "author" => "Autor", 
     56        "contest" => "Concurs", 
     57        "year" => "Editie", 
     58        "round" => "Runda", 
     59        "age_group" => "Grupa de varsta", 
     60        "method" => "Categorie", 
     61        "algorithm" => "Algoritm", 
     62        "tag" => "Tag" 
     63    ); 
     64    $output = '<ul class="tag_filters">'; 
     65    foreach ($tags as $tag) { 
     66        $output .= sprintf("<li>%s%s</li>", 
     67            format_link(url_task_search(array($tag["id"])), sprintf("%s: %s", 
     68                $tag_types[$tag["type"]], $tag["name"])), 
     69            tag_print(getattr($tag, "sub_tags", array())) 
     70        ); 
     71    } 
     72    $output .= "</ul>"; 
     73    return $output; 
     74} 
     75 
     76echo "<h1>Rezultatele filtrării</h1>"; 
     77echo tag_print($view["tags"]); 
    5078$tasks = $view['tasks']; 
    5179$options = pager_init_options(); 
    5280$options['total_entries'] = count($tasks); 
    5381$options['row_style'] = 'task_row_style'; 
    54 $options['css_class'] = 'tasks filter_results'; 
     82$options['css_class'] = 'tasks fill-screen filter_results'; 
    5583$options['show_count'] = true; 
    5684$options['show_display_entries'] = false; 
     
    6492$column_infos = array(); 
    6593$column_infos[] = array( 
    66         'title' => 'Numar', 
     94        'title' => 'Număr', 
    6795        'css_class' => 'number', 
    6896        'rowform' => create_function_cached('$row', 
     
    75103$column_infos[] = array( 
    76104        'title' => 'Autor(i)', 
     105        'css_class' => 'author', 
    77106        'rowform' => 'format_authors'); 
    78107$column_infos[] = array( 
    79         'title' => 'Sursa', 
     108        'title' => 'Sursă', 
    80109        'css_class' => 'source', 
    81         'key' => 'round_title',); 
     110        'key' => 'round_title'); 
    82111if (!is_null($user_id)) { 
    83112    $column_infos[] = array ( 
    84             'title' => 'Scorul tau', 
     113            'title' => 'Scorul tău', 
    85114            'css_class' => 'number score', 
    86115            'key' => 'score', 
     
    88117} 
    89118 
    90 $task_chunks = array_chunk($tasks, $options['display_entries']); 
    91 $chunk = $task_chunks[$options['first_entry'] / $options['display_entries']]; 
    92 echo format_table($chunk, $column_infos, $options); 
     119if (!count($tasks)) { 
     120    echo "Nicio problemă gasită."; 
     121} else { 
     122    $task_chunks = array_chunk($tasks, $options['display_entries']); 
     123    $chunk = $task_chunks[$options['first_entry'] / $options['display_entries']]; 
     124    echo format_table($chunk, $column_infos, $options); 
     125} 
     126 
    93127include('footer.php'); 
    94128?> 
  • trunk/www/views/textblock_header.php

    r1098 r1099  
    1111    <ul> 
    1212<?php if (($task_id = textblock_security_is_task($textblock['security'])) && identity_can('task-edit', $task = task_get($task_id))) { ?> 
    13 <li><?= format_link_access(url_task_edit($task['id']), 'Editeaza parametrii', 'p') ?></li> 
     13<li><?= format_link_access(url_task_edit($task['id']), 'Editează parametrii', 'p') ?></li> 
    1414<?php } ?> 
    1515<?php if ($task_id && identity_can('task-tag', $task)) { ?> 
    16 <li><?= format_link_access(url_task_edit_tags($task['id']), 'Editeaza tag-uri', 't') ?></li> 
     16<li><?= format_link_access(url_task_edit_tags($task['id']), 'Editează tag-uri', 't') ?></li> 
    1717<?php } ?> 
    1818<?php if (($round_id = textblock_security_is_round($textblock['security'])) && identity_can('round-edit', $round = round_get($round_id))) { ?> 
    19 <li><?= format_link_access(url_round_edit($round['id']), 'Editeaza parametrii', 'p') ?></li> 
     19<li><?= format_link_access(url_round_edit($round['id']), 'Editează parametrii', 'p') ?></li> 
    2020<?php } ?> 
    2121<?php if (identity_can('textblock-edit', $textblock)) { ?> 
    22 <li><?= format_link_access(url_textblock_edit($textblock['name']), ($task_id) ? 'Editeaza enunt' : 'Editeaza', 'e') ?></li> 
     22<li><?= format_link_access(url_textblock_edit($textblock['name']), ($task_id) ? 'Editează enunţ' : 'Editează', 'e') ?></li> 
    2323<?php } ?> 
    2424<?php if (identity_can('textblock-history', $textblock)) { ?> 
     
    2626<?php } ?> 
    2727<?php if (identity_can('textblock-move', $textblock)) { ?> 
    28 <li><?= format_link_access(url_textblock_move($textblock['name']), 'Muta', 'u') ?></li> 
     28<li><?= format_link_access(url_textblock_move($textblock['name']), 'Mută', 'u') ?></li> 
    2929<?php } ?> 
    3030<?php if (identity_can('textblock-copy', $textblock)) { ?> 
    31 <li><?= format_link_access(url_textblock_copy($textblock['name']), 'Copiaza', 'c') ?></li> 
     31<li><?= format_link_access(url_textblock_copy($textblock['name']), 'Copiază', 'c') ?></li> 
    3232<?php } ?> 
    3333<?php if (identity_can('textblock-delete', $textblock)) { ?> 
    3434<li><?= format_post_link( 
    3535    url_textblock_delete($textblock['name']), 
    36     'Sterge', array(), true, array('onclick' => 
     36    'Şterge', array(), true, array('onclick' => 
    3737    "return confirm('Aceasta actiune este ireversibila! Doresti sa continui?')"), 
    38     's') ?> 
     38    'r') ?> 
    3939</li> 
    4040<?php } ?> 
    4141<?php if (identity_can('textblock-attach', $textblock)) { ?> 
    42 <li><?= format_link_access(url_attachment_new($textblock['name']), 'Ataseaza', 'a') ?></li> 
     42<li><?= format_link_access(url_attachment_new($textblock['name']), 'Ataşează', 'a') ?></li> 
    4343<?php } ?> 
    4444<?php if (identity_can('textblock-list-attach', $textblock)) { ?> 
    45 <li><?= format_link_access(url_attachment_list($textblock['name']), 'Listeaza atasamente', 'l') ?></li> 
     45<li><?= format_link_access(url_attachment_list($textblock['name']), 'Listează ataşamente', 'l') ?></li> 
    4646<?php } ?> 
    4747     </ul> 
Note: See TracChangeset for help on using the changeset viewer.