+ return $joins;
+ }
+
+
+ /** ADDRESSES
+ */
+ private $with_pa = false;
+ public function addAddressFilter()
+ {
+ $this->requireProfiles();
+ $this->with_pa = true;
+ return 'pa';
+ }
+
+ private $with_pac = false;
+ public function addAddressCountryFilter()
+ {
+ $this->requireProfiles();
+ $this->addAddressFilter();
+ $this->with_pac = true;
+ return 'gc';
+ }
+
+ private $with_pal = false;
+ public function addAddressLocalityFilter()
+ {
+ $this->requireProfiles();
+ $this->addAddressFilter();
+ $this->with_pal = true;
+ return 'gl';
+ }
+
+ protected function addressJoins()
+ {
+ $joins = array();
+ if ($this->with_pa) {
+ $joins['pa'] = PlSqlJoin::left('profile_addresses', '$ME.pid = $PID');
+ }
+ if ($this->with_pac) {
+ $joins['gc'] = PlSqlJoin::left('geoloc_countries', '$ME.iso_3166_1_a2 = pa.countryID');
+ }
+ if ($this->with_pal) {
+ $joins['gl'] = PlSqlJoin::left('geoloc_localities', '$ME.id = pa.localityID');
+ }
+ return $joins;
+ }
+
+
+ /** CORPS
+ */
+
+ private $pc = false;
+ private $pce = array();
+ private $pcr = false;
+ public function addCorpsFilter($type)
+ {
+ $this->requireProfiles();
+ $this->pc = true;
+ if ($type == UFC_Corps::CURRENT) {
+ $pce['pcec'] = 'current_corpsid';
+ return 'pcec';
+ } else if ($type == UFC_Corps::ORIGIN) {
+ $pce['pceo'] = 'original_corpsid';
+ return 'pceo';
+ }
+ }
+
+ public function addCorpsRankFilter()
+ {
+ $this->requireProfiles();
+ $this->pc = true;
+ $this->pcr = true;
+ return 'pcr';
+ }
+
+ protected function corpsJoins()
+ {
+ $joins = array();
+ if ($this->pc) {
+ $joins['pc'] = PlSqlJoin::left('profile_corps', '$ME.pid = $PID');
+ }
+ if ($this->pcr) {
+ $joins['pcr'] = PlSqlJoin::left('profile_corps_rank_enum', '$ME.id = pc.rankid');
+ }
+ foreach($this->pce as $sub => $field) {
+ $joins[$sub] = PlSqlJoin::left('profile_corps_enum', '$ME.id = pc.' . $field);
+ }
+ return $joins;
+ }
+
+ /** JOBS
+ */
+
+ const JOB_USERDEFINED = 0x0001;
+ const JOB_CV = 0x0002;
+ const JOB_ANY = 0x0003;
+
+ /** Joins :
+ * pj => profile_job
+ * pje => profile_job_enum
+ * pjt => profile_job_terms
+ */
+ private $with_pj = false;
+ private $with_pje = false;
+ private $with_pjt = 0;
+
+ public function addJobFilter()
+ {
+ $this->requireProfiles();
+ $this->with_pj = true;
+ return 'pj';
+ }
+
+ public function addJobCompanyFilter()
+ {
+ $this->addJobFilter();
+ $this->with_pje = true;
+ return 'pje';
+ }
+
+ /**
+ * Adds a filter on job terms of profile.
+ * @param $nb the number of job terms to use
+ * @return an array of the fields to filter (one for each term).
+ */
+ public function addJobTermsFilter($nb = 1)
+ {
+ $this->with_pjt = $nb;
+ $jobtermstable = array();
+ for ($i = 1; $i <= $nb; ++$i) {
+ $jobtermstable[] = 'pjtr_'.$i;
+ }
+ return $jobtermstable;
+ }
+
+ protected function jobJoins()
+ {
+ $joins = array();
+ if ($this->with_pj) {
+ $joins['pj'] = PlSqlJoin::left('profile_job', '$ME.pid = $PID');
+ }
+ if ($this->with_pje) {
+ $joins['pje'] = PlSqlJoin::left('profile_job_enum', '$ME.id = pj.jobid');
+ }
+ if ($this->with_pjt > 0) {
+ for ($i = 1; $i <= $this->with_pjt; ++$i) {
+ $joins['pjt_'.$i] = PlSqlJoin::left('profile_job_term', '$ME.pid = $PID');
+ $joins['pjtr_'.$i] = PlSqlJoin::left('profile_job_term_relation', '$ME.jtid_2 = pjt_'.$i.'.jtid');