X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fprofile.php;h=b11e31d7ddd36adf8327e6e09184660072106192;hb=b0b1718db4bbbfd3474f3fbc5c83e6a51862e266;hp=b7a190cb49595e74e01047592da3906c1840d618;hpb=e22ff176d83e1f4ffd866e6ad928ee247906c6a5;p=platal.git diff --git a/classes/profile.php b/classes/profile.php index b7a190c..b11e31d 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -110,10 +110,13 @@ class Profile implements PlExportable const FETCH_JOB_TERMS = 0x000200; const FETCH_MENTOR_TERMS = 0x000400; const FETCH_DELTATEN = 0x000800; + const FETCH_PARTNER = 0x001000; + const FETCH_SKILL = 0x002000; + const FETCH_LANGUAGE = 0x004000; const FETCH_MINIFICHES = 0x00012D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_NETWORKING | FETCH_PHONES - const FETCH_ALL = 0x000FFF; // OR of FETCH_* + const FETCH_ALL = 0x007FFF; // OR of FETCH_* static public $descriptions = array( 'search_names' => 'Noms', @@ -160,12 +163,12 @@ class Profile implements PlExportable private $visibility = null; - private function __construct(array $data) + private function __construct(array $data, Visibility $visibility) { $this->data = $data; $this->pid = $this->data['pid']; $this->hrpid = $this->data['hrpid']; - $this->visibility = new ProfileVisibility(); + $this->visibility = $visibility; } public function id() @@ -318,6 +321,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 @@ -353,7 +366,7 @@ class Profile implements PlExportable public function firstName() { - return $this->firstname; + return $this->firstname_ordinary; } public function firstNames() @@ -363,7 +376,7 @@ class Profile implements PlExportable public function lastName() { - return $this->lastname; + return $this->lastname_ordinary; } public function lastNames() @@ -384,7 +397,7 @@ class Profile implements PlExportable public function displayEmail() { $o = $this->owner(); - if ($o != null) { + if ($o != null && $this->isVisible(Visibility::EXPORT_PRIVATE)) { return $o->bestEmail(); } else { return $this->email_directory; @@ -458,7 +471,8 @@ class Profile implements PlExportable * Clears a profile. * *always deletes in: profile_addresses, profile_binets, profile_deltaten, * profile_job, profile_langskills, profile_mentor, profile_networking, - * profile_phones, profile_skills, watch_profile + * profile_partnersharing_settings, profile_phones, profile_skills, + * watch_profile * *always keeps in: profile_corps, profile_display, profile_education, * profile_medals, profile_*_names, profile_photos, search_name * *modifies: profiles @@ -469,7 +483,7 @@ class Profile implements PlExportable 'profile_job', 'profile_langskills', 'profile_mentor', 'profile_networking', 'profile_skills', 'watch_profile', 'profile_phones', 'profile_addresses', 'profile_binets', - 'profile_deltaten'); + 'profile_deltaten', 'profile_partnersharing_settings'); foreach ($tables as $t) { XDB::execute('DELETE FROM ' . $t . ' @@ -479,21 +493,12 @@ 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()); } - /** Sets the level of visibility of the profile - * Sets $this->visibility to a list of valid visibilities. - * @param one of the self::VIS_* values - */ - public function setVisibilityLevel($visibility) - { - $this->visibility->setLevel($visibility); - } - /** Determine whether an item with visibility $visibility can be displayed * with the current level of visibility of the profile * @param $visibility The level of visibility to be checked @@ -683,7 +688,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) { @@ -708,7 +716,10 @@ 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; } @@ -803,7 +814,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) { @@ -830,7 +844,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) { @@ -840,6 +857,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 */ @@ -883,7 +944,7 @@ class Profile implements PlExportable */ public function getBinets() { - if ($this->visibility->isVisible(ProfileVisibility::VIS_PRIVATE)) { + if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) { return XDB::fetchColumn('SELECT binet_id FROM profile_binets WHERE pid = {?}', $this->id()); @@ -891,9 +952,22 @@ 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(ProfileVisibility::VIS_PRIVATE)) { + if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) { return XDB::fetchColumn('SELECT text FROM profile_binets AS pb LEFT JOIN profile_binet_enum AS pbe ON (pbe.id = pb.binet_id) @@ -914,7 +988,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(); @@ -922,6 +999,28 @@ class Profile implements PlExportable return $this->medals->medals; } + /** Sharing data with partner websites + */ + private $partners_settings = null; + public function setPartnersSettings(ProfilePartnerSharing $partners_settings) + { + $this->partners_settings = $partners_settings; + } + + public function getPartnerSettings($partner_id) + { + if ($this->partners_settings === null && !$this->fetched(self::FETCH_PARTNER)) { + $settings = $this->getProfileField(self::FETCH_PARTNER); + if ($settings) { + $this->setPartnersSettings($settings); + } + } + if ($this->partners_settings === null) { + return PartnerSettings::getEmpty($partner_id); + } + return $this->partners_settings->get($partner_id); + } + public function compareNames($firstname, $lastname) { $_lastname = mb_strtoupper($this->lastName()); @@ -971,22 +1070,24 @@ class Profile implements PlExportable $order = ''; } - $visibility = new ProfileVisibility($visibility); + if ($visibility === null) { + $visibility = Visibility::defaultForRead(); + } $it = XDB::Iterator('SELECT p.pid, p.hrpid, p.xorg_id, p.ax_id, p.birthdate, p.birthdate_ref, p.next_birthday, p.deathdate, p.deathdate_rec, p.sex = \'female\' AS sex, IF ({?}, p.cv, NULL) AS cv, p.medals_pub, p.alias_pub, p.email_directory, p.last_change, p.nationality1, p.nationality2, p.nationality3, - IF (p.freetext_pub IN {?}, p.freetext, NULL) AS freetext, + IF (p.freetext_pub >= {?}, p.freetext, NULL) AS freetext, pe.entry_year, pe.grad_year, pe.promo_year, pe.program, pe.fieldid, 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 IN {?}, pp.display_tel, NULL) AS mobile, - (ph.pub IN {?} AND ph.attach IS NOT NULL) AS has_photo, + IF (pp.pub >= {?}, pp.display_tel, NULL) AS mobile, + (ph.pub >= {?} AND ph.attach IS NOT NULL) AS has_photo, ph.pub as photo_pub, ph.x AS photo_width, ph.y AS photo_height, p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old, pm.expertise AS mentor_expertise, @@ -1006,13 +1107,13 @@ class Profile implements PlExportable WHERE p.pid IN {?} GROUP BY p.pid ' . $order, - $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // CV - $visibility->levels(), // freetext - $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // section - $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // nickname - $visibility->levels(), // mobile - $visibility->levels(), // photo - $visibility->isVisible(ProfileVisibility::VIS_PRIVATE), // deltaten_message + $visibility->isVisible(Visibility::EXPORT_PRIVATE), // CV + $visibility->level(), // freetext + $visibility->isVisible(Visibility::EXPORT_PRIVATE), // section + $visibility->isVisible(Visibility::EXPORT_PRIVATE), // nickname + $visibility->level(), // mobile + $visibility->level(), // photo + $visibility->isVisible(Visibility::EXPORT_PRIVATE), // deltaten_message $pids ); return new ProfileIterator($it, $pids, $fields, $visibility); @@ -1054,9 +1155,12 @@ class Profile implements PlExportable */ public static function get($login, $fields = 0x0000, $visibility = null) { + if ($visibility === null) { + $visibility = Visibility::defaultForRead(); + } + if (is_array($login)) { - $pf = new Profile($login); - $pf->setVisibilityLevel($visibility); + $pf = new Profile($login, $visibility); return $pf; } $pid = self::getPID($login); @@ -1069,7 +1173,7 @@ class Profile implements PlExportable if (!($login instanceof PlUser)) { $user = User::getSilent($login); if ($user && $user->hasProfile()) { - return $user->profile(); + return $user->profile(false, $fields, $visibility); } } return null; @@ -1123,18 +1227,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'; } } @@ -1271,12 +1376,12 @@ class ProfileIterator implements PlIterator const FETCH_ALL = 0x000033F; // FETCH_ADDRESSES | FETCH_CORPS | FETCH_EDU | FETCH_JOBS | FETCH_MEDALS | FETCH_NETWORKING | FETCH_PHONES | FETCH_JOB_TERMS - public function __construct(PlIterator $it, array $pids, $fields = 0x0000, ProfileVisibility $visibility = null) + public function __construct(PlIterator $it, array $pids, $fields = 0x0000, $visibility = null) { require_once 'profilefields.inc.php'; - if ($visibility == null) { - $visibility = new ProfileVisibility(); + if ($visibility === null) { + $visibility = Visibility::defaultForRead(); } $this->fields = $fields; @@ -1307,8 +1412,7 @@ class ProfileIterator implements PlIterator private function fillProfile(array $vals) { - $pf = Profile::get($vals[0]); - $pf->setVisibilityLevel($this->visibility->level()); + $pf = Profile::get($vals[0], 0x0, $this->visibility); $pf->setFetchedFields($this->fields); if ($this->hasData(Profile::FETCH_PHONES, $vals)) {