Change sorting order on ML display to use sort_name.
[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 sortName()
376 {
377 return $this->sort_name;
378 }
379
380 public function firstName()
381 {
382 return $this->firstname_ordinary;
383 }
384
385 public function firstNames()
386 {
387 return $this->nameVariants(self::FIRSTNAME);
388 }
389
390 public function lastName()
391 {
392 return $this->lastname_ordinary;
393 }
394
395 public function lastNames()
396 {
397 return $this->nameVariants(self::LASTNAME);
398 }
399
400 public function isFemale()
401 {
402 return $this->sex == PlUser::GENDER_FEMALE;
403 }
404
405 public function isDead()
406 {
407 return ($this->deathdate != null);
408 }
409
410 public function displayEmail()
411 {
412 $o = $this->owner();
413 if ($o != null && $this->isVisible(Visibility::EXPORT_PRIVATE)) {
414 return $o->bestEmail();
415 } else {
416 return $this->email_directory;
417 }
418 }
419
420 public function data()
421 {
422 $this->first_name;
423 return $this->data;
424 }
425
426 private function nameVariants($type)
427 {
428 $vals = array($this->$type);
429 foreach (self::$name_variants[$type] as $var) {
430 $vartype = $type . '_' . $var;
431 $varname = $this->$vartype;
432 if ($varname != null && $varname != "") {
433 $vals[] = $varname;
434 }
435 }
436 return array_unique($vals);
437 }
438
439 public function nationalities()
440 {
441 $nats = array();
442 $nationalities = DirEnum::getOptions(DirEnum::NATIONALITIES);
443 if ($this->nationality1) {
444 $nats[$this->nationality1] = $nationalities[$this->nationality1];
445 }
446 if ($this->nationality2) {
447 $nats[$this->nationality2] = $nationalities[$this->nationality2];
448 }
449 if ($this->nationality3) {
450 $nats[$this->nationality3] = $nationalities[$this->nationality3];
451 }
452 return $nats;
453 }
454
455 public function __get($name)
456 {
457 if (property_exists($this, $name)) {
458 return $this->$name;
459 }
460
461 if (isset($this->data[$name])) {
462 return $this->data[$name];
463 }
464
465 return null;
466 }
467
468 public function __isset($name)
469 {
470 return property_exists($this, $name) || isset($this->data[$name]);
471 }
472
473 public function __unset($name)
474 {
475 if (property_exists($this, $name)) {
476 $this->$name = null;
477 } else {
478 unset($this->data[$name]);
479 }
480 }
481
482
483 /**
484 * Clears a profile.
485 * *always deletes in: profile_addresses, profile_binets, profile_deltaten,
486 * profile_job, profile_langskills, profile_mentor, profile_networking,
487 * profile_partnersharing_settings, profile_phones, profile_skills,
488 * watch_profile
489 * *always keeps in: profile_corps, profile_display, profile_education,
490 * profile_medals, profile_*_names, profile_photos, search_name
491 * *modifies: profiles
492 */
493 public function clear()
494 {
495 $tables = array(
496 'profile_job', 'profile_langskills', 'profile_mentor',
497 'profile_networking', 'profile_skills', 'watch_profile',
498 'profile_phones', 'profile_addresses', 'profile_binets',
499 'profile_deltaten', 'profile_partnersharing_settings');
500
501 foreach ($tables as $t) {
502 XDB::execute('DELETE FROM ' . $t . '
503 WHERE pid = {?}',
504 $this->id());
505 }
506
507 XDB::execute("UPDATE profiles
508 SET cv = NULL, freetext = NULL, freetext_pub = 'private', axfreetext = NULL,
509 medals_pub = 'private', alias_pub = 'hidden',
510 email_directory = NULL
511 WHERE pid = {?}",
512 $this->id());
513 }
514
515 /** Determine whether an item with visibility $visibility can be displayed
516 * with the current level of visibility of the profile
517 * @param $visibility The level of visibility to be checked
518 */
519 public function isVisible($visibility)
520 {
521 return $this->visibility->isVisible($visibility);
522 }
523
524 /** Stores the list of fields which have already been fetched for this Profile
525 */
526 public function setFetchedFields($fields)
527 {
528 if (($fields | self::FETCH_ALL) != self::FETCH_ALL) {
529 Platal::page()->kill("Invalid fetched fields: $fields");
530 }
531
532 $this->fetched_fields = $fields;
533 }
534
535 /** Have we already fetched this field ?
536 */
537 private function fetched($field)
538 {
539 if (!array_key_exists($field, ProfileField::$fields)) {
540 Platal::page()->kill("Invalid field: $field");
541 }
542
543 return ($this->fetched_fields & $field);
544 }
545
546 /** If not already done, fetches data for the given field
547 * @param $field One of the Profile::FETCH_*
548 * @return A ProfileField, or null
549 */
550 private function getProfileField($field)
551 {
552 if (!array_key_exists($field, ProfileField::$fields)) {
553 Platal::page()->kill("Invalid field: $field");
554 }
555 if ($this->fetched($field)) {
556 return null;
557 } else {
558 $this->fetched_fields = $this->fetched_fields | $field;
559 }
560
561 $cls = ProfileField::$fields[$field];
562
563 return ProfileField::getForPID($cls, $this->id(), $this->visibility);
564 }
565
566 /** Consolidates internal data (addresses, phones, jobs)
567 */
568 private function consolidateFields()
569 {
570 // Link phones to addresses
571 if ($this->phones != null) {
572 if ($this->addresses != null) {
573 $this->addresses->addPhones($this->phones);
574 }
575
576 if ($this->jobs != null) {
577 $this->jobs->addPhones($this->phones);
578 }
579 }
580
581 // Link addresses to jobs
582 if ($this->addresses != null && $this->jobs != null) {
583 $this->jobs->addAddresses($this->addresses);
584 }
585
586 // Link jobterms to jobs
587 if ($this->jobs != null && $this->jobterms != null) {
588 $this->jobs->addJobTerms($this->jobterms);
589 }
590 }
591
592 /* Photo
593 */
594 private $photo = null;
595 public function getPhoto($fallback = true, $data = false)
596 {
597 if ($this->has_photo) {
598 if ($data && ($this->photo == null || $this->photo->mimeType == null)) {
599 $res = XDB::fetchOneAssoc('SELECT attach, attachmime, x, y, last_update
600 FROM profile_photos
601 WHERE pid = {?}', $this->pid);
602 $this->photo = PlImage::fromData($res['attach'], 'image/' .$res['attachmime'], $res['x'], $res['y'], $res['last_update']);
603 } else if ($this->photo == null) {
604 $this->photo = PlImage::fromData(null, null, $this->photo_width, $this->photo_height);
605 }
606 return $this->photo;
607 } else if ($fallback) {
608 if ($this->mainEducation() == 'X') {
609 return PlImage::fromFile(dirname(__FILE__) . '/../htdocs/images/none_x.png', 'image/png');
610 }
611 return PlImage::fromFile(dirname(__FILE__) . '/../htdocs/images/none_md.png', 'image/png');
612 }
613 return null;
614 }
615
616 /* Addresses
617 */
618 private $addresses = null;
619 public function setAddresses(ProfileAddresses $addr)
620 {
621 $this->addresses = $addr;
622 $this->consolidateFields();
623 }
624
625 private function fetchAddresses()
626 {
627 if ($this->addresses == null && !$this->fetched(self::FETCH_ADDRESSES)) {
628 $addr = $this->getProfileField(self::FETCH_ADDRESSES);
629 if ($addr) {
630 $this->setAddresses($addr);
631 $this->fetchPhones();
632 }
633 }
634 }
635
636 public function getAddresses($flags, $limit = null)
637 {
638 $this->fetchAddresses();
639
640 if ($this->addresses == null) {
641 return array();
642 }
643 return $this->addresses->get($flags, $limit);
644 }
645
646 public function iterAddresses($flags, $limit = null)
647 {
648 return PlIteratorUtils::fromArray($this->getAddresses($flags, $limit), 1, true);
649 }
650
651 public function getMainAddress()
652 {
653 $main = $this->getAddresses(self::ADDRESS_MAIN);
654 $perso = $this->getAddresses(self::ADDRESS_PERSO);
655
656 if (count($main)) {
657 return array_pop($main);
658 } else if (count($perso)) {
659 return array_pop($perso);
660 } else {
661 return null;
662 }
663 }
664
665 /* Phones
666 */
667 private $phones = null;
668 public function setPhones(ProfilePhones $phones)
669 {
670 $this->phones = $phones;
671 $this->consolidateFields();
672 }
673
674 private function fetchPhones()
675 {
676 if ($this->phones == null && !$this->fetched(self::FETCH_PHONES)) {
677 $phones = $this->getProfileField(self::FETCH_PHONES);
678 if (isset($phones)) {
679 $this->setPhones($phones);
680 }
681 }
682 }
683
684 public function getPhones($flags, $limit = null)
685 {
686 $this->fetchPhones();
687 if ($this->phones == null) {
688 return array();
689 }
690 return $this->phones->get($flags, $limit);
691 }
692
693 /* Educations
694 */
695 private $educations = null;
696 public function setEducations(ProfileEducation $edu)
697 {
698 $this->educations = $edu;
699 }
700
701 public function getEducations($flags, $limit = null)
702 {
703 if ($this->educations == null && !$this->fetched(self::FETCH_EDU)) {
704 $educations = $this->getProfileField(self::FETCH_EDU);
705 if ($educations) {
706 $this->setEducations($educations);
707 }
708 }
709
710 if ($this->educations == null) {
711 return array();
712 }
713 return $this->educations->get($flags, $limit);
714 }
715
716 public function getExtraEducations($limit = null)
717 {
718 return $this->getEducations(self::EDUCATION_EXTRA, $limit);
719 }
720
721 /* Corps
722 */
723 private $corps = null;
724 public function setCorps(ProfileCorps $corps)
725 {
726 $this->corps = $corps;
727 }
728
729 public function getCorps()
730 {
731 if ($this->corps == null && !$this->fetched(self::FETCH_CORPS)) {
732 $corps = $this->getProfileField(self::FETCH_CORPS);
733 if ($corps) {
734 $this->setCorps($corps);
735 }
736 }
737 return $this->corps;
738 }
739
740 /**
741 * Retrieve the name of the corps which has been done.
742 *
743 * Note: this function first tries getCorps(), and if this field is blank
744 * tries to find an education which degree is "Corps".
745 *
746 * Returns an empty string if nothing has been found.
747 */
748 public function getCorpsName()
749 {
750 $corps = $this->getCorps();
751 if ($corps && $corps->current) {
752 $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS);
753 return $corpsList[$corps->current];
754 }
755
756 foreach ($this->getExtraEducations() as $edu) {
757 if (!strcasecmp($edu->degree, 'Corps')) {
758 if ($edu->school_short) {
759 return $edu->school_short;
760 } elseif ($edu->school) {
761 return $edu->school;
762 }
763 }
764 }
765 return '';
766 }
767
768 /** Networking
769 */
770 private $networks = null;
771 public function setNetworking(ProfileNetworking $nw)
772 {
773 $this->networks = $nw;
774 }
775
776 public function getNetworking($flags, $limit = null)
777 {
778 if ($this->networks == null && !$this->fetched(self::FETCH_NETWORKING)) {
779 $nw = $this->getProfileField(self::FETCH_NETWORKING);
780 if ($nw) {
781 $this->setNetworking($nw);
782 }
783 }
784 if ($this->networks == null) {
785 return array();
786 }
787 return $this->networks->get($flags, $limit);
788 }
789
790 public function getWebSite()
791 {
792 $site = $this->getNetworking(self::NETWORKING_WEB, 1);
793 if (count($site) != 1) {
794 return null;
795 }
796 $site = array_pop($site);
797 return $site;
798 }
799
800
801 /** Jobs
802 */
803 private $jobs = null;
804 public function setJobs(ProfileJobs $jobs)
805 {
806 $this->jobs = $jobs;
807 $this->consolidateFields();
808 }
809
810 private function fetchJobs()
811 {
812 if ($this->jobs == null && !$this->fetched(self::FETCH_JOBS)) {
813 $jobs = $this->getProfileField(self::FETCH_JOBS);
814 if ($jobs) {
815 $this->setJobs($jobs);
816 $this->fetchAddresses();
817 }
818 }
819 }
820
821 public function getJobs($flags, $limit = null)
822 {
823 $this->fetchJobs();
824
825 if ($this->jobs == null) {
826 return array();
827 }
828 return $this->jobs->get($flags, $limit);
829 }
830
831 public function getMainJob()
832 {
833 $job = $this->getJobs(self::JOBS_MAIN, 1);
834 if (count($job) != 1) {
835 return null;
836 }
837 return array_pop($job);
838 }
839
840 /** JobTerms
841 */
842 private $jobterms = null;
843 public function setJobTerms(ProfileJobTerms $jobterms)
844 {
845 $this->jobterms = $jobterms;
846 $this->consolidateFields();
847 }
848
849 private $mentor_countries = null;
850 public function setMentoringCountries(ProfileMentoringCountries $countries)
851 {
852 $this->mentor_countries = $countries;
853 }
854
855 public function getMentoringCountries()
856 {
857 if ($this->mentor_countries == null && !$this->fetched(self::FETCH_MENTOR_COUNTRY)) {
858 $countries = $this->getProfileField(self::FETCH_MENTOR_COUNTRY);
859 if ($countries) {
860 $this->setMentoringCountries($countries);
861 }
862 }
863
864 if ($this->mentor_countries == null) {
865 return array();
866 } else {
867 return $this->mentor_countries->countries;
868 }
869 }
870
871 /** List of job terms to specify mentoring */
872 private $mentor_terms = null;
873 /**
874 * set job terms to specify mentoring
875 * @param $terms a ProfileMentoringTerms object listing terms only for this profile
876 */
877 public function setMentoringTerms(ProfileMentoringTerms $terms)
878 {
879 $this->mentor_terms = $terms;
880 }
881 /**
882 * get all job terms that specify mentoring
883 * @return an array of JobTerms objects
884 */
885 public function getMentoringTerms()
886 {
887 if ($this->mentor_terms == null && !$this->fetched(self::FETCH_MENTOR_TERMS)) {
888 $terms = $this->getProfileField(self::FETCH_MENTOR_TERMS);
889 if ($terms) {
890 $this->setMentoringTerms($terms);
891 }
892 }
893
894 if ($this->mentor_terms == null) {
895 return array();
896 } else {
897 return $this->mentor_terms->get();
898 }
899 }
900
901 /* Skills */
902 private $skills = null;
903 public function setSkills(ProfileSkills $skills)
904 {
905 $this->skills = $skills;
906 }
907 public function getSkills()
908 {
909 if ($this->skills == null && !$this->fetched(self::FETCH_SKILL)) {
910 $skills = $this->getProfileField(self::FETCH_SKILL);
911 if ($skills) {
912 $this->setSkills($skills);
913 }
914 }
915
916 if ($this->skills == null) {
917 return array();
918 } else {
919 return $this->skills->skills;
920 }
921 }
922
923 /* Languades */
924 private $languages = null;
925 public function setLanguages(ProfileLanguages $languages)
926 {
927 $this->languages = $languages;
928 }
929 public function getLanguages()
930 {
931 if ($this->languages == null && !$this->fetched(self::FETCH_LANGUAGE)) {
932 $languages = $this->getProfileField(self::FETCH_LANGUAGE);
933 if ($languages) {
934 $this->setLanguages($languages);
935 }
936 }
937
938 if ($this->languages == null) {
939 return array();
940 } else {
941 return $this->languages->languages;
942 }
943 }
944
945 /** DeltaTen
946 */
947
948 /** Find out whether this profile may take part to the "DeltaTen" operation.
949 * @param $role Which role to select ('young' or 'old')
950 * @return Boolean: whether it is enabled.
951 */
952 const DELTATEN_YOUNG = 'young';
953 const DELTATEN_OLD = 'old';
954 public function isDeltaTenEnabled($role)
955 {
956 global $globals;
957 switch ($role) {
958 case self::DELTATEN_YOUNG:
959 return ($this->mainGrade() == UserFilter::GRADE_ING && $this->yearpromo() >= $globals->deltaten->first_promo_young);
960 case self::DELTATEN_OLD:
961 // Roughly compute the current promo in second year on the campus:
962 // Promo 2010 is in second year between 09/2011 and 08/2012 => use 2012.
963 // DeltaTen program begins around January of the second year.
964 $promo_on_platal = ((int) date('Y')) - 2;
965 return ($this->mainGrade() == UserFilter::GRADE_ING && $this->yearpromo() >= $globals->deltaten->first_promo_young - 10 && $this->yearpromo() <= $promo_on_platal - 10);
966 default:
967 Platal::assert(false, "Invalid DeltaTen role $role");
968 }
969 }
970
971 /** Retrieve the "Deltaten" message of the user.
972 * Returns "null" if the message is empty or the user is not taking part to the
973 * DeltaTen operation.
974 */
975 public function getDeltatenMessage()
976 {
977 if ($this->isDeltaTenEnabled(self::DELTATEN_OLD)) {
978 return $this->deltaten_message;
979 } else {
980 return null;
981 }
982 }
983
984 /* Binets
985 */
986 public function getBinets()
987 {
988 if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
989 return XDB::fetchColumn('SELECT binet_id
990 FROM profile_binets
991 WHERE pid = {?}', $this->id());
992 } else {
993 return array();
994 }
995 }
996
997 public function getFullBinets()
998 {
999 if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
1000 return XDB::fetchAllAssoc('SELECT binet_id, text, url
1001 FROM profile_binets AS pb
1002 LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id)
1003 WHERE pid = {?}', $this->id());
1004 } else {
1005 return array();
1006 }
1007 }
1008
1009 public function getBinetsNames()
1010 {
1011 if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
1012 return XDB::fetchColumn('SELECT text
1013 FROM profile_binets AS pb
1014 LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id)
1015 WHERE pb.pid = {?}', $this->id());
1016 } else {
1017 return array();
1018 }
1019 }
1020
1021 /* Hobbies
1022 */
1023 public function getHobbies() {
1024 if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
1025 return XDB::fetchAllAssoc('type', 'SELECT type, GROUP_CONCAT(text)
1026 FROM profile_hobby
1027 WHERE pid = {?}
1028 GROUP BY type', $this->id());
1029 } else {
1030 return XDB::fetchAllAssoc('type', 'SELECT type, GROUP_CONCAT(text)
1031 FROM profile_hobby
1032 WHERE pub = \'public\' AND pid = {?}
1033 GROUP BY type', $this->id());
1034 }
1035 }
1036
1037 /* Medals
1038 */
1039 private $medals = null;
1040 public function setMedals(ProfileMedals $medals)
1041 {
1042 $this->medals = $medals;
1043 }
1044
1045 public function getMedals()
1046 {
1047 if ($this->medals == null && !$this->fetched(self::FETCH_MEDALS)) {
1048 $medals = $this->getProfileField(self::FETCH_MEDALS);
1049 if ($medals) {
1050 $this->setMedals($medals);
1051 }
1052 }
1053 if ($this->medals == null) {
1054 return array();
1055 }
1056 return $this->medals->medals;
1057 }
1058
1059 /** Sharing data with partner websites
1060 */
1061 private $partners_settings = null;
1062 public function setPartnersSettings(ProfilePartnerSharing $partners_settings)
1063 {
1064 $this->partners_settings = $partners_settings;
1065 }
1066
1067 public function getPartnerSettings($partner_id)
1068 {
1069 if ($this->partners_settings === null && !$this->fetched(self::FETCH_PARTNER)) {
1070 $settings = $this->getProfileField(self::FETCH_PARTNER);
1071 if ($settings) {
1072 $this->setPartnersSettings($settings);
1073 }
1074 }
1075 if ($this->partners_settings === null) {
1076 return PartnerSettings::getEmpty($partner_id);
1077 }
1078 return $this->partners_settings->get($partner_id);
1079 }
1080
1081 public function compareNames($firstname, $lastname)
1082 {
1083 $_lastname = mb_strtoupper($this->lastName());
1084 $_firstname = mb_strtoupper($this->firstName());
1085 $lastname = mb_strtoupper($lastname);
1086 $firstname = mb_strtoupper($firstname);
1087
1088 $isOk = (mb_strtoupper($_firstname) == mb_strtoupper($firstname));
1089 $tokens = preg_split("/[ \-']/", $lastname, -1, PREG_SPLIT_NO_EMPTY);
1090 $maxlen = 0;
1091
1092 foreach ($tokens as $str) {
1093 $isOk &= (strpos($_lastname, $str) !== false);
1094 $maxlen = max($maxlen, strlen($str));
1095 }
1096
1097 return ($isOk && ($maxlen > 2 || $maxlen == strlen($_lastname)));
1098 }
1099
1100 /* Export to JSON
1101 */
1102 public function export()
1103 {
1104 return array(
1105 'hrpid' => $this->hrid(),
1106 'display_name' => $this->shortName(),
1107 'full_name' => $this->fullName(),
1108 'directory_name' => $this->directory_name,
1109 'promo' => $this->promo(),
1110 'year_promo' => $this->yearpromo(),
1111 'is_active' => $this->isActive(),
1112 'first_name' => $this->firstName(),
1113 'last_name' => $this->lastName(),
1114 'is_female' => $this->isFemale(),
1115 );
1116 }
1117
1118 private static function fetchProfileData(array $pids, $respect_order = true, $fields = 0x0000, $visibility = null)
1119 {
1120 if (count($pids) == 0) {
1121 return null;
1122 }
1123
1124 if ($respect_order) {
1125 $order = 'ORDER BY ' . XDB::formatCustomOrder('p.pid', $pids);
1126 } else {
1127 $order = '';
1128 }
1129
1130 if ($visibility === null) {
1131 $visibility = Visibility::defaultForRead();
1132 }
1133
1134 $it = XDB::Iterator('SELECT p.pid, p.hrpid, p.xorg_id, p.ax_id, p.birthdate, p.birthdate_ref,
1135 p.next_birthday, p.deathdate, p.deathdate_rec, p.sex = \'female\' AS sex,
1136 IF ({?}, p.cv, NULL) AS cv, p.medals_pub, p.alias_pub, p.email_directory,
1137 p.last_change, p.nationality1, p.nationality2, p.nationality3,
1138 IF (p.freetext_pub >= {?}, p.freetext, NULL) AS freetext,
1139 pe.entry_year, pe.grad_year, pe.promo_year, pe.program, pe.fieldid,
1140 IF ({?}, pse.text, NULL) AS section,
1141 ppn.firstname_main AS firstname, ppn.lastname_main AS lastname, IF ({?}, pn.name, NULL) AS nickname,
1142 IF (ppn.firstname_ordinary = \'\', ppn.firstname_main, ppn.firstname_ordinary) AS firstname_ordinary,
1143 IF (ppn.lastname_ordinary = \'\', ppn.lastname_main, ppn.lastname_ordinary) AS lastname_ordinary,
1144 pd.yourself, pd.promo, pd.short_name, pd.public_name AS full_name,
1145 pd.directory_name, pd.public_name, pd.private_name, pd.sort_name,
1146 IF (pp.pub >= {?}, pp.display_tel, NULL) AS mobile,
1147 (ph.pub >= {?} AND ph.attach IS NOT NULL) AS has_photo, ph.pub as photo_pub,
1148 ph.x AS photo_width, ph.y AS photo_height,
1149 p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old,
1150 pm.expertise AS mentor_expertise,
1151 IF ({?}, pdt.message, NULL) AS deltaten_message,
1152 ap.uid AS owner_id
1153 FROM profiles AS p
1154 INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
1155 INNER JOIN profile_education AS pe ON (pe.pid = p.pid AND FIND_IN_SET(\'primary\', pe.flags))
1156 LEFT JOIN profile_section_enum AS pse ON (pse.id = p.section)
1157 INNER JOIN profile_public_names AS ppn ON (ppn.pid = p.pid)
1158 LEFT JOIN profile_private_names AS pn ON (pn.pid = p.pid AND type = \'nickname\')
1159 LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\')
1160 LEFT JOIN profile_photos AS ph ON (ph.pid = p.pid)
1161 LEFT JOIN profile_mentor AS pm ON (pm.pid = p.pid)
1162 LEFT JOIN profile_deltaten AS pdt ON (pdt.pid = p.pid)
1163 LEFT JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms))
1164 WHERE p.pid IN {?}
1165 GROUP BY p.pid
1166 ' . $order,
1167 $visibility->isVisible(Visibility::EXPORT_PRIVATE), // CV
1168 $visibility->level(), // freetext
1169 $visibility->isVisible(Visibility::EXPORT_PRIVATE), // section
1170 $visibility->isVisible(Visibility::EXPORT_PRIVATE), // nickname
1171 $visibility->level(), // mobile
1172 $visibility->level(), // photo
1173 $visibility->isVisible(Visibility::EXPORT_PRIVATE), // deltaten_message
1174 $pids
1175 );
1176 return new ProfileIterator($it, $pids, $fields, $visibility);
1177 }
1178
1179 public static function getPID($login)
1180 {
1181 if ($login instanceof PlUser) {
1182 return XDB::fetchOneCell('SELECT pid
1183 FROM account_profiles
1184 WHERE uid = {?} AND FIND_IN_SET(\'owner\', perms)',
1185 $login->id());
1186 } else if (ctype_digit($login)) {
1187 return XDB::fetchOneCell('SELECT pid
1188 FROM profiles
1189 WHERE pid = {?}', $login);
1190 } else {
1191 return XDB::fetchOneCell('SELECT pid
1192 FROM profiles
1193 WHERE hrpid = {?}', $login);
1194 }
1195 }
1196
1197 public static function getPIDsFromUIDs($uids, $respect_order = true)
1198 {
1199 if ($respect_order) {
1200 $order = 'ORDER BY ' . XDB::formatCustomOrder('uid', $uids);
1201 } else {
1202 $order = '';
1203 }
1204 return XDB::fetchAllAssoc('uid', 'SELECT ap.uid, ap.pid
1205 FROM account_profiles AS ap
1206 WHERE FIND_IN_SET(\'owner\', ap.perms)
1207 AND ap.uid IN ' . XDB::formatArray($uids) .'
1208 ' . $order);
1209 }
1210
1211 /** Return the profile associated with the given login.
1212 */
1213 public static function get($login, $fields = 0x0000, $visibility = null)
1214 {
1215 if ($visibility === null) {
1216 $visibility = Visibility::defaultForRead();
1217 }
1218
1219 if (is_array($login)) {
1220 $pf = new Profile($login, $visibility);
1221 return $pf;
1222 }
1223 $pid = self::getPID($login);
1224 if (!is_null($pid)) {
1225 $it = self::iterOverPIDs(array($pid), false, $fields, $visibility);
1226 return $it->next();
1227 } else {
1228 /* Let say we can identify a profile using the identifiers of its owner.
1229 */
1230 if (!($login instanceof PlUser)) {
1231 $user = User::getSilent($login);
1232 if ($user && $user->hasProfile()) {
1233 return $user->profile(false, $fields, $visibility);
1234 }
1235 }
1236 return null;
1237 }
1238 }
1239
1240 public static function iterOverUIDs($uids, $respect_order = true, $fields = 0x0000, $visibility = null)
1241 {
1242 return self::iterOverPIDs(self::getPIDsFromUIDs($uids), $respect_order, $fields, $visibility);
1243 }
1244
1245 public static function iterOverPIDs($pids, $respect_order = true, $fields = 0x0000, $visibility = null)
1246 {
1247 return self::fetchProfileData($pids, $respect_order, $fields, $visibility);
1248 }
1249
1250 /** Return profiles for the list of pids.
1251 */
1252 public static function getBulkProfilesWithPIDs(array $pids, $fields = 0x0000, $visibility = null)
1253 {
1254 if (count($pids) == 0) {
1255 return array();
1256 }
1257 $it = self::iterOverPIDs($pids, true, $fields, $visibility);
1258 $profiles = array();
1259 while ($p = $it->next()) {
1260 $profiles[$p->id()] = $p;
1261 }
1262 return $profiles;
1263 }
1264
1265 /** Return profiles for uids.
1266 */
1267 public static function getBulkProfilesWithUIDS(array $uids, $fields = 0x000, $visibility = null)
1268 {
1269 if (count($uids) == 0) {
1270 return array();
1271 }
1272 return self::getBulkProfilesWithPIDs(self::getPIDsFromUIDs($uids), $fields, $visibility);
1273 }
1274
1275 public static function isDisplayName($name)
1276 {
1277 return $name == self::DN_FULL || $name == self::DN_DISPLAY
1278 || $name == self::DN_YOURSELF || $name == self::DN_DIRECTORY
1279 || $name == self::DN_PRIVATE || $name == self::DN_PUBLIC
1280 || $name == self::DN_SHORT || $name == self::DN_SORT;
1281 }
1282
1283 /** Returns the closest "accounts only" name type for $name
1284 */
1285 public static function getAccountEquivalentName($name)
1286 {
1287 switch ($name) {
1288 case self::DN_DIRECTORY:
1289 return 'directory_name';
1290 case self::DN_SORT:
1291 return 'sort_name';
1292 case self::DN_FULL:
1293 case self::DN_PUBLIC:
1294 case self::DN_PRIVATE:
1295 case self::DN_SHORT:
1296 return 'full_name';
1297 case self::DN_YOURSELF:
1298 return 'display_name';
1299 default:
1300 return 'display_name';
1301 }
1302 }
1303
1304 public static function rebuildSearchTokens($pids, $transaction = true)
1305 {
1306 require_once 'name.func.inc.php';
1307 if (!is_array($pids)) {
1308 $pids = array($pids);
1309 }
1310 $keys = XDB::iterator("(SELECT pid, name, type, IF(type = 'nickname', 2, 1) AS score, '' AS public
1311 FROM profile_private_names
1312 WHERE pid IN {?})
1313 UNION
1314 (SELECT pid, lastname_main, 'lastname' AS type, 10 AS score, 'public' AS public
1315 FROM profile_public_names
1316 WHERE lastname_main != '' AND pid IN {?})
1317 UNION
1318 (SELECT pid, lastname_marital, 'lastname' AS type, 10 AS score, 'public' AS public
1319 FROM profile_public_names
1320 WHERE lastname_marital != '' AND pid IN {?})
1321 UNION
1322 (SELECT pid, lastname_ordinary, 'lastname' AS type, 10 AS score, 'public' AS public
1323 FROM profile_public_names
1324 WHERE lastname_ordinary != '' AND pid IN {?})
1325 UNION
1326 (SELECT pid, firstname_main, 'firstname' AS type, 10 AS score, 'public' AS public
1327 FROM profile_public_names
1328 WHERE firstname_main != '' AND pid IN {?})
1329 UNION
1330 (SELECT pid, firstname_ordinary, 'firstname' AS type, 10 AS score, 'public' AS public
1331 FROM profile_public_names
1332 WHERE firstname_ordinary != '' AND pid IN {?})
1333 UNION
1334 (SELECT pid, pseudonym, 'nickname' AS type, 10 AS score, 'public' AS public
1335 FROM profile_public_names
1336 WHERE pseudonym != '' AND pid IN {?})",
1337 $pids, $pids, $pids, $pids, $pids, $pids, $pids);
1338 $names = array();
1339 while ($key = $keys->next()) {
1340 if ($key['name'] == '') {
1341 continue;
1342 }
1343 $pid = $key['pid'];
1344 $toks = split_name_for_search($key['name']);
1345 $toks = array_reverse($toks);
1346
1347 /* Split the score between the tokens to avoid the user to be over-rated.
1348 * Let says my user name is "Machin-Truc Bidule" and I also have a user named
1349 * 'Machin Truc'. Distributing the score force "Machin Truc" to be displayed
1350 * before "Machin-Truc" for both "Machin Truc" and "Machin" searches.
1351 */
1352 $eltScore = ceil(((float)$key['score'])/((float)count($toks)));
1353 $token = '';
1354 foreach ($toks as $tok) {
1355 $token = $tok . $token;
1356 $names["$pid-$token"] = XDB::format('({?}, {?}, {?}, {?}, {?}, {?})',
1357 $token, $pid, soundex_fr($token),
1358 $eltScore, $key['public'], $key['type']);
1359 }
1360 }
1361 if ($transaction) {
1362 XDB::startTransaction();
1363 }
1364 XDB::execute('DELETE FROM search_name
1365 WHERE pid IN {?}',
1366 $pids);
1367 if (count($names) > 0) {
1368 XDB::rawExecute('INSERT INTO search_name (token, pid, soundex, score, flags, general_type)
1369 VALUES ' . implode(', ', $names));
1370 }
1371 if ($transaction) {
1372 XDB::commit();
1373 }
1374 }
1375
1376 /** The school identifier consists of 6 digits. The first 3 represent the
1377 * promotion entry year. The last 3 indicate the student's rank.
1378 *
1379 * Our identifier consists of 8 digits and both half have the same role.
1380 * This enables us to deal with bigger promotions and with a wider range
1381 * of promotions.
1382 *
1383 * getSchoolId returns a school identifier given one of ours.
1384 * getXorgId returns a X.org identifier given a school identifier.
1385 */
1386 public static function getSchoolId($xorgId)
1387 {
1388 if (!preg_match('/^[0-9]{8}$/', $xorgId)) {
1389 return null;
1390 }
1391
1392 $year = intval(substr($xorgId, 0, 4));
1393 $rank = intval(substr($xorgId, 5, 3));
1394 if ($year < 1996) {
1395 return null;
1396 } elseif ($year < 2000) {
1397 $year = intval(substr(1900 - $year, 1, 3));
1398 return sprintf('%02u0%03u', $year, $rank);
1399 } else {
1400 $year = intval(substr(1900 - $year, 1, 3));
1401 return sprintf('%03u%03u', $year, $rank);
1402 }
1403 }
1404
1405 public static function getXorgId($schoolId)
1406 {
1407 if (!preg_match('/^[0-9]{6}$/', $schoolId)) {
1408 return null;
1409 }
1410
1411 $year = intval(substr($schoolId, 0, 3));
1412 $rank = intval(substr($schoolId, 3, 3));
1413
1414 if ($year > 200) {
1415 $year /= 10;
1416 }
1417 if ($year < 96) {
1418 return null;
1419 } else {
1420 return sprintf('%04u%04u', 1900 + $year, $rank);
1421 }
1422 }
1423 }
1424
1425
1426 /** Iterator over a set of Profiles
1427 */
1428 class ProfileIterator implements PlIterator
1429 {
1430 private $iterator = null;
1431 private $fields;
1432 private $visibility;
1433
1434 const FETCH_ALL = 0x000033F; // FETCH_ADDRESSES | FETCH_CORPS | FETCH_EDU | FETCH_JOBS | FETCH_MEDALS | FETCH_NETWORKING | FETCH_PHONES | FETCH_JOB_TERMS
1435
1436 public function __construct(PlIterator $it, array $pids, $fields = 0x0000, $visibility = null)
1437 {
1438 require_once 'profilefields.inc.php';
1439
1440 if ($visibility === null) {
1441 $visibility = Visibility::defaultForRead();
1442 }
1443
1444 $this->fields = $fields;
1445 $this->visibility = $visibility;
1446
1447 $subits = array();
1448 $callbacks = array();
1449
1450 $subits[0] = $it;
1451 $callbacks[0] = PlIteratorUtils::arrayValueCallback('pid');
1452 $cb = PlIteratorUtils::objectPropertyCallback('pid');
1453
1454 $fields = $fields & self::FETCH_ALL;
1455 for ($field = 1; $field < $fields; $field *= 2) {
1456 if (($fields & $field) ) {
1457 $callbacks[$field] = $cb;
1458 $subits[$field] = new ProfileFieldIterator($field, $pids, $visibility);
1459 }
1460 }
1461
1462 $this->iterator = PlIteratorUtils::parallelIterator($subits, $callbacks, 0);
1463 }
1464
1465 private function hasData($field, $vals)
1466 {
1467 return ($this->fields & $field) && ($vals[$field] != null);
1468 }
1469
1470 private function fillProfile(array $vals)
1471 {
1472 $pf = Profile::get($vals[0], 0x0, $this->visibility);
1473 $pf->setFetchedFields($this->fields);
1474
1475 if ($this->hasData(Profile::FETCH_PHONES, $vals)) {
1476 $pf->setPhones($vals[Profile::FETCH_PHONES]);
1477 }
1478 if ($this->hasData(Profile::FETCH_ADDRESSES, $vals)) {
1479 $pf->setAddresses($vals[Profile::FETCH_ADDRESSES]);
1480 }
1481 if ($this->hasData(Profile::FETCH_JOBS, $vals)) {
1482 $pf->setJobs($vals[Profile::FETCH_JOBS]);
1483 }
1484 if ($this->hasData(Profile::FETCH_JOB_TERMS, $vals)) {
1485 $pf->setJobTerms($vals[Profile::FETCH_JOB_TERMS]);
1486 }
1487
1488 if ($this->hasData(Profile::FETCH_CORPS, $vals)) {
1489 $pf->setCorps($vals[Profile::FETCH_CORPS]);
1490 }
1491 if ($this->hasData(Profile::FETCH_EDU, $vals)) {
1492 $pf->setEducations($vals[Profile::FETCH_EDU]);
1493 }
1494 if ($this->hasData(Profile::FETCH_MEDALS, $vals)) {
1495 $pf->setMedals($vals[Profile::FETCH_MEDALS]);
1496 }
1497 if ($this->hasData(Profile::FETCH_NETWORKING, $vals)) {
1498 $pf->setNetworking($vals[Profile::FETCH_NETWORKING]);
1499 }
1500
1501 return $pf;
1502 }
1503
1504 public function next()
1505 {
1506 $vals = $this->iterator->next();
1507 if ($vals == null) {
1508 return null;
1509 }
1510 return $this->fillProfile($vals);
1511 }
1512
1513 public function first()
1514 {
1515 return $this->iterator->first();
1516 }
1517
1518 public function last()
1519 {
1520 return $this->iterator->last();
1521 }
1522
1523 public function total()
1524 {
1525 return $this->iterator->total();
1526 }
1527 }
1528
1529 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
1530 ?>