X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fprofile.php;h=663f2f7a723ea33392cd3d96c6f2f5ea21b53188;hb=7996ae8cd41fbb3ccd748eaed71a50f866269c6e;hp=5ad9c545013287479a992b6da4f3360e95bd81a6;hpb=39e2c58c3c95dba85134a4a63433512dca8d3aec;p=platal.git diff --git a/classes/profile.php b/classes/profile.php index 5ad9c54..663f2f7 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -195,6 +195,25 @@ class Profile return intval(substr($this->promo, 1, 4)); } + /** Check if user is an orange (associated with several promos) + */ + public function isMultiPromo() + { + return $this->grad_year != $this->entry_year + $this->mainEducationDuration(); + } + + /** Returns an array with all associated promo years. + */ + public function yearspromo() + { + $promos = array(); + $d = -$this->deltaPromoToGradYear(); + for ($g = $this->entry_year + $this->mainEducationDuration(); $g <= $this->grad_year; ++$g) { + $promos[] = $g + $d; + } + return $promos; + } + public function mainEducation() { if (empty($this->promo)) { @@ -204,6 +223,20 @@ class Profile } } + public function mainGrade() + { + switch ($this->mainEducation()) { + case 'X': + return UserFilter::GRADE_ING; + case 'M': + return UserFilter::GRADE_MST; + case 'D': + return UserFilter::GRADE_PHD; + default: + return null; + } + } + public function mainEducationDuration() { switch ($this->mainEducation()) { @@ -218,6 +251,18 @@ class Profile } } + /** Number of years between the promotion year until the + * graduation year. In standard schools it's 0, but for + * Polytechnique the promo year is the entry year. + */ + public function deltaPromoToGradYear() + { + if ($this->mainEducation() == 'X') { + return $this->mainEducationDuration(); + } + return 0; + } + /** Print a name with the given formatting: * %s = • for women * %f = firstname @@ -343,6 +388,16 @@ class Profile return property_exists($this, $name) || isset($this->data[$name]); } + public function __unset($name) + { + if (property_exists($this, $name)) { + $this->$name = null; + } else { + unset($this->data[$name]); + } + } + + /** Sets the level of visibility of the profile * Sets $this->visibility to a list of valid visibilities. * @param one of the self::VIS_* values @@ -451,7 +506,10 @@ class Profile public function getAddresses($flags, $limit = null) { if ($this->addresses == null && !$this->fetched(self::FETCH_ADDRESSES)) { - $this->setAddresses($this->getProfileField(self::FETCH_ADDRESSES)); + $addr = $this->getProfileField(self::FETCH_ADDRESSES); + if ($addr) { + $this->setAddresses($addr); + } } if ($this->addresses == null) { @@ -548,7 +606,10 @@ class Profile public function getNetworking($flags, $limit = null) { if ($this->networks == null && !$this->fetched(self::FETCH_NETWORKING)) { - $this->setNetworking($this->getProfileField(self::FETCH_NETWORKING)); + $nw = $this->getProfileField(self::FETCH_NETWORKING); + if ($nw) { + $this->setNetworking($nw); + } } if ($this->networks == null) { return array(); @@ -563,7 +624,7 @@ class Profile return null; } $site = array_pop($site); - return $site['address']; + return $site; } @@ -579,7 +640,10 @@ class Profile public function getJobs($flags, $limit = null) { if ($this->jobs == null && !$this->fetched(self::FETCH_JOBS)) { - $this->setJobs($this->getProfileField(self::FETCH_JOBS)); + $jobs = $this->getProfileField(self::FETCH_JOBS); + if ($jobs) { + $this->setJobs($jobs); + } } if ($this->jobs == null) { @@ -888,7 +952,7 @@ class Profile WHERE n.pid = {?}", $pid); - foreach ($keys as $i => $key) { + while ($key = $keys->next()) { if ($key['name'] == '') { continue; }