2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 // {{{ class ProfileField
23 /** To store a "field" from the profile
24 * Provides functions for loading a batch of such data
26 abstract class ProfileField
28 public static $fields = array(
29 Profile
::FETCH_ADDRESSES
=> 'ProfileAddresses',
30 Profile
::FETCH_CORPS
=> 'ProfileCorps',
31 Profile
::FETCH_EDU
=> 'ProfileEducation',
32 Profile
::FETCH_JOBS
=> 'ProfileJobs',
33 Profile
::FETCH_MEDALS
=> 'ProfileMedals',
34 Profile
::FETCH_NETWORKING
=> 'ProfileNetworking',
35 Profile
::FETCH_PHONES
=> 'ProfilePhones',
36 Profile
::FETCH_MENTOR_SECTOR
=> 'ProfileMentoringSectors',
37 Profile
::FETCH_MENTOR_COUNTRY
=> 'ProfileMentoringCountries',
40 /** The profile to which this field belongs
44 /** Fetches data from the database for the given pids, compatible with
45 * the visibility context.
46 * @param $pids An array of pids
47 * @param $visibility The level of visibility fetched fields must have
48 * @return a PlIterator yielding data suitable for a "new ProfileBlah($data)"
50 * MUST be reimplemented for each kind of ProfileField.
52 public static function fetchData(array $pids, ProfileVisibility
$visibility)
54 return PlIteratorUtils
::emptyIterator();
57 public static function buildForPID($cls, $pid, ProfileVisibility
$visibility)
59 $res = self
::buildFromPIDs($cls, array($pid), $visibility);
60 return array_pop($res);
63 /** Build a list of ProfileFields from a set of pids
64 * @param $cls The name of the field to create ('ProfileMedals', ...)
65 * @param $pids An array of pids
66 * @param $visibility An array of allowed visibility contexts
67 * @return An array of $pid => ProfileField
69 public static function buildFromPIDs($cls, array $pids, ProfileVisibility
$visibility)
71 $it = new ProfileFieldIterator($cls, $pids, $visibility);
73 while ($pf = $it->next()) {
79 public static function getForPID($cls, $pid, ProfileVisibility
$visibility)
81 $it = new ProfileFieldIterator($cls, array($pid), $visibility);
87 // {{{ class ProfileFieldIterator
88 class ProfileFieldIterator
implements PlIterator
93 public function __construct($cls, array $pids, ProfileVisibility
$visibility)
95 $this->data
= call_user_func(array($cls, 'fetchData'), $pids, $visibility);
99 public function next()
101 $d = $this->data
->next();
110 public function total()
112 return $this->data
->total();
115 public function first()
117 return $this->data
->first();
120 public function last()
122 return $this->data
->last();
130 const TYPE_FAX
= 'fax';
131 const TYPE_FIXED
= 'fixed';
132 const TYPE_MOBILE
= 'mobile';
137 public $comment = '';
139 const LINK_JOB
= 'pro';
140 const LINK_ADDRESS
= 'address';
141 const LINK_PROFILE
= 'user';
142 const LINK_COMPANY
= 'hq';
149 * $type, $search, $display, $link_type, $link_id, $comment, $pid, $id
151 public function __construct($data)
153 foreach ($data as $key => $val) {
158 /** Returns the unique ID of a phone
159 * This ID will allow to link it to an address, a user or a job
160 * The format is address_addressId_phoneId (where phoneId is the id
161 * of the phone in the list of those associated with the address)
163 public function uid() {
164 return $this->link_type
. '_' . $this->link_id
. '_' . $this->id
;
167 public function hasFlags($flags) {
168 return $this->hasType($flags) && $this->hasLink($flags);
171 /** Returns true if this phone's type matches the flags
173 public function hasType($flags) {
174 $flags = $flags & Profile
::PHONE_TYPE_ANY
;
176 ($flags == Profile
::PHONE_TYPE_ANY
)
178 (($flags & Profile
::PHONE_TYPE_FAX
) && $this->type
== self
::TYPE_FAX
)
180 (($flags & Profile
::PHONE_TYPE_FIXED
) && $this->type
== self
::TYPE_FIXED
)
182 (($flags & Profile
::PHONE_TYPE_MOBILE
) && $this->type
== self
::TYPE_MOBILE
)
186 /** User accessible version of the type
188 public function displayType($short = false
)
190 switch ($this->type
) {
191 case Phone
::TYPE_FIXED
:
192 return $short ?
'Tél' : 'Fixe';
193 case Phone
::TYPE_FAX
:
195 case Phone
::TYPE_MOBILE
:
196 return $short ?
'Mob' : 'Mobile';
202 /** Returns true if this phone's link matches the flags
204 public function hasLink($flags) {
205 $flags = $flags & Profile
::PHONE_LINK_ANY
;
207 ($flags == Profile
::PHONE_LINK_ANY
)
209 (($flags & Profile
::PHONE_LINK_COMPANY
) && $this->link_type
== self
::LINK_COMPANY
)
211 (($flags & Profile
::PHONE_LINK_JOB
) && $this->link_type
== self
::LINK_JOB
)
213 (($flags & Profile
::PHONE_LINK_ADDRESS
) && $this->link_type
== self
::LINK_ADDRESS
)
215 (($flags & Profile
::PHONE_LINK_PROFILE
) && $this->link_type
== self
::LINK_PROFILE
)
227 public $phone = null
;
228 public $address = null
;
231 * $id, $name, $acronym, $url
233 public function __construct($data)
235 foreach ($data as $key => $val) {
240 public function setPhone(Phone
&$phone)
242 if ($phone->link_type
== Phone
::LINK_COMPANY
&& $phone->link_id
== $this->id
) {
243 $this->phone
= $phone;
247 public function setAddress(Address
&$address)
249 if ($address->link_type
== Address
::LINK_COMPANY
&& $address->link_id
== $this->id
) {
250 $this->address
= $address;
262 public $company = null
;
263 public $phones = array();
264 public $address = null
;
274 public $subsubsector;
277 * pid, id, company_id, description, url, email
279 public function __construct($data)
281 foreach ($data as $key => $val) {
284 $this->company
= CompanyList
::get($this->jobid
);
285 if (is_null($this->company
)) {
286 require_once 'validations.inc.php';
287 $entreprise = ProfileValidate
::get_typed_requests($this->pid
, 'entreprise');
288 $this->company
= new Company(array('name' => $entreprise[$this->id
]->name
));
292 public function phones()
294 return $this->phones
;
297 public function address()
299 return $this->address
;
302 public function addPhone(Phone
&$phone)
304 if ($phone->link_type
== Phone
::LINK_JOB
&& $phone->link_id
== $this->id
&& $phone->pid
== $this->pid
) {
305 $this->phones
[$phone->uid()] = $phone;
309 public function setAddress(Address
$address)
311 if ($address->link_type
== Address
::LINK_JOB
&& $address->link_id
== $this->id
&& $address->pid
== $this->pid
) {
312 $this->address
= $address;
320 const LINK_JOB
= 'job';
321 const LINK_COMPANY
= 'hq';
322 const LINK_PROFILE
= 'home';
325 public $id; // The ID of the address among those associated with its link
326 public $link_id; // The ID of the object to which the address is linked (profile, job, company)
335 public $subAdministrativeArea;
336 public $administrativeArea;
341 private $phones = array();
344 * pîd, id, link_id, link_type, flags, text, postcode, country
346 public function __construct($data)
348 foreach ($data as $key => $val) {
351 $this->flags
= new PlFlagSet($this->flags
);
354 public function uid() {
355 $uid = $this->link_type
. '_';
356 if ($this->link_type
!= self
::LINK_COMPANY
) {
357 $uid .= $this->pid
. '_';
359 $uid .= $this->link_id
. '_' . $this->id
;
362 public function addPhone(Phone
&$phone)
365 $phone->link_type
== Phone
::LINK_ADDRESS
&& $phone->link_id
== $this->id
&&
366 ($this->link_type
== self
::LINK_COMPANY ||
$phone->pid
== $this->pid
) ) {
367 $this->phones
[$phone->uid()] = $phone;
371 public function phones()
373 return $this->phones
;
376 public function hasFlag($flag)
378 if (!$this->flags
instanceof PlFlagSet
) {
379 $this->flags
= new PlFlagSet($this->flags
);
381 return $this->flags
->hasFlag($flag);
385 // {{{ class Education
397 public $school_short;
402 public $degree_short;
403 public $degree_level;
407 public function __construct(array $data)
409 foreach ($data as $key => $val) {
412 $this->flags
= new PlFlagSet($this->flags
);
417 // {{{ class ProfileEducation [ Field ]
418 class ProfileEducation
extends ProfileField
420 private $educations = array();
422 public function __construct(PlInnerSubIterator
$it)
424 $this->pid
= $it->value();
425 while ($edu = $it->next()) {
426 $this->educations
[$edu['id']] = new Education($edu);
430 public function get($flags, $limit)
432 $educations = array();
434 $year = $year['year'];
436 foreach ($this->educations
as $id => $edu) {
438 (($flags & Profile
::EDUCATION_MAIN
) && $edu->flags
->hasFlag('primary'))
440 (($flags & Profile
::EDUCATION_EXTRA
) && !$edu->flags
->hasFlag('primary'))
442 (($flags & Profile
::EDUCATION_FINISHED
) && $edu->grad_year
<= $year)
444 (($flags & Profile
::EDUCATION_CURRENT
) && $edu->grad_year
> $year)
446 ($flags & Profile
::EDUCATION_ALL
)
448 $educations[$id] = $edu;
451 if ($limit != null
&& $nb >= $limit) {
458 public static function fetchData(array $pids, ProfileVisibility
$visibility)
460 $data = XDB
::iterator('SELECT pe.id, pe.pid,
461 pe.entry_year, pe.grad_year, pe.program, pe.flags,
462 pee.name AS school, pee.abbreviation AS school_short,
463 pee.url AS school_url, gc.countryFR AS country,
464 pede.degree, pede.abbreviation AS degree_short, pede.level AS degree_level,
466 FROM profile_education AS pe
467 LEFT JOIN profile_education_enum AS pee ON (pee.id = pe.eduid)
468 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pee.country)
469 LEFT JOIN profile_education_degree_enum AS pede ON (pede.id = pe.degreeid)
470 LEFT JOIN profile_education_field_enum AS pefe ON (pefe.id = pe.fieldid)
472 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids) . ',
473 NOT FIND_IN_SET(\'primary\', pe.flags), pe.entry_year, pe.id',
476 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
480 // {{{ class ProfileMedals [ Field ]
481 class ProfileMedals
extends ProfileField
483 public $medals = array();
485 public function __construct(PlInnerSubIterator
$it)
487 $this->pid
= $it->value();
488 while ($medal = $it->next()) {
489 $this->medals
[$medal['mid']] = $medal;
493 public static function fetchData(array $pids, ProfileVisibility
$visibility)
495 $data = XDB
::iterator('SELECT pm.pid, pm.mid, pm.gid, pme.text, pme.img, pmge.text AS grade
496 FROM profile_medals AS pm
497 LEFT JOIN profiles AS p ON (pm.pid = p.pid)
498 LEFT JOIN profile_medal_enum AS pme ON (pme.id = pm.mid)
499 LEFT JOIN profile_medal_grade_enum AS pmge ON (pmge.mid = pm.mid AND pmge.gid = pm.gid)
500 WHERE pm.pid IN {?} AND p.medals_pub IN {?}
501 ORDER BY ' . XDB
::formatCustomOrder('pm.pid', $pids),
502 $pids, $visibility->levels());
504 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
508 // {{{ class ProfileNetworking [ Field ]
509 class ProfileNetworking
extends ProfileField
511 private $networks = array();
513 public function __construct(PlInnerSubIterator
$it)
515 $this->pid
= $it->value();
516 while ($network = $it->next()) {
517 $network['network_type'] = new PlFlagSet($network['network_type']);
518 $this->networks
[$network['id']] = $network;
522 public static function fetchData(array $pids, ProfileVisibility
$visibility)
524 $data = XDB
::iterator('SELECT pid, id, address, pne.nwid, pne.network_type, pne.link, pne.name
525 FROM profile_networking AS pn
526 LEFT JOIN profile_networking_enum AS pne USING(nwid)
527 WHERE pid IN {?} AND pub IN {?}
528 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids) . ',
530 $pids, $visibility->levels());
532 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
535 public function get($flags, $limit = null
)
539 foreach ($this->networks
as $id => $nw) {
540 if (($flags & Profile
::NETWORKING_WEB
) && $nw['network_type']->hasFlag('web') ||
541 ($flags & Profile
::NETWORKING_IM
) && $nw['network_type']->hasFlag('im') ||
542 ($flags & Profile
::NETWORKING_SOCIAL
) && $nw['network_type']->hasFlag('social') ||
543 ($flags == Profile
::NETWORKING_ALL
)) {
546 if (isset($limit) && $nb >= $limit) {
555 // {{{ class ProfileCorps [ Field ]
556 class ProfileCorps
extends ProfileField
561 public $original_name;
562 public $original_abbrev;
563 public $original_still_exists;
565 public $current_name;
566 public $current_abbrev;
567 public $current_still_exists;
568 public $current_rank;
569 public $current_rank_abbrev;
571 public function __construct(array $data)
573 foreach ($data as $key => $val) {
578 public static function fetchData(array $pids, ProfileVisibility
$visibility)
580 $data = XDB
::iterator('SELECT pc.pid, pc.original_corpsid AS original, pc.current_corpsid AS current,
581 pceo.name AS original_name, pceo.abbreviation AS original_abbrev,
582 pceo.still_exists AS original_still_exists,
583 pcec.name AS current_name, pcec.abbreviation AS current_abbrev,
584 pcec.still_exists AS current_still_exists,
585 pcrec.name AS current_rank, pcrec.abbreviation AS current_rank_abbrev,
587 FROM profile_corps AS pc
588 LEFT JOIN profile_corps_enum AS pceo ON (pceo.id = pc.original_corpsid)
589 LEFT JOIN profile_corps_enum AS pcec ON (pcec.id = pc.current_corpsid)
590 LEFT JOIN profile_corps_rank_enum AS pcrec ON (pcrec.id = pc.rankid)
591 WHERE pc.pid IN {?} AND pc.corps_pub IN {?} AND pceo.id != 1
592 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids),
593 $pids, $visibility->levels());
599 // {{{ class ProfileMentoringSectors [ Field ]
600 class ProfileMentoringSectors
extends ProfileField
602 public $sectors = array();
604 public function __construct(PlInnerSubIterator
$it)
606 $this->pid
= $it->value();
607 while ($sector = $it->next()) {
608 $this->sectors
[] = $sector;
612 public static function fetchData(array $pids, ProfileVisibility
$visibility)
614 $data = XDB
::iterator('SELECT pms.pid, pjse.name AS sector, pjsse.name AS subsector
615 FROM profile_mentor_sector AS pms
616 LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pms.sectorid)
617 LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pms.subsectorid)
619 ORDER BY ' . XDB
::formatCustomOrder('pms.pid', $pids),
622 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
626 // {{{ class ProfileMentoringCountries [ Field ]
627 class ProfileMentoringCountries
extends ProfileField
629 public $countries = array();
631 public function __construct(PlInnerSubIterator
$it)
633 $this->pid
= $it->value();
634 while ($country = $it->next()) {
635 $this->countries
[$country['id']] = $country['name'];
639 public static function fetchData(array $pids, ProfileVisibility
$visibility)
641 $data = XDB
::iterator('SELECT pmc.pid, pmc.country AS id, gc.countryFR AS name
642 FROM profile_mentor_country AS pmc
643 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pmc.country)
645 ORDER BY ' . XDB
::formatCustomOrder('pmc.pid', $pids),
648 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
653 /** Loading of data for a Profile :
654 * 1) load jobs, addresses, phones
655 * 2) attach phones to addresses, jobs and profiles
656 * 3) attach addresses to jobs and profiles
659 // {{{ Database schema (profile_address, profile_phones, profile_jobs)
660 /** The database for this is very unclear, so here is a little schema :
661 * profile_job describes a Job, links to:
662 * - a Profile, through `pid`
663 * - a Company, through `jobid`
664 * The `id` field is the id of this job in the list of the jobs of its profile
666 * profile_addresses describes an Address, which
667 * related to either a Profile, a Job or a Company:
669 * - `type` is set to 'home'
670 * - `pid` is set to the related profile pid
671 * - `id` is the id of the address in the list of those related to that profile
675 * - `type` is set to 'hq'
676 * - `pid` is set to 0
677 * - `jobid` is set to the id of the company
678 * - `id` is set to 0 (only one address per Company)
681 * - `type` is set to 'job'
682 * - `pid` is set to the pid of the Profile of the related Job
683 * - `jobid` is set to the Company of the job (this information is redundant
684 * with that of the row of profile_job for the related job)
685 * - `id` is the id of the job to which we refer (i.e `profile_job.id`)
687 * profile_phone describes a Phone, which can be related to an Address,
688 * a Job, a Profile or a Company:
690 * - `link_type` is set to 'user'
691 * - `link_id` is set to 0
692 * - `pid` is set to the id of the related Profile
695 * - `link_type` is set to 'hq'
696 * - `link_id` is set to the id of the related Company
697 * - `pid` is set to 0
699 * - for an Address (this is only possible for a *personal* address)
700 * - `link_type` is set to 'address'
701 * - `link_id` is set to the related Address `id`
702 * - `pid` is set to the related Address `pid`
705 * - `link_type` is set to 'pro'
706 * - `link_id` is set to the related Job `id` (not `jobid`)
707 * - `pid` is set to the related Job `pid`
710 * The possible relations are as follow:
711 * An Address can be linked to a Company, a Profile, a Job
712 * A Job is linked to a Company and a Profile
713 * A Phone can be linked to a Company, a Profile, a Job, or a Profile-related Address
717 // {{{ class ProfileAddresses [ Field ]
718 class ProfileAddresses
extends ProfileField
720 private $addresses = array();
722 public function __construct(PlIterator
$it)
724 if ($it instanceof PlInnerSubIterator
) {
725 $this->pid
= $it->value();
728 while ($addr = $it->next()) {
729 $this->addresses
[] = new Address($addr);
733 public function get($flags, $limit = null
)
737 foreach ($this->addresses
as $addr) {
739 (($flags & Profile
::ADDRESS_MAIN
) && $addr->hasFlag('current'))
741 (($flags & Profile
::ADDRESS_POSTAL
) && $addr->hasFlag('mail'))
743 (($flags & Profile
::ADDRESS_PERSO
) && $addr->link_type
== Address
::LINK_PROFILE
)
745 (($flags & Profile
::ADDRESS_PRO
) && $addr->link_type
== Address
::LINK_JOB
)
750 if ($limit != null
&& $nb == $limit) {
757 public static function fetchData(array $pids, ProfileVisibility
$visibility)
759 $data = XDB
::iterator('SELECT pa.id, pa.pid, pa.flags, pa.type AS link_type,
760 IF(pa.type = \'home\', pid, IF(pa.type = \'job\', pa.id, jobid)) AS link_id,
761 pa.text, pa.postalCode, pa.latitude, pa.longitude, pa.comment,
762 gl.name AS locality, gas.name AS subAdministrativeArea,
763 ga.name AS administrativeArea, gc.countryFR AS country
764 FROM profile_addresses AS pa
765 LEFT JOIN geoloc_localities AS gl ON (gl.id = pa.localityId)
766 LEFT JOIN geoloc_administrativeareas AS ga ON (ga.id = pa.administrativeAreaId)
767 LEFT JOIN geoloc_administrativeareas AS gas ON (gas.id = pa.subAdministrativeAreaId)
768 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pa.countryId)
769 WHERE pa.pid in {?} AND pa.pub IN {?}
770 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids),
771 $pids, $visibility->levels());
773 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
776 public function addPhones(ProfilePhones
$phones)
778 $p = $phones->get(Profile
::PHONE_LINK_ADDRESS | Profile
::PHONE_TYPE_ANY
);
779 foreach ($p as $phone) {
780 if ($phone->link_type
== Phone
::LINK_ADDRESS
&& array_key_exists($phone->link_id
, $this->addresses
)) {
781 $this->addresses
[$phone->link_id
]->addPhone($phone);
787 // {{{ class ProfilePhones [ Field ]
788 class ProfilePhones
extends ProfileField
790 private $phones = array();
792 public function __construct(PlInnerSubIterator
$it)
794 $this->pid
= $it->value();
795 while ($phone = $it->next()) {
796 $this->phones
[] = new Phone($phone);
800 public function get($flags, $limit = null
)
804 foreach ($this->phones
as $id => $phone) {
805 if ($phone->hasFlags($flags)) {
806 $phones[$id] = $phone;
808 if ($limit != null
&& $nb == $limit) {
816 public static function fetchData(array $pids, ProfileVisibility
$visibility)
818 $data = XDB
::iterator('SELECT tel_type AS type, search_tel AS search, display_tel AS display, link_type, comment, pid, link_id, tel_id AS id
820 WHERE pid IN {?} AND pub IN {?}
821 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids),
822 $pids, $visibility->levels());
823 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
827 // {{{ class ProfileJobs [ Field ]
828 class ProfileJobs
extends ProfileField
830 private $jobs = array();
832 public function __construct(PlInnerSubIterator
$jobs)
834 $this->pid
= $jobs->value();
835 while ($job = $jobs->next()) {
836 $this->jobs
[$job['id']] = new Job($job);
840 public static function fetchData(array $pids, ProfileVisibility
$visibility)
842 CompanyList
::preload($pids);
843 $data = XDB
::iterator('SELECT pj.id, pj.pid, pj.description, pj.url as user_site,
844 IF(pj.email_pub IN {?}, pj.email, NULL) AS user_email,
845 pj.jobid, pjse.name AS sector, pjsse.name AS subsector,
846 pjssse.name AS subsubsector
847 FROM profile_job AS pj
848 LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pj.sectorid)
849 LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pj.subsectorid)
850 LEFT JOIN profile_job_subsubsector_enum AS pjssse ON (pjssse.id = pj.subsubsectorid)
851 WHERE pj.pid IN {?} AND pj.pub IN {?}
852 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids) . ',
854 $visibility->levels(), $pids, $visibility->levels());
855 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
858 public function get($flags, $limit = null
)
862 foreach ($this->jobs
as $id => $job) {
865 if ($limit != null
&& $nb >= $limit) {
872 public function addPhones(ProfilePhones
$phones)
874 $p = $phones->get(Profile
::PHONE_LINK_JOB | Profile
::PHONE_TYPE_ANY
);
875 foreach ($p as $phone) {
876 if ($phone->link_type
== Phone
::LINK_JOB
&& array_key_exists($phone->link_id
, $this->jobs
)) {
877 $this->jobs
[$phone->link_id
]->addPhone($phone);
882 public function addAddresses(ProfileAddresses
$addresses)
884 $a = $addresses->get(Profile
::ADDRESS_PRO
);
885 foreach ($a as $address) {
886 if ($address->link_type
== Address
::LINK_JOB
&& array_key_exists($address->link_id
, $this->jobs
)) {
887 $this->jobs
[$address->link_id
]->setAddress($address);
892 public function addCompanies(array $companies)
894 foreach ($this->jobs
as $job) {
895 $this->company
= $companies[$job->jobid
];
901 // {{{ class CompanyList
904 static private $fullload = false
;
905 static private $companies = array();
907 static public function preload($pids = array())
909 if (self
::$fullload) {
914 $join = 'LEFT JOIN profile_job ON (profile_job.jobid = pje.id)';
915 $where = 'WHERE profile_job.pid IN ' . XDB
::formatArray($pids);
921 $it = XDB
::iterator('SELECT pje.id, pje.name, pje.acronym, pje.url,
922 pa.flags, pa.text, pa.postalCode, pa.countryId,
924 FROM profile_job_enum AS pje
925 LEFT JOIN profile_addresses AS pa ON (pje.id = pa.jobid AND pa.type = \'hq\')
928 $newcompanies = array();
929 while ($row = $it->next()) {
930 $cp = new Company($row);
931 $addr = new Address($row);
932 $cp->setAddress($addr);
933 if (!array_key_exists($row['id'], self
::$companies)) {
934 $newcompanies[] = $row['id'];
936 self
::$companies[$row['id']] = $cp;
940 if (count($newcompanies)) {
941 $it = XDB
::iterator('SELECT search_tel AS search, display_tel AS display, comment, link_id, tel_type AS type, link_type, tel_id AS id
943 WHERE link_id IN {?} AND link_type = \'hq\'',
945 while ($row = $it->next()) {
946 $p = new Phone($row);
947 self
::$companies[$row['link_id']]->setPhone($p);
951 if (count($pids) == 0) {
952 self
::$fullload = true
;
956 static public function get($id)
958 if (!array_key_exists($id, self
::$companies)) {
961 return self
::$companies[$id];
965 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: