+ if ($this->with_rf) {
+ $joins['rf'] = PlSqlJoin::left('email_redirect_account', '$ME.uid = $UID AND $ME.type != \'imap\' AND $ME.flags = \'active\'');;
+ }
+ return $joins;
+ }
+
+
+ /** ADDRESSES
+ */
+ private $types = array();
+ public function addAddressFilter($type)
+ {
+ $this->requireProfiles();
+ $this->with_pa = true;
+
+ $sub = '_' . $this->option++;
+ $this->types[$type] = $sub;
+ return $sub;
+ }
+
+ protected function addressJoins()
+ {
+ $joins = array();
+ foreach ($this->types as $type => $sub) {
+ $joins['pa' . $sub] = PlSqlJoin::inner('profile_addresses', '$ME.pid = $PID');
+ $joins['pac' . $sub] = PlSqlJoin::inner('profile_addresses_components',
+ '$ME.pid = pa' . $sub . '.pid AND $ME.jobid = pa' . $sub . '.jobid AND $ME.groupid = pa' . $sub . '.groupid AND $ME.type = pa' . $sub . '.type AND $ME.id = pa' . $sub . '.id');
+ $joins['pace' . $sub] = PlSqlJoin::inner('profile_addresses_components_enum',
+ '$ME.id = pac' . $sub . '.component_id AND FIND_IN_SET({?}, $ME.types)', $type);
+ }
+
+ 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) {
+ $this->pce['pcec'] = 'current_corpsid';
+ return 'pcec';
+ } else if ($type == UFC_Corps::ORIGIN) {
+ $this->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');