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
= 0x000001;
86 const FETCH_CORPS
= 0x000002;
87 const FETCH_EDU
= 0x000004;
88 const FETCH_JOBS
= 0x000008;
89 const FETCH_MEDALS
= 0x000010;
90 const FETCH_NETWORKING
= 0x000020;
91 const FETCH_PHONES
= 0x000040;
93 const FETCH_MINIFICHES
= 0x00004D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_PHONES
95 const FETCH_ALL
= 0x0000FF; // OR of FETCH_*
99 private $data = array();
101 private $visibility = null
;
103 private function __construct(array $data)
106 $this->pid
= $this->data
['pid'];
107 $this->hrpid
= $this->data
['hrpid'];
109 $this->setVisibilityLevel(self
::VISIBILITY_PUBLIC
);
111 $this->setVisibilityLevel(self
::VISIBILITY_PRIVATE
);
115 static private $contexts = array();
117 /** Returns the best visibility context toward $visibility
118 * @param $visibility A wished visibility level
119 * @return An array of compatible visibilities
121 * if $visibility is null, the best visibility is returned
123 static public function getVisibilityContext($visibility = null
)
125 if (array_key_exists($visibility, self
::$contexts)) {
126 return self
::$contexts[$visibility];
129 $asked_vis = $visibility;
132 $minvis = self
::VISIBILITY_PRIVATE
;
134 $minvis = self
::VISIBILITY_PUBLIC
;
136 if ($visibility == null
) {
137 $visibility = $minvis;
140 if ($minvis == self
::VISIBILITY_PUBLIC
) {
141 $visibility = self
::VISIBILITY_PUBLIC
;
144 $visibility = self
::$v_values[$visibility];
145 self
::$contexts[$asked_vis] = $visibility;
155 public function hrid()
160 public function promo()
165 public function yearpromo()
167 return intval(substr($this->promo
, 1, 4));
170 /** Print a name with the given formatting:
178 public function name($format)
180 return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'),
181 array($this->isFemale() ?
'•' : '',
182 $this->firstName(), $this->lastName(),
183 $this->fullName(), $this->shortName(),
184 $this->promo()), $format);
187 public function fullName($with_promo = false
)
190 return $this->full_name
. ' (' . $this->promo
. ')';
192 return $this->full_name
;
195 public function shortName($with_promo = false
)
198 return $this->short_name
. ' (' . $this->promo
. ')';
200 return $this->short_name
;
203 public function firstName()
205 return $this->firstname
;
208 public function firstNames()
210 return $this->nameVariants(self
::FIRSTNAME
);
213 public function lastName()
215 return $this->lastname
;
218 public function lastNames()
220 return $this->nameVariants(self
::LASTNAME
);
223 public function isFemale()
225 return $this->sex
== PlUser
::GENDER_FEMALE
;
228 public function isDead()
230 return ($this->deathdate
!= null
);
233 public function data()
239 private function nameVariants($type)
241 $vals = array($this->$type);
242 foreach (self
::$name_variants[$type] as $var) {
243 $vartype = $type . '_' . $var;
244 $varname = $this->$vartype;
245 if ($varname != null
&& $varname != "") {
249 return array_unique($vals);
252 public function nationalities()
255 if ($this->nationality1
) {
256 $nats[] = $this->nationality1
;
258 if ($this->nationality2
) {
259 $nats[] = $this->nationality2
;
261 if ($this->nationality3
) {
262 $nats[] = $this->nationality3
;
267 public function __get($name)
269 if (property_exists($this, $name)) {
273 if (isset($this->data
[$name])) {
274 return $this->data
[$name];
280 public function __isset($name)
282 return property_exists($this, $name) ||
isset($this->data
[$name]);
285 /** Sets the level of visibility of the profile
286 * Sets $this->visibility to a list of valid visibilities.
287 * @param one of the self::VISIBILITY_* values
289 public function setVisibilityLevel($visibility)
291 if ($visibility != self
::VISIBILITY_PRIVATE
292 && $visibility != self
::VISIBILITY_AX
293 && $visibility != self
::VISIBILITY_PUBLIC
) {
294 Platal
::page()->kill("Visibility invalide: " . $visibility);
296 $this->visibility
= self
::$v_values[$visibility];
297 if ($this->mobile
&& !in_array($this->mobile_pub
, $this->visibility
)) {
298 unset($this->data
['mobile']);
302 /** Determine whether an item with visibility $visibility can be displayed
303 * with the current level of visibility of the profile
304 * @param $visibility The level of visibility to be checked
306 public function isVisible($visibility)
308 return in_array($visibility, $this->visibility
);
311 public static function getCompatibleVisibilities($visibility)
313 return self
::$v_values[$visibility];
316 private function getProfileField($cls)
318 return ProfileField
::getForPID($cls, $this->id(), $this->visibility
);
321 /** Consolidates internal data (addresses, phones, jobs)
323 private function consolidateFields()
325 if ($this->phones
!= null
) {
326 if ($this->addresses
!= null
) {
327 $this->addresses
->addPhones($this->phones
);
330 if ($this->jobs
!= null
) {
331 $this->jobs
->addPhones($this->phones
);
335 if ($this->addresses
!= null
&& $this->jobs
!= null
) {
336 $this->jobs
->addAddresses($this->addresses
);
342 private $_photo = null
;
343 public function getPhoto($fallback = true
, $data = false
)
345 if ($data && $this->has_photo
&& $this->isVisible($this->photo_pub
) &&
346 ($this->_photo
== null ||
$this->_photo
->mimeType() == null
)) {
347 $res = XDB
::fetchOneAssoc('SELECT attach, attachmime, x, y
349 WHERE pid = {?}', $this->pid
);
350 $this->_photo
= PlImage
::fromData($res['attach'], $res['attachmime'], $res['x'], $res['y']);
353 if (!$data && $this->_photo
== null
) {
354 $this->_photo
= PlImage
::fromData(null
, null
, $this->photo_width
, $this->photo_height
);
357 if ($this->has_photo
&& $this->isVisible($this->photo_pub
)) {
358 return $this->_photo
;
359 } else if ($fallback) {
360 return PlImage
::fromFile(dirname(__FILE__
).'/../htdocs/images/none.png',
368 private $addresses = null
;
369 public function setAddresses(ProfileAddresses
$addr)
371 $this->addresses
= $addr;
372 $this->consolidateFields();
375 public function getAddresses($flags, $limit = null
)
377 if ($this->addresses
== null
) {
378 $this->setAddresses($this->getProfileField('ProfileAddresses'));
381 if ($this->addresses
== null
) {
384 return $this->addresses
->get($flags, $limit);
387 public function iterAddresses($flags, $limit = null
)
389 return PlIteratorUtils
::fromArray($this->getAddresses($flags, $limit), 1, true
);
392 public function getMainAddress()
394 $addr = $this->getAddresses(self
::ADDRESS_PERSO | self
::ADDRESS_MAIN
);
395 if (count($addr) == 0) {
398 return array_pop($addr);
404 private $phones = null
;
405 public function setPhones(ProfilePhones
$phones)
407 $this->phones
= $phones;
408 $this->consolidateFields();
411 public function getPhones($flags, $limit = null
)
413 if ($this->phones
== null
) {
414 $this->setPhones($this->getProfileField('ProfilePhones'));
417 if ($this->phones
== null
) {
420 return $this->phones
->get($flags, $limit);
425 private $educations = null
;
426 public function setEducations(ProfileEducation
$edu)
428 $this->educations
= $edu;
431 public function getEducations($flags, $limit = null
)
433 if ($this->educations
== null
) {
434 $this->setEducations($this->getProfileField('ProfileEducation'));
437 if ($this->educations
== null
) {
440 return $this->educations
->get($flags, $limit);
443 public function getExtraEducations($limit = null
)
445 return $this->getEducations(self
::EDUCATION_EXTRA
, $limit);
450 private $corps = null
;
451 public function setCorps(ProfileCorps
$corps)
453 $this->corps
= $corps;
456 public function getCorps()
458 if ($this->corps
== null
) {
459 $this->setCorps($this->getProfileField('ProfileCorps'));
466 private $networks = null
;
467 public function setNetworking(ProfileNetworking
$nw)
469 $this->networks
= $nw;
472 public function getNetworking($flags, $limit = null
)
474 if ($this->networks
== null
) {
475 $this->setNetworking($this->getProfileField('ProfileNetworking'));
477 if ($this->networks
== null
) {
480 return $this->networks
->get($flags, $limit);
483 public function getWebSite()
485 $site = $this->getNetworking(self
::NETWORKING_WEB
, 1);
486 if (count($site) != 1) {
489 $site = array_pop($site);
490 return $site['address'];
496 private $jobs = null
;
497 public function setJobs(ProfileJobs
$jobs)
500 $this->consolidateFields();
503 public function getJobs($flags, $limit = null
)
505 if ($this->jobs
== null
) {
506 $this->setJobs($this->getProfileField('ProfileJobs'));
509 if ($this->jobs
== null
) {
512 return $this->jobs
->get($flags, $limit);
515 public function getMainJob()
517 $job = $this->getJobs(self
::JOBS_MAIN
, 1);
518 if (count($job) != 1) {
521 return array_pop($job);
526 public function getBinets()
528 return XDB
::fetchColumn('SELECT binet_id
530 WHERE pid = {?}', $this->id());
532 public function getBinetsNames()
534 return XDB
::fetchColumn('SELECT text
535 FROM profile_binets AS pb
536 LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id)
537 WHERE pb.pid = {?}', $this->id());
542 private $medals = null
;
543 public function setMedals(ProfileMedals
$medals)
545 $this->medals
= $medals;
548 public function getMedals()
550 if ($this->medals
== null
) {
551 $this->setMedals($this->getProfileField('ProfileMedals'));
553 if ($this->medals
== null
) {
556 return $this->medals
->medals
;
559 public function owner()
561 return User
::getSilent($this);
564 public function compareNames($firstname, $lastname)
566 $_lastname = mb_strtoupper($this->lastName());
567 $_firstname = mb_strtoupper($this->firstName());
568 $lastname = mb_strtoupper($lastname);
569 $firstname = mb_strtoupper($firstname);
571 $isOk = (mb_strtoupper($_firstname) == mb_strtoupper($firstname));
572 $tokens = preg_split("/[ \-']/", $lastname, -1, PREG_SPLIT_NO_EMPTY
);
575 foreach ($tokens as $str) {
576 $isOk &= (strpos($_lastname, $str) !== false
);
577 $maxlen = max($maxlen, strlen($str));
580 return ($isOk && ($maxlen > 2 ||
$maxlen == strlen($_lastname)));
583 private static function fetchProfileData(array $pids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
585 if (count($pids) == 0) {
589 if ($respect_order) {
590 $order = 'ORDER BY ' . XDB
::formatCustomOrder('p.pid', $pids);
596 $it = XDB
::Iterator('SELECT p.*, p.sex = \'female\' AS sex, pe.entry_year, pe.grad_year, pse.text AS section,
597 pn_f.name AS firstname, pn_l.name AS lastname, pn_n.name AS nickname,
598 IF(pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_ordinary,
599 IF(pn_ul.name IS NULL, pn_l.name, pn_ul.name) AS lastname_ordinary,
600 pd.promo AS promo, pd.short_name, pd.directory_name AS full_name,
601 pd.directory_name, pp.display_tel AS mobile, pp.pub AS mobile_pub,
602 ph.attach IS NOT NULL AS has_photo, ph.pub AS photo_pub,
603 ph.x AS photo_width, ph.y AS photo_height,
604 p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old,
605 pm.expertise AS mentor_expertise,
608 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
609 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags))
610 LEFT JOIN profile_section_enum AS pse ON (pse.id = p.section)
611 INNER JOIN profile_name AS pn_f ON (pn_f.pid = p.pid
612 AND pn_f.typeid = ' . self
::getNameTypeId('firstname', true
) . ')
613 INNER JOIN profile_name AS pn_l ON (pn_l.pid = p.pid
614 AND pn_l.typeid = ' . self
::getNameTypeId('lastname', true
) . ')
615 LEFT JOIN profile_name AS pn_uf ON (pn_uf.pid = p.pid
616 AND pn_uf.typeid = ' . self
::getNameTypeId('firstname_ordinary', true
) . ')
617 LEFT JOIN profile_name AS pn_ul ON (pn_ul.pid = p.pid
618 AND pn_ul.typeid = ' . self
::getNameTypeId('lastname_ordinary', true
) . ')
619 LEFT JOIN profile_name AS pn_n ON (pn_n.pid = p.pid
620 AND pn_n.typeid = ' . self
::getNameTypeId('nickname', true
) . ')
621 LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\')
622 LEFT JOIN profile_photos AS ph ON (ph.pid = p.pid)
623 LEFT JOIN profile_mentor AS pm ON (pm.pid = p.pid)
624 LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms))
625 WHERE p.pid IN ' . XDB
::formatArray($pids) . '
628 return new ProfileIterator($it, $pids, $fields, $visibility);
631 public static function getPID($login)
633 if ($login instanceof PlUser
) {
634 return XDB
::fetchOneCell('SELECT pid
635 FROM account_profiles
636 WHERE uid = {?} AND FIND_IN_SET(\'owner\', perms)',
638 } else if (ctype_digit($login)) {
639 return XDB
::fetchOneCell('SELECT pid
641 WHERE pid = {?}', $login);
643 return XDB
::fetchOneCell('SELECT pid
645 WHERE hrpid = {?}', $login);
649 public static function getPIDsFromUIDs($uids, $respect_order = true
)
651 if ($respect_order) {
652 $order = 'ORDER BY ' . XDB
::formatCustomOrder('uid', $uids);
656 return XDB
::fetchAllAssoc('uid', 'SELECT ap.uid, ap.pid
657 FROM account_profiles AS ap
658 WHERE FIND_IN_SET(\'owner\', ap.perms)
659 AND ap.uid IN ' . XDB
::formatArray($uids) .'
663 /** Return the profile associated with the given login.
665 public static function get($login, $fields = 0x0000, $visibility = null
)
667 if (is_array($login)) {
668 return new Profile($login);
670 $pid = self
::getPID($login);
671 if (!is_null($pid)) {
672 $it = self
::iterOverPIDs(array($pid), false
, $fields, $visibility);
675 /* Let say we can identify a profile using the identifiers of its owner.
677 if (!($login instanceof PlUser
)) {
678 $user = User
::getSilent($login);
679 if ($user && $user->hasProfile()) {
680 return $user->profile();
687 public static function iterOverUIDs($uids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
689 return self
::iterOverPIDs(self
::getPIDsFromUIDs($uids), $respect_order, $fields, $visibility);
692 public static function iterOverPIDs($pids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
694 return self
::fetchProfileData($pids, $respect_order, $fields, $visibility);
697 /** Return profiles for the list of pids.
699 public static function getBulkProfilesWithPIDs(array $pids, $fields = self
::FETCH_ADDRESSES
, $visibility = null
)
701 if (count($pids) == 0) {
704 $it = self
::iterOverPIDs($pids, true
, $fields, $visibility);
706 while ($p = $it->next()) {
707 $profiles[$p->id()] = $p;
712 /** Return profiles for uids.
714 public static function getBulkProfilesWithUIDS(array $uids, $fields = 0x000, $visibility = null
)
716 if (count($uids) == 0) {
719 return self
::getBulkProfilesWithPIDs(self
::getPIDsFromUIDs($uids), $fields, $visibility);
722 public static function isDisplayName($name)
724 return $name == self
::DN_FULL ||
$name == self
::DN_DISPLAY
725 ||
$name == self
::DN_YOURSELF ||
$name == self
::DN_DIRECTORY
726 ||
$name == self
::DN_PRIVATE ||
$name == self
::DN_PUBLIC
727 ||
$name == self
::DN_SHORT ||
$name == self
::DN_SORT
;
730 public static function getNameTypeId($type, $for_sql = false
)
732 if (!S
::has('name_types')) {
733 $table = XDB
::fetchAllAssoc('type', 'SELECT id, type
734 FROM profile_name_enum');
735 S
::set('name_types', $table);
737 $table = S
::v('name_types');
740 return XDB
::escape($table[$type]);
742 return $table[$type];
746 public static function rebuildSearchTokens($pid)
748 XDB
::execute('DELETE FROM search_name
751 $keys = XDB
::iterator("SELECT CONCAT(n.particle, n.name) AS name, e.score,
752 FIND_IN_SET('public', e.flags) AS public
753 FROM profile_name AS n
754 INNER JOIN profile_name_enum AS e ON (n.typeid = e.id)
758 foreach ($keys as $i => $key) {
759 if ($key['name'] == '') {
762 $toks = preg_split('/[ \'\-]+/', $key['name']);
766 $token = strtolower(replace_accent(array_pop($toks) . $token));
767 $score = ($toks ?
0 : 10 +
$first) * ($key['score'] / 10);
768 XDB
::execute('REPLACE INTO search_name (token, pid, soundex, score, flags)
769 VALUES ({?}, {?}, {?}, {?}, {?})',
770 $token, $pid, soundex_fr($token), $score, $key['public']);
776 /** The school identifier consists of 6 digits. The first 3 represent the
777 * promotion entry year. The last 3 indicate the student's rank.
779 * Our identifier consists of 8 digits and both half have the same role.
780 * This enables us to deal with bigger promotions and with a wider range
783 * getSchoolId returns a school identifier given one of ours.
784 * getXorgId returns a X.org identifier given a school identifier.
786 public static function getSchoolId($xorgId)
788 if (!preg_match('/^[0-9]{8}$/', $xorgId)) {
792 $year = intval(substr($xorgId, 0, 4));
793 $rank = intval(substr($xorgId, 5, 3));
796 } elseif ($year < 2000) {
797 $year = intval(substr(1900 - $year, 1, 3));
798 return sprintf('%02u0%03u', $year, $rank);
800 $year = intval(substr(1900 - $year, 1, 3));
801 return sprintf('%03u%03u', $year, $rank);
805 public static function getXorgId($schoolId)
807 if (!preg_match('/^[0-9]{6}$/', $schoolId)) {
811 $year = intval(substr($schoolId, 0, 3));
812 $rank = intval(substr($schoolId, 3, 3));
820 return sprintf('%04u%04u', 1900 +
$year, $rank);
826 /** Iterator over a set of Profiles
828 class ProfileIterator
implements PlIterator
830 private $iterator = null
;
833 public function __construct(PlIterator
$it, array $pids, $fields = 0x0000, $visibility = null
)
835 require_once 'profilefields.inc.php';
836 $visibility = Profile
::getVisibilityContext($visibility);
837 $this->fields
= $fields;
840 $callbacks = array();
843 $callbacks[0] = PlIteratorUtils
::arrayValueCallback('pid');
844 $cb = PlIteratorUtils
::objectPropertyCallback('pid');
846 if ($fields & Profile
::FETCH_ADDRESSES
) {
847 $callbacks[Profile
::FETCH_ADDRESSES
] = $cb;
848 $subits[Profile
::FETCH_ADDRESSES
] = new ProfileFieldIterator('ProfileAddresses', $pids, $visibility);
851 if ($fields & Profile
::FETCH_CORPS
) {
852 $callbacks[Profile
::FETCH_CORPS
] = $cb;
853 $subits[Profile
::FETCH_CORPS
] = new ProfileFieldIterator('ProfileCorps', $pids, $visibility);
856 if ($fields & Profile
::FETCH_EDU
) {
857 $callbacks[Profile
::FETCH_EDU
] = $cb;
858 $subits[Profile
::FETCH_EDU
] = new ProfileFieldIterator('ProfileEducation', $pids, $visibility);
861 if ($fields & Profile
::FETCH_JOBS
) {
862 $callbacks[Profile
::FETCH_JOBS
] = $cb;
863 $subits[Profile
::FETCH_JOBS
] = new ProfileFieldIterator('ProfileJobs', $pids, $visibility);
866 if ($fields & Profile
::FETCH_MEDALS
) {
867 $callbacks[Profile
::FETCH_MEDALS
] = $cb;
868 $subits[Profile
::FETCH_MEDALS
] = new ProfileFieldIterator('ProfileMedals', $pids, $visibility);
871 if ($fields & Profile
::FETCH_NETWORKING
) {
872 $callbacks[Profile
::FETCH_NETWORKING
] = $cb;
873 $subits[Profile
::FETCH_NETWORKING
] = new ProfileFieldIterator('ProfileNetworking', $pids, $visibility);
876 if ($fields & Profile
::FETCH_PHONES
) {
877 $callbacks[Profile
::FETCH_PHONES
] = $cb;
878 $subits[Profile
::FETCH_PHONES
] = new ProfileFieldIterator('ProfilePhones', $pids, $visibility);
881 $this->iterator
= PlIteratorUtils
::parallelIterator($subits, $callbacks, 0);
884 private function hasData($flag, $vals)
886 return ($this->fields
& $flag) && ($vals[$flag] != null
);
889 private function fillProfile(array $vals)
891 $pf = Profile
::get($vals[0]);
892 if ($this->hasData(Profile
::FETCH_PHONES
, $vals)) {
893 $pf->setPhones($vals[Profile
::FETCH_PHONES
]);
895 if ($this->hasData(Profile
::FETCH_ADDRESSES
, $vals)) {
896 $pf->setAddresses($vals[Profile
::FETCH_ADDRESSES
]);
898 if ($this->hasData(Profile
::FETCH_JOBS
, $vals)) {
899 $pf->setJobs($vals[Profile
::FETCH_JOBS
]);
902 if ($this->hasData(Profile
::FETCH_CORPS
, $vals)) {
903 $pf->setCorps($vals[Profile
::FETCH_CORPS
]);
905 if ($this->hasData(Profile
::FETCH_EDU
, $vals)) {
906 $pf->setEducations($vals[Profile
::FETCH_EDU
]);
908 if ($this->hasData(Profile
::FETCH_MEDALS
, $vals)) {
909 $pf->setMedals($vals[Profile
::FETCH_MEDALS
]);
911 if ($this->hasData(Profile
::FETCH_NETWORKING
, $vals)) {
912 $pf->setNetworking($vals[Profile
::FETCH_NETWORKING
]);
918 public function next()
920 $vals = $this->iterator
->next();
924 return $this->fillProfile($vals);
927 public function first()
929 return $this->iterator
->first();
932 public function last()
934 return $this->iterator
->last();
937 public function total()
939 return $this->iterator
->total();
943 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: