| [ PHPXref.com ] | [ Generated: Sun Jul 20 21:17:54 2008 ] | [ Zoph 0.5.1 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * This file is part of Zoph. 4 * 5 * Zoph is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * Zoph is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with Zoph; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 /* 20 * zoph_tree_table represents a hierarchical table. Since the album 21 * and category tables are identical in structure, some of the methods 22 * those classes share are abstracted and placed here. 23 */ 24 class zoph_tree_table extends zoph_table { 25 26 var $children; 27 var $ancestors; 28 29 /* 30 * Deletes a record along with all of its descendants. 31 */ 32 function delete($extra_tables = null) { 33 $this->get_children(); 34 if ($this->children) { 35 foreach ($this->children as $child) { 36 $child->delete(); 37 } 38 } 39 40 parent::delete(null, $extra_tables); 41 } 42 43 /* 44 * Gets the children of this record. 45 */ 46 function get_children($user = null, $order = null) { 47 48 if ($this->children) { return $this->children; } 49 if (!$this->primary_keys) { return; } 50 $key = $this->primary_keys[0]; 51 $id = $this->get($key); 52 if (!$id) { return; } 53 54 $sql = 55 "select * from $this->table_name " . 56 "where parent_$key = '" . escape_string($id) . "'"; 57 58 if ($order) { 59 $sql .= " order by $order"; 60 } 61 62 if ($this->DEBUG) { echo "$sql<br>\n"; } 63 64 $this->children = get_records_from_query(get_class($this), $sql); 65 return $this->children; 66 67 } 68 69 /* 70 * Gets the ancestors of this record. 71 */ 72 function get_ancestors($anc = array()) { 73 if (!$this->primary_keys) { return $anc; } 74 $key = $this->primary_keys[0]; 75 $pid = $this->get("parent_$key"); 76 // root of tree 77 if ($pid == 0) { 78 $this->ancestors = $anc; 79 return $this->ancestors; 80 } 81 82 $class = get_class($this); 83 $parent = new $class; 84 $parent->set($key, $pid); 85 $parent->lookup(); 86 87 array_push($anc, $parent); 88 89 $this->ancestors = $parent->get_ancestors($anc); 90 return $this->ancestors; 91 } 92 93 /* 94 * Gets a list of the id of this record along with the ids of 95 * all of its descendants. 96 */ 97 function get_branch_id_array(&$id_array, $user = null) { 98 $key = $this->primary_keys[0]; 99 $id_array[] = $this->get($key); 100 101 $this->get_children($user); 102 if ($this->children) { 103 foreach($this->children as $c) { 104 $c->get_branch_id_array($id_array, $user); 105 } 106 } 107 return $id_array; 108 } 109 110 /* 111 * Gets a comma separated string of this record's id along with 112 * all of its descendant's ids. Useful to make "record_id in 113 * (id_list)" clauses. 114 */ 115 function get_branch_ids($user = null) { 116 $id_array; 117 $this->get_branch_id_array($id_array, $user); 118 return implode(",", $id_array); 119 } 120 121 } 122 123 function get_root($class) { 124 return new $class(1); 125 } 126 127 function create_tree_select_array($name, $user = null, $rec = null, 128 $level = "", $select_array = null, $search = 0) { 129 130 if (!$rec) { 131 $rec = get_root($name); 132 $rec->lookup(); 133 $select_array[""] = ""; 134 } 135 if ($search) { 136 $key = $rec->get_branch_ids($user); 137 } 138 else { 139 $key = $rec->get($name . "_id"); 140 } 141 /* The main descriptor field for location is not "place", but "title" */ 142 $descname=$name; 143 if($descname=="place"){ $descname="title"; } 144 145 $select_array[$key] = $level . $rec->get($descname); 146 $children = $rec->get_children($user, $descname); 147 if ($children) { 148 foreach ($children as $child) { 149 $select_array = create_tree_select_array($name, $user, $child, 150 "$level ", $select_array, $search); 151 } 152 } 153 154 return $select_array; 155 } 156 157 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |