ae6b19790a97e5de7eece1855e7ba547ce1022df
2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
24 static private $v_values = array('public' => array('public'),
25 'ax' => array('ax', 'public'),
26 'private' => array('private', 'ax', 'public'));
28 const VISIBILITY_PUBLIC
= 'public';
29 const VISIBILITY_AX
= 'ax';
30 const VISIBILITY_PRIVATE
= 'private';
33 const LASTNAME
= 'lastname';
34 const FIRSTNAME
= 'firstname';
35 const NICKNAME
= 'nickname';
36 const PSEUDONYM
= 'pseudonym';
39 const VN_MARITAL
= 'marital';
40 const VN_ORDINARY
= 'ordinary';
41 const VN_OTHER
= 'other';
44 const DN_FULL
= 'directory_name';
45 const DN_DISPLAY
= 'yourself';
46 const DN_YOURSELF
= 'yourself';
47 const DN_DIRECTORY
= 'directory_name';
48 const DN_PRIVATE
= 'private_name';
49 const DN_PUBLIC
= 'public_name';
50 const DN_SHORT
= 'short_name';
51 const DN_SORT
= 'sort_name';
52 /* education related names */
53 const EDU_X
= 'École polytechnique';
54 const DEGREE_X
= 'Ingénieur';
55 const DEGREE_M
= 'Master';
56 const DEGREE_D
= 'Doctorat';
58 static public $name_variants = array(
59 self
::LASTNAME
=> array(self
::VN_MARITAL
, self
::VN_ORDINARY
),
60 self
::FIRSTNAME
=> array(self
::VN_ORDINARY
, self
::VN_INI
, self
::VN_OTHER
)
63 const ADDRESS_MAIN
= 0x000001;
64 const ADDRESS_PERSO
= 0x000002;
65 const ADDRESS_PRO
= 0x000004;
66 const ADDRESS_ALL
= 0x000006;
67 const ADDRESS_POSTAL
= 0x000008;
69 const EDUCATION_MAIN
= 0x000010;
70 const EDUCATION_EXTRA
= 0x000020;
71 const EDUCATION_ALL
= 0x000040;
72 const EDUCATION_FINISHED
= 0x000080;
73 const EDUCATION_CURRENT
= 0x000100;
75 const JOBS_MAIN
= 0x001000;
76 const JOBS_ALL
= 0x002000;
77 const JOBS_FINISHED
= 0x004000;
78 const JOBS_CURRENT
= 0x008000;
80 const NETWORKING_ALL
= 0x000000;
81 const NETWORKING_WEB
= 0x010000;
82 const NETWORKING_IM
= 0x020000;
83 const NETWORKING_SOCIAL
= 0x040000;
85 const FETCH_ADDRESSES
= 0x00001;
86 const FETCH_CORPS
= 0x00002;
87 const FETCH_EDU
= 0x00004;
88 const FETCH_JOBS
= 0x00008;
89 const FETCH_MEDALS
= 0x00010;
90 const FETCH_NETWORKING
= 0x00020;
91 const FETCH_PHONES
= 0x00040;
92 const FETCH_PHOTO
= 0x00080;
96 private $data = array();
98 private $visibility = null
;
100 private function __construct(array $data)
103 $this->pid
= $this->data
['pid'];
104 $this->hrpid
= $this->data
['hrpid'];
106 $this->setVisibilityLevel(self
::VISIBILITY_PUBLIC
);
110 static private $contexts = array();
112 /** Returns the best visibility context toward $visibility
113 * @param $visibility A wished visibility level
114 * @return The closest allowed visibility level
116 * if $visibility is null, the best visibility is returned
118 static public function getVisibilityContext($visibility = null
)
120 if (array_key_exists($visibility, self
::$contexts)) {
121 return self
::$contexts[$visibility];
124 $asked_vis = $visibility;
127 $minvis = self
::VISIBILITY_PRIVATE
;
129 $minvis = self
::VISIBILITY_PUBLIC
;
131 if ($visibility == null
) {
132 $visibility = array($minvis);
135 if ($minvis == self
::VISIBILITY_PUBLIC
) {
136 $visibility = array(self
::VISIBILITY_PUBLIC
);
139 self
::$contexts[$asked_vis] = $visibility;
149 public function hrid()
154 public function promo()
159 public function yearpromo()
161 return intval(substr($this->promo
, 1, 4));
164 /** Print a name with the given formatting:
172 public function name($format)
174 return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'),
175 array($this->isFemale() ?
'•' : '',
176 $this->firstName(), $this->lastName(),
177 $this->fullName(), $this->shortName(),
178 $this->promo()), $format);
181 public function fullName($with_promo = false
)
184 return $this->full_name
. ' (' . $this->promo
. ')';
186 return $this->full_name
;
189 public function shortName($with_promo = false
)
192 return $this->short_name
. ' (' . $this->promo
. ')';
194 return $this->short_name
;
197 public function firstName()
199 return $this->firstname
;
202 public function firstNames()
204 return $this->nameVariants(self
::FIRSTNAME
);
207 public function lastName()
209 return $this->lastname
;
212 public function lastNames()
214 return $this->nameVariants(self
::LASTNAME
);
217 public function isFemale()
219 return $this->sex
== PlUser
::GENDER_FEMALE
;
222 public function data()
228 private function nameVariants($type)
230 $vals = array($this->$type);
231 foreach (self
::$name_variants[$type] as $var) {
232 $vartype = $type . '_' . $var;
233 $varname = $this->$vartype;
234 if ($varname != null
&& $varname != "") {
238 return array_unique($vals);
241 public function nationalities()
244 if ($this->nationality1
) {
245 $nats[] = $this->nationality1
;
247 if ($this->nationality2
) {
248 $nats[] = $this->nationality2
;
250 if ($this->nationality3
) {
251 $nats[] = $this->nationality3
;
256 public function __get($name)
258 if (property_exists($this, $name)) {
262 if (isset($this->data
[$name])) {
263 return $this->data
[$name];
269 public function __isset($name)
271 return property_exists($this, $name) ||
isset($this->data
[$name]);
274 /** Sets the level of visibility of the profile
275 * Sets $this->visibility to a list of valid visibilities.
276 * @param one of the self::VISIBILITY_* values
278 public function setVisibilityLevel($visibility)
280 if ($visibility != self
::VISIBILITY_PRIVATE
281 && $visibility != self
::VISIBILITY_AX
282 && $visibility != self
::VISIBILITY_PUBLIC
) {
283 Platal
::page()->kill("Visibility invalide: " . $visibility);
285 $this->visibility
= self
::$v_values[$visibility];
286 if ($this->mobile
&& !in_array($this->mobile_pub
, $this->visibility
)) {
287 unset($this->data
['mobile']);
291 /** Determine whether an item with visibility $visibility can be displayed
292 * with the current level of visibility of the profile
293 * @param $visibility The level of visibility to be checked
295 public function isVisible($visibility)
297 return in_array($visibility, $this->visibility
);
300 public static function getCompatibleVisibilities($visibility)
302 return self
::$v_values[$visibility];
307 private $photo = null
;
308 public function setPhoto(ProfilePhoto
$photo)
310 $this->photo
= $photo;
313 public function getPhoto($fallback = true
)
315 if ($this->photo
!= null
) {
316 return $this->photo
->pic
;
317 } else if ($fallback) {
318 return PlImage
::fromFile(dirname(__FILE__
).'/../htdocs/images/none.png',
326 private $addresses = null
;
327 public function setAddresses(ProfileAddresses
$addr)
329 $this->addresses
= $addr;
332 public function getAddresses($flags, $limit = null
)
334 if ($this->addresses
== null
) {
335 return PlIteratorUtils
::fromArray(array());
337 return $this->addresses
->get($flags, $limit);
341 public function getMainAddress()
343 $it = $this->getAddresses(self
::ADDRESS_PERSO | self
::ADDRESS_MAIN
);
344 if ($it->total() == 0) {
354 public function getEducations($flags, $limit = null
)
356 $where = XDB
::format('pe.pid = {?}', $this->id());
357 if ($flags & self
::EDUCATION_MAIN
) {
358 $where .= ' AND FIND_IN_SET(\'primary\', pe.flags)';
359 } else if ($flags & self
::EDUCATION_EXTRA
) {
360 $where .= ' AND NOT FIND_IN_SET(\'primary\', pe.flags)';
361 } else if ($flags & self
::EDUCATION_FINISHED
) {
362 $where .= ' AND pe.grad_year <= YEAR(CURDATE())';
363 } else if ($flags & self
::EDUCATION_CURRENT
) {
364 $where .= ' AND pe.grad_year > YEAR(CURDATE())';
366 $limit = is_null($limit) ?
'' : XDB
::format('LIMIT {?}', (int)$limit);
367 return XDB
::iterator('SELECT pe.entry_year, pe.grad_year, pe.program,
368 pee.name AS school, pee.abbreviation AS school_short, pee.url AS school_url, gc.countryFR AS country,
369 pede.degree, pede.abbreviation AS degree_short, pede.level AS degree_level, pefe.field,
370 FIND_IN_SET(\'primary\', pe.flags) AS prim
371 FROM profile_education AS pe
372 INNER JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
373 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pee.country)
374 INNER JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
375 LEFT JOIN profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
377 ORDER BY NOT FIND_IN_SET(\'primary\', pe.flags), pe.entry_year, pe.id
381 public function getExtraEducations($limit = null
)
383 return $this->getEducations(self
::EDUCATION_EXTRA
, $limit);
390 public function getNetworking($flags, $limit = null
)
392 $where = XDB
::format('pn.pid = {?}', $this->id());
393 if ($flags & self
::NETWORKING_WEB
) {
394 $where .= ' AND pn.network_type = 0'; // XXX hardcoded reference to web site index
396 if ($this->visibility
) {
397 $where .= ' AND pn.pub IN ' . XDB
::formatArray($this->visibility
);
399 $limit = is_null($limit) ?
'' : XDB
::format('LIMIT {?}', (int)$limit);
400 return XDB
::iterator('SELECT pne.name, pne.icon,
401 IF (LENGTH(pne.link) > 0, REPLACE(pne.link, \'%s\', pn.address),
402 pn.address) AS address
403 FROM profile_networking AS pn
404 INNER JOIN profile_networking_enum AS pne ON (pn.network_type = pne.network_type)
406 ORDER BY pn.network_type, pn.nwid
410 public function getWebSite()
412 $site = $this->getNetworking(self
::NETWORKING_WEB
, 1);
413 if ($site->total() != 1) {
416 $site = $site->next();
417 return $site['address'];
424 public function getJobs($flags, $limit = null
)
426 $where = XDB
::format('pj.pid = {?}', $this->id());
428 if ($this->visibility
) {
429 $where .= ' AND pj.pub IN ' . XDB
::formatArray($this->visibility
);
430 $cond = 'pj.email_pub IN ' . XDB
::formatArray($this->visibility
);
432 $limit = is_null($limit) ?
'' : XDB
::format('LIMIT {?}', (int)$limit);
433 return XDB
::iterator('SELECT pje.name, pje.acronym, pje.url, pje.email, pje.NAF_code,
434 pj.description, pj.url AS user_site,
435 IF (' . $cond . ', pj.email, NULL) AS user_email,
436 pjse.name AS sector, pjsse.name AS subsector,
437 pjssse.name AS subsubsector
438 FROM profile_job AS pj
439 INNER JOIN profile_job_enum AS pje ON (pje.id = pj.jobid)
440 LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pj.sectorid)
441 LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pj.subsectorid)
442 LEFT JOIN profile_job_subsubsector_enum AS pjssse ON (pjssse.id = pj.subsubsectorid)
448 public function getMailJob()
450 $job = $this->getJobs(self
::JOBS_MAIN
, 1);
451 if ($job->total() != 1) {
459 public function getBinets()
461 return XDB
::fetchColumn('SELECT binet_id
463 WHERE pid = {?}', $this->id());
467 public function owner()
469 return User
::getSilent($this);
472 public function compareNames($firstname, $lastname)
474 $_lastname = mb_strtoupper($this->lastName());
475 $_firstname = mb_strtoupper($this->firstName());
476 $lastname = mb_strtoupper($lastname);
477 $firstname = mb_strtoupper($firstname);
479 $isOk = (mb_strtoupper($_firstname) == mb_strtoupper($firstname));
480 $tokens = preg_split("/[ \-']/", $lastname, -1, PREG_SPLIT_NO_EMPTY
);
483 foreach ($tokens as $str) {
484 $isOk &= (strpos($_lastname, $str) !== false
);
485 $maxlen = max($maxlen, strlen($str));
488 return ($isOk && ($maxlen > 2 ||
$maxlen == strlen($_lastname)));
491 private static function fetchProfileData(array $pids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
493 if (count($pids) == 0) {
497 if ($respect_order) {
498 $order = 'ORDER BY ' . XDB
::formatCustomOrder('p.pid', $pids);
504 $it = XDB
::Iterator('SELECT p.*, p.sex = \'female\' AS sex, pe.entry_year, pe.grad_year,
505 pn_f.name AS firstname, pn_l.name AS lastname, pn_n.name AS nickname,
506 IF(pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_ordinary,
507 IF(pn_ul.name IS NULL, pn_l.name, pn_ul.name) AS lastname_ordinary,
508 pd.promo AS promo, pd.short_name, pd.directory_name AS full_name,
509 pd.directory_name, pp.display_tel AS mobile, pp.pub AS mobile_pub,
510 ph.attach IS NOT NULL AS has_photo, ph.pub AS photo_pub,
511 p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old,
514 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
515 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags))
516 INNER JOIN profile_name AS pn_f ON (pn_f.pid = p.pid
517 AND pn_f.typeid = ' . self
::getNameTypeId('firstname', true
) . ')
518 INNER JOIN profile_name AS pn_l ON (pn_l.pid = p.pid
519 AND pn_l.typeid = ' . self
::getNameTypeId('lastname', true
) . ')
520 LEFT JOIN profile_name AS pn_uf ON (pn_uf.pid = p.pid
521 AND pn_uf.typeid = ' . self
::getNameTypeId('firstname_ordinary', true
) . ')
522 LEFT JOIN profile_name AS pn_ul ON (pn_ul.pid = p.pid
523 AND pn_ul.typeid = ' . self
::getNameTypeId('lastname_ordinary', true
) . ')
524 LEFT JOIN profile_name AS pn_n ON (pn_n.pid = p.pid
525 AND pn_n.typeid = ' . self
::getNameTypeId('nickname', true
) . ')
526 LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\')
527 LEFT JOIN profile_photos AS ph ON (ph.pid = p.pid)
528 LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms))
529 WHERE p.pid IN ' . XDB
::formatArray($pids) . '
532 return new ProfileDataIterator($it, $pids, $fields, $visibility);
535 public static function getPID($login)
537 if ($login instanceof PlUser
) {
538 return XDB
::fetchOneCell('SELECT pid
539 FROM account_profiles
540 WHERE uid = {?} AND FIND_IN_SET(\'owner\', perms)',
542 } else if (ctype_digit($login)) {
543 return XDB
::fetchOneCell('SELECT pid
545 WHERE pid = {?}', $login);
547 return XDB
::fetchOneCell('SELECT pid
549 WHERE hrpid = {?}', $login);
553 public static function getPIDsFromUIDs($uids, $respect_order = true
)
555 if ($respect_order) {
556 $order = 'ORDER BY ' . XDB
::formatCustomOrder('uid', $uids);
560 return XDB
::fetchAllAssoc('uid', 'SELECT ap.uid, ap.pid
561 FROM account_profiles AS ap
562 WHERE FIND_IN_SET(\'owner\', ap.perms)
563 AND ap.uid IN ' . XDB
::formatArray($uids) .'
567 /** Return the profile associated with the given login.
569 public static function get($login, $fields = 0x0000, $visibility = null
)
571 if (is_array($login)) {
572 return new Profile($login);
574 $pid = self
::getPID($login);
575 if (!is_null($pid)) {
576 $it = self
::iterOverPIDs(array($pid), false
, $fields, $visibility);
579 /* Let say we can identify a profile using the identifiers of its owner.
581 if (!($login instanceof PlUser
)) {
582 $user = User
::getSilent($login);
583 if ($user && $user->hasProfile()) {
584 return $user->profile();
591 public static function iterOverUIDs($uids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
593 return self
::iterOverPIDs(self
::getPIDsFromUIDs($uids), $respect_order, $fields, $visibility);
596 public static function iterOverPIDs($pids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
598 return self
::fetchProfileData($pids, $respect_order, $fields, $visibility);
601 /** Return profiles for the list of pids.
603 public static function getBulkProfilesWithPIDs(array $pids, $fields = self
::FETCH_ADDRESSES
, $visibility = null
)
605 if (count($pids) == 0) {
608 $it = self
::iterOverPIDs($pids, true
, $fields, $visibility);
610 while ($p = $it->next()) {
611 $profiles[$p->id()] = $p;
616 /** Return profiles for uids.
618 public static function getBulkProfilesWithUIDS(array $uids, $fields = 0x000, $visibility = null
)
620 if (count($uids) == 0) {
623 return self
::getBulkProfilesWithPIDs(self
::getPIDsFromUIDs($uids), $fields, $visibility);
626 public static function isDisplayName($name)
628 return $name == self
::DN_FULL ||
$name == self
::DN_DISPLAY
629 ||
$name == self
::DN_YOURSELF ||
$name == self
::DN_DIRECTORY
630 ||
$name == self
::DN_PRIVATE ||
$name == self
::DN_PUBLIC
631 ||
$name == self
::DN_SHORT ||
$name == self
::DN_SORT
;
634 public static function getNameTypeId($type, $for_sql = false
)
636 if (!S
::has('name_types')) {
637 $table = XDB
::fetchAllAssoc('type', 'SELECT id, type
638 FROM profile_name_enum');
639 S
::set('name_types', $table);
641 $table = S
::v('name_types');
644 return XDB
::escape($table[$type]);
646 return $table[$type];
650 public static function rebuildSearchTokens($pid)
652 XDB
::execute('DELETE FROM search_name
655 $keys = XDB
::iterator("SELECT CONCAT(n.particle, n.name) AS name, e.score,
656 FIND_IN_SET('public', e.flags) AS public
657 FROM profile_name AS n
658 INNER JOIN profile_name_enum AS e ON (n.typeid = e.id)
662 foreach ($keys as $i => $key) {
663 if ($key['name'] == '') {
666 $toks = preg_split('/[ \'\-]+/', $key['name']);
670 $token = strtolower(replace_accent(array_pop($toks) . $token));
671 $score = ($toks ?
0 : 10 +
$first) * ($key['score'] / 10);
672 XDB
::execute('REPLACE INTO search_name (token, pid, soundex, score, flags)
673 VALUES ({?}, {?}, {?}, {?}, {?})',
674 $token, $pid, soundex_fr($token), $score, $key['public']);
680 /** The school identifier consists of 6 digits. The first 3 represent the
681 * promotion entry year. The last 3 indicate the student's rank.
683 * Our identifier consists of 8 digits and both half have the same role.
684 * This enables us to deal with bigger promotions and with a wider range
687 * getSchoolId returns a school identifier given one of ours.
688 * getXorgId returns a X.org identifier given a school identifier.
690 public static function getSchoolId($xorgId)
692 if (!preg_match('/^[0-9]{8}$/', $xorgId)) {
696 $year = intval(substr($xorgId, 0, 4));
697 $rank = intval(substr($xorgId, 5, 3));
700 } elseif ($year < 2000) {
701 $year = intval(substr(1900 - $year, 1, 3));
702 return sprintf('%02u0%03u', $year, $rank);
704 $year = intval(substr(1900 - $year, 1, 3));
705 return sprintf('%03u%03u', $year, $rank);
709 public static function getXorgId($schoolId)
711 if (!preg_match('/^[0-9]{6}$/', $schoolId)) {
715 $year = intval(substr($schoolId, 0, 3));
716 $rank = intval(substr($schoolId, 3, 3));
724 return sprintf('%04u%04u', 1900 +
$year, $rank);
729 class ProfileDataIterator
731 private $iterator = null
;
734 public function __construct(PlIterator
$it, array $pids, $fields = 0x0000, $visibility = null
)
736 require_once 'profilefields.inc.php';
737 $visibility = Profile
::getVisibilityContext($visibility);
738 $this->fields
= $fields;
741 $callbacks = array();
744 $callbacks[0] = PlIteratorUtils
::arrayValueCallback('pid');
745 $cb = PlIteratorUtils
::objectPropertyCallback('pid');
747 if ($fields & Profile
::FETCH_ADDRESSES
) {
748 $callbacks[Profile
::FETCH_ADDRESSES
] = $cb;
749 $subits[Profile
::FETCH_ADDRESSES
] = new ProfileFieldIterator('ProfileAddresses', $pids, $visibility);
752 if ($fields & Profile
::FETCH_CORPS
) {
753 $callbacks[Profile
::FETCH_CORPS
] = $cb;
754 $subits[Profile
::FETCH_CORPS
] = new ProfileFieldIterator('ProfileCorps', $pids, $visibility);
757 if ($fields & Profile
::FETCH_EDU
) {
758 $callbacks[Profile
::FETCH_EDU
] = $cb;
759 $subits[Profile
::FETCH_EDU
] = new ProfileFieldIterator('ProfileEducation', $pids, $visibility);
762 if ($fields & Profile
::FETCH_JOBS
) {
763 $callbacks[Profile
::FETCH_JOBS
] = $cb;
764 $subits[Profile
::FETCH_JOBS
] = new ProfileFieldIterator('ProfileJobs', $pids, $visibility);
767 if ($fields & Profile
::FETCH_MEDALS
) {
768 $callbacks[Profile
::FETCH_MEDALS
] = $cb;
769 $subits[Profile
::FETCH_MEDALS
] = new ProfileFieldIterator('ProfileMedals', $pids, $visibility);
772 if ($fields & Profile
::FETCH_NETWORKING
) {
773 $callbacks[Profile
::FETCH_NETWORKING
] = $cb;
774 $subits[Profile
::FETCH_NETWORKING
] = new ProfileFieldIterator('ProfileNetworking', $pids, $visibility);
777 if ($fields & Profile
::FETCH_PHONES
) {
778 $callbacks[Profile
::FETCH_PHONES
] = $cb;
779 $subits[Profile
::FETCH_PHONES
] = new ProfileFieldIterator('ProfilePhones', $pids, $visibility);
782 if ($fields & Profile
::FETCH_PHOTO
) {
783 $callbacks[Profile
::FETCH_PHOTO
] = $cb;
784 $subits[Profile
::FETCH_PHOTO
] = new ProfileFieldIterator('ProfilePhoto', $pids, $visibility);
787 $this->iterator
= PlIteratorUtils
::parallelIterator($subits, $callbacks, 0);
790 private function consolidateFields(array $pf)
792 if ($this->fields
& Profile
::FETCH_PHONES
) {
793 $phones = $pf[Profile
::FETCH_PHONES
];
795 if ($this->fields
& Profile
::FETCH_ADDRESSES
&& $pf[Profile
::FETCH_ADDRESSES
] != null
) {
796 $pf[Profile
::FETCH_ADDRESSES
]->addPhones($phones);
798 if ($this->fields
& Profile
::FETCH_JOBS
&& $pf[Profile
::FETCH_JOBS
] != null
) {
799 $pf[Profile
::FETCH_JOBS
]->addPhones($phones);
803 if ($this->fields
& Profile
::FETCH_ADDRESSES
) {
804 $addrs = $pf[Profile
::FETCH_ADDRESSES
];
805 if ($this->fields
& Profile
::FETCH_JOBS
&& $pf[Profile
::FETCH_JOBS
] != null
) {
806 $pf[Profile
::FETCH_JOBS
]->addAddresses($addrs);
813 private function fillProfile(array $vals)
815 $vals = $this->consolidateFields($vals);
817 $pf = Profile
::get($vals[0]);
818 if ($this->fields
& Profile
::FETCH_ADDRESSES
) {
819 if ($vals[Profile
::FETCH_ADDRESSES
] != null
) {
820 $pf->setAddresses($vals[Profile
::FETCH_ADDRESSES
]);
823 if ($this->fields
& Profile
::FETCH_CORPS
) {
824 $pf->setCorps($vals[Profile
::FETCH_CORPS
]);
826 if ($this->fields
& Profile
::FETCH_EDU
) {
827 $pf->setEdu($vals[Profile
::FETCH_EDU
]);
829 if ($this->fields
& Profile
::FETCH_JOBS
) {
830 $pf->setJobs($vals[Profile
::FETCH_JOBS
]);
832 if ($this->fields
& Profile
::FETCH_MEDALS
) {
833 $pf->setMedals($vals[Profile
::FETCH_MEDALS
]);
835 if ($this->fields
& Profile
::FETCH_NETWORKING
) {
836 $pf->setNetworking($vals[Profile
::FETCH_NETWORKING
]);
838 if ($this->fields
& Profile
::FETCH_PHONES
) {
839 $pf->setPhones($vals[Profile
::FETCH_PHONES
]);
841 if ($this->fields
& Profile
::FETCH_PHOTO
) {
842 if ($vals[Profile
::FETCH_PHOTO
] != null
) {
843 $pf->setPhoto($vals[Profile
::FETCH_PHOTO
]);
850 public function next()
852 $vals = $this->iterator
->next();
856 return $this->fillProfile($vals);
859 public function first()
861 return $this->iterator
->first();
864 public function last()
866 return $this->iterator
->last();
869 public function total()
871 return $this->iterator
->total();
875 /** Iterator over a set of Profiles
876 * @param an XDB::Iterator obtained from a Profile::fetchProfileData
878 class ProfileIterator
implements PlIterator
883 public function __construct(ProfileDataIterator
&$pdi)
886 $this->dbiter
= $pdi->iterator();
889 public function next()
891 $data = $this->dbiter
->next();
895 return $this->pdi
->fillProfile(Profile
::get($data));
899 public function total()
901 return $this->dbiter
->total();
904 public function first()
906 return $this->dbiter
->first();
909 public function last()
911 return $this->dbiter
->last();
915 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: