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',
38 Profile
::FETCH_JOB_TERMS
=> 'ProfileJobTerms',
39 Profile
::FETCH_MENTOR_TERMS
=> 'ProfileMentoringTerms',
42 /** The profile to which this field belongs
46 /** Fetches data from the database for the given pids, compatible with
47 * the visibility context.
48 * @param $pids An array of pids
49 * @param $visibility The level of visibility fetched fields must have
50 * @return a PlIterator yielding data suitable for a "new ProfileBlah($data)"
52 * MUST be reimplemented for each kind of ProfileField.
54 public static function fetchData(array $pids, ProfileVisibility
$visibility)
56 return PlIteratorUtils
::emptyIterator();
59 public static function buildForPID($cls, $pid, ProfileVisibility
$visibility)
61 $res = self
::buildFromPIDs($cls, array($pid), $visibility);
62 return array_pop($res);
65 /** Build a list of ProfileFields from a set of pids
66 * @param $cls The name of the field to create ('ProfileMedals', ...)
67 * @param $pids An array of pids
68 * @param $visibility An array of allowed visibility contexts
69 * @return An array of $pid => ProfileField
71 public static function buildFromPIDs($cls, array $pids, ProfileVisibility
$visibility)
73 $it = new ProfileFieldIterator($cls, $pids, $visibility);
75 while ($pf = $it->next()) {
81 public static function getForPID($cls, $pid, ProfileVisibility
$visibility)
83 $it = new ProfileFieldIterator($cls, array($pid), $visibility);
89 // {{{ class ProfileFieldIterator
90 class ProfileFieldIterator
implements PlIterator
95 public function __construct($cls, array $pids, ProfileVisibility
$visibility)
97 if (is_numeric($cls) && isset(ProfileField
::$fields[$cls])) {
98 $cls = ProfileField
::$fields[$cls];
100 $this->data
= call_user_func(array($cls, 'fetchData'), $pids, $visibility);
104 public function next()
106 $d = $this->data
->next();
115 public function total()
117 return $this->data
->total();
120 public function first()
122 return $this->data
->first();
125 public function last()
127 return $this->data
->last();
139 public $phone = null
;
140 public $address = null
;
143 * $id, $name, $acronym, $url
145 public function __construct($data)
147 foreach ($data as $key => $val) {
152 public function setPhone(Phone
&$phone)
154 if ($phone->linkType() == Phone
::LINK_COMPANY
&& $phone->linkId() == $this->id
) {
155 $this->phone
= $phone;
159 public function setAddress(Address
&$address)
161 if ($address->link_type
== Address
::LINK_COMPANY
&& $address->link_id
== $this->id
) {
162 $this->address
= $address;
174 public $company = null
;
175 public $phones = array();
176 public $address = null
;
177 public $terms = array();
187 public $subsubsector;
190 * pid, id, company_id, description, url, email
192 public function __construct($data)
194 foreach ($data as $key => $val) {
197 $this->company
= CompanyList
::get($this->jobid
);
198 if (is_null($this->company
)) {
199 require_once 'validations.inc.php';
200 $entreprise = ProfileValidate
::get_typed_requests($this->pid
, 'entreprise');
201 $this->company
= new Company(array('name' => $entreprise[$this->id
]->name
));
205 public function phones()
207 return $this->phones
;
210 public function address()
212 return $this->address
;
215 public function addPhone(Phone
&$phone)
217 if ($phone->linkType() == Phone
::LINK_JOB
&& $phone->linkId() == $this->id
&& $phone->pid() == $this->pid
) {
218 $this->phones
[$phone->uniqueId()] = $phone;
222 public function setAddress(Address
$address)
224 if ($address->link_type
== Address
::LINK_JOB
&& $address->link_id
== $this->id
&& $address->pid
== $this->pid
) {
225 $this->address
= $address;
229 public function addTerm(JobTerm
&$term)
231 $this->terms
[$term->jtid
] = $term;
244 * pid, jid, jtid, full_name
246 public function __construct($data)
248 foreach ($data as $key => $val) {
257 const LINK_JOB
= 'job';
258 const LINK_COMPANY
= 'hq';
259 const LINK_PROFILE
= 'home';
262 public $id; // The ID of the address among those associated with its link
263 public $link_id; // The ID of the object to which the address is linked (profile, job, company)
272 public $subAdministrativeArea;
273 public $administrativeArea;
278 private $phones = array();
281 * pîd, id, link_id, link_type, flags, text, postcode, country
283 public function __construct($data)
285 foreach ($data as $key => $val) {
288 $this->flags
= new PlFlagSet($this->flags
);
291 public function uid() {
292 $uid = $this->link_type
. '_';
293 if ($this->link_type
!= self
::LINK_COMPANY
) {
294 $uid .= $this->pid
. '_';
296 $uid .= $this->link_id
. '_' . $this->id
;
299 public function addPhone(Phone
&$phone)
302 $phone->linkType() == Phone
::LINK_ADDRESS
&& $phone->linkId() == $this->id
&&
303 ($this->link_type
== self
::LINK_COMPANY ||
$phone->pid() == $this->pid
) ) {
304 $this->phones
[$phone->uniqueId()] = $phone;
308 public function phones()
310 return $this->phones
;
313 public function hasFlag($flag)
315 if (!$this->flags
instanceof PlFlagSet
) {
316 $this->flags
= new PlFlagSet($this->flags
);
318 return $this->flags
->hasFlag($flag);
322 // {{{ class Education
334 public $school_short;
339 public $degree_short;
340 public $degree_level;
344 public function __construct(array $data)
346 foreach ($data as $key => $val) {
349 $this->flags
= new PlFlagSet($this->flags
);
354 // {{{ class ProfileEducation [ Field ]
355 class ProfileEducation
extends ProfileField
357 private $educations = array();
359 public function __construct(PlInnerSubIterator
$it)
361 $this->pid
= $it->value();
362 while ($edu = $it->next()) {
363 $this->educations
[$edu['id']] = new Education($edu);
367 public function get($flags, $limit)
369 $educations = array();
371 $year = $year['year'];
373 foreach ($this->educations
as $id => $edu) {
375 (($flags & Profile
::EDUCATION_MAIN
) && $edu->flags
->hasFlag('primary'))
377 (($flags & Profile
::EDUCATION_EXTRA
) && !$edu->flags
->hasFlag('primary'))
379 (($flags & Profile
::EDUCATION_FINISHED
) && $edu->grad_year
<= $year)
381 (($flags & Profile
::EDUCATION_CURRENT
) && $edu->grad_year
> $year)
383 ($flags & Profile
::EDUCATION_ALL
)
385 $educations[$id] = $edu;
388 if ($limit != null
&& $nb >= $limit) {
395 public static function fetchData(array $pids, ProfileVisibility
$visibility)
397 $data = XDB
::iterator('SELECT pe.id, pe.pid,
398 pe.entry_year, pe.grad_year, pe.program, pe.flags,
399 pee.name AS school, pee.abbreviation AS school_short,
400 pee.url AS school_url, gc.countryFR AS country,
401 pede.degree, pede.abbreviation AS degree_short, pede.level AS degree_level,
403 FROM profile_education AS pe
404 LEFT JOIN profile_education_enum AS pee ON (pee.id = pe.eduid)
405 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pee.country)
406 LEFT JOIN profile_education_degree_enum AS pede ON (pede.id = pe.degreeid)
407 LEFT JOIN profile_education_field_enum AS pefe ON (pefe.id = pe.fieldid)
409 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids) . ',
410 NOT FIND_IN_SET(\'primary\', pe.flags), pe.entry_year, pe.id',
413 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
417 // {{{ class ProfileMedals [ Field ]
418 class ProfileMedals
extends ProfileField
420 public $medals = array();
422 public function __construct(PlInnerSubIterator
$it)
424 $this->pid
= $it->value();
425 while ($medal = $it->next()) {
426 $this->medals
[$medal['mid']] = $medal;
430 public static function fetchData(array $pids, ProfileVisibility
$visibility)
432 $data = XDB
::iterator('SELECT pm.pid, pm.mid, pm.gid, pme.text, pme.img, pmge.text AS grade
433 FROM profile_medals AS pm
434 LEFT JOIN profiles AS p ON (pm.pid = p.pid)
435 LEFT JOIN profile_medal_enum AS pme ON (pme.id = pm.mid)
436 LEFT JOIN profile_medal_grade_enum AS pmge ON (pmge.mid = pm.mid AND pmge.gid = pm.gid)
437 WHERE pm.pid IN {?} AND p.medals_pub IN {?}
438 ORDER BY ' . XDB
::formatCustomOrder('pm.pid', $pids),
439 $pids, $visibility->levels());
441 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
445 // {{{ class ProfileNetworking [ Field ]
446 class ProfileNetworking
extends ProfileField
448 private $networks = array();
450 public function __construct(PlInnerSubIterator
$it)
452 $this->pid
= $it->value();
453 while ($network = $it->next()) {
454 $network['network_type'] = new PlFlagSet($network['network_type']);
455 $this->networks
[$network['id']] = $network;
459 public static function fetchData(array $pids, ProfileVisibility
$visibility)
461 $data = XDB
::iterator('SELECT pid, id, address, pne.nwid, pne.network_type, pne.link, pne.name
462 FROM profile_networking AS pn
463 LEFT JOIN profile_networking_enum AS pne USING(nwid)
464 WHERE pid IN {?} AND pub IN {?}
465 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids) . ',
467 $pids, $visibility->levels());
469 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
472 public function get($flags, $limit = null
)
476 foreach ($this->networks
as $id => $nw) {
477 if (($flags & Profile
::NETWORKING_WEB
) && $nw['network_type']->hasFlag('web') ||
478 ($flags & Profile
::NETWORKING_IM
) && $nw['network_type']->hasFlag('im') ||
479 ($flags & Profile
::NETWORKING_SOCIAL
) && $nw['network_type']->hasFlag('social') ||
480 ($flags == Profile
::NETWORKING_ALL
)) {
483 if (isset($limit) && $nb >= $limit) {
492 // {{{ class ProfileCorps [ Field ]
493 class ProfileCorps
extends ProfileField
498 public $original_name;
499 public $original_abbrev;
500 public $original_still_exists;
502 public $current_name;
503 public $current_abbrev;
504 public $current_still_exists;
505 public $current_rank;
506 public $current_rank_abbrev;
508 public function __construct(array $data)
510 foreach ($data as $key => $val) {
515 public static function fetchData(array $pids, ProfileVisibility
$visibility)
517 $data = XDB
::iterator('SELECT pc.pid, pc.original_corpsid AS original, pc.current_corpsid AS current,
518 pceo.name AS original_name, pceo.abbreviation AS original_abbrev,
519 pceo.still_exists AS original_still_exists,
520 pcec.name AS current_name, pcec.abbreviation AS current_abbrev,
521 pcec.still_exists AS current_still_exists,
522 pcrec.name AS current_rank, pcrec.abbreviation AS current_rank_abbrev,
524 FROM profile_corps AS pc
525 LEFT JOIN profile_corps_enum AS pceo ON (pceo.id = pc.original_corpsid)
526 LEFT JOIN profile_corps_enum AS pcec ON (pcec.id = pc.current_corpsid)
527 LEFT JOIN profile_corps_rank_enum AS pcrec ON (pcrec.id = pc.rankid)
528 WHERE pc.pid IN {?} AND pc.corps_pub IN {?} AND pceo.id != 1
529 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids),
530 $pids, $visibility->levels());
536 // {{{ class ProfileMentoringSectors [ Field ]
537 class ProfileMentoringSectors
extends ProfileField
539 public $sectors = array();
541 public function __construct(PlInnerSubIterator
$it)
543 $this->pid
= $it->value();
544 while ($sector = $it->next()) {
545 $this->sectors
[] = $sector;
549 public static function fetchData(array $pids, ProfileVisibility
$visibility)
551 $data = XDB
::iterator('SELECT pms.pid, pjse.name AS sector, pjsse.name AS subsector
552 FROM profile_mentor_sector AS pms
553 LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pms.sectorid)
554 LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pms.subsectorid)
556 ORDER BY ' . XDB
::formatCustomOrder('pms.pid', $pids),
559 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
563 // {{{ class ProfileMentoringCountries [ Field ]
564 class ProfileMentoringCountries
extends ProfileField
566 public $countries = array();
568 public function __construct(PlInnerSubIterator
$it)
570 $this->pid
= $it->value();
571 while ($country = $it->next()) {
572 $this->countries
[$country['id']] = $country['name'];
576 public static function fetchData(array $pids, ProfileVisibility
$visibility)
578 $data = XDB
::iterator('SELECT pmc.pid, pmc.country AS id, gc.countryFR AS name
579 FROM profile_mentor_country AS pmc
580 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pmc.country)
582 ORDER BY ' . XDB
::formatCustomOrder('pmc.pid', $pids),
585 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
590 /** Loading of data for a Profile :
591 * 1) load jobs, addresses, phones
592 * 2) attach phones to addresses, jobs and profiles
593 * 3) attach addresses to jobs and profiles
596 // {{{ Database schema (profile_address, profile_jobs)
597 /** The database for this is very unclear, so here is a little schema :
598 * profile_job describes a Job, links to:
599 * - a Profile, through `pid`
600 * - a Company, through `jobid`
601 * The `id` field is the id of this job in the list of the jobs of its profile
603 * profile_addresses describes an Address, which
604 * related to either a Profile, a Job or a Company:
606 * - `type` is set to 'home'
607 * - `pid` is set to the related profile pid
608 * - `id` is the id of the address in the list of those related to that profile
612 * - `type` is set to 'hq'
613 * - `pid` is set to 0
614 * - `jobid` is set to the id of the company
615 * - `id` is set to 0 (only one address per Company)
618 * - `type` is set to 'job'
619 * - `pid` is set to the pid of the Profile of the related Job
620 * - `jobid` is set to the Company of the job (this information is redundant
621 * with that of the row of profile_job for the related job)
622 * - `id` is the id of the job to which we refer (i.e `profile_job.id`)
624 * For the documentation of the phone table, please see classes/phone.php.
626 * The possible relations are as follow:
627 * An Address can be linked to a Company, a Profile, a Job
628 * A Job is linked to a Company and a Profile
632 // {{{ class ProfileAddresses [ Field ]
633 class ProfileAddresses
extends ProfileField
635 private $addresses = array();
637 public function __construct(PlIterator
$it)
639 if ($it instanceof PlInnerSubIterator
) {
640 $this->pid
= $it->value();
643 while ($addr = $it->next()) {
644 $this->addresses
[] = new Address($addr);
648 public function get($flags, $limit = null
)
652 foreach ($this->addresses
as $addr) {
654 (($flags & Profile
::ADDRESS_MAIN
) && $addr->hasFlag('current'))
656 (($flags & Profile
::ADDRESS_POSTAL
) && $addr->hasFlag('mail'))
658 (($flags & Profile
::ADDRESS_PERSO
) && $addr->link_type
== Address
::LINK_PROFILE
)
660 (($flags & Profile
::ADDRESS_PRO
) && $addr->link_type
== Address
::LINK_JOB
)
665 if ($limit != null
&& $nb == $limit) {
672 public static function fetchData(array $pids, ProfileVisibility
$visibility)
674 $data = XDB
::iterator('SELECT pa.id, pa.pid, pa.flags, pa.type AS link_type,
675 IF(pa.type = \'home\', pid, IF(pa.type = \'job\', pa.id, jobid)) AS link_id,
676 pa.text, pa.postalCode, pa.latitude, pa.longitude, pa.comment,
677 gl.name AS locality, gas.name AS subAdministrativeArea,
678 ga.name AS administrativeArea, gc.countryFR AS country
679 FROM profile_addresses AS pa
680 LEFT JOIN geoloc_localities AS gl ON (gl.id = pa.localityId)
681 LEFT JOIN geoloc_administrativeareas AS ga ON (ga.id = pa.administrativeAreaId)
682 LEFT JOIN geoloc_administrativeareas AS gas ON (gas.id = pa.subAdministrativeAreaId)
683 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pa.countryId)
684 WHERE pa.pid in {?} AND pa.pub IN {?}
685 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids),
686 $pids, $visibility->levels());
688 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
691 public function addPhones(ProfilePhones
$phones)
693 $p = $phones->get(Profile
::PHONE_LINK_ADDRESS | Profile
::PHONE_TYPE_ANY
);
694 foreach ($p as $phone) {
695 if ($phone->linkType() == Phone
::LINK_ADDRESS
&& array_key_exists($phone->linkId(), $this->addresses
)) {
696 $this->addresses
[$phone->linkId()]->addPhone($phone);
702 // {{{ class ProfilePhones [ Field ]
703 class ProfilePhones
extends ProfileField
705 private $phones = array();
707 public function __construct(PlInnerSubIterator
$it)
709 $this->pid
= $it->value();
710 while ($phone = $it->next()) {
711 $this->phones
[] = new Phone($phone);
715 public function get($flags, $limit = null
)
719 foreach ($this->phones
as $id => $phone) {
720 if ($phone->hasFlags($flags)) {
721 $phones[$id] = $phone;
723 if ($limit != null
&& $nb == $limit) {
731 public static function fetchData(array $pids, ProfileVisibility
$visibility)
733 $it = Phone
::iterate($pids, array(), array(), $visibility->levels());
734 return PlIteratorUtils
::subIterator($it->value(), PlIteratorUtils
::arrayValueCallback('pid'));
738 // {{{ class ProfileJobs [ Field ]
739 class ProfileJobs
extends ProfileField
741 private $jobs = array();
743 public function __construct(PlInnerSubIterator
$jobs)
745 $this->pid
= $jobs->value();
746 while ($job = $jobs->next()) {
747 $this->jobs
[$job['id']] = new Job($job);
751 public static function fetchData(array $pids, ProfileVisibility
$visibility)
753 CompanyList
::preload($pids);
754 $data = XDB
::iterator('SELECT pj.id, pj.pid, pj.description, pj.url as user_site,
755 IF(pj.email_pub IN {?}, pj.email, NULL) AS user_email,
756 pj.jobid, pjse.name AS sector, pjsse.name AS subsector,
757 pjssse.name AS subsubsector
758 FROM profile_job AS pj
759 LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pj.sectorid)
760 LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pj.subsectorid)
761 LEFT JOIN profile_job_subsubsector_enum AS pjssse ON (pjssse.id = pj.subsubsectorid)
762 WHERE pj.pid IN {?} AND pj.pub IN {?}
763 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids) . ',
765 $visibility->levels(), $pids, $visibility->levels());
766 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
769 public function get($flags, $limit = null
)
773 foreach ($this->jobs
as $id => $job) {
776 if ($limit != null
&& $nb >= $limit) {
783 public function addPhones(ProfilePhones
$phones)
785 $p = $phones->get(Profile
::PHONE_LINK_JOB | Profile
::PHONE_TYPE_ANY
);
786 foreach ($p as $phone) {
787 if ($phone->linkType() == Phone
::LINK_JOB
&& array_key_exists($phone->linkId(), $this->jobs
)) {
788 $this->jobs
[$phone->linkId()]->addPhone($phone);
793 public function addAddresses(ProfileAddresses
$addresses)
795 $a = $addresses->get(Profile
::ADDRESS_PRO
);
796 foreach ($a as $address) {
797 if ($address->link_type
== Address
::LINK_JOB
&& array_key_exists($address->link_id
, $this->jobs
)) {
798 $this->jobs
[$address->link_id
]->setAddress($address);
803 public function addCompanies(array $companies)
805 foreach ($this->jobs
as $job) {
806 $this->company
= $companies[$job->jobid
];
810 public function addJobTerms(ProfileJobTerms
$jobterms)
812 $terms = $jobterms->get();
813 foreach ($terms as $term) {
814 if ($this->pid
== $term->pid
&& array_key_exists($term->jid
, $this->jobs
)) {
815 $this->jobs
[$term->jid
]->addTerm(&$term);
821 // {{{ class ProfileJobTerms [ Field ]
822 class ProfileJobTerms
extends ProfileField
824 private $jobterms = array();
826 public function __construct(PlInnerSubIterator
$it)
828 $this->pid
= $it->value();
829 while ($term = $it->next()) {
830 $this->jobterms
[] = new JobTerm($term);
834 public function get()
836 return $this->jobterms
;
839 public static function fetchData(array $pids, ProfileVisibility
$visibility)
841 $data = XDB
::iterator('SELECT jt.jtid, jte.full_name, jt.pid, jt.jid
842 FROM profile_job_term AS jt
843 INNER JOIN profile_job AS j ON (jt.pid = j.pid AND jt.jid = j.id)
844 LEFT JOIN profile_job_term_enum AS jte USING(jtid)
845 WHERE jt.pid IN {?} AND j.pub IN {?}
846 ORDER BY ' . XDB
::formatCustomOrder('jt.pid', $pids),
847 $pids, $visibility->levels());
848 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
852 // {{{ class ProfileMentoringTerms [ Field ]
853 class ProfileMentoringTerms
extends ProfileJobTerms
855 public static function fetchData(array $pids, ProfileVisibility
$visibility)
857 $data = XDB
::iterator('SELECT mt.jtid, jte.full_name, mt.pid
858 FROM profile_mentor_term AS mt
859 LEFT JOIN profile_job_term_enum AS jte USING(jtid)
861 ORDER BY ' . XDB
::formatCustomOrder('mt.pid', $pids),
863 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
867 // {{{ class CompanyList
870 static private $fullload = false
;
871 static private $companies = array();
873 static public function preload($pids = array())
875 if (self
::$fullload) {
880 $join = 'LEFT JOIN profile_job ON (profile_job.jobid = pje.id)';
881 $where = 'WHERE profile_job.pid IN ' . XDB
::formatArray($pids);
887 $it = XDB
::iterator('SELECT pje.id, pje.name, pje.acronym, pje.url,
888 pa.flags, pa.text, pa.postalCode, pa.countryId,
890 FROM profile_job_enum AS pje
891 LEFT JOIN profile_addresses AS pa ON (pje.id = pa.jobid AND pa.type = \'hq\')
894 $newcompanies = array();
895 while ($row = $it->next()) {
896 $cp = new Company($row);
897 $addr = new Address($row);
898 $cp->setAddress($addr);
899 if (!array_key_exists($row['id'], self
::$companies)) {
900 $newcompanies[] = $row['id'];
902 self
::$companies[$row['id']] = $cp;
906 if (count($newcompanies)) {
907 $it = Phone
::iterate(array(), array(Phone
::LINK_COMPANY
), $newcompanies);
908 while ($phone = $it->next()) {
909 self
::$companies[$phone->linkId()]->setPhone($phone);
913 if (count($pids) == 0) {
914 self
::$fullload = true
;
918 static public function get($id)
920 if (!array_key_exists($id, self
::$companies)) {
923 return self
::$companies[$id];
927 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: