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 ***************************************************************************/
22 class ProfileVisibility
24 static private $v_values = array(self
::VIS_PUBLIC
=> array(self
::VIS_PUBLIC
),
25 self
::VIS_AX
=> array(self
::VIS_AX
, self
::VIS_PUBLIC
),
26 self
::VIS_PRIVATE
=> array(self
::VIS_PRIVATE
, self
::VIS_AX
, self
::VIS_PUBLIC
));
28 const VIS_PUBLIC
= 'public';
30 const VIS_PRIVATE
= 'private';
34 public function __construct($level = null
)
36 $this->setLevel($level);
39 public function setLevel($level = self
::VIS_PUBLIC
)
41 if ($level != null
&& $level != self
::VIS_PRIVATE
&& $level != self
::VIS_AX
&& $level != self
::VIS_PUBLIC
) {
42 Platal
::page()->kill("Invalid visibility: " . $level);
46 $level = self
::VIS_PUBLIC
;
47 } else if ($level == null
) {
48 $level = self
::VIS_PRIVATE
;
51 if ($this->level
== null ||
$this->level
== self
::VIS_PRIVATE
) {
52 $this->level
= $level;
53 } else if ($this->level
== self
::VIS_AX
&& $level == self
::VIS_PRIVATE
) {
56 $this->level
= self
::VIS_PUBLIC
;
60 public function level()
62 if ($this->level
== null
) {
63 return self
::VIS_PUBLIC
;
69 public function levels()
71 return self
::$v_values[$this->level()];
74 public function isVisible($visibility)
76 return in_array($visibility, $this->levels());
84 const LASTNAME
= 'lastname';
85 const FIRSTNAME
= 'firstname';
86 const NICKNAME
= 'nickname';
87 const PSEUDONYM
= 'pseudonym';
90 const VN_MARITAL
= 'marital';
91 const VN_ORDINARY
= 'ordinary';
92 const VN_OTHER
= 'other';
95 const DN_FULL
= 'directory_name';
96 const DN_DISPLAY
= 'yourself';
97 const DN_YOURSELF
= 'yourself';
98 const DN_DIRECTORY
= 'directory_name';
99 const DN_PRIVATE
= 'private_name';
100 const DN_PUBLIC
= 'public_name';
101 const DN_SHORT
= 'short_name';
102 const DN_SORT
= 'sort_name';
103 /* education related names */
104 const EDU_X
= 'École polytechnique';
105 const DEGREE_X
= 'Ingénieur';
106 const DEGREE_M
= 'Master';
107 const DEGREE_D
= 'Doctorat';
109 static public $name_variants = array(
110 self
::LASTNAME
=> array(self
::VN_MARITAL
, self
::VN_ORDINARY
),
111 self
::FIRSTNAME
=> array(self
::VN_ORDINARY
, self
::VN_INI
, self
::VN_OTHER
)
114 const ADDRESS_MAIN
= 0x000001;
115 const ADDRESS_PERSO
= 0x000002;
116 const ADDRESS_PRO
= 0x000004;
117 const ADDRESS_ALL
= 0x000006;
118 const ADDRESS_POSTAL
= 0x000008;
120 const EDUCATION_MAIN
= 0x000010;
121 const EDUCATION_EXTRA
= 0x000020;
122 const EDUCATION_ALL
= 0x000040;
123 const EDUCATION_FINISHED
= 0x000080;
124 const EDUCATION_CURRENT
= 0x000100;
126 const JOBS_MAIN
= 0x001000;
127 const JOBS_ALL
= 0x002000;
128 const JOBS_FINISHED
= 0x004000;
129 const JOBS_CURRENT
= 0x008000;
131 const NETWORKING_ALL
= 0x000000;
132 const NETWORKING_WEB
= 0x010000;
133 const NETWORKING_IM
= 0x020000;
134 const NETWORKING_SOCIAL
= 0x040000;
136 const FETCH_ADDRESSES
= 0x000001;
137 const FETCH_CORPS
= 0x000002;
138 const FETCH_EDU
= 0x000004;
139 const FETCH_JOBS
= 0x000008;
140 const FETCH_MEDALS
= 0x000010;
141 const FETCH_NETWORKING
= 0x000020;
142 const FETCH_PHONES
= 0x000040;
144 const FETCH_MINIFICHES
= 0x00006D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_NETWORKING | FETCH_PHONES
146 const FETCH_ALL
= 0x0000FF; // OR of FETCH_*
148 private $fetched_fields = 0x000000;
152 private $data = array();
154 private $visibility = null
;
157 private function __construct(array $data)
160 $this->pid
= $this->data
['pid'];
161 $this->hrpid
= $this->data
['hrpid'];
162 $this->visibility
= new ProfileVisibility();
170 public function hrid()
175 public function promo()
180 public function yearpromo()
182 return intval(substr($this->promo
, 1, 4));
185 /** Print a name with the given formatting:
193 public function name($format)
195 return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'),
196 array($this->isFemale() ?
'•' : '',
197 $this->firstName(), $this->lastName(),
198 $this->fullName(), $this->shortName(),
199 $this->promo()), $format);
202 public function fullName($with_promo = false
)
205 return $this->full_name
. ' (' . $this->promo
. ')';
207 return $this->full_name
;
210 public function shortName($with_promo = false
)
213 return $this->short_name
. ' (' . $this->promo
. ')';
215 return $this->short_name
;
218 public function firstName()
220 return $this->firstname
;
223 public function firstNames()
225 return $this->nameVariants(self
::FIRSTNAME
);
228 public function lastName()
230 return $this->lastname
;
233 public function lastNames()
235 return $this->nameVariants(self
::LASTNAME
);
238 public function isFemale()
240 return $this->sex
== PlUser
::GENDER_FEMALE
;
243 public function isDead()
245 return ($this->deathdate
!= null
);
248 public function data()
254 private function nameVariants($type)
256 $vals = array($this->$type);
257 foreach (self
::$name_variants[$type] as $var) {
258 $vartype = $type . '_' . $var;
259 $varname = $this->$vartype;
260 if ($varname != null
&& $varname != "") {
264 return array_unique($vals);
267 public function nationalities()
270 if ($this->nationality1
) {
271 $nats[] = $this->nationality1
;
273 if ($this->nationality2
) {
274 $nats[] = $this->nationality2
;
276 if ($this->nationality3
) {
277 $nats[] = $this->nationality3
;
282 public function __get($name)
284 if (property_exists($this, $name)) {
288 if (isset($this->data
[$name])) {
289 return $this->data
[$name];
295 public function __isset($name)
297 return property_exists($this, $name) ||
isset($this->data
[$name]);
300 /** Sets the level of visibility of the profile
301 * Sets $this->visibility to a list of valid visibilities.
302 * @param one of the self::VIS_* values
304 public function setVisibilityLevel($visibility)
306 $this->visibility
->setLevel($visibility);
309 /** Determine whether an item with visibility $visibility can be displayed
310 * with the current level of visibility of the profile
311 * @param $visibility The level of visibility to be checked
313 public function isVisible($visibility)
315 return $this->visibility
->isVisible($visibility);
318 /** Stores the list of fields which have already been fetched for this Profile
320 public function setFetchedFields($fields)
322 if (($fields | self
::FETCH_ALL
) != self
::FETCH_ALL
) {
323 Platal
::page()->kill("Invalid fetched fields: $fields");
326 $this->fetched_fields
= $fields;
329 private function fetched($field)
331 if (!array_key_exists($field, ProfileField
::$fields)) {
332 Platal
::page()->kill("Invalid field: $field");
335 return ($this->fetched_fields
& $field);
338 /** If not already done, fetches data for the given field
339 * @param $field One of the Profile::FETCH_*
340 * @return A ProfileField, or null
342 private function getProfileField($field)
344 if ($this->fetched($field)) {
347 $this->fetched_fields
= $this->fetched_fields |
$field;
350 $cls = ProfileField
::$fields[$field];
352 return ProfileField
::getForPID($cls, $this->id(), $this->visibility
);
355 /** Consolidates internal data (addresses, phones, jobs)
357 private function consolidateFields()
359 if ($this->phones
!= null
) {
360 if ($this->addresses
!= null
) {
361 $this->addresses
->addPhones($this->phones
);
364 if ($this->jobs
!= null
) {
365 $this->jobs
->addPhones($this->phones
);
369 if ($this->addresses
!= null
&& $this->jobs
!= null
) {
370 $this->jobs
->addAddresses($this->addresses
);
376 private $photo = null
;
377 public function getPhoto($fallback = true
, $data = false
)
379 if ($this->has_photo
) {
380 if ($data && ($this->photo
== null ||
$this->photo
->mimeType
== null
)) {
381 $res = XDB
::fetchOneAssoc('SELECT attach, attachmime, x, y
383 WHERE pid = {?}', $this->pid
);
384 $this->photo
= PlImage
::fromData($res['attach'], $res['attachmime'], $res['x'], $res['y']);
385 } else if ($this->photo
== null
) {
386 $this->photo
= PlImage
::fromData(null
, null
, $this->photo_width
, $this->photo_height
);
389 } else if ($fallback) {
390 return PlImage
::fromFile(dirname(__FILE__
).'/../htdocs/images/none.png',
398 private $addresses = null
;
399 public function setAddresses(ProfileAddresses
$addr)
401 $this->addresses
= $addr;
402 $this->consolidateFields();
405 public function getAddresses($flags, $limit = null
)
407 if ($this->addresses
== null
&& !$this->fetched(self
::FETCH_ADDRESSES
)) {
408 $this->setAddresses($this->getProfileField(self
::FETCH_ADDRESSES
));
411 if ($this->addresses
== null
) {
414 return $this->addresses
->get($flags, $limit);
417 public function iterAddresses($flags, $limit = null
)
419 return PlIteratorUtils
::fromArray($this->getAddresses($flags, $limit), 1, true
);
422 public function getMainAddress()
424 $addr = $this->getAddresses(self
::ADDRESS_PERSO | self
::ADDRESS_MAIN
);
425 if (count($addr) == 0) {
428 return array_pop($addr);
434 private $phones = null
;
435 public function setPhones(ProfilePhones
$phones)
437 $this->phones
= $phones;
438 $this->consolidateFields();
441 public function getPhones($flags, $limit = null
)
443 if ($this->phones
== null
&& !$this->fetched(self
::FETCH_PHONES
)) {
444 $this->setPhones($this->getProfileField(self
::FETCH_PHONES
));
447 if ($this->phones
== null
) {
450 return $this->phones
->get($flags, $limit);
455 private $educations = null
;
456 public function setEducations(ProfileEducation
$edu)
458 $this->educations
= $edu;
461 public function getEducations($flags, $limit = null
)
463 if ($this->educations
== null
&& !$this->fetched(self
::FETCH_EDU
)) {
464 $this->setEducations($this->getProfileField(self
::FETCH_EDU
));
467 if ($this->educations
== null
) {
470 return $this->educations
->get($flags, $limit);
473 public function getExtraEducations($limit = null
)
475 return $this->getEducations(self
::EDUCATION_EXTRA
, $limit);
480 private $corps = null
;
481 public function setCorps(ProfileCorps
$corps)
483 $this->corps
= $corps;
486 public function getCorps()
488 if ($this->corps
== null
&& !$this->fetched(self
::FETCH_CORPS
)) {
489 $this->setCorps($this->getProfileField(self
::FETCH_CORPS
));
496 private $networks = null
;
497 public function setNetworking(ProfileNetworking
$nw)
499 $this->networks
= $nw;
502 public function getNetworking($flags, $limit = null
)
504 if ($this->networks
== null
&& !$this->fetched(self
::FETCH_NETWORKING
)) {
505 $this->setNetworking($this->getProfileField(self
::FETCH_NETWORKING
));
507 if ($this->networks
== null
) {
510 return $this->networks
->get($flags, $limit);
513 public function getWebSite()
515 $site = $this->getNetworking(self
::NETWORKING_WEB
, 1);
516 if (count($site) != 1) {
519 $site = array_pop($site);
520 return $site['address'];
526 private $jobs = null
;
527 public function setJobs(ProfileJobs
$jobs)
530 $this->consolidateFields();
533 public function getJobs($flags, $limit = null
)
535 if ($this->jobs
== null
&& !$this->fetched(self
::FETCH_JOBS
)) {
536 $this->setJobs($this->getProfileField(self
::FETCH_JOBS
));
539 if ($this->jobs
== null
) {
542 return $this->jobs
->get($flags, $limit);
545 public function getMainJob()
547 $job = $this->getJobs(self
::JOBS_MAIN
, 1);
548 if (count($job) != 1) {
551 return array_pop($job);
556 public function getBinets()
558 return XDB
::fetchColumn('SELECT binet_id
560 WHERE pid = {?}', $this->id());
562 public function getBinetsNames()
564 return XDB
::fetchColumn('SELECT text
565 FROM profile_binets AS pb
566 LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id)
567 WHERE pb.pid = {?}', $this->id());
572 private $medals = null
;
573 public function setMedals(ProfileMedals
$medals)
575 $this->medals
= $medals;
578 public function getMedals()
580 if ($this->medals
== null
&& !$this->fetched(self
::FETCH_MEDALS
)) {
581 $this->setMedals($this->getProfileField(self
::FETCH_MEDALS
));
583 if ($this->medals
== null
) {
586 return $this->medals
->medals
;
589 public function owner()
591 return User
::getSilent($this);
594 public function compareNames($firstname, $lastname)
596 $_lastname = mb_strtoupper($this->lastName());
597 $_firstname = mb_strtoupper($this->firstName());
598 $lastname = mb_strtoupper($lastname);
599 $firstname = mb_strtoupper($firstname);
601 $isOk = (mb_strtoupper($_firstname) == mb_strtoupper($firstname));
602 $tokens = preg_split("/[ \-']/", $lastname, -1, PREG_SPLIT_NO_EMPTY
);
605 foreach ($tokens as $str) {
606 $isOk &= (strpos($_lastname, $str) !== false
);
607 $maxlen = max($maxlen, strlen($str));
610 return ($isOk && ($maxlen > 2 ||
$maxlen == strlen($_lastname)));
613 private static function fetchProfileData(array $pids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
615 if (count($pids) == 0) {
619 if ($respect_order) {
620 $order = 'ORDER BY ' . XDB
::formatCustomOrder('p.pid', $pids);
625 $visibility = new ProfileVisibility($visibility);
627 $it = XDB
::Iterator('SELECT p.*, p.sex = \'female\' AS sex, pe.entry_year, pe.grad_year, pse.text AS section,
628 pn_f.name AS firstname, pn_l.name AS lastname, pn_n.name AS nickname,
629 IF(pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_ordinary,
630 IF(pn_ul.name IS NULL, pn_l.name, pn_ul.name) AS lastname_ordinary,
631 pd.promo AS promo, pd.short_name, pd.directory_name AS full_name,
632 pd.directory_name, IF(pp.pub IN {?}, pp.display_tel, NULL) AS mobile,
633 (ph.pub IN {?} AND ph.attach IS NOT NULL) AS has_photo,
634 ph.x AS photo_width, ph.y AS photo_height,
635 p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old,
636 pm.expertise AS mentor_expertise,
639 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
640 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags))
641 LEFT JOIN profile_section_enum AS pse ON (pse.id = p.section)
642 INNER JOIN profile_name AS pn_f ON (pn_f.pid = p.pid
643 AND pn_f.typeid = ' . self
::getNameTypeId('firstname', true
) . ')
644 INNER JOIN profile_name AS pn_l ON (pn_l.pid = p.pid
645 AND pn_l.typeid = ' . self
::getNameTypeId('lastname', true
) . ')
646 LEFT JOIN profile_name AS pn_uf ON (pn_uf.pid = p.pid
647 AND pn_uf.typeid = ' . self
::getNameTypeId('firstname_ordinary', true
) . ')
648 LEFT JOIN profile_name AS pn_ul ON (pn_ul.pid = p.pid
649 AND pn_ul.typeid = ' . self
::getNameTypeId('lastname_ordinary', true
) . ')
650 LEFT JOIN profile_name AS pn_n ON (pn_n.pid = p.pid
651 AND pn_n.typeid = ' . self
::getNameTypeId('nickname', true
) . ')
652 LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\')
653 LEFT JOIN profile_photos AS ph ON (ph.pid = p.pid)
654 LEFT JOIN profile_mentor AS pm ON (pm.pid = p.pid)
655 LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms))
656 WHERE p.pid IN ' . XDB
::formatArray($pids) . '
658 ' . $order, $visibility->levels(), $visibility->levels());
659 return new ProfileIterator($it, $pids, $fields, $visibility);
662 public static function getPID($login)
664 if ($login instanceof PlUser
) {
665 return XDB
::fetchOneCell('SELECT pid
666 FROM account_profiles
667 WHERE uid = {?} AND FIND_IN_SET(\'owner\', perms)',
669 } else if (ctype_digit($login)) {
670 return XDB
::fetchOneCell('SELECT pid
672 WHERE pid = {?}', $login);
674 return XDB
::fetchOneCell('SELECT pid
676 WHERE hrpid = {?}', $login);
680 public static function getPIDsFromUIDs($uids, $respect_order = true
)
682 if ($respect_order) {
683 $order = 'ORDER BY ' . XDB
::formatCustomOrder('uid', $uids);
687 return XDB
::fetchAllAssoc('uid', 'SELECT ap.uid, ap.pid
688 FROM account_profiles AS ap
689 WHERE FIND_IN_SET(\'owner\', ap.perms)
690 AND ap.uid IN ' . XDB
::formatArray($uids) .'
694 /** Return the profile associated with the given login.
696 public static function get($login, $fields = 0x0000, $visibility = null
)
698 if (is_array($login)) {
699 $pf = new Profile($login);
700 $pf->setVisibilityLevel($visibility);
703 $pid = self
::getPID($login);
704 if (!is_null($pid)) {
705 $it = self
::iterOverPIDs(array($pid), false
, $fields, $visibility);
708 /* Let say we can identify a profile using the identifiers of its owner.
710 if (!($login instanceof PlUser
)) {
711 $user = User
::getSilent($login);
712 if ($user && $user->hasProfile()) {
713 return $user->profile();
720 public static function iterOverUIDs($uids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
722 return self
::iterOverPIDs(self
::getPIDsFromUIDs($uids), $respect_order, $fields, $visibility);
725 public static function iterOverPIDs($pids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
727 return self
::fetchProfileData($pids, $respect_order, $fields, $visibility);
730 /** Return profiles for the list of pids.
732 public static function getBulkProfilesWithPIDs(array $pids, $fields = 0x0000, $visibility = null
)
734 if (count($pids) == 0) {
737 $it = self
::iterOverPIDs($pids, true
, $fields, $visibility);
739 while ($p = $it->next()) {
740 $profiles[$p->id()] = $p;
745 /** Return profiles for uids.
747 public static function getBulkProfilesWithUIDS(array $uids, $fields = 0x000, $visibility = null
)
749 if (count($uids) == 0) {
752 return self
::getBulkProfilesWithPIDs(self
::getPIDsFromUIDs($uids), $fields, $visibility);
755 public static function isDisplayName($name)
757 return $name == self
::DN_FULL ||
$name == self
::DN_DISPLAY
758 ||
$name == self
::DN_YOURSELF ||
$name == self
::DN_DIRECTORY
759 ||
$name == self
::DN_PRIVATE ||
$name == self
::DN_PUBLIC
760 ||
$name == self
::DN_SHORT ||
$name == self
::DN_SORT
;
763 public static function getNameTypeId($type, $for_sql = false
)
765 if (!S
::has('name_types')) {
766 $table = XDB
::fetchAllAssoc('type', 'SELECT id, type
767 FROM profile_name_enum');
768 S
::set('name_types', $table);
770 $table = S
::v('name_types');
773 return XDB
::escape($table[$type]);
775 return $table[$type];
779 public static function rebuildSearchTokens($pid)
781 XDB
::execute('DELETE FROM search_name
784 $keys = XDB
::iterator("SELECT CONCAT(n.particle, n.name) AS name, e.score,
785 FIND_IN_SET('public', e.flags) AS public
786 FROM profile_name AS n
787 INNER JOIN profile_name_enum AS e ON (n.typeid = e.id)
791 foreach ($keys as $i => $key) {
792 if ($key['name'] == '') {
795 $toks = preg_split('/[ \'\-]+/', $key['name']);
799 $token = strtolower(replace_accent(array_pop($toks) . $token));
800 $score = ($toks ?
0 : 10 +
$first) * ($key['score'] / 10);
801 XDB
::execute('REPLACE INTO search_name (token, pid, soundex, score, flags)
802 VALUES ({?}, {?}, {?}, {?}, {?})',
803 $token, $pid, soundex_fr($token), $score, $key['public']);
809 /** The school identifier consists of 6 digits. The first 3 represent the
810 * promotion entry year. The last 3 indicate the student's rank.
812 * Our identifier consists of 8 digits and both half have the same role.
813 * This enables us to deal with bigger promotions and with a wider range
816 * getSchoolId returns a school identifier given one of ours.
817 * getXorgId returns a X.org identifier given a school identifier.
819 public static function getSchoolId($xorgId)
821 if (!preg_match('/^[0-9]{8}$/', $xorgId)) {
825 $year = intval(substr($xorgId, 0, 4));
826 $rank = intval(substr($xorgId, 5, 3));
829 } elseif ($year < 2000) {
830 $year = intval(substr(1900 - $year, 1, 3));
831 return sprintf('%02u0%03u', $year, $rank);
833 $year = intval(substr(1900 - $year, 1, 3));
834 return sprintf('%03u%03u', $year, $rank);
838 public static function getXorgId($schoolId)
840 if (!preg_match('/^[0-9]{6}$/', $schoolId)) {
844 $year = intval(substr($schoolId, 0, 3));
845 $rank = intval(substr($schoolId, 3, 3));
853 return sprintf('%04u%04u', 1900 +
$year, $rank);
859 /** Iterator over a set of Profiles
861 class ProfileIterator
implements PlIterator
863 private $iterator = null
;
867 public function __construct(PlIterator
$it, array $pids, $fields = 0x0000, ProfileVisibility
$visibility = null
)
869 require_once 'profilefields.inc.php';
871 if ($visibility == null
) {
872 $visibility = new ProfileVisibility();
875 $this->fields
= $fields;
876 $this->visibility
= $visibility;
879 $callbacks = array();
882 $callbacks[0] = PlIteratorUtils
::arrayValueCallback('pid');
883 $cb = PlIteratorUtils
::objectPropertyCallback('pid');
885 if ($fields & Profile
::FETCH_ADDRESSES
) {
886 $callbacks[Profile
::FETCH_ADDRESSES
] = $cb;
887 $subits[Profile
::FETCH_ADDRESSES
] = new ProfileFieldIterator('ProfileAddresses', $pids, $visibility);
890 if ($fields & Profile
::FETCH_CORPS
) {
891 $callbacks[Profile
::FETCH_CORPS
] = $cb;
892 $subits[Profile
::FETCH_CORPS
] = new ProfileFieldIterator('ProfileCorps', $pids, $visibility);
895 if ($fields & Profile
::FETCH_EDU
) {
896 $callbacks[Profile
::FETCH_EDU
] = $cb;
897 $subits[Profile
::FETCH_EDU
] = new ProfileFieldIterator('ProfileEducation', $pids, $visibility);
900 if ($fields & Profile
::FETCH_JOBS
) {
901 $callbacks[Profile
::FETCH_JOBS
] = $cb;
902 $subits[Profile
::FETCH_JOBS
] = new ProfileFieldIterator('ProfileJobs', $pids, $visibility);
905 if ($fields & Profile
::FETCH_MEDALS
) {
906 $callbacks[Profile
::FETCH_MEDALS
] = $cb;
907 $subits[Profile
::FETCH_MEDALS
] = new ProfileFieldIterator('ProfileMedals', $pids, $visibility);
910 if ($fields & Profile
::FETCH_NETWORKING
) {
911 $callbacks[Profile
::FETCH_NETWORKING
] = $cb;
912 $subits[Profile
::FETCH_NETWORKING
] = new ProfileFieldIterator('ProfileNetworking', $pids, $visibility);
915 if ($fields & Profile
::FETCH_PHONES
) {
916 $callbacks[Profile
::FETCH_PHONES
] = $cb;
917 $subits[Profile
::FETCH_PHONES
] = new ProfileFieldIterator('ProfilePhones', $pids, $visibility);
920 $this->iterator
= PlIteratorUtils
::parallelIterator($subits, $callbacks, 0);
923 private function hasData($field, $vals)
925 return ($this->fields
& $field) && ($vals[$field] != null
);
928 private function fillProfile(array $vals)
930 $pf = Profile
::get($vals[0]);
931 $pf->setVisibilityLevel($this->visibility
->level());
932 $pf->setFetchedFields($this->fields
);
934 if ($this->hasData(Profile
::FETCH_PHONES
, $vals)) {
935 $pf->setPhones($vals[Profile
::FETCH_PHONES
]);
937 if ($this->hasData(Profile
::FETCH_ADDRESSES
, $vals)) {
938 $pf->setAddresses($vals[Profile
::FETCH_ADDRESSES
]);
940 if ($this->hasData(Profile
::FETCH_JOBS
, $vals)) {
941 $pf->setJobs($vals[Profile
::FETCH_JOBS
]);
944 if ($this->hasData(Profile
::FETCH_CORPS
, $vals)) {
945 $pf->setCorps($vals[Profile
::FETCH_CORPS
]);
947 if ($this->hasData(Profile
::FETCH_EDU
, $vals)) {
948 $pf->setEducations($vals[Profile
::FETCH_EDU
]);
950 if ($this->hasData(Profile
::FETCH_MEDALS
, $vals)) {
951 $pf->setMedals($vals[Profile
::FETCH_MEDALS
]);
953 if ($this->hasData(Profile
::FETCH_NETWORKING
, $vals)) {
954 $pf->setNetworking($vals[Profile
::FETCH_NETWORKING
]);
960 public function next()
962 $vals = $this->iterator
->next();
966 return $this->fillProfile($vals);
969 public function first()
971 return $this->iterator
->first();
974 public function last()
976 return $this->iterator
->last();
979 public function total()
981 return $this->iterator
->total();
985 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: