| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
| 4 | * http://opensource.polytechnique.org/ * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., * |
| 19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | class Profile |
| 23 | { |
| 24 | |
| 25 | /* name tokens */ |
| 26 | const LASTNAME = 'lastname'; |
| 27 | const FIRSTNAME = 'firstname'; |
| 28 | const NICKNAME = 'nickname'; |
| 29 | const PSEUDONYM = 'pseudonym'; |
| 30 | const NAME = 'name'; |
| 31 | /* name variants */ |
| 32 | const VN_MARITAL = 'marital'; |
| 33 | const VN_ORDINARY = 'ordinary'; |
| 34 | const VN_OTHER = 'other'; |
| 35 | const VN_INI = 'ini'; |
| 36 | /* display names */ |
| 37 | const DN_FULL = 'directory_name'; |
| 38 | const DN_DISPLAY = 'yourself'; |
| 39 | const DN_YOURSELF = 'yourself'; |
| 40 | const DN_DIRECTORY = 'directory_name'; |
| 41 | const DN_PRIVATE = 'private_name'; |
| 42 | const DN_PUBLIC = 'public_name'; |
| 43 | const DN_SHORT = 'short_name'; |
| 44 | const DN_SORT = 'sort_name'; |
| 45 | /* education related names */ |
| 46 | const EDU_X = 'École polytechnique'; |
| 47 | const DEGREE_X = 'Ingénieur'; |
| 48 | const DEGREE_M = 'Master'; |
| 49 | const DEGREE_D = 'Doctorat'; |
| 50 | |
| 51 | static public $name_variants = array( |
| 52 | self::LASTNAME => array(self::VN_MARITAL, self::VN_ORDINARY), |
| 53 | self::FIRSTNAME => array(self::VN_ORDINARY, self::VN_INI, self::VN_OTHER) |
| 54 | ); |
| 55 | |
| 56 | const ADDRESS_MAIN = 0x00000001; |
| 57 | const ADDRESS_PERSO = 0x00000002; |
| 58 | const ADDRESS_PRO = 0x00000004; |
| 59 | const ADDRESS_ALL = 0x00000006; |
| 60 | const ADDRESS_POSTAL = 0x00000008; |
| 61 | |
| 62 | const EDUCATION_MAIN = 0x00000010; |
| 63 | const EDUCATION_EXTRA = 0x00000020; |
| 64 | const EDUCATION_ALL = 0x00000040; |
| 65 | const EDUCATION_FINISHED = 0x00000080; |
| 66 | const EDUCATION_CURRENT = 0x00000100; |
| 67 | |
| 68 | const JOBS_MAIN = 0x00001000; |
| 69 | const JOBS_ALL = 0x00002000; |
| 70 | const JOBS_FINISHED = 0x00004000; |
| 71 | const JOBS_CURRENT = 0x00008000; |
| 72 | |
| 73 | const NETWORKING_ALL = 0x00070000; |
| 74 | const NETWORKING_WEB = 0x00010000; |
| 75 | const NETWORKING_IM = 0x00020000; |
| 76 | const NETWORKING_SOCIAL = 0x00040000; |
| 77 | |
| 78 | const PHONE_LINK_JOB = 0x00100000; |
| 79 | const PHONE_LINK_ADDRESS = 0x00200000; |
| 80 | const PHONE_LINK_PROFILE = 0x00400000; |
| 81 | const PHONE_LINK_COMPANY = 0x00800000; |
| 82 | const PHONE_LINK_ANY = 0x00F00000; |
| 83 | |
| 84 | const PHONE_TYPE_FAX = 0x01000000; |
| 85 | const PHONE_TYPE_FIXED = 0x02000000; |
| 86 | const PHONE_TYPE_MOBILE = 0x04000000; |
| 87 | const PHONE_TYPE_ANY = 0x07000000; |
| 88 | |
| 89 | const PHONE_ANY = 0x07F00000; |
| 90 | |
| 91 | const FETCH_ADDRESSES = 0x000001; |
| 92 | const FETCH_CORPS = 0x000002; |
| 93 | const FETCH_EDU = 0x000004; |
| 94 | const FETCH_JOBS = 0x000008; |
| 95 | const FETCH_MEDALS = 0x000010; |
| 96 | const FETCH_NETWORKING = 0x000020; |
| 97 | const FETCH_MENTOR_SECTOR = 0x000040; |
| 98 | const FETCH_MENTOR_COUNTRY = 0x000080; |
| 99 | const FETCH_PHONES = 0x000100; |
| 100 | const FETCH_JOB_TERMS = 0x000200; |
| 101 | const FETCH_MENTOR_TERMS = 0x000400; |
| 102 | |
| 103 | const FETCH_MINIFICHES = 0x00012D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_NETWORKING | FETCH_PHONES |
| 104 | |
| 105 | const FETCH_ALL = 0x0007FF; // OR of FETCH_* |
| 106 | |
| 107 | private $fetched_fields = 0x000000; |
| 108 | |
| 109 | private $pid; |
| 110 | private $hrpid; |
| 111 | private $owner; |
| 112 | private $owner_fetched = false; |
| 113 | private $data = array(); |
| 114 | |
| 115 | private $visibility = null; |
| 116 | |
| 117 | |
| 118 | private function __construct(array $data) |
| 119 | { |
| 120 | $this->data = $data; |
| 121 | $this->pid = $this->data['pid']; |
| 122 | $this->hrpid = $this->data['hrpid']; |
| 123 | $this->visibility = new ProfileVisibility(); |
| 124 | } |
| 125 | |
| 126 | public function id() |
| 127 | { |
| 128 | return $this->pid; |
| 129 | } |
| 130 | |
| 131 | public function hrid() |
| 132 | { |
| 133 | return $this->hrpid; |
| 134 | } |
| 135 | |
| 136 | public function owner() |
| 137 | { |
| 138 | if ($this->owner == null && !$this->owner_fetched) { |
| 139 | $this->owner_fetched = true; |
| 140 | $this->owner = User::getSilent($this); |
| 141 | } |
| 142 | return $this->owner; |
| 143 | } |
| 144 | |
| 145 | public function isActive() |
| 146 | { |
| 147 | if ($this->owner()) { |
| 148 | return $this->owner->isActive(); |
| 149 | } |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | public function promo() |
| 154 | { |
| 155 | return $this->promo; |
| 156 | } |
| 157 | |
| 158 | public function yearpromo() |
| 159 | { |
| 160 | return intval(substr($this->promo, 1, 4)); |
| 161 | } |
| 162 | |
| 163 | /** Check if user is an orange (associated with several promos) |
| 164 | */ |
| 165 | public function isMultiPromo() |
| 166 | { |
| 167 | return $this->grad_year != $this->entry_year + $this->mainEducationDuration(); |
| 168 | } |
| 169 | |
| 170 | /** Returns an array with all associated promo years. |
| 171 | */ |
| 172 | public function yearspromo() |
| 173 | { |
| 174 | $promos = array(); |
| 175 | $d = -$this->deltaPromoToGradYear(); |
| 176 | for ($g = $this->entry_year + $this->mainEducationDuration(); $g <= $this->grad_year; ++$g) { |
| 177 | $promos[] = $g + $d; |
| 178 | } |
| 179 | return $promos; |
| 180 | } |
| 181 | |
| 182 | public function mainEducation() |
| 183 | { |
| 184 | if (empty($this->promo)) { |
| 185 | return null; |
| 186 | } else { |
| 187 | return $this->promo{0}; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | public function mainGrade() |
| 192 | { |
| 193 | switch ($this->mainEducation()) { |
| 194 | case 'X': |
| 195 | return UserFilter::GRADE_ING; |
| 196 | case 'M': |
| 197 | return UserFilter::GRADE_MST; |
| 198 | case 'D': |
| 199 | return UserFilter::GRADE_PHD; |
| 200 | default: |
| 201 | return null; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | public function mainEducationDuration() |
| 206 | { |
| 207 | switch ($this->mainEducation()) { |
| 208 | case 'X': |
| 209 | return 3; |
| 210 | case 'M': |
| 211 | return 2; |
| 212 | case 'D': |
| 213 | return 3; |
| 214 | default: |
| 215 | return 0; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | /** Number of years between the promotion year until the |
| 220 | * graduation year. In standard schools it's 0, but for |
| 221 | * Polytechnique the promo year is the entry year. |
| 222 | */ |
| 223 | public function deltaPromoToGradYear() |
| 224 | { |
| 225 | if ($this->mainEducation() == 'X') { |
| 226 | return $this->mainEducationDuration(); |
| 227 | } |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | /** Print a name with the given formatting: |
| 232 | * %s = • for women |
| 233 | * %f = firstname |
| 234 | * %l = lastname |
| 235 | * %F = fullname |
| 236 | * %S = shortname |
| 237 | * %p = promo |
| 238 | */ |
| 239 | public function name($format) |
| 240 | { |
| 241 | return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'), |
| 242 | array($this->isFemale() ? '•' : '', |
| 243 | $this->firstName(), $this->lastName(), |
| 244 | $this->fullName(), $this->shortName(), |
| 245 | $this->promo()), $format); |
| 246 | } |
| 247 | |
| 248 | public function fullName($with_promo = false) |
| 249 | { |
| 250 | if ($with_promo) { |
| 251 | return $this->full_name . ' (' . $this->promo . ')'; |
| 252 | } |
| 253 | return $this->full_name; |
| 254 | } |
| 255 | |
| 256 | public function shortName($with_promo = false) |
| 257 | { |
| 258 | if ($with_promo) { |
| 259 | return $this->short_name . ' (' . $this->promo . ')'; |
| 260 | } |
| 261 | return $this->short_name; |
| 262 | } |
| 263 | |
| 264 | public function firstName() |
| 265 | { |
| 266 | return $this->firstname; |
| 267 | } |
| 268 | |
| 269 | public function firstNames() |
| 270 | { |
| 271 | return $this->nameVariants(self::FIRSTNAME); |
| 272 | } |
| 273 | |
| 274 | public function lastName() |
| 275 | { |
| 276 | return $this->lastname; |
| 277 | } |
| 278 | |
| 279 | public function lastNames() |
| 280 | { |
| 281 | return $this->nameVariants(self::LASTNAME); |
| 282 | } |
| 283 | |
| 284 | public function isFemale() |
| 285 | { |
| 286 | return $this->sex == PlUser::GENDER_FEMALE; |
| 287 | } |
| 288 | |
| 289 | public function isDead() |
| 290 | { |
| 291 | return ($this->deathdate != null); |
| 292 | } |
| 293 | |
| 294 | public function displayEmail() |
| 295 | { |
| 296 | $o = $this->owner(); |
| 297 | if ($o != null) { |
| 298 | return $o->bestEmail(); |
| 299 | } else { |
| 300 | return $this->email_directory; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | public function data() |
| 305 | { |
| 306 | $this->first_name; |
| 307 | return $this->data; |
| 308 | } |
| 309 | |
| 310 | private function nameVariants($type) |
| 311 | { |
| 312 | $vals = array($this->$type); |
| 313 | foreach (self::$name_variants[$type] as $var) { |
| 314 | $vartype = $type . '_' . $var; |
| 315 | $varname = $this->$vartype; |
| 316 | if ($varname != null && $varname != "") { |
| 317 | $vals[] = $varname; |
| 318 | } |
| 319 | } |
| 320 | return array_unique($vals); |
| 321 | } |
| 322 | |
| 323 | public function nationalities() |
| 324 | { |
| 325 | $nats = array(); |
| 326 | $countries = DirEnum::getOptions(DirEnum::COUNTRIES); |
| 327 | if ($this->nationality1) { |
| 328 | $nats[$this->nationality1] = $countries[$this->nationality1]; |
| 329 | } |
| 330 | if ($this->nationality2) { |
| 331 | $nats[$this->nationality2] = $countries[$this->nationality2]; |
| 332 | } |
| 333 | if ($this->nationality3) { |
| 334 | $nats[$this->nationality3] = $countries[$this->nationality3]; |
| 335 | } |
| 336 | return $nats; |
| 337 | } |
| 338 | |
| 339 | public function __get($name) |
| 340 | { |
| 341 | if (property_exists($this, $name)) { |
| 342 | return $this->$name; |
| 343 | } |
| 344 | |
| 345 | if (isset($this->data[$name])) { |
| 346 | return $this->data[$name]; |
| 347 | } |
| 348 | |
| 349 | return null; |
| 350 | } |
| 351 | |
| 352 | public function __isset($name) |
| 353 | { |
| 354 | return property_exists($this, $name) || isset($this->data[$name]); |
| 355 | } |
| 356 | |
| 357 | public function __unset($name) |
| 358 | { |
| 359 | if (property_exists($this, $name)) { |
| 360 | $this->$name = null; |
| 361 | } else { |
| 362 | unset($this->data[$name]); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | |
| 367 | /** |
| 368 | * Clears a profile. |
| 369 | * *always deletes in: profile_addresses, profile_binets, profile_job, |
| 370 | * profile_langskills, profile_mentor, profile_networking, |
| 371 | * profile_phones, profile_skills, watch_profile |
| 372 | * *always keeps in: profile_corps, profile_display, profile_education, |
| 373 | * profile_medals, profile_name, profile_photos, search_name |
| 374 | * *modifies: profiles |
| 375 | */ |
| 376 | public function clear() |
| 377 | { |
| 378 | $tables = array( |
| 379 | 'profile_job', 'profile_langskills', 'profile_mentor', |
| 380 | 'profile_networking', 'profile_skills', 'watch_profile', |
| 381 | 'profile_phones', 'profile_addresses', 'profile_binets'); |
| 382 | |
| 383 | foreach ($tables as $t) { |
| 384 | XDB::execute('DELETE FROM ' . $t . ' |
| 385 | WHERE pid = {?}', |
| 386 | $this->id()); |
| 387 | } |
| 388 | |
| 389 | XDB::execute("UPDATE profiles |
| 390 | SET cv = NULL, freetext = NULL, freetext_pub = 'private', |
| 391 | medals_pub = 'private', alias_pub = 'private', |
| 392 | email_directory = NULL |
| 393 | WHERE pid = {?}", |
| 394 | $this->id()); |
| 395 | } |
| 396 | |
| 397 | /** Sets the level of visibility of the profile |
| 398 | * Sets $this->visibility to a list of valid visibilities. |
| 399 | * @param one of the self::VIS_* values |
| 400 | */ |
| 401 | public function setVisibilityLevel($visibility) |
| 402 | { |
| 403 | $this->visibility->setLevel($visibility); |
| 404 | } |
| 405 | |
| 406 | /** Determine whether an item with visibility $visibility can be displayed |
| 407 | * with the current level of visibility of the profile |
| 408 | * @param $visibility The level of visibility to be checked |
| 409 | */ |
| 410 | public function isVisible($visibility) |
| 411 | { |
| 412 | return $this->visibility->isVisible($visibility); |
| 413 | } |
| 414 | |
| 415 | /** Stores the list of fields which have already been fetched for this Profile |
| 416 | */ |
| 417 | public function setFetchedFields($fields) |
| 418 | { |
| 419 | if (($fields | self::FETCH_ALL) != self::FETCH_ALL) { |
| 420 | Platal::page()->kill("Invalid fetched fields: $fields"); |
| 421 | } |
| 422 | |
| 423 | $this->fetched_fields = $fields; |
| 424 | } |
| 425 | |
| 426 | /** Have we already fetched this field ? |
| 427 | */ |
| 428 | private function fetched($field) |
| 429 | { |
| 430 | if (!array_key_exists($field, ProfileField::$fields)) { |
| 431 | Platal::page()->kill("Invalid field: $field"); |
| 432 | } |
| 433 | |
| 434 | return ($this->fetched_fields & $field); |
| 435 | } |
| 436 | |
| 437 | /** If not already done, fetches data for the given field |
| 438 | * @param $field One of the Profile::FETCH_* |
| 439 | * @return A ProfileField, or null |
| 440 | */ |
| 441 | private function getProfileField($field) |
| 442 | { |
| 443 | if (!array_key_exists($field, ProfileField::$fields)) { |
| 444 | Platal::page()->kill("Invalid field: $field"); |
| 445 | } |
| 446 | if ($this->fetched($field)) { |
| 447 | return null; |
| 448 | } else { |
| 449 | $this->fetched_fields = $this->fetched_fields | $field; |
| 450 | } |
| 451 | |
| 452 | $cls = ProfileField::$fields[$field]; |
| 453 | |
| 454 | return ProfileField::getForPID($cls, $this->id(), $this->visibility); |
| 455 | } |
| 456 | |
| 457 | /** Consolidates internal data (addresses, phones, jobs) |
| 458 | */ |
| 459 | private function consolidateFields() |
| 460 | { |
| 461 | // Link phones to addresses |
| 462 | if ($this->phones != null) { |
| 463 | if ($this->addresses != null) { |
| 464 | $this->addresses->addPhones($this->phones); |
| 465 | } |
| 466 | |
| 467 | if ($this->jobs != null) { |
| 468 | $this->jobs->addPhones($this->phones); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | // Link addresses to jobs |
| 473 | if ($this->addresses != null && $this->jobs != null) { |
| 474 | $this->jobs->addAddresses($this->addresses); |
| 475 | } |
| 476 | |
| 477 | // Link jobterms to jobs |
| 478 | if ($this->jobs != null && $this->jobterms != null) { |
| 479 | $this->jobs->addJobTerms($this->jobterms); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | /* Photo |
| 484 | */ |
| 485 | private $photo = null; |
| 486 | public function getPhoto($fallback = true, $data = false) |
| 487 | { |
| 488 | if ($this->has_photo) { |
| 489 | if ($data && ($this->photo == null || $this->photo->mimeType == null)) { |
| 490 | $res = XDB::fetchOneAssoc('SELECT attach, attachmime, x, y |
| 491 | FROM profile_photos |
| 492 | WHERE pid = {?}', $this->pid); |
| 493 | $this->photo = PlImage::fromData($res['attach'], $res['attachmime'], $res['x'], $res['y']); |
| 494 | } else if ($this->photo == null) { |
| 495 | $this->photo = PlImage::fromData(null, null, $this->photo_width, $this->photo_height); |
| 496 | } |
| 497 | return $this->photo; |
| 498 | } else if ($fallback) { |
| 499 | return PlImage::fromFile(dirname(__FILE__).'/../htdocs/images/none.png', |
| 500 | 'image/png'); |
| 501 | } |
| 502 | return null; |
| 503 | } |
| 504 | |
| 505 | /* Addresses |
| 506 | */ |
| 507 | private $addresses = null; |
| 508 | public function setAddresses(ProfileAddresses $addr) |
| 509 | { |
| 510 | $this->addresses = $addr; |
| 511 | $this->consolidateFields(); |
| 512 | } |
| 513 | |
| 514 | private function fetchAddresses() |
| 515 | { |
| 516 | if ($this->addresses == null && !$this->fetched(self::FETCH_ADDRESSES)) { |
| 517 | $addr = $this->getProfileField(self::FETCH_ADDRESSES); |
| 518 | if ($addr) { |
| 519 | $this->setAddresses($addr); |
| 520 | $this->fetchPhones(); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | public function getAddresses($flags, $limit = null) |
| 526 | { |
| 527 | $this->fetchAddresses(); |
| 528 | |
| 529 | if ($this->addresses == null) { |
| 530 | return array(); |
| 531 | } |
| 532 | return $this->addresses->get($flags, $limit); |
| 533 | } |
| 534 | |
| 535 | public function iterAddresses($flags, $limit = null) |
| 536 | { |
| 537 | return PlIteratorUtils::fromArray($this->getAddresses($flags, $limit), 1, true); |
| 538 | } |
| 539 | |
| 540 | public function getMainAddress() |
| 541 | { |
| 542 | $addr = $this->getAddresses(self::ADDRESS_PERSO | self::ADDRESS_MAIN); |
| 543 | if (count($addr) == 0) { |
| 544 | return null; |
| 545 | } else { |
| 546 | return array_pop($addr); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | /* Phones |
| 551 | */ |
| 552 | private $phones = null; |
| 553 | public function setPhones(ProfilePhones $phones) |
| 554 | { |
| 555 | $this->phones = $phones; |
| 556 | $this->consolidateFields(); |
| 557 | } |
| 558 | |
| 559 | private function fetchPhones() |
| 560 | { |
| 561 | if ($this->phones == null && !$this->fetched(self::FETCH_PHONES)) { |
| 562 | $phones = $this->getProfileField(self::FETCH_PHONES); |
| 563 | if (isset($phones)) { |
| 564 | $this->setPhones($phones); |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | public function getPhones($flags, $limit = null) |
| 570 | { |
| 571 | $this->fetchPhones(); |
| 572 | if ($this->phones == null) { |
| 573 | return array(); |
| 574 | } |
| 575 | return $this->phones->get($flags, $limit); |
| 576 | } |
| 577 | |
| 578 | /* Educations |
| 579 | */ |
| 580 | private $educations = null; |
| 581 | public function setEducations(ProfileEducation $edu) |
| 582 | { |
| 583 | $this->educations = $edu; |
| 584 | } |
| 585 | |
| 586 | public function getEducations($flags, $limit = null) |
| 587 | { |
| 588 | if ($this->educations == null && !$this->fetched(self::FETCH_EDU)) { |
| 589 | $this->setEducations($this->getProfileField(self::FETCH_EDU)); |
| 590 | } |
| 591 | |
| 592 | if ($this->educations == null) { |
| 593 | return array(); |
| 594 | } |
| 595 | return $this->educations->get($flags, $limit); |
| 596 | } |
| 597 | |
| 598 | public function getExtraEducations($limit = null) |
| 599 | { |
| 600 | return $this->getEducations(self::EDUCATION_EXTRA, $limit); |
| 601 | } |
| 602 | |
| 603 | /* Corps |
| 604 | */ |
| 605 | private $corps = null; |
| 606 | public function setCorps(ProfileCorps $corps) |
| 607 | { |
| 608 | $this->corps = $corps; |
| 609 | } |
| 610 | |
| 611 | public function getCorps() |
| 612 | { |
| 613 | if ($this->corps == null && !$this->fetched(self::FETCH_CORPS)) { |
| 614 | $this->setCorps($this->getProfileField(self::FETCH_CORPS)); |
| 615 | } |
| 616 | return $this->corps; |
| 617 | } |
| 618 | |
| 619 | /** Networking |
| 620 | */ |
| 621 | private $networks = null; |
| 622 | public function setNetworking(ProfileNetworking $nw) |
| 623 | { |
| 624 | $this->networks = $nw; |
| 625 | } |
| 626 | |
| 627 | public function getNetworking($flags, $limit = null) |
| 628 | { |
| 629 | if ($this->networks == null && !$this->fetched(self::FETCH_NETWORKING)) { |
| 630 | $nw = $this->getProfileField(self::FETCH_NETWORKING); |
| 631 | if ($nw) { |
| 632 | $this->setNetworking($nw); |
| 633 | } |
| 634 | } |
| 635 | if ($this->networks == null) { |
| 636 | return array(); |
| 637 | } |
| 638 | return $this->networks->get($flags, $limit); |
| 639 | } |
| 640 | |
| 641 | public function getWebSite() |
| 642 | { |
| 643 | $site = $this->getNetworking(self::NETWORKING_WEB, 1); |
| 644 | if (count($site) != 1) { |
| 645 | return null; |
| 646 | } |
| 647 | $site = array_pop($site); |
| 648 | return $site; |
| 649 | } |
| 650 | |
| 651 | |
| 652 | /** Jobs |
| 653 | */ |
| 654 | private $jobs = null; |
| 655 | public function setJobs(ProfileJobs $jobs) |
| 656 | { |
| 657 | $this->jobs = $jobs; |
| 658 | $this->consolidateFields(); |
| 659 | } |
| 660 | |
| 661 | private function fetchJobs() |
| 662 | { |
| 663 | if ($this->jobs == null && !$this->fetched(self::FETCH_JOBS)) { |
| 664 | $jobs = $this->getProfileField(self::FETCH_JOBS); |
| 665 | if ($jobs) { |
| 666 | $this->setJobs($jobs); |
| 667 | $this->fetchAddresses(); |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | public function getJobs($flags, $limit = null) |
| 673 | { |
| 674 | $this->fetchJobs(); |
| 675 | |
| 676 | if ($this->jobs == null) { |
| 677 | return array(); |
| 678 | } |
| 679 | return $this->jobs->get($flags, $limit); |
| 680 | } |
| 681 | |
| 682 | public function getMainJob() |
| 683 | { |
| 684 | $job = $this->getJobs(self::JOBS_MAIN, 1); |
| 685 | if (count($job) != 1) { |
| 686 | return null; |
| 687 | } |
| 688 | return array_pop($job); |
| 689 | } |
| 690 | |
| 691 | /** JobTerms |
| 692 | */ |
| 693 | private $jobterms = null; |
| 694 | public function setJobTerms(ProfileJobTerms $jobterms) |
| 695 | { |
| 696 | $this->jobterms = $jobterms; |
| 697 | $this->consolidateFields(); |
| 698 | } |
| 699 | |
| 700 | /* Mentoring |
| 701 | */ |
| 702 | private $mentor_sectors = null; |
| 703 | public function setMentoringSectors(ProfileMentoringSectors $sectors) |
| 704 | { |
| 705 | $this->mentor_sectors = $sectors; |
| 706 | } |
| 707 | |
| 708 | public function getMentoringSectors() |
| 709 | { |
| 710 | if ($this->mentor_sectors == null && !$this->fetched(self::FETCH_MENTOR_SECTOR)) { |
| 711 | $this->setMentoringSectors($this->getProfileField(self::FETCH_MENTOR_SECTOR)); |
| 712 | } |
| 713 | |
| 714 | if ($this->mentor_sectors == null) { |
| 715 | return array(); |
| 716 | } else { |
| 717 | return $this->mentor_sectors->sectors; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | private $mentor_countries = null; |
| 722 | public function setMentoringCountries(ProfileMentoringCountries $countries) |
| 723 | { |
| 724 | $this->mentor_countries = $countries; |
| 725 | } |
| 726 | |
| 727 | public function getMentoringCountries() |
| 728 | { |
| 729 | if ($this->mentor_countries == null && !$this->fetched(self::FETCH_MENTOR_COUNTRY)) { |
| 730 | $this->setMentoringCountries($this->getProfileField(self::FETCH_MENTOR_COUNTRY)); |
| 731 | } |
| 732 | |
| 733 | if ($this->mentor_countries == null) { |
| 734 | return array(); |
| 735 | } else { |
| 736 | return $this->mentor_countries->countries; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | /** List of job terms to specify mentoring */ |
| 741 | private $mentor_terms = null; |
| 742 | /** |
| 743 | * set job terms to specify mentoring |
| 744 | * @param $terms a ProfileMentoringTerms object listing terms only for this profile |
| 745 | */ |
| 746 | public function setMentoringTerms(ProfileMentoringTerms $terms) |
| 747 | { |
| 748 | $this->mentor_terms = $terms; |
| 749 | } |
| 750 | /** |
| 751 | * get all job terms that specify mentoring |
| 752 | * @return an array of JobTerms objects |
| 753 | */ |
| 754 | public function getMentoringTerms() |
| 755 | { |
| 756 | if ($this->mentor_terms == null && !$this->fetched(self::FETCH_MENTOR_TERMS)) { |
| 757 | $this->setMentoringTerms($this->getProfileField(self::FETCH_MENTOR_TERMS)); |
| 758 | } |
| 759 | |
| 760 | if ($this->mentor_terms == null) { |
| 761 | return array(); |
| 762 | } else { |
| 763 | return $this->mentor_terms->get(); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | |
| 768 | /* Binets |
| 769 | */ |
| 770 | public function getBinets() |
| 771 | { |
| 772 | if ($this->visibility->isVisible(ProfileVisibility::VIS_PRIVATE)) { |
| 773 | return XDB::fetchColumn('SELECT binet_id |
| 774 | FROM profile_binets |
| 775 | WHERE pid = {?}', $this->id()); |
| 776 | } else { |
| 777 | return array(); |
| 778 | } |
| 779 | } |
| 780 | public function getBinetsNames() |
| 781 | { |
| 782 | if ($this->visibility->isVisible(ProfileVisibility::VIS_PRIVATE)) { |
| 783 | return XDB::fetchColumn('SELECT text |
| 784 | FROM profile_binets AS pb |
| 785 | LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id) |
| 786 | WHERE pb.pid = {?}', $this->id()); |
| 787 | } else { |
| 788 | return array(); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | /* Medals |
| 793 | */ |
| 794 | private $medals = null; |
| 795 | public function setMedals(ProfileMedals $medals) |
| 796 | { |
| 797 | $this->medals = $medals; |
| 798 | } |
| 799 | |
| 800 | public function getMedals() |
| 801 | { |
| 802 | if ($this->medals == null && !$this->fetched(self::FETCH_MEDALS)) { |
| 803 | $this->setMedals($this->getProfileField(self::FETCH_MEDALS)); |
| 804 | } |
| 805 | if ($this->medals == null) { |
| 806 | return array(); |
| 807 | } |
| 808 | return $this->medals->medals; |
| 809 | } |
| 810 | |
| 811 | public function compareNames($firstname, $lastname) |
| 812 | { |
| 813 | $_lastname = mb_strtoupper($this->lastName()); |
| 814 | $_firstname = mb_strtoupper($this->firstName()); |
| 815 | $lastname = mb_strtoupper($lastname); |
| 816 | $firstname = mb_strtoupper($firstname); |
| 817 | |
| 818 | $isOk = (mb_strtoupper($_firstname) == mb_strtoupper($firstname)); |
| 819 | $tokens = preg_split("/[ \-']/", $lastname, -1, PREG_SPLIT_NO_EMPTY); |
| 820 | $maxlen = 0; |
| 821 | |
| 822 | foreach ($tokens as $str) { |
| 823 | $isOk &= (strpos($_lastname, $str) !== false); |
| 824 | $maxlen = max($maxlen, strlen($str)); |
| 825 | } |
| 826 | |
| 827 | return ($isOk && ($maxlen > 2 || $maxlen == strlen($_lastname))); |
| 828 | } |
| 829 | |
| 830 | private static function fetchProfileData(array $pids, $respect_order = true, $fields = 0x0000, $visibility = null) |
| 831 | { |
| 832 | if (count($pids) == 0) { |
| 833 | return null; |
| 834 | } |
| 835 | |
| 836 | if ($respect_order) { |
| 837 | $order = 'ORDER BY ' . XDB::formatCustomOrder('p.pid', $pids); |
| 838 | } else { |
| 839 | $order = ''; |
| 840 | } |
| 841 | |
| 842 | $visibility = new ProfileVisibility($visibility); |
| 843 | |
| 844 | $it = XDB::Iterator('SELECT p.pid, p.hrpid, p.xorg_id, p.ax_id, p.birthdate, p.birthdate_ref, |
| 845 | p.next_birthday, p.deathdate, p.deathdate_rec, p.sex = \'female\' AS sex, |
| 846 | IF ({?}, p.cv, NULL) AS cv, p.medals_pub, p.alias_pub, p.email_directory, |
| 847 | p.last_change, p.nationality1, p.nationality2, p.nationality3, |
| 848 | IF (p.freetext_pub IN {?}, p.freetext, NULL) AS freetext, |
| 849 | pe.entry_year, pe.grad_year, |
| 850 | IF ({?}, pse.text, NULL) AS section, |
| 851 | pn_f.name AS firstname, pn_l.name AS lastname, |
| 852 | IF( {?}, pn_n.name, NULL) AS nickname, |
| 853 | IF(pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_ordinary, |
| 854 | IF(pn_ul.name IS NULL, pn_l.name, pn_ul.name) AS lastname_ordinary, |
| 855 | pd.yourself, pd.promo, pd.short_name, pd.public_name AS full_name, |
| 856 | pd.directory_name, pd.public_name, pd.private_name, |
| 857 | IF(pp.pub IN {?}, pp.display_tel, NULL) AS mobile, |
| 858 | (ph.pub IN {?} AND ph.attach IS NOT NULL) AS has_photo, |
| 859 | ph.x AS photo_width, ph.y AS photo_height, |
| 860 | p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old, |
| 861 | pm.expertise AS mentor_expertise, |
| 862 | ap.uid AS owner_id |
| 863 | FROM profiles AS p |
| 864 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) |
| 865 | INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags)) |
| 866 | LEFT JOIN profile_section_enum AS pse ON (pse.id = p.section) |
| 867 | INNER JOIN profile_name AS pn_f ON (pn_f.pid = p.pid |
| 868 | AND pn_f.typeid = ' . self::getNameTypeId('firstname', true) . ') |
| 869 | INNER JOIN profile_name AS pn_l ON (pn_l.pid = p.pid |
| 870 | AND pn_l.typeid = ' . self::getNameTypeId('lastname', true) . ') |
| 871 | LEFT JOIN profile_name AS pn_uf ON (pn_uf.pid = p.pid |
| 872 | AND pn_uf.typeid = ' . self::getNameTypeId('firstname_ordinary', true) . ') |
| 873 | LEFT JOIN profile_name AS pn_ul ON (pn_ul.pid = p.pid |
| 874 | AND pn_ul.typeid = ' . self::getNameTypeId('lastname_ordinary', true) . ') |
| 875 | LEFT JOIN profile_name AS pn_n ON (pn_n.pid = p.pid |
| 876 | AND pn_n.typeid = ' . self::getNameTypeId('nickname', true) . ') |
| 877 | LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\') |
| 878 | LEFT JOIN profile_photos AS ph ON (ph.pid = p.pid) |
| 879 | LEFT JOIN profile_mentor AS pm ON (pm.pid = p.pid) |
| 880 | LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms)) |
| 881 | WHERE p.pid IN {?} |
| 882 | GROUP BY p.pid |
| 883 | ' . $order, |
| 884 | $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // CV |
| 885 | $visibility->levels(), // freetext |
| 886 | $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // section |
| 887 | $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // nickname |
| 888 | $visibility->levels(), // mobile |
| 889 | $visibility->levels(), // photo |
| 890 | $pids |
| 891 | ); |
| 892 | return new ProfileIterator($it, $pids, $fields, $visibility); |
| 893 | } |
| 894 | |
| 895 | public static function getPID($login) |
| 896 | { |
| 897 | if ($login instanceof PlUser) { |
| 898 | return XDB::fetchOneCell('SELECT pid |
| 899 | FROM account_profiles |
| 900 | WHERE uid = {?} AND FIND_IN_SET(\'owner\', perms)', |
| 901 | $login->id()); |
| 902 | } else if (ctype_digit($login)) { |
| 903 | return XDB::fetchOneCell('SELECT pid |
| 904 | FROM profiles |
| 905 | WHERE pid = {?}', $login); |
| 906 | } else { |
| 907 | return XDB::fetchOneCell('SELECT pid |
| 908 | FROM profiles |
| 909 | WHERE hrpid = {?}', $login); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | public static function getPIDsFromUIDs($uids, $respect_order = true) |
| 914 | { |
| 915 | if ($respect_order) { |
| 916 | $order = 'ORDER BY ' . XDB::formatCustomOrder('uid', $uids); |
| 917 | } else { |
| 918 | $order = ''; |
| 919 | } |
| 920 | return XDB::fetchAllAssoc('uid', 'SELECT ap.uid, ap.pid |
| 921 | FROM account_profiles AS ap |
| 922 | WHERE FIND_IN_SET(\'owner\', ap.perms) |
| 923 | AND ap.uid IN ' . XDB::formatArray($uids) .' |
| 924 | ' . $order); |
| 925 | } |
| 926 | |
| 927 | /** Return the profile associated with the given login. |
| 928 | */ |
| 929 | public static function get($login, $fields = 0x0000, $visibility = null) |
| 930 | { |
| 931 | if (is_array($login)) { |
| 932 | $pf = new Profile($login); |
| 933 | $pf->setVisibilityLevel($visibility); |
| 934 | return $pf; |
| 935 | } |
| 936 | $pid = self::getPID($login); |
| 937 | if (!is_null($pid)) { |
| 938 | $it = self::iterOverPIDs(array($pid), false, $fields, $visibility); |
| 939 | return $it->next(); |
| 940 | } else { |
| 941 | /* Let say we can identify a profile using the identifiers of its owner. |
| 942 | */ |
| 943 | if (!($login instanceof PlUser)) { |
| 944 | $user = User::getSilent($login); |
| 945 | if ($user && $user->hasProfile()) { |
| 946 | return $user->profile(); |
| 947 | } |
| 948 | } |
| 949 | return null; |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | public static function iterOverUIDs($uids, $respect_order = true, $fields = 0x0000, $visibility = null) |
| 954 | { |
| 955 | return self::iterOverPIDs(self::getPIDsFromUIDs($uids), $respect_order, $fields, $visibility); |
| 956 | } |
| 957 | |
| 958 | public static function iterOverPIDs($pids, $respect_order = true, $fields = 0x0000, $visibility = null) |
| 959 | { |
| 960 | return self::fetchProfileData($pids, $respect_order, $fields, $visibility); |
| 961 | } |
| 962 | |
| 963 | /** Return profiles for the list of pids. |
| 964 | */ |
| 965 | public static function getBulkProfilesWithPIDs(array $pids, $fields = 0x0000, $visibility = null) |
| 966 | { |
| 967 | if (count($pids) == 0) { |
| 968 | return array(); |
| 969 | } |
| 970 | $it = self::iterOverPIDs($pids, true, $fields, $visibility); |
| 971 | $profiles = array(); |
| 972 | while ($p = $it->next()) { |
| 973 | $profiles[$p->id()] = $p; |
| 974 | } |
| 975 | return $profiles; |
| 976 | } |
| 977 | |
| 978 | /** Return profiles for uids. |
| 979 | */ |
| 980 | public static function getBulkProfilesWithUIDS(array $uids, $fields = 0x000, $visibility = null) |
| 981 | { |
| 982 | if (count($uids) == 0) { |
| 983 | return array(); |
| 984 | } |
| 985 | return self::getBulkProfilesWithPIDs(self::getPIDsFromUIDs($uids), $fields, $visibility); |
| 986 | } |
| 987 | |
| 988 | public static function isDisplayName($name) |
| 989 | { |
| 990 | return $name == self::DN_FULL || $name == self::DN_DISPLAY |
| 991 | || $name == self::DN_YOURSELF || $name == self::DN_DIRECTORY |
| 992 | || $name == self::DN_PRIVATE || $name == self::DN_PUBLIC |
| 993 | || $name == self::DN_SHORT || $name == self::DN_SORT; |
| 994 | } |
| 995 | |
| 996 | /** Returns the closest "accounts only" name type for $name |
| 997 | */ |
| 998 | public static function getAccountEquivalentName($name) |
| 999 | { |
| 1000 | switch ($name) |
| 1001 | { |
| 1002 | case self::DN_DIRECTORY: |
| 1003 | case self::DN_SORT: |
| 1004 | return 'directory_name'; |
| 1005 | case self::DN_FULL: |
| 1006 | case self::DN_PUBLIC: |
| 1007 | return 'full_name'; |
| 1008 | case self::DN_PRIVATE: |
| 1009 | case self::DN_SHORT: |
| 1010 | case self::DN_YOURSELF: |
| 1011 | default: |
| 1012 | return 'display_name'; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | public static function getNameTypeId($type, $for_sql = false) |
| 1017 | { |
| 1018 | if (!S::has('name_types')) { |
| 1019 | $table = XDB::fetchAllAssoc('type', 'SELECT id, type |
| 1020 | FROM profile_name_enum'); |
| 1021 | S::set('name_types', $table); |
| 1022 | } else { |
| 1023 | $table = S::v('name_types'); |
| 1024 | } |
| 1025 | if ($for_sql) { |
| 1026 | return XDB::escape($table[$type]); |
| 1027 | } else { |
| 1028 | return $table[$type]; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | public static function rebuildSearchTokens($pid) |
| 1033 | { |
| 1034 | XDB::execute('DELETE FROM search_name |
| 1035 | WHERE pid = {?}', |
| 1036 | $pid); |
| 1037 | $keys = XDB::iterator("SELECT CONCAT(n.particle, n.name) AS name, e.score, |
| 1038 | FIND_IN_SET('public', e.flags) AS public |
| 1039 | FROM profile_name AS n |
| 1040 | INNER JOIN profile_name_enum AS e ON (n.typeid = e.id) |
| 1041 | WHERE n.pid = {?}", |
| 1042 | $pid); |
| 1043 | |
| 1044 | while ($key = $keys->next()) { |
| 1045 | if ($key['name'] == '') { |
| 1046 | continue; |
| 1047 | } |
| 1048 | $toks = preg_split('/[ \'\-]+/', $key['name']); |
| 1049 | $token = ''; |
| 1050 | $first = 5; |
| 1051 | while ($toks) { |
| 1052 | $token = strtolower(replace_accent(array_pop($toks) . $token)); |
| 1053 | $score = ($toks ? 0 : 10 + $first) * ($key['score'] / 10); |
| 1054 | XDB::execute('REPLACE INTO search_name (token, pid, soundex, score, flags) |
| 1055 | VALUES ({?}, {?}, {?}, {?}, {?})', |
| 1056 | $token, $pid, soundex_fr($token), $score, $key['public']); |
| 1057 | $first = 0; |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | /** The school identifier consists of 6 digits. The first 3 represent the |
| 1063 | * promotion entry year. The last 3 indicate the student's rank. |
| 1064 | * |
| 1065 | * Our identifier consists of 8 digits and both half have the same role. |
| 1066 | * This enables us to deal with bigger promotions and with a wider range |
| 1067 | * of promotions. |
| 1068 | * |
| 1069 | * getSchoolId returns a school identifier given one of ours. |
| 1070 | * getXorgId returns a X.org identifier given a school identifier. |
| 1071 | */ |
| 1072 | public static function getSchoolId($xorgId) |
| 1073 | { |
| 1074 | if (!preg_match('/^[0-9]{8}$/', $xorgId)) { |
| 1075 | return null; |
| 1076 | } |
| 1077 | |
| 1078 | $year = intval(substr($xorgId, 0, 4)); |
| 1079 | $rank = intval(substr($xorgId, 5, 3)); |
| 1080 | if ($year < 1996) { |
| 1081 | return null; |
| 1082 | } elseif ($year < 2000) { |
| 1083 | $year = intval(substr(1900 - $year, 1, 3)); |
| 1084 | return sprintf('%02u0%03u', $year, $rank); |
| 1085 | } else { |
| 1086 | $year = intval(substr(1900 - $year, 1, 3)); |
| 1087 | return sprintf('%03u%03u', $year, $rank); |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | public static function getXorgId($schoolId) |
| 1092 | { |
| 1093 | if (!preg_match('/^[0-9]{6}$/', $schoolId)) { |
| 1094 | return null; |
| 1095 | } |
| 1096 | |
| 1097 | $year = intval(substr($schoolId, 0, 3)); |
| 1098 | $rank = intval(substr($schoolId, 3, 3)); |
| 1099 | |
| 1100 | if ($year > 200) { |
| 1101 | $year /= 10; |
| 1102 | } |
| 1103 | if ($year < 96) { |
| 1104 | return null; |
| 1105 | } else { |
| 1106 | return sprintf('%04u%04u', 1900 + $year, $rank); |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | |
| 1112 | /** Iterator over a set of Profiles |
| 1113 | */ |
| 1114 | class ProfileIterator implements PlIterator |
| 1115 | { |
| 1116 | private $iterator = null; |
| 1117 | private $fields; |
| 1118 | private $visibility; |
| 1119 | |
| 1120 | const FETCH_ALL = 0x000033F; // FETCH_ADDRESSES | FETCH_CORPS | FETCH_EDU | FETCH_JOBS | FETCH_MEDALS | FETCH_NETWORKING | FETCH_PHONES | FETCH_JOB_TERMS |
| 1121 | |
| 1122 | public function __construct(PlIterator $it, array $pids, $fields = 0x0000, ProfileVisibility $visibility = null) |
| 1123 | { |
| 1124 | require_once 'profilefields.inc.php'; |
| 1125 | |
| 1126 | if ($visibility == null) { |
| 1127 | $visibility = new ProfileVisibility(); |
| 1128 | } |
| 1129 | |
| 1130 | $this->fields = $fields; |
| 1131 | $this->visibility = $visibility; |
| 1132 | |
| 1133 | $subits = array(); |
| 1134 | $callbacks = array(); |
| 1135 | |
| 1136 | $subits[0] = $it; |
| 1137 | $callbacks[0] = PlIteratorUtils::arrayValueCallback('pid'); |
| 1138 | $cb = PlIteratorUtils::objectPropertyCallback('pid'); |
| 1139 | |
| 1140 | $fields = $fields & self::FETCH_ALL; |
| 1141 | for ($field = 1; $field < $fields; $field *= 2) { |
| 1142 | if (($fields & $field) ) { |
| 1143 | $callbacks[$field] = $cb; |
| 1144 | $subits[$field] = new ProfileFieldIterator($field, $pids, $visibility); |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | $this->iterator = PlIteratorUtils::parallelIterator($subits, $callbacks, 0); |
| 1149 | } |
| 1150 | |
| 1151 | private function hasData($field, $vals) |
| 1152 | { |
| 1153 | return ($this->fields & $field) && ($vals[$field] != null); |
| 1154 | } |
| 1155 | |
| 1156 | private function fillProfile(array $vals) |
| 1157 | { |
| 1158 | $pf = Profile::get($vals[0]); |
| 1159 | $pf->setVisibilityLevel($this->visibility->level()); |
| 1160 | $pf->setFetchedFields($this->fields); |
| 1161 | |
| 1162 | if ($this->hasData(Profile::FETCH_PHONES, $vals)) { |
| 1163 | $pf->setPhones($vals[Profile::FETCH_PHONES]); |
| 1164 | } |
| 1165 | if ($this->hasData(Profile::FETCH_ADDRESSES, $vals)) { |
| 1166 | $pf->setAddresses($vals[Profile::FETCH_ADDRESSES]); |
| 1167 | } |
| 1168 | if ($this->hasData(Profile::FETCH_JOBS, $vals)) { |
| 1169 | $pf->setJobs($vals[Profile::FETCH_JOBS]); |
| 1170 | } |
| 1171 | if ($this->hasData(Profile::FETCH_JOB_TERMS, $vals)) { |
| 1172 | $pf->setJobTerms($vals[Profile::FETCH_JOB_TERMS]); |
| 1173 | } |
| 1174 | |
| 1175 | if ($this->hasData(Profile::FETCH_CORPS, $vals)) { |
| 1176 | $pf->setCorps($vals[Profile::FETCH_CORPS]); |
| 1177 | } |
| 1178 | if ($this->hasData(Profile::FETCH_EDU, $vals)) { |
| 1179 | $pf->setEducations($vals[Profile::FETCH_EDU]); |
| 1180 | } |
| 1181 | if ($this->hasData(Profile::FETCH_MEDALS, $vals)) { |
| 1182 | $pf->setMedals($vals[Profile::FETCH_MEDALS]); |
| 1183 | } |
| 1184 | if ($this->hasData(Profile::FETCH_NETWORKING, $vals)) { |
| 1185 | $pf->setNetworking($vals[Profile::FETCH_NETWORKING]); |
| 1186 | } |
| 1187 | |
| 1188 | return $pf; |
| 1189 | } |
| 1190 | |
| 1191 | public function next() |
| 1192 | { |
| 1193 | $vals = $this->iterator->next(); |
| 1194 | if ($vals == null) { |
| 1195 | return null; |
| 1196 | } |
| 1197 | return $this->fillProfile($vals); |
| 1198 | } |
| 1199 | |
| 1200 | public function first() |
| 1201 | { |
| 1202 | return $this->iterator->first(); |
| 1203 | } |
| 1204 | |
| 1205 | public function last() |
| 1206 | { |
| 1207 | return $this->iterator->last(); |
| 1208 | } |
| 1209 | |
| 1210 | public function total() |
| 1211 | { |
| 1212 | return $this->iterator->total(); |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 1217 | ?> |