X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations%2Fmedals.inc.php;h=dbfbb4b2083b73e0b02ff09a0944c1a25c5d9f2d;hb=cafb410fea6f257f45da08631c6cdb5c35f86b17;hp=e419e4605016551f7f397528e75288b4035ba519;hpb=eaf30d86cc99df2414cf4f171a9b0f11b0561e3b;p=platal.git diff --git a/include/validations/medals.inc.php b/include/validations/medals.inc.php index e419e46..dbfbb4b 100644 --- a/include/validations/medals.inc.php +++ b/include/validations/medals.inc.php @@ -1,6 +1,6 @@ mid = $_idmedal; + parent::__construct($_user, $_profile, false, 'medal', $_stamp); + $this->mid = $_idmedal; $this->gid = $_subidmedal; + if (is_null($this->gid)) { + $this->gid = 0; + } } // }}} @@ -51,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(); } // }}} @@ -60,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.'; } } @@ -71,13 +74,10 @@ class MedalReq extends Validate public function medal_name() { - //var_dump($this); - $r = XDB::query(" - SELECT IF (g.text IS NOT NULL, CONCAT(m.text,' - ', g.text), m.text) - FROM profile_medals AS m - LEFT JOIN profile_medals_grades AS g ON(g.mid = m.id AND g.gid = {?}) - WHERE m.id = {?}", $this->gid, $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(); } // }}} @@ -86,7 +86,7 @@ class MedalReq extends Validate public function submit() { $res = XDB::query("SELECT FIND_IN_SET('validation', flags) - FROM profile_medals + FROM profile_medal_enum WHERE id = {?}", $this->mid); if ($res->fetchOneCell()) { parent::submit(); @@ -100,7 +100,25 @@ class MedalReq extends Validate public function commit () { - return XDB::execute('REPLACE INTO profile_medals_sub VALUES({?}, {?}, {?})', $this->uid, $this->mid, $this->gid); + return XDB::execute('INSERT INTO profile_medals (pid, mid, gid) + VALUES ({?}, {?}, {?}) + ON DUPLICATE KEY UPDATE gid = VALUES(gid)', + $this->profile->id(), $this->mid, + is_null($this->gid) ? 0 : $this->gid); + } + + // }}} + // {{{ function get_request($medal) + + static public function get_request($pid, $type) + { + $reqs = parent::get_typed_requests($pid, 'medal'); + foreach ($reqs as &$req) { + if ($req->mid == $type) { + return $req; + } + } + return null; } // }}}