Changeset 1081 for trunk/common
- Timestamp:
- 12/17/09 00:03:05 (2 years ago)
- Location:
- trunk/common
- Files:
-
- 3 edited
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 ?>
Note: See TracChangeset
for help on using the changeset viewer.
![[infoarena] development](/chrome/site/logo.png)