X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fprofile.php;h=0f5eb73d0b7a380023a793b735f39e170f1d9249;hb=bc0276a2d79d88a56656514fe24bd427c0ef3b88;hp=6574d0a3b85e8a035b36444df36135a0cda53c9e;hpb=d89a495539357b3ad30f7b891bd23d1805355a52;p=platal.git diff --git a/classes/profile.php b/classes/profile.php index 6574d0a..0f5eb73 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -1,6 +1,6 @@ 'Noms', @@ -169,6 +171,13 @@ class Profile implements PlExportable $this->visibility = $visibility; } + public function __destruct() + { + // Need to delete objects allocated by the profile + // http://www.php.net/manual/en/function.unset.php#98692 + unset($this->owner); + } + public function id() { return $this->pid; @@ -319,6 +328,16 @@ class Profile implements PlExportable } } + // Returns younger/older promotion year for a given education. + static public function extremePromotions($education) + { + return XDB::fetchOneRow("SELECT MIN(pe.promo_year) AS min, MAX(pe.promo_year) AS max + FROM profile_education AS pe + INNER JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id) + WHERE pede.degree = {?} AND FIND_IN_SET('primary', pe.flags)", + $education); + } + /** Print a name with the given formatting: * %s = • for women * %f = firstname @@ -354,7 +373,7 @@ class Profile implements PlExportable public function firstName() { - return $this->firstname; + return $this->firstname_ordinary; } public function firstNames() @@ -364,7 +383,7 @@ class Profile implements PlExportable public function lastName() { - return $this->lastname; + return $this->lastname_ordinary; } public function lastNames() @@ -481,7 +500,7 @@ class Profile implements PlExportable XDB::execute("UPDATE profiles SET cv = NULL, freetext = NULL, freetext_pub = 'private', - medals_pub = 'private', alias_pub = 'private', + medals_pub = 'private', alias_pub = 'hidden', email_directory = NULL WHERE pid = {?}", $this->id()); @@ -676,7 +695,10 @@ class Profile implements PlExportable public function getEducations($flags, $limit = null) { if ($this->educations == null && !$this->fetched(self::FETCH_EDU)) { - $this->setEducations($this->getProfileField(self::FETCH_EDU)); + $educations = $this->getProfileField(self::FETCH_EDU); + if ($educations) { + $this->setEducations($educations); + } } if ($this->educations == null) { @@ -701,11 +723,42 @@ class Profile implements PlExportable public function getCorps() { if ($this->corps == null && !$this->fetched(self::FETCH_CORPS)) { - $this->setCorps($this->getProfileField(self::FETCH_CORPS)); + $corps = $this->getProfileField(self::FETCH_CORPS); + if ($corps) { + $this->setCorps($corps); + } } return $this->corps; } + /** + * Retrieve the name of the corps which has been done. + * + * Note: this function first tries getCorps(), and if this field is blank + * tries to find an education which degree is "Corps". + * + * Returns an empty string if nothing has been found. + */ + public function getCorpsName() + { + $corps = $this->getCorps(); + if ($corps && $corps->current) { + $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS); + return $corpsList[$corps->current]; + } + + foreach ($this->getExtraEducations() as $edu) { + if (!strcasecmp($edu->degree, 'Corps')) { + if ($edu->school_short) { + return $edu->school_short; + } elseif ($edu->school) { + return $edu->school; + } + } + } + return ''; + } + /** Networking */ private $networks = null; @@ -796,7 +849,10 @@ class Profile implements PlExportable public function getMentoringCountries() { if ($this->mentor_countries == null && !$this->fetched(self::FETCH_MENTOR_COUNTRY)) { - $this->setMentoringCountries($this->getProfileField(self::FETCH_MENTOR_COUNTRY)); + $countries = $this->getProfileField(self::FETCH_MENTOR_COUNTRY); + if ($countries) { + $this->setMentoringCountries($countries); + } } if ($this->mentor_countries == null) { @@ -823,7 +879,10 @@ class Profile implements PlExportable public function getMentoringTerms() { if ($this->mentor_terms == null && !$this->fetched(self::FETCH_MENTOR_TERMS)) { - $this->setMentoringTerms($this->getProfileField(self::FETCH_MENTOR_TERMS)); + $terms = $this->getProfileField(self::FETCH_MENTOR_TERMS); + if ($terms) { + $this->setMentoringTerms($terms); + } } if ($this->mentor_terms == null) { @@ -833,6 +892,50 @@ class Profile implements PlExportable } } + /* Skills */ + private $skills = null; + public function setSkills(ProfileSkills $skills) + { + $this->skills = $skills; + } + public function getSkills() + { + if ($this->skills == null && !$this->fetched(self::FETCH_SKILL)) { + $skills = $this->getProfileField(self::FETCH_SKILL); + if ($skills) { + $this->setSkills($skills); + } + } + + if ($this->skills == null) { + return array(); + } else { + return $this->skills->skills; + } + } + + /* Languades */ + private $languages = null; + public function setLanguages(ProfileLanguages $languages) + { + $this->languages = $languages; + } + public function getLanguages() + { + if ($this->languages == null && !$this->fetched(self::FETCH_LANGUAGE)) { + $languages = $this->getProfileField(self::FETCH_LANGUAGE); + if ($languages) { + $this->setLanguages($languages); + } + } + + if ($this->languages == null) { + return array(); + } else { + return $this->languages->languages; + } + } + /** DeltaTen */ @@ -884,6 +987,19 @@ class Profile implements PlExportable return array(); } } + + public function getFullBinets() + { + if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) { + return XDB::fetchAllAssoc('SELECT binet_id, text, url + FROM profile_binets AS pb + LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id) + WHERE pid = {?}', $this->id()); + } else { + return array(); + } + } + public function getBinetsNames() { if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) { @@ -907,7 +1023,10 @@ class Profile implements PlExportable public function getMedals() { if ($this->medals == null && !$this->fetched(self::FETCH_MEDALS)) { - $this->setMedals($this->getProfileField(self::FETCH_MEDALS)); + $medals = $this->getProfileField(self::FETCH_MEDALS); + if ($medals) { + $this->setMedals($medals); + } } if ($this->medals == null) { return array(); @@ -926,7 +1045,10 @@ class Profile implements PlExportable public function getPartnerSettings($partner_id) { if ($this->partners_settings === null && !$this->fetched(self::FETCH_PARTNER)) { - $this->setPartnersSettings($this->getProfileField(self::FETCH_PARTNER)); + $settings = $this->getProfileField(self::FETCH_PARTNER); + if ($settings) { + $this->setPartnersSettings($settings); + } } if ($this->partners_settings === null) { return PartnerSettings::getEmpty($partner_id); @@ -996,7 +1118,7 @@ class Profile implements PlExportable IF ({?}, pse.text, NULL) AS section, ppn.firstname_main AS firstname, ppn.lastname_main AS lastname, IF ({?}, pn.name, NULL) AS nickname, IF (ppn.firstname_ordinary = \'\', ppn.firstname_main, ppn.firstname_ordinary) AS firstname_ordinary, - IF (ppn.lastname_ordinary = \'\', ppn.firstname_main, ppn.lastname_ordinary) AS lastname_ordinary, + IF (ppn.lastname_ordinary = \'\', ppn.lastname_main, ppn.lastname_ordinary) AS lastname_ordinary, pd.yourself, pd.promo, pd.short_name, pd.public_name AS full_name, pd.directory_name, pd.public_name, pd.private_name, IF (pp.pub >= {?}, pp.display_tel, NULL) AS mobile, @@ -1140,18 +1262,19 @@ class Profile implements PlExportable */ public static function getAccountEquivalentName($name) { - switch ($name) - { - case self::DN_DIRECTORY: - case self::DN_SORT: + switch ($name) { + case self::DN_DIRECTORY: return 'directory_name'; - case self::DN_FULL: - case self::DN_PUBLIC: + case self::DN_SORT: + return 'sort_name'; + case self::DN_FULL: + case self::DN_PUBLIC: + case self::DN_PRIVATE: + case self::DN_SHORT: return 'full_name'; - case self::DN_PRIVATE: - case self::DN_SHORT: - case self::DN_YOURSELF: - default: + case self::DN_YOURSELF: + return 'display_name'; + default: return 'display_name'; } }