| [ 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 /* 4 * A class corresponding to the people table. 5 * 6 * This file is part of Zoph. 7 * 8 * Zoph is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * Zoph is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * You should have received a copy of the GNU General Public License 18 * along with Zoph; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 class person extends zoph_table { 23 24 var $home; 25 var $work; 26 27 function person($id = 0) { 28 parent::zoph_table("people", array("person_id"), array("first_name")); 29 $this->set("person_id", $id); 30 } 31 32 function lookup() { 33 parent::lookup(); 34 $this->lookup_places(); 35 } 36 37 function lookup_places() { 38 if ($this->get("home_id") > 0) { 39 $this->home = new place($this->get("home_id")); 40 $this->home->lookup(); 41 } 42 if ($this->get("work_id") > 0) { 43 $this->work = new place($this->get("work_id")); 44 $this->work->lookup(); 45 } 46 } 47 48 function delete() { 49 parent::delete(null, array("photo_people")); 50 } 51 52 function get_gender() { 53 if ($this->get("gender") == 1) { return translate("male"); } 54 if ($this->get("gender") == 2) { return translate("female"); } 55 return; 56 } 57 58 function get_father() { 59 return get_person($this->get("father_id")); 60 } 61 62 function get_mother() { 63 return new person($this->get("mother_id")); 64 } 65 66 function get_spouse() { 67 return new person($this->get("spouse_id")); 68 } 69 70 function get_children() { 71 $constraints["falther_id"] = $this->get("father_id"); 72 $constraints["mother_id"] = $this->get("mother_id"); 73 return get_people($constraints, "or", "dob"); 74 } 75 76 function get_name() { 77 if ($this->get("called")) { 78 $name = $this->get("called"); 79 } 80 else { 81 $name = $this->get("first_name"); 82 } 83 84 if ($this->get("last_name")) { 85 $name .= " " . $this->get("last_name"); 86 } 87 88 return $name; 89 } 90 91 function get_email() { 92 $email = $this->get("email"); 93 return $email; 94 } 95 96 function to_html() { 97 return get_name(); 98 } 99 100 function get_link($show_last_name = 1) { 101 if ($show_last_name) { 102 $name = $this->get_name(); 103 } 104 else { 105 $name = $this->get("called") ? $this->get("called") : 106 $this->get("first_name"); 107 } 108 109 return "<a href=\"person.php?person_id=" . $this->get("person_id") . "\">$name</a>"; 110 } 111 112 function get_display_array() { 113 return array( 114 translate("called") => $this->get("called"), 115 translate("date of birth") => create_date_link($this->get("dob")), 116 translate("date of death") => create_date_link($this->get("dod")), 117 translate("gender") => $this->get_gender(), 118 translate("mother") => get_link("person", $this->get("mother_id")), 119 translate("father") => get_link("person", $this->get("father_id")), 120 translate("spouse") => get_link("person", $this->get("spouse_id"))); 121 } 122 123 } 124 125 function get_people($constraints = null, $conj = "and", $ops = null, 126 $order = "last_name, first_name") { 127 128 return get_records("person", $order, $constraints, $conj, $ops); 129 } 130 131 function get_photographed_people($user = null) { 132 133 if ($user && !$user->is_admin()) { 134 $query = 135 "select distinct ppl.* from " . 136 DB_PREFIX . "people as ppl, " . 137 DB_PREFIX . "photos as ph, " . 138 DB_PREFIX . "photo_people as pp, " . 139 DB_PREFIX . "photo_albums as pa, " . 140 DB_PREFIX . "album_permissions as ap " . 141 "where ap.user_id = '" . escape_string($user->get("user_id")) . "' " . 142 " and ap.album_id = pa.album_id" . 143 " and pa.photo_id = ph.photo_id" . 144 " and ap.access_level >= ph.level" . 145 " and ph.photo_id = pp.photo_id " . 146 " and pp.person_id = ppl.person_id " . 147 "order by ppl.last_name, ppl.called, ppl.first_name"; 148 } 149 else { 150 $query = 151 "select distinct ppl.* from " . 152 DB_PREFIX . "people as ppl, " . 153 DB_PREFIX . "photo_people as pp " . 154 "where ppl.person_id = pp.person_id " . 155 "order by ppl.last_name, ppl.called, ppl.first_name"; 156 } 157 158 return get_records_from_query("person", $query); 159 } 160 161 function get_photographers($user = null) { 162 163 if ($user && !$user->is_admin()) { 164 $query = 165 "select distinct ppl.* from " . 166 DB_PREFIX . "people as ppl, " . 167 DB_PREFIX . "photos as ph, " . 168 DB_PREFIX . "photo_albums as pa, " . 169 DB_PREFIX . "album_permissions as ap " . 170 "where ap.user_id = '" . escape_string($user->get("user_id")) . "' " . 171 " and ap.album_id = pa.album_id" . 172 " and pa.photo_id = ph.photo_id" . 173 " and ap.access_level >= ph.level" . 174 " and ph.photographer_id = ppl.person_id " . 175 "order by ppl.last_name, ppl.called, ppl.first_name"; 176 } 177 else { 178 $query = 179 "select distinct ppl.* from " . 180 DB_PREFIX . "people as ppl, " . 181 DB_PREFIX . "photos as ph " . 182 "where ppl.person_id = ph.photographer_id " . 183 "order by ppl.last_name, ppl.called, ppl.first_name"; 184 } 185 186 return get_records_from_query("person", $query); 187 } 188 189 function get_people_select_array($people_array = null) { 190 191 $ppl[""] = ""; 192 193 if (!$people_array) { 194 $people_array = get_people(); 195 } 196 197 if ($people_array) { 198 foreach ($people_array as $person) { 199 $ppl[$person->get("person_id")] = 200 ($person->get("last_name") ? $person->get("last_name") . ", " : "") . 201 ($person->get("called") ? $person->get("called") : $person->get("first_name")); 202 } 203 } 204 205 return $ppl; 206 } 207 208 209 function get_photo_person_links($photo) { 210 211 $links = ""; 212 if (!$photo) { return $links; } 213 $people = $photo->lookup_people(); 214 if ($people) { 215 foreach ($people as $person) { 216 if ($links) { $links .= ", "; } 217 $links .= $person->get_link(0); 218 } 219 } 220 221 return $links; 222 } 223 224 function get_person_by_name($first_name = null, $last_name = null) { 225 if (!$first_name && !$last_name) { 226 return ""; 227 } 228 229 if ($first_name) { 230 $first_name = 231 "lower(first_name) like '%" . escape_string(strtolower($first_name)) . "%'"; 232 } 233 234 if ($last_name) { 235 $last_name = 236 "lower(last_name) like '%" . escape_string(strtolower($last_name)) . "%'"; 237 } 238 239 $where = $first_name; 240 if ($first_name && $last_name) { 241 $where .= " and "; 242 } 243 $where .= $last_name; 244 245 $query = "select person_id from " . DB_PREFIX . "people where $where"; 246 247 return get_records_from_query("person", $query); 248 } 249 250 function get_popular_people($user) { 251 252 global $TOP_N; 253 254 if ($user && !$user->is_admin()) { 255 $sql = 256 "select ppl.*, count(distinct ph.photo_id) as count from " . 257 DB_PREFIX . "people as ppl, " . 258 DB_PREFIX . "photo_people as pp, " . 259 DB_PREFIX . "photos as ph, " . 260 DB_PREFIX . "photo_albums as pa, " . 261 DB_PREFIX . "album_permissions as ap " . 262 "where ap.user_id = '" . escape_string($user->get("user_id")) . "' " . 263 " and ap.album_id = pa.album_id" . 264 " and pa.photo_id = pp.photo_id" . 265 " and pp.person_id = ppl.person_id" . 266 " and pp.photo_id = ph.photo_id" . 267 " and ap.access_level >= ph.level " . 268 "group by ppl.person_id " . 269 "order by count desc, ppl.last_name, ppl.first_name " . 270 "limit 0, $TOP_N"; 271 } 272 else { 273 $sql = 274 "select ppl.*, count(*) as count from " . 275 DB_PREFIX . "people as ppl, " . 276 DB_PREFIX . "photo_people as pp " . 277 "where ppl.person_id = pp.person_id " . 278 "group by ppl.person_id " . 279 "order by count desc, ppl.last_name, ppl.first_name " . 280 "limit 0, $TOP_N"; 281 } 282 283 return get_popular_results("person", $sql); 284 285 } 286 287 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |