- Timestamp:
- 12/17/09 00:03:05 (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
-
common/db/tags.php (modified) (3 diffs)
-
common/tags.php (modified) (1 diff)
-
common/task.php (modified) (1 diff)
-
www/controllers/task.php (modified) (2 diffs)
-
www/index.php (modified) (2 diffs)
-
www/static/css/sitewide.css (modified) (1 diff)
-
www/url.php (modified) (1 diff)
-
www/views/task_edit.php (modified) (1 diff)
-
www/views/task_tag_edit.php (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/db/tags.php
r1080 r1081 54 54 } 55 55 56 // Receives an array of tag_id's 57 // Return an array with id's of their parents 58 // Each parent id appears only once 59 function tag_get_parents($tags) { 60 $query = sprintf("SELECT DISTINCT(`parent`) 61 FROM ia_tags 62 WHERE `id` IN (%s)", 63 implode(",", array_map('db_quote', $tags)) 64 ); 65 $result = db_fetch_all($query); 66 $ret = Array(); 67 foreach ($result as $row) { 68 $ret[] = $row['parent']; 69 } 70 return $ret; 71 } 72 56 73 // Get tag id for a certain tag 57 74 function tag_get_id($tag) { … … 81 98 } 82 99 100 // Get a list of tags from a list of tag ids 101 function tag_get_by_ids($tag_ids) { 102 $query = sprintf( 103 "SELECT `id` AS tag_id, `name` AS tag_name, 104 `parent` AS tag_parent, `type` AS tag_type 105 FROM ia_tags 106 WHERE `id` IN (%s)", implode(', ', array_map('db_quote', $tag_ids)) 107 ); 108 return db_fetch_all($query); 109 } 110 83 111 // Assign numeric id to a given tag name 84 112 function tag_assign_id($tag) { … … 170 198 db_escape($obj), $where, "%s" 171 199 ); 172 if (is_null($type)) { 173 $join = "";174 } else{200 201 $join = ""; 202 if (!is_null($type)) { 175 203 $join = "LEFT JOIN ia_tags AS tags ON obj_tags.tag_id = tags.id"; 176 204 $where .= sprintf(" AND tags.type = %s", db_quote($type)); 177 205 } 206 178 207 $subquery = sprintf("SELECT tag_id FROM ia_%s_tags AS obj_tags %s WHERE %s", 179 208 db_escape($obj), $join, $where); -
trunk/common/tags.php
r1080 r1081 52 52 } 53 53 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"); 60 61 $parent_tags_key = Array(); 62 foreach ($parent_tags as $key => $tag) { 63 $parent_tags[$key]['sub_tags'] = Array(); 64 $parent_tags_key[ $tag['tag_id'] ] = $key; 65 } 66 67 foreach ($sub_tags as $tag) { 68 log_assert(isset($parent_tags_key[ $tag['tag_parent'] ]), "Child tag doesn't have a parent"); 69 $parent_tag_key = $parent_tags_key[ $tag['tag_parent'] ]; 70 $parent_tags[ $parent_tag_key ]['sub_tags'][] = $tag; 71 } 72 73 return $parent_tags; 74 } 75 54 76 // Receives a list of tags of a certain type and, optionally, with a 55 77 // certain parent and updates the tag list for the specified object. -
trunk/common/task.php
r996 r1081 277 277 } 278 278 279 // Receives a list of method and algorithm tag ids and adds links them to task_id 280 function task_update_tags($task_id, $method_tags_id, $algorithm_tags_id) { 281 log_assert(is_array($method_tags_id), 'method_tags must be an array'); 282 log_assert(is_array($algorithm_tags_id), 'algorithm_tags must be an array'); 283 log_assert(is_task_id($task_id), "Invalid task_id"); 284 285 tag_clear('task', $task_id, 'method'); 286 tag_clear('task', $task_id, 'algorithm'); 287 288 foreach ($method_tags_id as $tag_id) { 289 tag_add('task', $task_id, $tag_id); 290 } 291 292 foreach ($algorithm_tags_id as $tag_id) { 293 tag_add('task', $task_id, $tag_id); 294 } 295 } 296 279 297 ?> -
trunk/www/controllers/task.php
r1080 r1081 65 65 66 66 // Tag data 67 $tag_types = Array('author', 'contest', 'year', 'round', 'age_group' , 'method', 'algorithm');67 $tag_types = Array('author', 'contest', 'year', 'round', 'age_group'); 68 68 $tag_parents = Array('year' => 'contest', 'round' => 'year', 'age_group' => 'contest'); 69 69 … … 265 265 } 266 266 267 // Tag a task 268 function controller_task_tag($task_id) { 269 if (!is_task_id($task_id)) { 270 flash_error("Problema inexistenta"); 271 redirect(url_home()); 272 } 273 274 $task = task_get($task_id); 275 identity_require('task-tag', $task); 276 277 if (!$task) { 278 flash_error("Problema inexistenta"); 279 redirect(url_home()); 280 } 281 282 if (request_is_post()) { 283 $algorithm_tags_id = request("algorithm_tags"); 284 $method_tags_id = tag_get_parents($algorithm_tags_id); 285 286 if (!is_array($algorithm_tags_id)) { 287 flash_error("Datele trimise sunt invalide. Raporteaza aceasta problema unui admin."); 288 redirect(url_task_edit_tag($task_id)); 289 } 290 291 foreach ($algorithm_tags_id as $tag_id) { 292 if (!is_tag_id($tag_id)) { 293 flash_error("Datele trimise sunt invalide. Raporteaza aceasta problema unui admin."); 294 redirect(url_task_edit_tag($task_id)); 295 } 296 } 297 298 $algorithm_tags = tag_get_by_ids($algorithm_tags_id); 299 $count = 0; 300 foreach ($algorithm_tags as $tag) { 301 if ($tag['tag_type'] == 'algorithm') { 302 $count++; 303 } 304 } 305 if ($count != count($algorithm_tags_id)) { 306 flash_error("Datele trimise sunt invalide. Raporteaza aceasta problema unui admin."); 307 redirect(url_task_edit_tag($task_id)); 308 } 309 310 task_update_tags($task_id, $method_tags_id, $algorithm_tags_id); 311 flash("Tagurile au fost salvate cu succes"); 312 } 313 314 $tags = tag_get_all( Array('method') ); 315 $sub_tags = tag_get_all( Array('algorithm') ); 316 317 // Build_tags_tree looks for tag_id, tag_name etc. 318 // tag_get_all return id, name, etc. 319 foreach ($tags as &$tag) { 320 $tag['tag_id'] = $tag['id']; 321 $tag['tag_name'] = $tag['name']; 322 $tag['tag_type'] = $tag['type']; 323 $tag['tag_parent'] = $tag['parent']; 324 } 325 326 // Same for subtags 327 foreach ($sub_tags as &$tag) { 328 $tag['tag_id'] = $tag['id']; 329 $tag['tag_name'] = $tag['name']; 330 $tag['tag_type'] = $tag['type']; 331 $tag['tag_parent'] = $tag['parent']; 332 } 333 334 $tags_tree = build_tags_tree($tags, $sub_tags); 335 336 // Get tags for task_id 337 $task_tags = tag_get('task', $task_id, 'algorithm'); 338 339 $view['title'] = "Editeaza tagurile pentru problema ".$task['title']; 340 $view['task'] = $task; 341 $view['tags_tree'] = $tags_tree; 342 $view['task_tags'] = $task_tags; 343 execute_view_die('views/task_tag_edit.php', $view); 344 } 267 345 268 346 ?> -
trunk/www/index.php
r1080 r1081 85 85 // Task detail editor 86 86 else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'problema') { 87 require_once(IA_ROOT_DIR.'www/controllers/task.php'); 87 88 $obj_id = implode("/", array_slice($pagepath, 2)); 88 require_once(IA_ROOT_DIR.'www/controllers/task.php'); 89 controller_task_details($obj_id); 89 $action = request('action'); 90 if ($action == 'tag-edit') { 91 controller_task_tag($obj_id); 92 } else { 93 controller_task_details($obj_id); 94 } 90 95 } 91 96 … … 117 122 } 118 123 119 // Round registration 124 // Round registration 120 125 else if ($urlstart == 'inregistrare-runda') { 121 126 $obj_id = implode("/", array_slice($pagepath, 1)); -
trunk/www/static/css/sitewide.css
r1042 r1081 276 276 } 277 277 278 a.show_tag_list { 279 display: none; 280 padding: 5px; 281 outline-style: none; 282 } 283 284 ul.tag_list { 285 list-style-type: none; 286 } 287 288 li.tag_list_item { 289 padding-left: 15px; 290 } -
trunk/www/url.php
r1080 r1081 253 253 } 254 254 255 function url_task_edit_tags($task_id) { 256 log_assert(is_task_id($task_id)); 257 return url_complex("admin/problema/{$task_id}", array( 'action' => 'tag-edit')); 258 } 259 255 260 function url_task_create() { 256 261 return url_complex("admin/problema-noua"); -
trunk/www/views/task_edit.php
r1080 r1081 139 139 'age_group' => Array("label" => "Grupa de varsta", 140 140 "name" => "tag_age_group"), 141 'method' => Array("label" => "Metoda de programare",142 "name" => "tag_method"),143 'algorithm' => Array("label" => "Algoritm",144 "name" => "tag_algorithm")145 141 ); 146 142 ?>
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)