7065598a0233c3245ece6425322fe9276cbbea12
[platal.git] / classes / profile.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2014 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 class Profile implements PlExportable
23 {
24
25 /* name tokens */
26 const LASTNAME = 'lastname';
27 const FIRSTNAME = 'firstname';
28 const NICKNAME = 'nickname';
29 const PSEUDONYM = 'pseudonym';
30 const NAME = 'name';
31 /* name variants */
32 const VN_MARITAL = 'marital';
33 const VN_ORDINARY = 'ordinary';
34 const VN_OTHER = 'other';
35 const VN_INI = 'ini';
36 /* display names */
37 const DN_FULL = 'directory_name';
38 const DN_DISPLAY = 'yourself';
39 const DN_YOURSELF = 'yourself';
40 const DN_DIRECTORY = 'directory_name';
41 const DN_PRIVATE = 'private_name';
42 const DN_PUBLIC = 'public_name';
43 const DN_SHORT = 'short_name';
44 const DN_SORT = 'sort_name';
45 /* education related names */
46 const EDU_X = 'École polytechnique';
47 const DEGREE_X = 'Ingénieur';
48 const DEGREE_M = 'Master';
49 const DEGREE_D = 'Doctorat';
50
51 static public $cycles = array(
52 self::DEGREE_X => 'polytechnicien',
53 self::DEGREE_M => 'master',
54 self::DEGREE_D => 'docteur'
55 );
56 static public $cycle_prefixes = array(
57 self::DEGREE_X => 'X',
58 self::DEGREE_M => 'M',
59 self::DEGREE_D => 'D'
60 );
61
62 static public $name_variants = array(
63 self::LASTNAME => array(self::VN_MARITAL, self::VN_ORDINARY),
64 self::FIRSTNAME => array(self::VN_ORDINARY, self::VN_INI, self::VN_OTHER)
65 );
66
67 const ADDRESS_MAIN = 0x00000001;
68 const ADDRESS_PERSO = 0x00000002;
69 const ADDRESS_PRO = 0x00000004;
70 const ADDRESS_ALL = 0x00000006;
71 const ADDRESS_POSTAL = 0x00000008;
72
73 const EDUCATION_MAIN = 0x00000010;
74 const EDUCATION_EXTRA = 0x00000020;
75 const EDUCATION_ALL = 0x00000040;
76 const EDUCATION_FINISHED = 0x00000080;
77 const EDUCATION_CURRENT = 0x00000100;
78
79 const JOBS_MAIN = 0x00001000;
80 const JOBS_ALL = 0x00002000;
81 const JOBS_FINISHED = 0x00004000;
82 const JOBS_CURRENT = 0x00008000;
83
84 const NETWORKING_ALL = 0x00070000;
85 const NETWORKING_WEB = 0x00010000;
86 const NETWORKING_IM = 0x00020000;
87 const NETWORKING_SOCIAL = 0x00040000;
88
89 const PHONE_LINK_JOB = 0x00100000;
90 const PHONE_LINK_ADDRESS = 0x00200000;
91 const PHONE_LINK_PROFILE = 0x00400000;
92 const PHONE_LINK_COMPANY = 0x00800000;
93 const PHONE_LINK_ANY = 0x00F00000;
94
95 const PHONE_TYPE_FAX = 0x01000000;
96 const PHONE_TYPE_FIXED = 0x02000000;
97 const PHONE_TYPE_MOBILE = 0x04000000;
98 const PHONE_TYPE_ANY = 0x07000000;
99
100 const PHONE_ANY = 0x07F00000;
101
102 const FETCH_ADDRESSES = 0x000001;
103 const FETCH_CORPS = 0x000002;
104 const FETCH_EDU = 0x000004;
105 const FETCH_JOBS = 0x000008;
106 const FETCH_MEDALS = 0x000010;
107 const FETCH_NETWORKING = 0x000020;
108 const FETCH_MENTOR_COUNTRY = 0x000080;
109 const FETCH_PHONES = 0x000100;
110 const FETCH_JOB_TERMS = 0x000200;
111 const FETCH_MENTOR_TERMS = 0x000400;
112 const FETCH_DELTATEN = 0x000800;
113 const FETCH_PARTNER = 0x001000;
114 const FETCH_SKILL = 0x002000;
115 const FETCH_LANGUAGE = 0x004000;
116
117 const FETCH_MINIFICHES = 0x00012D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_NETWORKING | FETCH_PHONES
118
119 const FETCH_ALL = 0x007FFF; // OR of FETCH_*
120
121 static public $descriptions = array(
122 'search_names' => 'Noms',
123 'nationality1' => 'Nationalité',
124 'nationality2' => '2e nationalité',
125 'nationality3' => '3e nationalité',
126 'promo_display' => 'Promotion affichée',
127 'email_directory' => 'Email annuaire papier',
128 'networking' => 'Messageries…',
129 'tels' => 'Téléphones',
130 'edus' => 'Formations',
131 'main_edus' => 'Formations à l\'X',
132 'promo' => 'Promotion de sortie',
133 'birthdate' => 'Date de naissance',
134 'yourself' => 'Nom affiché',
135 'freetext' => 'Commentaire',
136 'freetext_pub' => 'Affichage du commentaire',
137 'axfreetext' => 'Commentaire AX',
138 'photo' => 'Photographie',
139 'photo_pub' => 'Affichage de la photographie',
140 'addresses' => 'Adresses',
141 'corps' => 'Corps',
142 'cv' => 'CV',
143 'jobs' => 'Emplois',
144 'section' => 'Section',
145 'binets' => 'Binets',
146 'medals' => 'Décorations',
147 'medals_pub' => 'Affichage des décorations',
148 'competences' => 'Compétences',
149 'langues' => 'Langues',
150 'expertise' => 'Expertises (mentoring)',
151 'terms' => 'Compétences (mentoring)',
152 'countries' => 'Pays (mentoring)',
153 'deltaten' => 'Opération N N-10',
154 );
155
156 private $fetched_fields = 0x000000;
157
158 private $pid;
159 private $hrpid;
160 private $owner;
161 private $owner_fetched = false;
162 private $data = array();
163
164 private $visibility = null;
165
166
167 private function __construct(array $data, Visibility $visibility)
168 {
169 $this->data = $data;
170 $this->pid = $this->data['pid'];
171 $this->hrpid = $this->data['hrpid'];
172 $this->visibility = $visibility;
173 }
174
175 public function __destruct()
176 {
177 // Need to delete objects allocated by the profile
178 // http://www.php.net/manual/en/function.unset.php#98692
179 unset($this->owner);
180 }
181
182 public function id()
183 {
184 return $this->pid;
185 }
186
187 public function hrid()
188 {
189 return $this->hrpid;
190 }
191
192 public function owner()
193 {
194 if ($this->owner == null && !$this->owner_fetched) {
195 $this->owner_fetched = true;
196 $this->owner = User::getSilent($this);
197 }
198 return $this->owner;
199 }
200
201 public function isActive()
202 {
203 if ($this->owner()) {
204 return $this->owner->isActive();
205 }
206 return false;
207 }
208
209 public function promo($details = false)
210 {
211 if ($details && ($this->program || $this->fieldid)) {
212 $text = array();
213 if ($this->program) {
214 $text[] = $this->program;
215 }
216 if ($this->fieldid) {
217 $fieldsList = DirEnum::getOptions(DirEnum::EDUFIELDS);
218 $text[] = $fieldsList[$this->fieldid];
219 }
220 return $this->promo . ' (' . implode(', ', $text) . ')';
221 }
222
223 return $this->promo;
224 }
225
226 public function yearpromo()
227 {
228 return $this->promo_year;
229 }
230
231 /** Check if user is an orange (associated with several promos)
232 */
233 public function isMultiPromo()
234 {
235 return $this->grad_year != $this->entry_year + $this->mainEducationDuration();
236 }
237
238 /** Returns an array with all associated promo years.
239 */
240 public function yearspromo()
241 {
242 $promos = array();
243 $d = -$this->deltaPromoToGradYear();
244 for ($g = $this->entry_year + $this->mainEducationDuration(); $g <= $this->grad_year; ++$g) {
245 $promos[] = $g + $d;
246 }
247 return $promos;
248 }
249
250 public function mainEducation()
251 {
252 if (empty($this->promo)) {
253 return null;
254 } else {
255 return $this->promo{0};
256 }
257 }
258
259 public function mainGrade()
260 {
261 switch ($this->mainEducation()) {
262 case 'X':
263 return UserFilter::GRADE_ING;
264 case 'M':
265 return UserFilter::GRADE_MST;
266 case 'D':
267 return UserFilter::GRADE_PHD;
268 default:
269 return null;
270 }
271 }
272
273 public function mainEducationDuration()
274 {
275 switch ($this->mainEducation()) {
276 case 'X':
277 return 3;
278 case 'M':
279 return 2;
280 case 'D':
281 return 3;
282 default:
283 return 0;
284 }
285 }
286
287 public static function educationDuration($education)
288 {
289 switch ($education) {
290 case self::DEGREE_X:
291 return 3;
292 case self::DEGREE_M:
293 return 2;
294 case self::DEGREE_D:
295 return 3;
296 default:
297 return 0;
298 }
299 }
300
301 /** Number of years between the promotion year until the
302 * graduation year. In standard schools it's 0, but for
303 * Polytechnique the promo year is the entry year.
304 */
305 public function deltaPromoToGradYear()
306 {
307 if ($this->mainEducation() == 'X') {
308 return $this->mainEducationDuration();
309 }
310 return 0;
311 }
312
313 // Returns the profile's color.
314 public function promoColor()
315 {
316 switch ($this->mainEducation()) {
317 case 'X':
318 if (($this->yearpromo() % 2) === 0) {
319 return 'red';
320 } else {
321 return 'yellow';
322 }
323 case 'M':
324 return 'green';
325 case 'D':
326 return 'blue';
327 default:
328 return 'gray';
329 }
330 }
331
332 // Returns younger/older promotion year for a given education.
333 static public function extremePromotions($education)
334 {
335 return XDB::fetchOneRow("SELECT MIN(pe.promo_year) AS min, MAX(pe.promo_year) AS max
336 FROM profile_education AS pe
337 INNER JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
338 WHERE pede.degree = {?} AND FIND_IN_SET('primary', pe.flags)",
339 $education);
340 }
341
342 /** Print a name with the given formatting:
343 * %s = • for women
344 * %f = firstname
345 * %l = lastname
346 * %F = fullname
347 * %S = shortname
348 * %p = promo
349 */
350 public function name($format)
351 {
352 return str_replace(array('%s', '%f', '%l', '%F', '%S', '%p'),
353 array($this->isFemale() ? '•' : '',
354 $this->firstName(), $this->lastName(),
355 $this->fullName(), $this->shortName(),
356 $this->promo()), $format);
357 }
358
359 public function fullName($with_promo = false)
360 {
361 if ($with_promo) {
362 return $this->full_name . ' (' . $this->promo . ')';
363 }
364 return $this->full_name;
365 }
366
367 public function shortName($with_promo = false)
368 {
369 if ($with_promo) {
370 return $this->short_name . ' (' . $this->promo . ')';
371 }
372 return $this->short_name;
373 }
374
375 public function firstName()
376 {
377 return $this->firstname_ordinary;
378 }
379
380 public function firstNames()
381 {
382 return $this->nameVariants(self::FIRSTNAME);
383 }
384
385 public function lastName()
386 {
387 return $this->lastname_ordinary;
388 }
389
390 public function lastNames()
391 {
392 return $this->nameVariants(self::LASTNAME);
393 }
394
395 public function isFemale()
396 {
397 return $this->sex == PlUser::GENDER_FEMALE;
398 }
399
400 public function isDead()
401 {
402 return ($this->deathdate != null);
403 }
404
405 public function displayEmail()
406 {
407 $o = $this->owner();
408 if ($o != null && $this->isVisible(Visibility::EXPORT_PRIVATE)) {
409 return $o->bestEmail();
410 } else {
411 return $this->email_directory;
412 }
413 }
414
415 public function data()
416 {
417 $this->first_name;
418 return $this->data;
419 }
420
421 private function nameVariants($type)
422 {
423 $vals = array($this->$type);
424 foreach (self::$name_variants[$type] as $var) {
425 $vartype = $type . '_' . $var;
426 $varname = $this->$vartype;
427 if ($varname != null && $varname != "") {
428 $vals[] = $varname;
429 }
430 }
431 return array_unique($vals);
432 }
433
434 public function nationalities()
435 {
436 $nats = array();
437 $nationalities = DirEnum::getOptions(DirEnum::NATIONALITIES);
438 if ($this->nationality1) {
439 $nats[$this->nationality1] = $nationalities[$this->nationality1];
440 }
441 if ($this->nationality2) {
442 $nats[$this->nationality2] = $nationalities[$this->nationality2];
443 }
444 if ($this->nationality3) {
445 $nats[$this->nationality3] = $nationalities[$this->nationality3];
446 }
447 return $nats;
448 }
449
450 public function __get($name)
451 {
452 if (property_exists($this, $name)) {
453 return $this->$name;
454 }
455
456 if (isset($this->data[$name])) {
457 return $this->data[$name];
458 }
459
460 return null;
461 }
462
463 public function __isset($name)
464 {
465 return property_exists($this, $name) || isset($this->data[$name]);
466 }
467
468 public function __unset($name)
469 {
470 if (property_exists($this, $name)) {
471 $this->$name = null;
472 } else {
473 unset($this->data[$name]);
474 }
475 }
476
477
478 /**
479 * Clears a profile.
480 * *always deletes in: profile_addresses, profile_binets, profile_deltaten,
481 * profile_job, profile_langskills, profile_mentor, profile_networking,
482 * profile_partnersharing_settings, profile_phones, profile_skills,
483 * watch_profile
484 * *always keeps in: profile_corps, profile_display, profile_education,
485 * profile_medals, profile_*_names, profile_photos, search_name
486 * *modifies: profiles
487 */
488 public function clear()
489 {
490 $tables = array(
491 'profile_job', 'profile_langskills', 'profile_mentor',
492 'profile_networking', 'profile_skills', 'watch_profile',
493 'profile_phones', 'profile_addresses', 'profile_binets',
494 'profile_deltaten', 'profile_partnersharing_settings');
495
496 foreach ($tables as $t) {
497 XDB::execute('DELETE FROM ' . $t . '
498 WHERE pid = {?}',
499 $this->id());
500 }
501
502 XDB::execute("UPDATE profiles
503 SET cv = NULL, freetext = NULL, freetext_pub = 'private', axfreetext = NULL,
504 medals_pub = 'private', alias_pub = 'hidden',
505 email_directory = NULL
506 WHERE pid = {?}",
507 $this->id());
508 }
509
510 /** Determine whether an item with visibility $visibility can be displayed
511 * with the current level of visibility of the profile
512 * @param $visibility The level of visibility to be checked
513 */
514 public function isVisible($visibility)
515 {
516 return $this->visibility->isVisible($visibility);
517 }
518
519 /** Stores the list of fields which have already been fetched for this Profile
520 */
521 public function setFetchedFields($fields)
522 {
523 if (($fields | self::FETCH_ALL) != self::FETCH_ALL) {
524 Platal::page()->kill("Invalid fetched fields: $fields");
525 }
526
527 $this->fetched_fields = $fields;
528 }
529
530 /** Have we already fetched this field ?
531 */
532 private function fetched($field)
533 {
534 if (!array_key_exists($field, ProfileField::$fields)) {
535 Platal::page()->kill("Invalid field: $field");
536 }
537
538 return ($this->fetched_fields & $field);
539 }
540
541 /** If not already done, fetches data for the given field
542 * @param $field One of the Profile::FETCH_*
543 * @return A ProfileField, or null
544 */
545 private function getProfileField($field)
546 {
547 if (!array_key_exists($field, ProfileField::$fields)) {
548 Platal::page()->kill("Invalid field: $field");
549 }
550 if ($this->fetched($field)) {
551 return null;
552 } else {
553 $this->fetched_fields = $this->fetched_fields | $field;
554 }
555
556 $cls = ProfileField::$fields[$field];
557
558 return ProfileField::getForPID($cls, $this->id(), $this->visibility);
559 }
560
561 /** Consolidates internal data (addresses, phones, jobs)
562 */
563 private function consolidateFields()
564 {
565 // Link phones to addresses
566 if ($this->phones != null) {
567 if ($this->addresses != null) {
568 $this->addresses->addPhones($this->phones);
569 }
570
571 if ($this->jobs != null) {
572 $this->jobs->addPhones($this->phones);
573 }
574 }
575
576 // Link addresses to jobs
577 if ($this->addresses != null && $this->jobs != null) {
578 $this->jobs->addAddresses($this->addresses);
579 }
580
581 // Link jobterms to jobs
582 if ($this->jobs != null && $this->jobterms != null) {
583 $this->jobs->addJobTerms($this->jobterms);
584 }
585 }
586
587 /* Photo
588 */
589 private $photo = null;
590 public function getPhoto($fallback = true, $data = false)
591 {
592 if ($this->has_photo) {
593 if ($data && ($this->photo == null || $this->photo->mimeType == null)) {
594 $res = XDB::fetchOneAssoc('SELECT attach, attachmime, x, y, last_update
595 FROM profile_photos
596 WHERE pid = {?}', $this->pid);
597 $this->photo = PlImage::fromData($res['attach'], 'image/' .$res['attachmime'], $res['x'], $res['y'], $res['last_update']);
598 } else if ($this->photo == null) {
599 $this->photo = PlImage::fromData(null, null, $this->photo_width, $this->photo_height);
600 }
601 return $this->photo;
602 } else if ($fallback) {
603 if ($this->mainEducation() == 'X') {
604 return PlImage::fromFile(dirname(__FILE__) . '/../htdocs/images/none_x.png', 'image/png');
605 }
606 return PlImage::fromFile(dirname(__FILE__) . '/../htdocs/images/none_md.png', 'image/png');
607 }
608 return null;
609 }
610
611 /* Addresses
612 */
613 private $addresses = null;
614 public function setAddresses(ProfileAddresses $addr)
615 {
616 $this->addresses = $addr;
617 $this->consolidateFields();
618 }
619
620 private function fetchAddresses()
621 {
622 if ($this->addresses == null && !$this->fetched(self::FETCH_ADDRESSES)) {
623 $addr = $this->getProfileField(self::FETCH_ADDRESSES);
624 if ($addr) {
625 $this->setAddresses($addr);
626 $this->fetchPhones();
627 }
628 }
629 }
630
631 public function getAddresses($flags, $limit = null)
632 {
633 $this->fetchAddresses();
634
635 if ($this->addresses == null) {
636 return array();
637 }
638 return $this->addresses->get($flags, $limit);
639 }
640
641 public function iterAddresses($flags, $limit = null)
642 {
643 return PlIteratorUtils::fromArray($this->getAddresses($flags, $limit), 1, true);
644 }
645
646 public function getMainAddress()
647 {
648 $main = $this->getAddresses(self::ADDRESS_MAIN);
649 $perso = $this->getAddresses(self::ADDRESS_PERSO);
650
651 if (count($main)) {
652 return array_pop($main);
653 } else if (count($perso)) {
654 return array_pop($perso);
655 } else {
656 return null;
657 }
658 }
659
660 /* Phones
661 */
662 private $phones = null;
663 public function setPhones(ProfilePhones $phones)
664 {
665 $this->phones = $phones;
666 $this->consolidateFields();
667 }
668
669 private function fetchPhones()
670 {
671 if ($this->phones == null && !$this->fetched(self::FETCH_PHONES)) {
672 $phones = $this->getProfileField(self::FETCH_PHONES);
673 if (isset($phones)) {
674 $this->setPhones($phones);
675 }
676 }
677 }
678
679 public function getPhones($flags, $limit = null)
680 {
681 $this->fetchPhones();
682 if ($this->phones == null) {
683 return array();
684 }
685 return $this->phones->get($flags, $limit);
686 }
687
688 /* Educations
689 */
690 private $educations = null;
691 public function setEducations(ProfileEducation $edu)
692 {
693 $this->educations = $edu;
694 }
695
696 public function getEducations($flags, $limit = null)
697 {
698 if ($this->educations == null && !$this->fetched(self::FETCH_EDU)) {
699 $educations = $this->getProfileField(self::FETCH_EDU);
700 if ($educations) {
701 $this->setEducations($educations);
702 }
703 }
704
705 if ($this->educations == null) {
706 return array();
707 }
708 return $this->educations->get($flags, $limit);
709 }
710
711 public function getExtraEducations($limit = null)
712 {
713 return $this->getEducations(self::EDUCATION_EXTRA, $limit);
714 }
715
716 /* Corps
717 */
718 private $corps = null;
719 public function setCorps(ProfileCorps $corps)
720 {
721 $this->corps = $corps;
722 }
723
724 public function getCorps()
725 {
726 if ($this->corps == null && !$this->fetched(self::FETCH_CORPS)) {
727 $corps = $this->getProfileField(self::FETCH_CORPS);
728 if ($corps) {
729 $this->setCorps($corps);
730 }
731 }
732 return $this->corps;
733 }
734
735 /**
736 * Retrieve the name of the corps which has been done.
737 *
738 * Note: this function first tries getCorps(), and if this field is blank
739 * tries to find an education which degree is "Corps".
740 *
741 * Returns an empty string if nothing has been found.
742 */
743 public function getCorpsName()
744 {
745 $corps = $this->getCorps();
746 if ($corps && $corps->current) {
747 $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS);
748 return $corpsList[$corps->current];
749 }
750
751 foreach ($this->getExtraEducations() as $edu) {
752 if (!strcasecmp($edu->degree, 'Corps')) {
753 if ($edu->school_short) {
754 return $edu->school_short;
755 } elseif ($edu->school) {
756 return $edu->school;
757 }
758 }
759 }
760 return '';
761 }
762
763 /** Networking
764 */
765 private $networks = null;
766 public function setNetworking(ProfileNetworking $nw)
767 {
768 $this->networks = $nw;
769 }
770
771 public function getNetworking($flags, $limit = null)
772 {
773 if ($this->networks == null && !$this->fetched(self::FETCH_NETWORKING)) {
774 $nw = $this->getProfileField(self::FETCH_NETWORKING);
775 if ($nw) {
776 $this->setNetworking($nw);
777 }
778 }
779 if ($this->networks == null) {
780 return array();
781 }
782 return $this->networks->get($flags, $limit);
783 }
784
785 public function getWebSite()
786 {
787 $site = $this->getNetworking(self::NETWORKING_WEB, 1);
788 if (count($site) != 1) {
789 return null;
790 }
791 $site = array_pop($site);
792 return $site;
793 }
794
795
796 /** Jobs
797 */
798 private $jobs = null;
799 public function setJobs(ProfileJobs $jobs)
800 {
801 $this->jobs = $jobs;
802 $this->consolidateFields();
803 }
804
805 private function fetchJobs()
806 {
807 if ($this->jobs == null && !$this->fetched(self::FETCH_JOBS)) {
808 $jobs = $this->getProfileField(self::FETCH_JOBS);
809 if ($jobs) {
810 $this->setJobs($jobs);
811 $this->fetchAddresses();
812 }
813 }
814 }
815
816 public function getJobs($flags, $limit = null)
817 {
818 $this->fetchJobs();
819
820 if ($this->jobs == null) {
821 return array();
822 }
823 return $this->jobs->get($flags, $limit);
824 }
825
826 public function getMainJob()
827 {
828 $job = $this->getJobs(self::JOBS_MAIN, 1);
829 if (count($job) != 1) {
830 return null;
831 }
832 return array_pop($job);
833 }
834
835 /** JobTerms
836 */
837 private $jobterms = null;
838 public function setJobTerms(ProfileJobTerms $jobterms)
839 {
840 $this->jobterms = $jobterms;
841 $this->consolidateFields();
842 }
843
844 private $mentor_countries = null;
845 public function setMentoringCountries(ProfileMentoringCountries $countries)
846 {
847 $this->mentor_countries = $countries;
848 }
849
850 public function getMentoringCountries()
851 {
852 if ($this->mentor_countries == null && !$this->fetched(self::FETCH_MENTOR_COUNTRY)) {
853 $countries = $this->getProfileField(self::FETCH_MENTOR_COUNTRY);
854 if ($countries) {
855 $this->setMentoringCountries($countries);
856 }
857 }
858
859 if ($this->mentor_countries == null) {
860 return array();
861 } else {
862 return $this->mentor_countries->countries;
863 }
864 }
865
866 /** List of job terms to specify mentoring */
867 private $mentor_terms = null;
868 /**
869 * set job terms to specify mentoring
870 * @param $terms a ProfileMentoringTerms object listing terms only for this profile
871 */
872 public function setMentoringTerms(ProfileMentoringTerms $terms)
873 {
874 $this->mentor_terms = $terms;
875 }
876 /**
877 * get all job terms that specify mentoring
878 * @return an array of JobTerms objects
879 */
880 public function getMentoringTerms()
881 {
882 if ($this->mentor_terms == null && !$this->fetched(self::FETCH_MENTOR_TERMS)) {
883 $terms = $this->getProfileField(self::FETCH_MENTOR_TERMS);
884 if ($terms) {
885 $this->setMentoringTerms($terms);
886 }
887 }
888
889 if ($this->mentor_terms == null) {
890 return array();
891 } else {
892 return $this->mentor_terms->get();
893 }
894 }
895
896 /* Skills */
897 private $skills = null;
898 public function setSkills(ProfileSkills $skills)
899 {
900 $this->skills = $skills;
901 }
902 public function getSkills()
903 {
904 if ($this->skills == null && !$this->fetched(self::FETCH_SKILL)) {
905 $skills = $this->getProfileField(self::FETCH_SKILL);
906 if ($skills) {
907 $this->setSkills($skills);
908 }
909 }
910
911 if ($this->skills == null) {
912 return array();
913 } else {
914 return $this->skills->skills;
915 }
916 }
917
918 /* Languades */
919 private $languages = null;
920 public function setLanguages(ProfileLanguages $languages)
921 {
922 $this->languages = $languages;
923 }
924 public function getLanguages()
925 {
926 if ($this->languages == null && !$this->fetched(self::FETCH_LANGUAGE)) {
927 $languages = $this->getProfileField(self::FETCH_LANGUAGE);
928 if ($languages) {
929 $this->setLanguages($languages);
930 }
931 }
932
933 if ($this->languages == null) {
934 return array();
935 } else {
936 return $this->languages->languages;
937 }
938 }
939
940 /** DeltaTen
941 */
942
943 /** Find out whether this profile may take part to the "DeltaTen" operation.
944 * @param $role Which role to select ('young' or 'old')
945 * @return Boolean: whether it is enabled.
946 */
947 const DELTATEN_YOUNG = 'young';
948 const DELTATEN_OLD = 'old';
949 public function isDeltaTenEnabled($role)
950 {
951 global $globals;
952 switch ($role) {
953 case self::DELTATEN_YOUNG:
954 return ($this->mainGrade() == UserFilter::GRADE_ING && $this->yearpromo() >= $globals->deltaten->first_promo_young);
955 case self::DELTATEN_OLD:
956 // Roughly compute the current promo in second year on the campus:
957 // Promo 2010 is in second year between 09/2011 and 08/2012 => use 2012.
958 // DeltaTen program begins around January of the second year.
959 $promo_on_platal = ((int) date('Y')) - 2;
960 return ($this->mainGrade() == UserFilter::GRADE_ING && $this->yearpromo() >= $globals->deltaten->first_promo_young - 10 && $this->yearpromo() <= $promo_on_platal - 10);
961 default:
962 Platal::assert(false, "Invalid DeltaTen role $role");
963 }
964 }
965
966 /** Retrieve the "Deltaten" message of the user.
967 * Returns "null" if the message is empty or the user is not taking part to the
968 * DeltaTen operation.
969 */
970 public function getDeltatenMessage()
971 {
972 if ($this->isDeltaTenEnabled(self::DELTATEN_OLD)) {
973 return $this->deltaten_message;
974 } else {
975 return null;
976 }
977 }
978
979 /* Binets
980 */
981 public function getBinets()
982 {
983 if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
984 return XDB::fetchColumn('SELECT binet_id
985 FROM profile_binets
986 WHERE pid = {?}', $this->id());
987 } else {
988 return array();
989 }
990 }
991
992 public function getFullBinets()
993 {
994 if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
995 return XDB::fetchAllAssoc('SELECT binet_id, text, url
996 FROM profile_binets AS pb
997 LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id)
998 WHERE pid = {?}', $this->id());
999 } else {
1000 return array();
1001 }
1002 }
1003
1004 public function getBinetsNames()
1005 {
1006 if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
1007 return XDB::fetchColumn('SELECT text
1008 FROM profile_binets AS pb
1009 LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id)
1010 WHERE pb.pid = {?}', $this->id());
1011 } else {
1012 return array();
1013 }
1014 }
1015
1016 /* Hobbies
1017 */
1018 public function getHobbies() {
1019 if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
1020 return XDB::fetchAllAssoc('type', 'SELECT type, GROUP_CONCAT(text)
1021 FROM profile_hobby
1022 WHERE pid = {?}
1023 GROUP BY type', $this->id());
1024 } else {
1025 return XDB::fetchAllAssoc('type', 'SELECT type, GROUP_CONCAT(text)
1026 FROM profile_hobby
1027 WHERE pub = \'public\' AND pid = {?}
1028 GROUP BY type', $this->id());
1029 }
1030 }
1031
1032 /* Medals
1033 */
1034 private $medals = null;
1035 public function setMedals(ProfileMedals $medals)
1036 {
1037 $this->medals = $medals;
1038 }
1039
1040 public function getMedals()
1041 {
1042 if ($this->medals == null && !$this->fetched(self::FETCH_MEDALS)) {
1043 $medals = $this->getProfileField(self::FETCH_MEDALS);
1044 if ($medals) {
1045 $this->setMedals($medals);
1046 }
1047 }
1048 if ($this->medals == null) {
1049 return array();
1050 }
1051 return $this->medals->medals;
1052 }
1053
1054 /** Sharing data with partner websites
1055 */
1056 private $partners_settings = null;
1057 public function setPartnersSettings(ProfilePartnerSharing $partners_settings)
1058 {
1059 $this->partners_settings = $partners_settings;
1060 }
1061
1062 public function getPartnerSettings($partner_id)
1063 {
1064 if ($this->partners_settings === null && !$this->fetched(self::FETCH_PARTNER)) {
1065 $settings = $this->getProfileField(self::FETCH_PARTNER);
1066 if ($settings) {
1067 $this->setPartnersSettings($settings);
1068 }
1069 }
1070 if ($this->partners_settings === null) {
1071 return PartnerSettings::getEmpty($partner_id);
1072 }
1073 return $this->partners_settings->get($partner_id);
1074 }
1075
1076 public function compareNames($firstname, $lastname)
1077 {
1078 $_lastname = mb_strtoupper($this->lastName());
1079 $_firstname = mb_strtoupper($this->firstName());
1080 $lastname = mb_strtoupper($lastname);
1081 $firstname = mb_strtoupper($firstname);
1082
1083 $isOk = (mb_strtoupper($_firstname) == mb_strtoupper($firstname));
1084 $tokens = preg_split("/[ \-']/", $lastname, -1, PREG_SPLIT_NO_EMPTY);
1085 $maxlen = 0;
1086
1087 foreach ($tokens as $str) {
1088 $isOk &= (strpos($_lastname, $str) !== false);
1089 $maxlen = max($maxlen, strlen($str));
1090 }
1091
1092 return ($isOk && ($maxlen > 2 || $maxlen == strlen($_lastname)));
1093 }
1094
1095 /* Export to JSON
1096 */
1097 public function export()
1098 {
1099 return array(
1100 'hrpid' => $this->hrid(),
1101 'display_name' => $this->shortName(),
1102 'full_name' => $this->fullName(),
1103 'directory_name' => $this->directory_name,
1104 'promo' => $this->promo(),
1105 'year_promo' => $this->yearpromo(),
1106 'is_active' => $this->isActive(),
1107 'first_name' => $this->firstName(),
1108 'last_name' => $this->lastName(),
1109 'is_female' => $this->isFemale(),
1110 );
1111 }
1112
1113 private static function fetchProfileData(array $pids, $respect_order = true, $fields = 0x0000, $visibility = null)
1114 {
1115 if (count($pids) == 0) {
1116 return null;
1117 }
1118
1119 if ($respect_order) {
1120 $order = 'ORDER BY ' . XDB::formatCustomOrder('p.pid', $pids);
1121 } else {
1122 $order = '';
1123 }
1124
1125 if ($visibility === null) {
1126 $visibility = Visibility::defaultForRead();
1127 }
1128
1129 $it = XDB::Iterator('SELECT p.pid, p.hrpid, p.xorg_id, p.ax_id, p.birthdate, p.birthdate_ref,
1130 p.next_birthday, p.deathdate, p.deathdate_rec, p.sex = \'female\' AS sex,
1131 IF ({?}, p.cv, NULL) AS cv, p.medals_pub, p.alias_pub, p.email_directory,
1132 p.last_change, p.nationality1, p.nationality2, p.nationality3,
1133 IF (p.freetext_pub >= {?}, p.freetext, NULL) AS freetext,
1134 pe.entry_year, pe.grad_year, pe.promo_year, pe.program, pe.fieldid,
1135 IF ({?}, pse.text, NULL) AS section,
1136 ppn.firstname_main AS firstname, ppn.lastname_main AS lastname, IF ({?}, pn.name, NULL) AS nickname,
1137 IF (ppn.firstname_ordinary = \'\', ppn.firstname_main, ppn.firstname_ordinary) AS firstname_ordinary,
1138 IF (ppn.lastname_ordinary = \'\', ppn.lastname_main, ppn.lastname_ordinary) AS lastname_ordinary,
1139 pd.yourself, pd.promo, pd.short_name, pd.public_name AS full_name,
1140 pd.directory_name, pd.public_name, pd.private_name,
1141 IF (pp.pub >= {?}, pp.display_tel, NULL) AS mobile,
1142 (ph.pub >= {?} AND ph.attach IS NOT NULL) AS has_photo, ph.pub as photo_pub,
1143 ph.x AS photo_width, ph.y AS photo_height,
1144 p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old,
1145 pm.expertise AS mentor_expertise,
1146 IF ({?}, pdt.message, NULL) AS deltaten_message,
1147 ap.uid AS owner_id
1148 FROM profiles AS p
1149 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
1150 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags))
1151 LEFT JOIN profile_section_enum AS pse ON (pse.id = p.section)
1152 INNER JOIN profile_public_names AS ppn ON (ppn.pid = p.pid)
1153 LEFT JOIN profile_private_names AS pn ON (pn.pid = p.pid AND type = \'nickname\')
1154 LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\')
1155 LEFT JOIN profile_photos AS ph ON (ph.pid = p.pid)
1156 LEFT JOIN profile_mentor AS pm ON (pm.pid = p.pid)
1157 LEFT JOIN profile_deltaten AS pdt ON (pdt.pid = p.pid)
1158 LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms))
1159 WHERE p.pid IN {?}
1160 GROUP BY p.pid
1161 ' . $order,
1162 $visibility->isVisible(Visibility::EXPORT_PRIVATE), // CV
1163 $visibility->level(), // freetext
1164 $visibility->isVisible(Visibility::EXPORT_PRIVATE), // section
1165 $visibility->isVisible(Visibility::EXPORT_PRIVATE), // nickname
1166 $visibility->level(), // mobile
1167 $visibility->level(), // photo
1168 $visibility->isVisible(Visibility::EXPORT_PRIVATE), // deltaten_message
1169 $pids
1170 );
1171 return new ProfileIterator($it, $pids, $fields, $visibility);
1172 }
1173
1174 public static function getPID($login)
1175 {
1176 if ($login instanceof PlUser) {
1177 return XDB::fetchOneCell('SELECT pid
1178 FROM account_profiles
1179 WHERE uid = {?} AND FIND_IN_SET(\'owner\', perms)',
1180 $login->id());
1181 } else if (ctype_digit($login)) {
1182 return XDB::fetchOneCell('SELECT pid
1183 FROM profiles
1184 WHERE pid = {?}', $login);
1185 } else {
1186 return XDB::fetchOneCell('SELECT pid
1187 FROM profiles
1188 WHERE hrpid = {?}', $login);
1189 }
1190 }
1191
1192 public static function getPIDsFromUIDs($uids, $respect_order = true)
1193 {
1194 if ($respect_order) {
1195 $order = 'ORDER BY ' . XDB::formatCustomOrder('uid', $uids);
1196 } else {
1197 $order = '';
1198 }
1199 return XDB::fetchAllAssoc('uid', 'SELECT ap.uid, ap.pid
1200 FROM account_profiles AS ap
1201 WHERE FIND_IN_SET(\'owner\', ap.perms)
1202 AND ap.uid IN ' . XDB::formatArray($uids) .'
1203 ' . $order);
1204 }
1205
1206 /** Return the profile associated with the given login.
1207 */
1208 public static function get($login, $fields = 0x0000, $visibility = null)
1209 {
1210 if ($visibility === null) {
1211 $visibility = Visibility::defaultForRead();
1212 }
1213
1214 if (is_array($login)) {
1215 $pf = new Profile($login, $visibility);
1216 return $pf;
1217 }
1218 $pid = self::getPID($login);
1219 if (!is_null($pid)) {
1220 $it = self::iterOverPIDs(array($pid), false, $fields, $visibility);
1221 return $it->next();
1222 } else {
1223 /* Let say we can identify a profile using the identifiers of its owner.
1224 */
1225 if (!($login instanceof PlUser)) {
1226 $user = User::getSilent($login);
1227 if ($user && $user->hasProfile()) {
1228 return $user->profile(false, $fields, $visibility);
1229 }
1230 }
1231 return null;
1232 }
1233 }
1234
1235 public static function iterOverUIDs($uids, $respect_order = true, $fields = 0x0000, $visibility = null)
1236 {
1237 return self::iterOverPIDs(self::getPIDsFromUIDs($uids), $respect_order, $fields, $visibility);
1238 }
1239
1240 public static function iterOverPIDs($pids, $respect_order = true, $fields = 0x0000, $visibility = null)
1241 {
1242 return self::fetchProfileData($pids, $respect_order, $fields, $visibility);
1243 }
1244
1245 /** Return profiles for the list of pids.
1246 */
1247 public static function getBulkProfilesWithPIDs(array $pids, $fields = 0x0000, $visibility = null)
1248 {
1249 if (count($pids) == 0) {
1250 return array();
1251 }
1252 $it = self::iterOverPIDs($pids, true, $fields, $visibility);
1253 $profiles = array();
1254 while ($p = $it->next()) {
1255 $profiles[$p->id()] = $p;
1256 }
1257 return $profiles;
1258 }
1259
1260 /** Return profiles for uids.
1261 */
1262 public static function getBulkProfilesWithUIDS(array $uids, $fields = 0x000, $visibility = null)
1263 {
1264 if (count($uids) == 0) {
1265 return array();
1266 }
1267 return self::getBulkProfilesWithPIDs(self::getPIDsFromUIDs($uids), $fields, $visibility);
1268 }
1269
1270 public static function isDisplayName($name)
1271 {
1272 return $name == self::DN_FULL || $name == self::DN_DISPLAY
1273 || $name == self::DN_YOURSELF || $name == self::DN_DIRECTORY
1274 || $name == self::DN_PRIVATE || $name == self::DN_PUBLIC
1275 || $name == self::DN_SHORT || $name == self::DN_SORT;
1276 }
1277
1278 /** Returns the closest "accounts only" name type for $name
1279 */
1280 public static function getAccountEquivalentName($name)
1281 {
1282 switch ($name) {
1283 case self::DN_DIRECTORY:
1284 return 'directory_name';
1285 case self::DN_SORT:
1286 return 'sort_name';
1287 case self::DN_FULL:
1288 case self::DN_PUBLIC:
1289 case self::DN_PRIVATE:
1290 case self::DN_SHORT:
1291 return 'full_name';
1292 case self::DN_YOURSELF:
1293 return 'display_name';
1294 default:
1295 return 'display_name';
1296 }
1297 }
1298
1299 public static function rebuildSearchTokens($pids, $transaction = true)
1300 {
1301 require_once 'name.func.inc.php';
1302 if (!is_array($pids)) {
1303 $pids = array($pids);
1304 }
1305 $keys = XDB::iterator("(SELECT pid, name, type, IF(type = 'nickname', 2, 1) AS score, '' AS public
1306 FROM profile_private_names
1307 WHERE pid IN {?})
1308 UNION
1309 (SELECT pid, lastname_main, 'lastname' AS type, 10 AS score, 'public' AS public
1310 FROM profile_public_names
1311 WHERE lastname_main != '' AND pid IN {?})
1312 UNION
1313 (SELECT pid, lastname_marital, 'lastname' AS type, 10 AS score, 'public' AS public
1314 FROM profile_public_names
1315 WHERE lastname_marital != '' AND pid IN {?})
1316 UNION
1317 (SELECT pid, lastname_ordinary, 'lastname' AS type, 10 AS score, 'public' AS public
1318 FROM profile_public_names
1319 WHERE lastname_ordinary != '' AND pid IN {?})
1320 UNION
1321 (SELECT pid, firstname_main, 'firstname' AS type, 10 AS score, 'public' AS public
1322 FROM profile_public_names
1323 WHERE firstname_main != '' AND pid IN {?})
1324 UNION
1325 (SELECT pid, firstname_ordinary, 'firstname' AS type, 10 AS score, 'public' AS public
1326 FROM profile_public_names
1327 WHERE firstname_ordinary != '' AND pid IN {?})
1328 UNION
1329 (SELECT pid, pseudonym, 'nickname' AS type, 10 AS score, 'public' AS public
1330 FROM profile_public_names
1331 WHERE pseudonym != '' AND pid IN {?})",
1332 $pids, $pids, $pids, $pids, $pids, $pids, $pids);
1333 $names = array();
1334 while ($key = $keys->next()) {
1335 if ($key['name'] == '') {
1336 continue;
1337 }
1338 $pid = $key['pid'];
1339 $toks = split_name_for_search($key['name']);
1340 $toks = array_reverse($toks);
1341
1342 /* Split the score between the tokens to avoid the user to be over-rated.
1343 * Let says my user name is "Machin-Truc Bidule" and I also have a user named
1344 * 'Machin Truc'. Distributing the score force "Machin Truc" to be displayed
1345 * before "Machin-Truc" for both "Machin Truc" and "Machin" searches.
1346 */
1347 $eltScore = ceil(((float)$key['score'])/((float)count($toks)));
1348 $token = '';
1349 foreach ($toks as $tok) {
1350 $token = $tok . $token;
1351 $names["$pid-$token"] = XDB::format('({?}, {?}, {?}, {?}, {?}, {?})',
1352 $token, $pid, soundex_fr($token),
1353 $eltScore, $key['public'], $key['type']);
1354 }
1355 }
1356 if ($transaction) {
1357 XDB::startTransaction();
1358 }
1359 XDB::execute('DELETE FROM search_name
1360 WHERE pid IN {?}',
1361 $pids);
1362 if (count($names) > 0) {
1363 XDB::rawExecute('INSERT INTO search_name (token, pid, soundex, score, flags, general_type)
1364 VALUES ' . implode(', ', $names));
1365 }
1366 if ($transaction) {
1367 XDB::commit();
1368 }
1369 }
1370
1371 /** The school identifier consists of 6 digits. The first 3 represent the
1372 * promotion entry year. The last 3 indicate the student's rank.
1373 *
1374 * Our identifier consists of 8 digits and both half have the same role.
1375 * This enables us to deal with bigger promotions and with a wider range
1376 * of promotions.
1377 *
1378 * getSchoolId returns a school identifier given one of ours.
1379 * getXorgId returns a X.org identifier given a school identifier.
1380 */
1381 public static function getSchoolId($xorgId)
1382 {
1383 if (!preg_match('/^[0-9]{8}$/', $xorgId)) {
1384 return null;
1385 }
1386
1387 $year = intval(substr($xorgId, 0, 4));
1388 $rank = intval(substr($xorgId, 5, 3));
1389 if ($year < 1996) {
1390 return null;
1391 } elseif ($year < 2000) {
1392 $year = intval(substr(1900 - $year, 1, 3));
1393 return sprintf('%02u0%03u', $year, $rank);
1394 } else {
1395 $year = intval(substr(1900 - $year, 1, 3));
1396 return sprintf('%03u%03u', $year, $rank);
1397 }
1398 }
1399
1400 public static function getXorgId($schoolId)
1401 {
1402 if (!preg_match('/^[0-9]{6}$/', $schoolId)) {
1403 return null;
1404 }
1405
1406 $year = intval(substr($schoolId, 0, 3));
1407 $rank = intval(substr($schoolId, 3, 3));
1408
1409 if ($year > 200) {
1410 $year /= 10;
1411 }
1412 if ($year < 96) {
1413 return null;
1414 } else {
1415 return sprintf('%04u%04u', 1900 + $year, $rank);
1416 }
1417 }
1418 }
1419
1420
1421 /** Iterator over a set of Profiles
1422 */
1423 class ProfileIterator implements PlIterator
1424 {
1425 private $iterator = null;
1426 private $fields;
1427 private $visibility;
1428
1429 const FETCH_ALL = 0x000033F; // FETCH_ADDRESSES | FETCH_CORPS | FETCH_EDU | FETCH_JOBS | FETCH_MEDALS | FETCH_NETWORKING | FETCH_PHONES | FETCH_JOB_TERMS
1430
1431 public function __construct(PlIterator $it, array $pids, $fields = 0x0000, $visibility = null)
1432 {
1433 require_once 'profilefields.inc.php';
1434
1435 if ($visibility === null) {
1436 $visibility = Visibility::defaultForRead();
1437 }
1438
1439 $this->fields = $fields;
1440 $this->visibility = $visibility;
1441
1442 $subits = array();
1443 $callbacks = array();
1444
1445 $subits[0] = $it;
1446 $callbacks[0] = PlIteratorUtils::arrayValueCallback('pid');
1447 $cb = PlIteratorUtils::objectPropertyCallback('pid');
1448
1449 $fields = $fields & self::FETCH_ALL;
1450 for ($field = 1; $field < $fields; $field *= 2) {
1451 if (($fields & $field) ) {
1452 $callbacks[$field] = $cb;
1453 $subits[$field] = new ProfileFieldIterator($field, $pids, $visibility);
1454 }
1455 }
1456
1457 $this->iterator = PlIteratorUtils::parallelIterator($subits, $callbacks, 0);
1458 }
1459
1460 private function hasData($field, $vals)
1461 {
1462 return ($this->fields & $field) && ($vals[$field] != null);
1463 }
1464
1465 private function fillProfile(array $vals)
1466 {
1467 $pf = Profile::get($vals[0], 0x0, $this->visibility);
1468 $pf->setFetchedFields($this->fields);
1469
1470 if ($this->hasData(Profile::FETCH_PHONES, $vals)) {
1471 $pf->setPhones($vals[Profile::FETCH_PHONES]);
1472 }
1473 if ($this->hasData(Profile::FETCH_ADDRESSES, $vals)) {
1474 $pf->setAddresses($vals[Profile::FETCH_ADDRESSES]);
1475 }
1476 if ($this->hasData(Profile::FETCH_JOBS, $vals)) {
1477 $pf->setJobs($vals[Profile::FETCH_JOBS]);
1478 }
1479 if ($this->hasData(Profile::FETCH_JOB_TERMS, $vals)) {
1480 $pf->setJobTerms($vals[Profile::FETCH_JOB_TERMS]);
1481 }
1482
1483 if ($this->hasData(Profile::FETCH_CORPS, $vals)) {
1484 $pf->setCorps($vals[Profile::FETCH_CORPS]);
1485 }
1486 if ($this->hasData(Profile::FETCH_EDU, $vals)) {
1487 $pf->setEducations($vals[Profile::FETCH_EDU]);
1488 }
1489 if ($this->hasData(Profile::FETCH_MEDALS, $vals)) {
1490 $pf->setMedals($vals[Profile::FETCH_MEDALS]);
1491 }
1492 if ($this->hasData(Profile::FETCH_NETWORKING, $vals)) {
1493 $pf->setNetworking($vals[Profile::FETCH_NETWORKING]);
1494 }
1495
1496 return $pf;
1497 }
1498
1499 public function next()
1500 {
1501 $vals = $this->iterator->next();
1502 if ($vals == null) {
1503 return null;
1504 }
1505 return $this->fillProfile($vals);
1506 }
1507
1508 public function first()
1509 {
1510 return $this->iterator->first();
1511 }
1512
1513 public function last()
1514 {
1515 return $this->iterator->last();
1516 }
1517
1518 public function total()
1519 {
1520 return $this->iterator->total();
1521 }
1522 }
1523
1524 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
1525 ?>