0d380faa495f9fb0b59200202e672d05603f590b
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;
92 const FETCH_PHOTO
= 0x000080;
94 const FETCH_MINIFICHES
= 0x0000CD; // FETCH_ADDRESSES & FETCH_EDU & FETCH_JOBS & FETCH_PHONES & FETCH_PHOTO
96 const FETCH_ALL
= 0x0000FF; // xor of all FETCH_*
100 private $data = array();
102 private $visibility = null
;
104 private function __construct(array $data)
107 $this->pid
= $this->data
['pid'];
108 $this->hrpid
= $this->data
['hrpid'];
110 $this->setVisibilityLevel(self
::VISIBILITY_PUBLIC
);
112 $this->setVisibilityLevel(self
::VISIBILITY_PRIVATE
);
116 static private $contexts = array();
118 /** Returns the best visibility context toward $visibility
119 * @param $visibility A wished visibility level
120 * @return An array of compatible visibilities
122 * if $visibility is null, the best visibility is returned
124 static public function getVisibilityContext($visibility = null
)
126 if (array_key_exists($visibility, self
::$contexts)) {
127 return self
::$contexts[$visibility];
130 $asked_vis = $visibility;
133 $minvis = self
::VISIBILITY_PRIVATE
;
135 $minvis = self
::VISIBILITY_PUBLIC
;
137 if ($visibility == null
) {
138 $visibility = $minvis;
141 if ($minvis == self
::VISIBILITY_PUBLIC
) {
142 $visibility = self
::VISIBILITY_PUBLIC
;
145 $visibility = self
::$v_values[$visibility];
146 self
::$contexts[$asked_vis] = $visibility;
156 public function hrid()
161 public function promo()
166 public function yearpromo()
168 return intval(substr($this->promo
, 1, 4));
171 /** Print a name with the given formatting:
179 public function name($format)
181 return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'),
182 array($this->isFemale() ?
'•' : '',
183 $this->firstName(), $this->lastName(),
184 $this->fullName(), $this->shortName(),
185 $this->promo()), $format);
188 public function fullName($with_promo = false
)
191 return $this->full_name
. ' (' . $this->promo
. ')';
193 return $this->full_name
;
196 public function shortName($with_promo = false
)
199 return $this->short_name
. ' (' . $this->promo
. ')';
201 return $this->short_name
;
204 public function firstName()
206 return $this->firstname
;
209 public function firstNames()
211 return $this->nameVariants(self
::FIRSTNAME
);
214 public function lastName()
216 return $this->lastname
;
219 public function lastNames()
221 return $this->nameVariants(self
::LASTNAME
);
224 public function isFemale()
226 return $this->sex
== PlUser
::GENDER_FEMALE
;
229 public function isDead()
231 return ($this->deathdate
!= null
);
234 public function data()
240 private function nameVariants($type)
242 $vals = array($this->$type);
243 foreach (self
::$name_variants[$type] as $var) {
244 $vartype = $type . '_' . $var;
245 $varname = $this->$vartype;
246 if ($varname != null
&& $varname != "") {
250 return array_unique($vals);
253 public function nationalities()
256 if ($this->nationality1
) {
257 $nats[] = $this->nationality1
;
259 if ($this->nationality2
) {
260 $nats[] = $this->nationality2
;
262 if ($this->nationality3
) {
263 $nats[] = $this->nationality3
;
268 public function __get($name)
270 if (property_exists($this, $name)) {
274 if (isset($this->data
[$name])) {
275 return $this->data
[$name];
281 public function __isset($name)
283 return property_exists($this, $name) ||
isset($this->data
[$name]);
286 /** Sets the level of visibility of the profile
287 * Sets $this->visibility to a list of valid visibilities.
288 * @param one of the self::VISIBILITY_* values
290 public function setVisibilityLevel($visibility)
292 if ($visibility != self
::VISIBILITY_PRIVATE
293 && $visibility != self
::VISIBILITY_AX
294 && $visibility != self
::VISIBILITY_PUBLIC
) {
295 Platal
::page()->kill("Visibility invalide: " . $visibility);
297 $this->visibility
= self
::$v_values[$visibility];
298 if ($this->mobile
&& !in_array($this->mobile_pub
, $this->visibility
)) {
299 unset($this->data
['mobile']);
303 /** Determine whether an item with visibility $visibility can be displayed
304 * with the current level of visibility of the profile
305 * @param $visibility The level of visibility to be checked
307 public function isVisible($visibility)
309 return in_array($visibility, $this->visibility
);
312 public static function getCompatibleVisibilities($visibility)
314 return self
::$v_values[$visibility];
317 private function getProfileField($cls)
319 return ProfileField
::getForPID($cls, $this->id(), $this->visibility
);
322 /** Consolidates internal data (addresses, phones, jobs)
324 private function consolidateFields()
326 if ($this->phones
!= null
) {
327 if ($this->addresses
!= null
) {
328 $this->addresses
->addPhones($this->phones
);
331 if ($this->jobs
!= null
) {
332 $this->jobs
->addPhones($this->phones
);
336 if ($this->addresses
!= null
&& $this->jobs
!= null
) {
337 $this->jobs
->addAddresses($this->addresses
);
343 private $photo = null
;
344 public function setPhoto(ProfilePhoto
$photo)
346 $this->photo
= $photo;
349 public function getPhoto($fallback = true
)
351 if ($this->photo
== null
) {
352 $this->setPhoto($this->getProfileField('ProfilePhoto'));
355 if ($this->photo
!= null
) {
356 return $this->photo
->pic
;
357 } else if ($fallback) {
358 return PlImage
::fromFile(dirname(__FILE__
).'/../htdocs/images/none.png',
366 private $addresses = null
;
367 public function setAddresses(ProfileAddresses
$addr)
369 $this->addresses
= $addr;
370 $this->consolidateFields();
373 public function getAddresses($flags, $limit = null
)
375 if ($this->addresses
== null
) {
376 $this->setAddresses($this->getProfileField('ProfileAddresses'));
379 if ($this->addresses
== null
) {
382 return $this->addresses
->get($flags, $limit);
385 public function iterAddresses($flags, $limit = null
)
387 return PlIteratorUtils
::fromArray($this->getAddresses($flags, $limit), 1, true
);
390 public function getMainAddress()
392 $addr = $this->getAddresses(self
::ADDRESS_PERSO | self
::ADDRESS_MAIN
);
393 if (count($addr) == 0) {
396 return array_pop($addr);
402 private $phones = null
;
403 public function setPhones(ProfilePhones
$phones)
405 $this->phones
= $phones;
406 $this->consolidateFields();
409 public function getPhones($flags, $limit = null
)
411 if ($this->phones
== null
) {
412 $this->setPhones($this->getProfileField('ProfilePhones'));
415 if ($this->phones
== null
) {
418 return $this->phones
->get($flags, $limit);
423 private $educations = null
;
424 public function setEducations(ProfileEducation
$edu)
426 $this->educations
= $edu;
429 public function getEducations($flags, $limit = null
)
431 if ($this->educations
== null
) {
432 $this->setEducations($this->getProfileField('ProfileEducation'));
435 if ($this->educations
== null
) {
438 return $this->educations
->get($flags, $limit);
441 public function getExtraEducations($limit = null
)
443 return $this->getEducations(self
::EDUCATION_EXTRA
, $limit);
448 private $corps = null
;
449 public function setCorps(ProfileCorps
$corps)
451 $this->corps
= $corps;
454 public function getCorps()
456 if ($this->corps
== null
) {
457 $this->setCorps($this->getProfileField('ProfileCorps'));
464 private $networks = null
;
465 public function setNetworking(ProfileNetworking
$nw)
467 $this->networks
= $nw;
470 public function getNetworking($flags, $limit = null
)
472 if ($this->networks
== null
) {
473 $this->setNetworking($this->getProfileField('ProfileNetworking'));
475 if ($this->networks
== null
) {
478 return $this->networks
->get($flags, $limit);
481 public function getWebSite()
483 $site = $this->getNetworking(self
::NETWORKING_WEB
, 1);
484 if (count($site) != 1) {
487 $site = array_pop($site);
488 return $site['address'];
494 private $jobs = null
;
495 public function setJobs(ProfileJobs
$jobs)
498 $this->consolidateFields();
501 public function getJobs($flags, $limit = null
)
503 if ($this->jobs
== null
) {
504 $this->setJobs($this->getProfileField('ProfileJobs'));
507 if ($this->jobs
== null
) {
510 return $this->jobs
->get($flags, $limit);
513 public function getMainJob()
515 $job = $this->getJobs(self
::JOBS_MAIN
, 1);
516 if (count($job) != 1) {
519 return array_pop($job);
524 public function getBinets()
526 return XDB
::fetchColumn('SELECT binet_id
528 WHERE pid = {?}', $this->id());
530 public function getBinetsNames()
532 return XDB
::fetchColumn('SELECT text
533 FROM profile_binets AS pb
534 LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id)
535 WHERE pb.pid = {?}', $this->id());
540 private $medals = null
;
541 public function setMedals(ProfileMedals
$medals)
543 $this->medals
= $medals;
546 public function getMedals()
548 if ($this->medals
== null
) {
549 $this->setMedals($this->getProfileField('ProfileMedals'));
551 if ($this->medals
== null
) {
554 return $this->medals
->medals
;
557 public function owner()
559 return User
::getSilent($this);
562 public function compareNames($firstname, $lastname)
564 $_lastname = mb_strtoupper($this->lastName());
565 $_firstname = mb_strtoupper($this->firstName());
566 $lastname = mb_strtoupper($lastname);
567 $firstname = mb_strtoupper($firstname);
569 $isOk = (mb_strtoupper($_firstname) == mb_strtoupper($firstname));
570 $tokens = preg_split("/[ \-']/", $lastname, -1, PREG_SPLIT_NO_EMPTY
);
573 foreach ($tokens as $str) {
574 $isOk &= (strpos($_lastname, $str) !== false
);
575 $maxlen = max($maxlen, strlen($str));
578 return ($isOk && ($maxlen > 2 ||
$maxlen == strlen($_lastname)));
581 private static function fetchProfileData(array $pids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
583 if (count($pids) == 0) {
587 if ($respect_order) {
588 $order = 'ORDER BY ' . XDB
::formatCustomOrder('p.pid', $pids);
594 $it = XDB
::Iterator('SELECT p.*, p.sex = \'female\' AS sex, pe.entry_year, pe.grad_year, pse.text AS section,
595 pn_f.name AS firstname, pn_l.name AS lastname, pn_n.name AS nickname,
596 IF(pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_ordinary,
597 IF(pn_ul.name IS NULL, pn_l.name, pn_ul.name) AS lastname_ordinary,
598 pd.promo AS promo, pd.short_name, pd.directory_name AS full_name,
599 pd.directory_name, pp.display_tel AS mobile, pp.pub AS mobile_pub,
600 ph.attach IS NOT NULL AS has_photo, ph.pub AS photo_pub,
601 p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old,
602 pm.expertise AS mentor_expertise,
605 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
606 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags))
607 LEFT JOIN profile_section_enum AS pse ON (pse.id = p.section)
608 INNER JOIN profile_name AS pn_f ON (pn_f.pid = p.pid
609 AND pn_f.typeid = ' . self
::getNameTypeId('firstname', true
) . ')
610 INNER JOIN profile_name AS pn_l ON (pn_l.pid = p.pid
611 AND pn_l.typeid = ' . self
::getNameTypeId('lastname', true
) . ')
612 LEFT JOIN profile_name AS pn_uf ON (pn_uf.pid = p.pid
613 AND pn_uf.typeid = ' . self
::getNameTypeId('firstname_ordinary', true
) . ')
614 LEFT JOIN profile_name AS pn_ul ON (pn_ul.pid = p.pid
615 AND pn_ul.typeid = ' . self
::getNameTypeId('lastname_ordinary', true
) . ')
616 LEFT JOIN profile_name AS pn_n ON (pn_n.pid = p.pid
617 AND pn_n.typeid = ' . self
::getNameTypeId('nickname', true
) . ')
618 LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\')
619 LEFT JOIN profile_photos AS ph ON (ph.pid = p.pid)
620 LEFT JOIN profile_mentor AS pm ON (pm.pid = p.pid)
621 LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms))
622 WHERE p.pid IN ' . XDB
::formatArray($pids) . '
625 return new ProfileIterator($it, $pids, $fields, $visibility);
628 public static function getPID($login)
630 if ($login instanceof PlUser
) {
631 return XDB
::fetchOneCell('SELECT pid
632 FROM account_profiles
633 WHERE uid = {?} AND FIND_IN_SET(\'owner\', perms)',
635 } else if (ctype_digit($login)) {
636 return XDB
::fetchOneCell('SELECT pid
638 WHERE pid = {?}', $login);
640 return XDB
::fetchOneCell('SELECT pid
642 WHERE hrpid = {?}', $login);
646 public static function getPIDsFromUIDs($uids, $respect_order = true
)
648 if ($respect_order) {
649 $order = 'ORDER BY ' . XDB
::formatCustomOrder('uid', $uids);
653 return XDB
::fetchAllAssoc('uid', 'SELECT ap.uid, ap.pid
654 FROM account_profiles AS ap
655 WHERE FIND_IN_SET(\'owner\', ap.perms)
656 AND ap.uid IN ' . XDB
::formatArray($uids) .'
660 /** Return the profile associated with the given login.
662 public static function get($login, $fields = 0x0000, $visibility = null
)
664 if (is_array($login)) {
665 return new Profile($login);
667 $pid = self
::getPID($login);
668 if (!is_null($pid)) {
669 $it = self
::iterOverPIDs(array($pid), false
, $fields, $visibility);
672 /* Let say we can identify a profile using the identifiers of its owner.
674 if (!($login instanceof PlUser
)) {
675 $user = User
::getSilent($login);
676 if ($user && $user->hasProfile()) {
677 return $user->profile();
684 public static function iterOverUIDs($uids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
686 return self
::iterOverPIDs(self
::getPIDsFromUIDs($uids), $respect_order, $fields, $visibility);
689 public static function iterOverPIDs($pids, $respect_order = true
, $fields = 0x0000, $visibility = null
)
691 return self
::fetchProfileData($pids, $respect_order, $fields, $visibility);
694 /** Return profiles for the list of pids.
696 public static function getBulkProfilesWithPIDs(array $pids, $fields = self
::FETCH_ADDRESSES
, $visibility = null
)
698 if (count($pids) == 0) {
701 $it = self
::iterOverPIDs($pids, true
, $fields, $visibility);
703 while ($p = $it->next()) {
704 $profiles[$p->id()] = $p;
709 /** Return profiles for uids.
711 public static function getBulkProfilesWithUIDS(array $uids, $fields = 0x000, $visibility = null
)
713 if (count($uids) == 0) {
716 return self
::getBulkProfilesWithPIDs(self
::getPIDsFromUIDs($uids), $fields, $visibility);
719 public static function isDisplayName($name)
721 return $name == self
::DN_FULL ||
$name == self
::DN_DISPLAY
722 ||
$name == self
::DN_YOURSELF ||
$name == self
::DN_DIRECTORY
723 ||
$name == self
::DN_PRIVATE ||
$name == self
::DN_PUBLIC
724 ||
$name == self
::DN_SHORT ||
$name == self
::DN_SORT
;
727 public static function getNameTypeId($type, $for_sql = false
)
729 if (!S
::has('name_types')) {
730 $table = XDB
::fetchAllAssoc('type', 'SELECT id, type
731 FROM profile_name_enum');
732 S
::set('name_types', $table);
734 $table = S
::v('name_types');
737 return XDB
::escape($table[$type]);
739 return $table[$type];
743 public static function rebuildSearchTokens($pid)
745 XDB
::execute('DELETE FROM search_name
748 $keys = XDB
::iterator("SELECT CONCAT(n.particle, n.name) AS name, e.score,
749 FIND_IN_SET('public', e.flags) AS public
750 FROM profile_name AS n
751 INNER JOIN profile_name_enum AS e ON (n.typeid = e.id)
755 foreach ($keys as $i => $key) {
756 if ($key['name'] == '') {
759 $toks = preg_split('/[ \'\-]+/', $key['name']);
763 $token = strtolower(replace_accent(array_pop($toks) . $token));
764 $score = ($toks ?
0 : 10 +
$first) * ($key['score'] / 10);
765 XDB
::execute('REPLACE INTO search_name (token, pid, soundex, score, flags)
766 VALUES ({?}, {?}, {?}, {?}, {?})',
767 $token, $pid, soundex_fr($token), $score, $key['public']);
773 /** The school identifier consists of 6 digits. The first 3 represent the
774 * promotion entry year. The last 3 indicate the student's rank.
776 * Our identifier consists of 8 digits and both half have the same role.
777 * This enables us to deal with bigger promotions and with a wider range
780 * getSchoolId returns a school identifier given one of ours.
781 * getXorgId returns a X.org identifier given a school identifier.
783 public static function getSchoolId($xorgId)
785 if (!preg_match('/^[0-9]{8}$/', $xorgId)) {
789 $year = intval(substr($xorgId, 0, 4));
790 $rank = intval(substr($xorgId, 5, 3));
793 } elseif ($year < 2000) {
794 $year = intval(substr(1900 - $year, 1, 3));
795 return sprintf('%02u0%03u', $year, $rank);
797 $year = intval(substr(1900 - $year, 1, 3));
798 return sprintf('%03u%03u', $year, $rank);
802 public static function getXorgId($schoolId)
804 if (!preg_match('/^[0-9]{6}$/', $schoolId)) {
808 $year = intval(substr($schoolId, 0, 3));
809 $rank = intval(substr($schoolId, 3, 3));
817 return sprintf('%04u%04u', 1900 +
$year, $rank);
823 /** Iterator over a set of Profiles
825 class ProfileIterator
implements PlIterator
827 private $iterator = null
;
830 public function __construct(PlIterator
$it, array $pids, $fields = 0x0000, $visibility = null
)
832 require_once 'profilefields.inc.php';
833 $visibility = Profile
::getVisibilityContext($visibility);
834 $this->fields
= $fields;
837 $callbacks = array();
840 $callbacks[0] = PlIteratorUtils
::arrayValueCallback('pid');
841 $cb = PlIteratorUtils
::objectPropertyCallback('pid');
843 if ($fields & Profile
::FETCH_ADDRESSES
) {
844 $callbacks[Profile
::FETCH_ADDRESSES
] = $cb;
845 $subits[Profile
::FETCH_ADDRESSES
] = new ProfileFieldIterator('ProfileAddresses', $pids, $visibility);
848 if ($fields & Profile
::FETCH_CORPS
) {
849 $callbacks[Profile
::FETCH_CORPS
] = $cb;
850 $subits[Profile
::FETCH_CORPS
] = new ProfileFieldIterator('ProfileCorps', $pids, $visibility);
853 if ($fields & Profile
::FETCH_EDU
) {
854 $callbacks[Profile
::FETCH_EDU
] = $cb;
855 $subits[Profile
::FETCH_EDU
] = new ProfileFieldIterator('ProfileEducation', $pids, $visibility);
858 if ($fields & Profile
::FETCH_JOBS
) {
859 $callbacks[Profile
::FETCH_JOBS
] = $cb;
860 $subits[Profile
::FETCH_JOBS
] = new ProfileFieldIterator('ProfileJobs', $pids, $visibility);
863 if ($fields & Profile
::FETCH_MEDALS
) {
864 $callbacks[Profile
::FETCH_MEDALS
] = $cb;
865 $subits[Profile
::FETCH_MEDALS
] = new ProfileFieldIterator('ProfileMedals', $pids, $visibility);
868 if ($fields & Profile
::FETCH_NETWORKING
) {
869 $callbacks[Profile
::FETCH_NETWORKING
] = $cb;
870 $subits[Profile
::FETCH_NETWORKING
] = new ProfileFieldIterator('ProfileNetworking', $pids, $visibility);
873 if ($fields & Profile
::FETCH_PHONES
) {
874 $callbacks[Profile
::FETCH_PHONES
] = $cb;
875 $subits[Profile
::FETCH_PHONES
] = new ProfileFieldIterator('ProfilePhones', $pids, $visibility);
878 if ($fields & Profile
::FETCH_PHOTO
) {
879 $callbacks[Profile
::FETCH_PHOTO
] = $cb;
880 $subits[Profile
::FETCH_PHOTO
] = new ProfileFieldIterator('ProfilePhoto', $pids, $visibility);
883 $this->iterator
= PlIteratorUtils
::parallelIterator($subits, $callbacks, 0);
886 private function hasData($flag, $vals)
888 return ($this->fields
& $flag) && ($vals[$flag] != null
);
891 private function fillProfile(array $vals)
893 $pf = Profile
::get($vals[0]);
894 if ($this->hasData(Profile
::FETCH_PHONES
, $vals)) {
895 $pf->setPhones($vals[Profile
::FETCH_PHONES
]);
897 if ($this->hasData(Profile
::FETCH_ADDRESSES
, $vals)) {
898 $pf->setAddresses($vals[Profile
::FETCH_ADDRESSES
]);
900 if ($this->hasData(Profile
::FETCH_JOBS
, $vals)) {
901 $pf->setJobs($vals[Profile
::FETCH_JOBS
]);
904 if ($this->hasData(Profile
::FETCH_CORPS
, $vals)) {
905 $pf->setCorps($vals[Profile
::FETCH_CORPS
]);
907 if ($this->hasData(Profile
::FETCH_EDU
, $vals)) {
908 $pf->setEducations($vals[Profile
::FETCH_EDU
]);
910 if ($this->hasData(Profile
::FETCH_MEDALS
, $vals)) {
911 $pf->setMedals($vals[Profile
::FETCH_MEDALS
]);
913 if ($this->hasData(Profile
::FETCH_NETWORKING
, $vals)) {
914 $pf->setNetworking($vals[Profile
::FETCH_NETWORKING
]);
916 if ($this->hasData(Profile
::FETCH_PHOTO
, $vals)) {
917 $pf->setPhoto($vals[Profile
::FETCH_PHOTO
]);
923 public function next()
925 $vals = $this->iterator
->next();
929 return $this->fillProfile($vals);
932 public function first()
934 return $this->iterator
->first();
937 public function last()
939 return $this->iterator
->last();
942 public function total()
944 return $this->iterator
->total();
948 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: