+ $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');
+ }
+ }
+ return $joins;
+ }
+
+ /** NETWORKING
+ */
+
+ private $with_pnw = false;
+ public function addNetworkingFilter()
+ {
+ $this->requireAccounts();
+ $this->with_pnw = true;
+ return 'pnw';
+ }
+
+ protected function networkingJoins()
+ {
+ $joins = array();
+ if ($this->with_pnw) {
+ $joins['pnw'] = PlSqlJoin::left('profile_networking', '$ME.pid = $PID');
+ }
+ return $joins;
+ }
+
+ /** PHONE
+ */
+
+ private $with_ptel = false;
+
+ public function addPhoneFilter()
+ {
+ $this->requireAccounts();
+ $this->with_ptel = true;
+ return 'ptel';
+ }
+
+ protected function phoneJoins()
+ {
+ $joins = array();
+ if ($this->with_ptel) {
+ $joins['ptel'] = PlSqlJoin::left('profile_phones', '$ME.pid = $PID');
+ }
+ return $joins;
+ }
+
+ /** MEDALS
+ */
+
+ private $with_pmed = false;
+ public function addMedalFilter()
+ {
+ $this->requireProfiles();
+ $this->with_pmed = true;
+ return 'pmed';
+ }
+
+ protected function medalJoins()
+ {
+ $joins = array();
+ if ($this->with_pmed) {
+ $joins['pmed'] = PlSqlJoin::left('profile_medals', '$ME.pid = $PID');
+ }
+ return $joins;
+ }
+
+ /** DELTATEN
+ */
+ private $dts = array();
+ const DELTATEN = 1;
+ const DELTATEN_MESSAGE = 2;
+ // TODO: terms
+
+ public function addDeltaTenFilter($type)
+ {
+ $this->requireProfiles();
+ switch ($type) {
+ case self::DELTATEN:
+ $this->dts['pdt'] = 'profile_deltaten';
+ return 'pdt';
+ case self::DELTATEN_MESSAGE:
+ $this->dts['pdtm'] = 'profile_deltaten';
+ return 'pdtm';
+ default:
+ Platal::page()->killError("Undefined DeltaTen filter.");
+ }
+ }
+
+ protected function deltatenJoins()
+ {
+ $joins = array();
+ foreach ($this->dts as $sub => $tab) {
+ $joins[$sub] = PlSqlJoin::left($tab, '$ME.pid = $PID');
+ }
+ return $joins;
+ }
+
+ /** MENTORING
+ */
+
+ private $pms = array();
+ private $mjtr = false;
+ const MENTOR = 1;
+ const MENTOR_EXPERTISE = 2;
+ const MENTOR_COUNTRY = 3;
+ const MENTOR_TERM = 4;
+
+ public function addMentorFilter($type)
+ {
+ $this->requireProfiles();
+ switch($type) {
+ case self::MENTOR:
+ $this->pms['pm'] = 'profile_mentor';
+ return 'pm';
+ case self::MENTOR_EXPERTISE:
+ $this->pms['pme'] = 'profile_mentor';
+ return 'pme';
+ case self::MENTOR_COUNTRY:
+ $this->pms['pmc'] = 'profile_mentor_country';
+ return 'pmc';
+ case self::MENTOR_TERM:
+ $this->pms['pmt'] = 'profile_mentor_term';
+ $this->mjtr = true;
+ return 'mjtr';
+ default:
+ Platal::page()->killError("Undefined mentor filter.");
+ }
+ }
+
+ protected function mentorJoins()
+ {
+ $joins = array();
+ foreach ($this->pms as $sub => $tab) {
+ $joins[$sub] = PlSqlJoin::left($tab, '$ME.pid = $PID');
+ }
+ if ($this->mjtr) {
+ $joins['mjtr'] = PlSqlJoin::left('profile_job_term_relation', '$ME.jtid_2 = pmt.jtid');