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)"
49 * XXX MUST be reimplemented for each kind of ProfileField
51 public static function fetchData(array $pids, ProfileVisibility
$visibility)
53 return PlIteratorUtils
::emptyIterator();
56 public static function buildForPID($cls, $pid, ProfileVisibility
$visibility)
58 $res = self
::buildFromPIDs($cls, array($pid), $visibility);
59 return array_pop($res);
62 /** Build a list of ProfileFields from a set of pids
63 * @param $cls The name of the field to create ('ProfileMedals', ...)
64 * @param $pids An array of pids
65 * @param $visibility An array of allowed visibility contexts
66 * @return An array of $pid => ProfileField
68 public static function buildFromPIDs($cls, array $pids, ProfileVisibility
$visibility)
70 $it = new ProfileFieldIterator($cls, $pids, $visibility);
72 while ($pf = $it->next()) {
78 public static function getForPID($cls, $pid, ProfileVisibility
$visibility)
80 $it = new ProfileFieldIterator($cls, array($pid), $visibility);
86 // {{{ class ProfileFieldIterator
87 class ProfileFieldIterator
implements PlIterator
92 public function __construct($cls, array $pids, ProfileVisibility
$visibility)
94 $this->data
= call_user_func(array($cls, 'fetchData'), $pids, $visibility);
98 public function next()
100 $d = $this->data
->next();
109 public function total()
111 return $this->data
->total();
114 public function first()
116 return $this->data
->first();
119 public function last()
121 return $this->data
->last();
129 const TYPE_FAX
= 'fax';
130 const TYPE_FIXED
= 'fixed';
131 const TYPE_MOBILE
= 'mobile';
136 public $comment = '';
138 const LINK_JOB
= 'pro';
139 const LINK_ADDRESS
= 'address';
140 const LINK_PROFILE
= 'user';
141 const LINK_COMPANY
= 'hq';
148 * $type, $search, $display, $link_type, $link_id, $comment, $pid, $id
150 public function __construct($data)
152 foreach ($data as $key => $val) {
157 /** Returns the unique ID of a phone
158 * This ID will allow to link it to an address, a user or a job
159 * The format is address_addressId_phoneId (where phoneId is the id
160 * of the phone in the list of those associated with the address)
162 public function uid() {
163 return $this->link_type
. '_' . $this->link_id
. '_' . $this->id
;
166 public function hasFlags($flags) {
167 return $this->hasType($flags) && $this->hasLink($flags);
170 /** Returns true if this phone's type matches the flags
172 public function hasType($flags) {
173 $flags = $flags & Profile
::PHONE_TYPE_ANY
;
175 ($flags == Profile
::PHONE_TYPE_ANY
)
177 (($flags & Profile
::PHONE_TYPE_FAX
) && $this->type
== self
::TYPE_FAX
)
179 (($flags & Profile
::PHONE_TYPE_FIXED
) && $this->type
== self
::TYPE_FIXED
)
181 (($flags & Profile
::PHONE_TYPE_MOBILE
) && $this->type
== self
::TYPE_MOBILE
)
185 /** User accessible version of the type
187 public function displayType($short = false
)
189 switch ($this->type
) {
190 case Phone
::TYPE_FIXED
:
191 return $short ?
'Tél' : 'Fixe';
192 case Phone
::TYPE_FAX
:
194 case Phone
::TYPE_MOBILE
:
195 return $short ?
'Mob' : 'Mobile';
201 /** Returns true if this phone's link matches the flags
203 public function hasLink($flags) {
204 $flags = $flags & Profile
::PHONE_LINK_ANY
;
206 ($flags == Profile
::PHONE_LINK_ANY
)
208 (($flags & Profile
::PHONE_LINK_COMPANY
) && $this->link_type
== self
::LINK_COMPANY
)
210 (($flags & Profile
::PHONE_LINK_JOB
) && $this->link_type
== self
::LINK_JOB
)
212 (($flags & Profile
::PHONE_LINK_ADDRESS
) && $this->link_type
== self
::LINK_ADDRESS
)
214 (($flags & Profile
::PHONE_LINK_PROFILE
) && $this->link_type
== self
::LINK_PROFILE
)
226 public $phone = null
;
227 public $address = null
;
230 * $id, $name, $acronym, $url
232 public function __construct($data)
234 foreach ($data as $key => $val) {
239 public function setPhone(Phone
&$phone)
241 if ($phone->link_type
== Phone
::LINK_COMPANY
&& $phone->link_id
== $this->id
) {
242 $this->phone
= $phone;
246 public function setAddress(Address
&$address)
248 if ($address->link_type
== Address
::LINK_COMPANY
&& $address->link_id
== $this->id
) {
249 $this->address
= $address;
261 public $company = null
;
262 public $phones = array();
263 public $address = null
;
273 public $subsubsector;
276 * pid, id, company_id, description, url, email
278 public function __construct($data)
280 foreach ($data as $key => $val) {
283 $this->company
= CompanyList
::get($this->jobid
);
286 public function phones()
288 return $this->phones
;
291 public function address()
293 return $this->address
;
296 public function addPhone(Phone
&$phone)
298 if ($phone->link_type
== Phone
::LINK_JOB
&& $phone->link_id
== $this->id
&& $phone->pid
== $this->pid
) {
299 $this->phones
[$phone->uid()] = $phone;
303 public function setAddress(Address
$address)
305 if ($address->link_type
== Address
::LINK_JOB
&& $address->link_id
== $this->id
&& $address->pid
== $this->pid
) {
306 $this->address
= $address;
314 const LINK_JOB
= 'job';
315 const LINK_COMPANY
= 'hq';
316 const LINK_PROFILE
= 'home';
319 public $id; // The ID of the address among those associated with its link
320 public $link_id; // The ID of the object to which the address is linked (profile, job, company)
329 public $subAdministrativeArea;
330 public $administrativeArea;
335 private $phones = array();
338 * pîd, id, link_id, link_type, flags, text, postcode, country
340 public function __construct($data)
342 foreach ($data as $key => $val) {
345 $this->flags
= new PlFlagSet($this->flags
);
348 public function uid() {
349 $uid = $this->link_type
. '_';
350 if ($this->link_type
!= self
::LINK_COMPANY
) {
351 $uid .= $this->pid
. '_';
353 $uid .= $this->link_id
. '_' . $this->id
;
356 public function addPhone(Phone
&$phone)
359 $phone->link_type
== Phone
::LINK_ADDRESS
&& $phone->link_id
== $this->id
&&
360 ($this->link_type
== self
::LINK_COMPANY ||
$phone->pid
== $this->pid
) ) {
361 $this->phones
[$phone->uid()] = $phone;
365 public function phones()
367 return $this->phones
;
370 public function hasFlag($flag)
372 if (!$this->flags
instanceof PlFlagSet
) {
373 $this->flags
= new PlFlagSet($this->flags
);
375 return $this->flags
->hasFlag($flag);
379 // {{{ class Education
391 public $school_short;
396 public $degree_short;
397 public $degree_level;
401 public function __construct(array $data)
403 foreach ($data as $key => $val) {
406 $this->flags
= new PlFlagSet($this->flags
);
411 // {{{ class ProfileEducation [ Field ]
412 class ProfileEducation
extends ProfileField
414 private $educations = array();
416 public function __construct(PlInnerSubIterator
$it)
418 $this->pid
= $it->value();
419 while ($edu = $it->next()) {
420 $this->educations
[$edu['id']] = new Education($edu);
424 public function get($flags, $limit)
426 $educations = array();
428 $year = $year['year'];
430 foreach ($this->educations
as $id => $edu) {
432 (($flags & Profile
::EDUCATION_MAIN
) && $edu->flags
->hasFlag('primary'))
434 (($flags & Profile
::EDUCATION_EXTRA
) && !$edu->flags
->hasFlag('primary'))
436 (($flags & Profile
::EDUCATION_FINISHED
) && $edu->grad_year
<= $year)
438 (($flags & Profile
::EDUCATION_CURRENT
) && $edu->grad_year
> $year)
440 ($flags & Profile
::EDUCATION_ALL
)
442 $educations[$id] = $edu;
445 if ($limit != null
&& $nb >= $limit) {
452 public static function fetchData(array $pids, ProfileVisibility
$visibility)
454 $data = XDB
::iterator('SELECT pe.id, pe.pid,
455 pe.entry_year, pe.grad_year, pe.program, pe.flags,
456 pee.name AS school, pee.abbreviation AS school_short,
457 pee.url AS school_url, gc.countryFR AS country,
458 pede.degree, pede.abbreviation AS degree_short, pede.level AS degree_level,
460 FROM profile_education AS pe
461 LEFT JOIN profile_education_enum AS pee ON (pee.id = pe.eduid)
462 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pee.country)
463 LEFT JOIN profile_education_degree_enum AS pede ON (pede.id = pe.degreeid)
464 LEFT JOIN profile_education_field_enum AS pefe ON (pefe.id = pe.fieldid)
466 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids) . ',
467 NOT FIND_IN_SET(\'primary\', pe.flags), pe.entry_year, pe.id',
470 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
474 // {{{ class ProfileMedals [ Field ]
475 class ProfileMedals
extends ProfileField
477 public $medals = array();
479 public function __construct(PlInnerSubIterator
$it)
481 $this->pid
= $it->value();
482 while ($medal = $it->next()) {
483 $this->medals
[$medal['mid']] = $medal;
487 public static function fetchData(array $pids, ProfileVisibility
$visibility)
489 $data = XDB
::iterator('SELECT pm.pid, pm.mid, pm.gid, pme.text, pme.img, pmge.text AS grade
490 FROM profile_medals AS pm
491 LEFT JOIN profiles AS p ON (pm.pid = p.pid)
492 LEFT JOIN profile_medal_enum AS pme ON (pme.id = pm.mid)
493 LEFT JOIN profile_medal_grade_enum AS pmge ON (pmge.mid = pm.mid AND pmge.gid = pm.gid)
494 WHERE pm.pid IN {?} AND p.medals_pub IN {?}
495 ORDER BY ' . XDB
::formatCustomOrder('pm.pid', $pids),
496 $pids, $visibility->levels());
498 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
502 // {{{ class ProfileNetworking [ Field ]
503 class ProfileNetworking
extends ProfileField
505 private $networks = array();
507 public function __construct(PlInnerSubIterator
$it)
509 $this->pid
= $it->value();
510 while ($network = $it->next()) {
511 $network['network_type'] = new PlFlagSet($network['network_type']);
512 $this->networks
[$network['id']] = $network;
516 public static function fetchData(array $pids, ProfileVisibility
$visibility)
518 $data = XDB
::iterator('SELECT pid, id, address, pne.nwid, pne.network_type, pne.link, pne.name
519 FROM profile_networking AS pn
520 LEFT JOIN profile_networking_enum AS pne USING(nwid)
521 WHERE pid IN {?} AND pub IN {?}
522 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids) . ',
524 $pids, $visibility->levels());
526 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
529 public function get($flags, $limit = null
)
533 foreach ($this->networks
as $id => $nw) {
534 if (($flags & Profile
::NETWORKING_WEB
) && $nw['network_type']->hasFlag('web') ||
535 ($flags & Profile
::NETWORKING_IM
) && $nw['network_type']->hasFlag('im') ||
536 ($flags & Profile
::NETWORKING_SOCIAL
) && $nw['network_type']->hasFlag('social') ||
537 ($flags == Profile
::NETWORKING_ALL
)) {
540 if (isset($limit) && $nb >= $limit) {
549 // {{{ class ProfileCorps [ Field ]
550 class ProfileCorps
extends ProfileField
555 public $original_name;
556 public $original_abbrev;
557 public $original_still_exists;
559 public $current_name;
560 public $current_abbrev;
561 public $current_still_exists;
562 public $current_rank;
563 public $current_rank_abbrev;
565 public function __construct(array $data)
567 foreach ($data as $key => $val) {
572 public static function fetchData(array $pids, ProfileVisibility
$visibility)
574 $data = XDB
::iterator('SELECT pc.pid, pc.original_corpsid AS original, pc.current_corpsid AS current,
575 pceo.name AS original_name, pceo.abbreviation AS original_abbrev,
576 pceo.still_exists AS original_still_exists,
577 pcec.name AS current_name, pcec.abbreviation AS current_abbrev,
578 pcec.still_exists AS current_still_exists,
579 pcrec.name AS current_rank, pcrec.abbreviation AS current_rank_abbrev,
581 FROM profile_corps AS pc
582 LEFT JOIN profile_corps_enum AS pceo ON (pceo.id = pc.original_corpsid)
583 LEFT JOIN profile_corps_enum AS pcec ON (pcec.id = pc.current_corpsid)
584 LEFT JOIN profile_corps_rank_enum AS pcrec ON (pcrec.id = pc.rankid)
585 WHERE pc.pid IN {?} AND pc.corps_pub IN {?} AND pceo.id != 1
586 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids),
587 $pids, $visibility->levels());
593 // {{{ class ProfileMentoringSectors [ Field ]
594 class ProfileMentoringSectors
extends ProfileField
596 public $sectors = array();
598 public function __construct(PlInnerSubIterator
$it)
600 $this->pid
= $it->value();
601 while ($sector = $it->next()) {
602 $this->sectors
[] = $sector;
606 public static function fetchData(array $pids, ProfileVisibility
$visibility)
608 $data = XDB
::iterator('SELECT pms.pid, pjse.name AS sector, pjsse.name AS subsector
609 FROM profile_mentor_sector AS pms
610 LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pms.sectorid)
611 LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pms.subsectorid)
613 ORDER BY ' . XDB
::formatCustomOrder('pms.pid', $pids),
616 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
620 // {{{ class ProfileMentoringCountries [ Field ]
621 class ProfileMentoringCountries
extends ProfileField
623 public $countries = array();
625 public function __construct(PlInnerSubIterator
$it)
627 $this->pid
= $it->value();
628 while ($country = $it->next()) {
629 $this->countries
[$country['id']] = $country['name'];
633 public static function fetchData(array $pids, ProfileVisibility
$visibility)
635 $data = XDB
::iterator('SELECT pmc.pid, pmc.country AS id, gc.countryFR AS name
636 FROM profile_mentor_country AS pmc
637 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pmc.country)
639 ORDER BY ' . XDB
::formatCustomOrder('pmc.pid', $pids),
642 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
647 /** Loading of data for a Profile :
648 * 1) load jobs, addresses, phones
649 * 2) attach phones to addresses, jobs and profiles
650 * 3) attach addresses to jobs and profiles
653 // {{{ Database schema (profile_address, profile_phones, profile_jobs)
654 /** The database for this is very unclear, so here is a little schema :
655 * profile_job describes a Job, links to:
656 * - a Profile, through `pid`
657 * - a Company, through `jobid`
658 * The `id` field is the id of this job in the list of the jobs of its profile
660 * profile_addresses describes an Address, which
661 * related to either a Profile, a Job or a Company:
663 * - `type` is set to 'home'
664 * - `pid` is set to the related profile pid
665 * - `id` is the id of the address in the list of those related to that profile
669 * - `type` is set to 'hq'
670 * - `pid` is set to 0
671 * - `jobid` is set to the id of the company
672 * - `id` is set to 0 (only one address per Company)
675 * - `type` is set to 'job'
676 * - `pid` is set to the pid of the Profile of the related Job
677 * - `jobid` is set to the Company of the job (this information is redundant
678 * with that of the row of profile_job for the related job)
679 * - `id` is the id of the job to which we refer (i.e `profile_job.id`)
681 * profile_phone describes a Phone, which can be related to an Address,
682 * a Job, a Profile or a Company:
684 * - `link_type` is set to 'user'
685 * - `link_id` is set to 0
686 * - `pid` is set to the id of the related Profile
689 * - `link_type` is set to 'hq'
690 * - `link_id` is set to the id of the related Company
691 * - `pid` is set to 0
693 * - for an Address (this is only possible for a *personal* address)
694 * - `link_type` is set to 'address'
695 * - `link_id` is set to the related Address `id`
696 * - `pid` is set to the related Address `pid`
699 * - `link_type` is set to 'pro'
700 * - `link_id` is set to the related Job `id` (not `jobid`)
701 * - `pid` is set to the related Job `pid`
704 * The possible relations are as follow:
705 * An Address can be linked to a Company, a Profile, a Job
706 * A Job is linked to a Company and a Profile
707 * A Phone can be linked to a Company, a Profile, a Job, or a Profile-related Address
711 // {{{ class ProfileAddresses [ Field ]
712 class ProfileAddresses
extends ProfileField
714 private $addresses = array();
716 public function __construct(PlIterator
$it)
718 if ($it instanceof PlInnerSubIterator
) {
719 $this->pid
= $it->value();
722 while ($addr = $it->next()) {
723 $this->addresses
[] = new Address($addr);
727 public function get($flags, $limit = null
)
731 foreach ($this->addresses
as $addr) {
733 (($flags & Profile
::ADDRESS_MAIN
) && $addr->hasFlag('current'))
735 (($flags & Profile
::ADDRESS_POSTAL
) && $addr->hasFlag('mail'))
737 (($flags & Profile
::ADDRESS_PERSO
) && $addr->link_type
== Address
::LINK_PROFILE
)
739 (($flags & Profile
::ADDRESS_PRO
) && $addr->link_type
== Address
::LINK_JOB
)
744 if ($limit != null
&& $nb == $limit) {
751 public static function fetchData(array $pids, ProfileVisibility
$visibility)
753 $data = XDB
::iterator('SELECT pa.id, pa.pid, pa.flags, pa.type AS link_type,
754 IF(pa.type = \'home\', pid, IF(pa.type = \'job\', pa.id, jobid)) AS link_id,
755 pa.text, pa.postalCode, pa.latitude, pa.longitude, pa.comment,
756 gl.name AS locality, gas.name AS subAdministrativeArea,
757 ga.name AS administrativeArea, gc.countryFR AS country
758 FROM profile_addresses AS pa
759 LEFT JOIN geoloc_localities AS gl ON (gl.id = pa.localityId)
760 LEFT JOIN geoloc_administrativeareas AS ga ON (ga.id = pa.administrativeAreaId)
761 LEFT JOIN geoloc_administrativeareas AS gas ON (gas.id = pa.subAdministrativeAreaId)
762 LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pa.countryId)
763 WHERE pa.pid in {?} AND pa.pub IN {?}
764 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids),
765 $pids, $visibility->levels());
767 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
770 public function addPhones(ProfilePhones
$phones)
772 $p = $phones->get(Profile
::PHONE_LINK_ADDRESS | Profile
::PHONE_TYPE_ANY
);
773 foreach ($p as $phone) {
774 if ($phone->link_type
== Phone
::LINK_ADDRESS
&& array_key_exists($phone->link_id
, $this->addresses
)) {
775 $this->addresses
[$phone->link_id
]->addPhone($phone);
781 // {{{ class ProfilePhones [ Field ]
782 class ProfilePhones
extends ProfileField
784 private $phones = array();
786 public function __construct(PlInnerSubIterator
$it)
788 $this->pid
= $it->value();
789 while ($phone = $it->next()) {
790 $this->phones
[] = new Phone($phone);
794 public function get($flags, $limit = null
)
798 foreach ($this->phones
as $id => $phone) {
799 if ($phone->hasFlags($flags)) {
800 $phones[$id] = $phone;
802 if ($limit != null
&& $nb == $limit) {
810 public static function fetchData(array $pids, ProfileVisibility
$visibility)
812 $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
814 WHERE pid IN {?} AND pub IN {?}
815 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids),
816 $pids, $visibility->levels());
817 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
821 // {{{ class ProfileJobs [ Field ]
822 class ProfileJobs
extends ProfileField
824 private $jobs = array();
826 public function __construct(PlInnerSubIterator
$jobs)
828 $this->pid
= $jobs->value();
829 while ($job = $jobs->next()) {
830 $this->jobs
[$job['id']] = new Job($job);
834 public static function fetchData(array $pids, ProfileVisibility
$visibility)
836 CompanyList
::preload($pids);
837 $data = XDB
::iterator('SELECT pj.id, pj.pid, pj.description, pj.url as user_site,
838 IF(pj.email_pub IN {?}, pj.email, NULL) AS user_email,
839 pj.jobid, pjse.name AS sector, pjsse.name AS subsector,
840 pjssse.name AS subsubsector
841 FROM profile_job AS pj
842 LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pj.sectorid)
843 LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pj.subsectorid)
844 LEFT JOIN profile_job_subsubsector_enum AS pjssse ON (pjssse.id = pj.subsubsectorid)
845 WHERE pj.pid IN {?} AND pj.pub IN {?}
846 ORDER BY ' . XDB
::formatCustomOrder('pid', $pids) . ',
848 $visibility->levels(), $pids, $visibility->levels());
849 return PlIteratorUtils
::subIterator($data, PlIteratorUtils
::arrayValueCallback('pid'));
852 public function get($flags, $limit = null
)
856 foreach ($this->jobs
as $id => $job) {
859 if ($limit != null
&& $nb >= $limit) {
866 public function addPhones(ProfilePhones
$phones)
868 $p = $phones->get(Profile
::PHONE_LINK_JOB | Profile
::PHONE_TYPE_ANY
);
869 foreach ($p as $phone) {
870 if ($phone->link_type
== Phone
::LINK_JOB
&& array_key_exists($phone->link_id
, $this->jobs
)) {
871 $this->jobs
[$phone->link_id
]->addPhone($phone);
876 public function addAddresses(ProfileAddresses
$addresses)
878 $a = $addresses->get(Profile
::ADDRESS_PRO
);
879 foreach ($a as $address) {
880 if ($address->link_type
== Address
::LINK_JOB
&& array_key_exists($address->link_id
, $this->jobs
)) {
881 $this->jobs
[$address->link_id
]->setAddress($address);
886 public function addCompanies(array $companies)
888 foreach ($this->jobs
as $job) {
889 $this->company
= $companies[$job->jobid
];
895 // {{{ class CompanyList
898 static private $fullload = false
;
899 static private $companies = array();
901 static public function preload($pids = array())
903 if (self
::$fullload) {
908 $join = 'LEFT JOIN profile_job ON (profile_job.jobid = pje.id)';
909 $where = 'WHERE profile_job.pid IN ' . XDB
::formatArray($pids);
915 $it = XDB
::iterator('SELECT pje.id, pje.name, pje.acronym, pje.url,
916 pa.flags, pa.text, pa.postalCode, pa.countryId,
918 FROM profile_job_enum AS pje
919 LEFT JOIN profile_addresses AS pa ON (pje.id = pa.jobid AND pa.type = \'hq\')
922 $newcompanies = array();
923 while ($row = $it->next()) {
924 $cp = new Company($row);
925 $addr = new Address($row);
926 $cp->setAddress($addr);
927 if (!array_key_exists($row['id'], self
::$companies)) {
928 $newcompanies[] = $row['id'];
930 self
::$companies[$row['id']] = $cp;
933 // TODO: determine whether there can be phones attached to a hq's address
935 if (count($newcompanies)) {
936 $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
938 WHERE link_id IN {?} AND link_type = \'hq\'',
940 while ($row = $it->next()) {
941 $p = new Phone($row);
942 self
::$companies[$row['link_id']]->setPhone($p);
946 if (count($pids) == 0) {
947 self
::$fullload = true
;
951 static public function get($id)
953 if (!array_key_exists($id, self
::$companies)) {
956 return self
::$companies[$id];
960 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: