From: Stéphane Jacob Date: Mon, 28 Jun 2010 07:54:47 +0000 (+0200) Subject: Adapts profile related validation requests to ProfileValidate. X-Git-Tag: xorg/1.0.0~12 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=c3d1e6b6f02b31adc59d058899814fea9d046d70;p=platal.git Adapts profile related validation requests to ProfileValidate. Signed-off-by: Stéphane Jacob --- diff --git a/include/validations/entreprises.inc.php b/include/validations/entreprises.inc.php index 6becf7a..6734855 100644 --- a/include/validations/entreprises.inc.php +++ b/include/validations/entreprises.inc.php @@ -21,7 +21,7 @@ // {{{ class EntrReq -class EntrReq extends Validate +class EntrReq extends ProfileValidate { // {{{ properties @@ -43,9 +43,9 @@ class EntrReq extends Validate // }}} // {{{ constructor - public function __construct(User &$_user, $_id, $_name, $_acronym, $_url, $_email, $_tel, $_fax, $_address, $_stamp = 0) + public function __construct(User &$_user, Profile &$_profile, $_id, $_name, $_acronym, $_url, $_email, $_tel, $_fax, $_address, $_stamp = 0) { - parent::__construct($_user, false, 'entreprise', $_stamp); + parent::__construct($_user, $_profile, false, 'entreprise', $_stamp); $this->id = $_id; $this->name = $_name; $this->acronym = $_acronym; @@ -99,18 +99,18 @@ class EntrReq extends Validate protected function handle_editor() { if (Env::has('holdingid')) { - $this->holdingid = trim(Env::v('holdingid')); + $this->holdingid = Env::t('holdingid'); } if (Env::has('name')) { - $this->name = trim(Env::v('name')); + $this->name = Env::t('name'); if (Env::has('acronym')) { - $this->acronym = trim(Env::v('acronym')); + $this->acronym = Env::t('acronym'); if (Env::has('url')) { - $this->url = trim(Env::v('url')); + $this->url = Env::t('url'); if (Env::has('NAF_code')) { - $this->NAF_code = trim(Env::v('NAF_code')); + $this->NAF_code = Env::t('NAF_code'); if (Env::has('AX_code')) { - $this->AX_code = trim(Env::v('AX_code')); + $this->AX_code = Env::t('AX_code'); return true; } } @@ -196,7 +196,7 @@ class EntrReq extends Validate return XDB::execute('UPDATE profile_job SET jobid = {?} WHERE pid = {?} AND id = {?}', - $jobid, $this->user->profile()->id(), $this->id); + $jobid, $this->profile->id(), $this->id); } // }}} diff --git a/include/validations/medals.inc.php b/include/validations/medals.inc.php index 32455e8..df04da6 100644 --- a/include/validations/medals.inc.php +++ b/include/validations/medals.inc.php @@ -21,7 +21,7 @@ // {{{ class MedalReq -class MedalReq extends Validate +class MedalReq extends ProfileValidate { // {{{ properties @@ -31,9 +31,9 @@ class MedalReq extends Validate // }}} // {{{ constructor - public function __construct(User &$_user, $_idmedal, $_subidmedal, $_stamp=0) + public function __construct(User &$_user, Profile &$_profile, $_idmedal, $_subidmedal, $_stamp = 0) { - parent::__construct($_user, false, 'medal', $_stamp); + parent::__construct($_user, $_profile, false, 'medal', $_stamp); $this->mid = $_idmedal; $this->gid = $_subidmedal; if (is_null($this->gid)) { @@ -54,7 +54,7 @@ class MedalReq extends Validate protected function _mail_subj() { - return "[Polytechnique.org/Décoration] Demande de décoration : ".$this->medal_name(); + return '[Polytechnique.org/Décoration] Demande de décoration : ' . $this->medal_name(); } // }}} @@ -63,9 +63,9 @@ class MedalReq extends Validate protected function _mail_body($isok) { if ($isok) { - return " La décoration ".$this->medal_name()." vient d'être ajoutée à ta fiche."; + return ' La décoration ' . $this->medal_name() . ' vient d\'être ajoutée à ta fiche.'; } else { - return " La demande que tu avais faite pour la décoration ".$this->medal_name()." a été refusée."; + return ' La demande que tu avais faite pour la décoration ' . $this->medal_name() . ' a été refusée.'; } } @@ -74,11 +74,10 @@ class MedalReq extends Validate public function medal_name() { - $r = XDB::query(" - SELECT m.text - FROM profile_medal_enum AS m - WHERE m.id = {?}", $this->mid); - return $r->fetchOneCell(); + $res = XDB::query('SELECT m.text + FROM profile_medal_enum AS m + WHERE m.id = {?}', $this->mid); + return $res->fetchOneCell(); } // }}} @@ -103,16 +102,16 @@ class MedalReq extends Validate { return XDB::execute('REPLACE INTO profile_medals VALUES ({?}, {?}, {?})', - $this->user->profile()->id(), $this->mid, + $this->profile->id(), $this->mid, is_null($this->gid) ? 0 : $this->gid); } // }}} // {{{ function get_request($medal) - static public function get_request($uid, $type) + static public function get_request($pid, $type) { - $reqs = Validate::get_typed_requests($uid, 'medal'); + $reqs = parent::get_typed_requests($pid, 'medal'); foreach ($reqs as &$req) { if ($req->mid == $type) { return $req; diff --git a/include/validations/names.inc.php b/include/validations/names.inc.php index 3bdd3f3..08fd85b 100644 --- a/include/validations/names.inc.php +++ b/include/validations/names.inc.php @@ -21,7 +21,7 @@ // {{{ class NamesReq4 -class NamesReq extends Validate +class NamesReq extends ProfileValidate { // {{{ properties @@ -39,36 +39,39 @@ class NamesReq extends Validate // }}} // {{{ constructor - public function __construct(User &$_user, $_search_names, $_private_name_end) + public function __construct(User &$_user, Profile &$_profile, $_search_names, $_private_name_end) { - parent::__construct($_user, true, 'usage'); + parent::__construct($_user, $_profile, true, 'usage'); require_once 'name.func.inc.php'; $this->sn_types = build_types(); - $this->sn_old = build_sn_pub($this->user->profile()->id()); + $this->sn_old = build_sn_pub($this->profile->id()); $this->sn_new = $_search_names; $this->new_alias = true; $this->display_names = array(); build_display_names($this->display_names, $_search_names, - $this->user->profile()->isFemale(), $_private_name_end, $this->new_alias); + $this->profile->isFemale(), $_private_name_end, $this->new_alias); foreach ($this->sn_new AS $key => &$sn) { if (!isset($sn['pub'])) { unset($this->sn_new[$key]); } } - $res = XDB::query("SELECT alias - FROM aliases - WHERE uid = {?} AND type = 'alias' AND FIND_IN_SET('usage', flags)", - $this->user->id()); - $this->old_alias = $res->fetchOneCell(); - if ($this->old_alias != $this->new_alias) { - $res = XDB::query("SELECT uid + + if (!is_null($this->profileOwner)) { + $res = XDB::query("SELECT alias FROM aliases - WHERE alias = {?}", - $this->new_alias); - if ($res->fetchOneCell()) { - $this->new_alias = null; + WHERE uid = {?} AND type = 'alias' AND FIND_IN_SET('usage', flags)", + $this->profileOwner->id()); + $this->old_alias = $res->fetchOneCell(); + if ($this->old_alias != $this->new_alias) { + $res = XDB::query("SELECT uid + FROM aliases + WHERE alias = {?}", + $this->new_alias); + if ($res->fetchOneCell()) { + $this->new_alias = null; + } } } } @@ -97,19 +100,21 @@ class NamesReq extends Validate global $globals; if ($isok) { $res = " Le changement de nom que tu as demandé vient d'être effectué."; - if ($this->old_alias != $this->new_alias) { - if ($this->old_alias) { - $res .= "\n\n Les alias {$this->old_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} ont été supprimés."; + if (!is_null($this->profileOwner)) { + if ($this->old_alias != $this->new_alias) { + if ($this->old_alias) { + $res .= "\n\n Les alias {$this->old_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} ont été supprimés."; + } + if ($this->new_alias) { + $res .= "\n\n Les alias {$this->new_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} sont maintenant à ta disposition !"; + } } - if ($this->new_alias) { - $res .= "\n\n Les alias {$this->new_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} sont maintenant à ta disposition !"; - } - } - if ($globals->mailstorage->googleapps_domain) { - require_once 'googleapps.inc.php'; - $account = new GoogleAppsAccount($this->user); - if ($account->active()) { - $res .= "\n\n Si tu utilises Google Apps, tu peux changer ton nom d'usage sur https://mail.google.com/a/polytechnique.org/#settings/accounts."; + if ($globals->mailstorage->googleapps_domain) { + require_once 'googleapps.inc.php'; + $account = new GoogleAppsAccount($this->profileOwner); + if ($account->active()) { + $res .= "\n\n Si tu utilises Google Apps, tu peux changer ton nom d'usage sur https://mail.google.com/a/polytechnique.org/#settings/accounts."; + } } } return $res; @@ -125,12 +130,15 @@ class NamesReq extends Validate { require_once 'name.func.inc.php'; - set_profile_display($this->display_names, $this->user->profile()->id()); - set_alias_names($this->sn_new, $this->sn_old, $this->user->profile()->id(), - $this->user->id(), true, $this->new_alias); + set_profile_display($this->display_names, $this->profile->id()); - // Update the local User object, to pick up the new bestalias. - $this->user = User::getSilent($this->user->id()); + if (!is_null($this->profileOwner)) { + set_alias_names($this->sn_new, $this->sn_old, $this->profile->id(), + $this->profileOwner->id(), true, $this->new_alias); + + // Update the local User object, to pick up the new bestalias. + $this->profileOwner = User::getSilent($this->profileOwner->id()); + } return true; } diff --git a/include/validations/orange.inc.php b/include/validations/orange.inc.php index e2e2987..068aff8 100644 --- a/include/validations/orange.inc.php +++ b/include/validations/orange.inc.php @@ -21,7 +21,7 @@ // {{{ class OrangeReq -class OrangeReq extends Validate +class OrangeReq extends ProfileValidate { // {{{ properties @@ -38,13 +38,14 @@ class OrangeReq extends Validate // }}} // {{{ constructor - public function __construct(User &$_user, $_newGradYear) + public function __construct(User &$_user, Profile &$_profile, $_newGradYear) { - parent::__construct($_user, true, 'orange'); + parent::__construct($_user, $_profile, true, 'orange'); $this->newGradYear = $_newGradYear; $res = XDB::query("SELECT entry_year, grad_year FROM profile_education - WHERE pid = {?} AND FIND_IN_SET('primary', flags)", $this->user->profile()->id()); + WHERE pid = {?} AND FIND_IN_SET('primary', flags)", + $this->profile->id()); $years = $res->fetchOneRow(); $this->entryYear = $years[0]; $this->oldGradYear = $years[1]; @@ -88,7 +89,7 @@ class OrangeReq extends Validate XDB::execute("UPDATE profile_education SET grad_year = {?} WHERE pid = {?} AND FIND_IN_SET('primary', flags)", - $this->newGradYear, $this->user->profile()->id()); + $this->newGradYear, $this->profile->id()); return true; } diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index f78607d..60b6ae1 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -21,7 +21,7 @@ // {{{ class PhotoReq -class PhotoReq extends Validate +class PhotoReq extends ProfileValidate { // {{{ properties @@ -43,9 +43,9 @@ class PhotoReq extends Validate // }}} // {{{ constructor - public function __construct(User &$_user, PlUpload &$upload, $_stamp=0) + public function __construct(User &$_user, Profile &$_profile, PlUpload &$upload, $_stamp = 0) { - parent::__construct($_user, true, 'photo', $_stamp); + parent::__construct($_user, $_profile, true, 'photo', $_stamp); $this->read($upload); } @@ -56,7 +56,7 @@ class PhotoReq extends Validate { $this->valid = $upload->resizeImage(240, 300, 160, 0, SIZE_MAX); if (!$this->valid) { - $this->trigError('Le fichier que tu as transmis n\'est pas une image valide, ou est trop gros pour être traité'); + $this->trigError('Le fichier que tu as transmis n\'est pas une image valide, ou est trop gros pour être traité.'); } $this->data = $upload->getContents(); list($this->x, $this->y, $this->mimetype) = $upload->imageInfo(); @@ -64,7 +64,7 @@ class PhotoReq extends Validate } // }}} - // {{{ function isValid() + // {{{ function isValid() public function isValid() { @@ -74,9 +74,9 @@ class PhotoReq extends Validate // }}} // {{{ function get_request() - static public function get_request($uid) + static public function get_request($pid) { - return parent::get_typed_request($uid, 'photo'); + return parent::get_typed_request($pid, 'photo'); } // }}} @@ -103,7 +103,7 @@ class PhotoReq extends Validate if (isset($_FILES['userfile'])) { $upload =& PlUpload::get($_FILES['userfile'], S::user()->login(), 'photo'); if (!$upload) { - $this->trigError('Une erreur est survenue lors du téléchargement du fichier'); + $this->trigError('Une erreur est survenue lors du téléchargement du fichier.'); return false; } $this->read($upload); @@ -139,7 +139,7 @@ class PhotoReq extends Validate { XDB::execute('REPLACE INTO profile_photos (pid, attachmime, attach, x, y) VALUES ({?},{?},{?},{?},{?})', - $this->user->profile()->id(), $this->mimetype, $this->data, $this->x, $this->y); + $this->profile->id(), $this->mimetype, $this->data, $this->x, $this->y); return true; }