X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvalidations%2Fmedals.inc.php;h=09c252015278d6c496f3b08b570e1f8167a353d7;hb=15d26d450f109e27b8fad7839d98ebae788147e7;hp=c308d4d982d7d5bf75166090a9f6df984f6707d6;hpb=a7de4ef724d1a3b0bf978a50ce7cc9d23412c7a0;p=platal.git diff --git a/include/validations/medals.inc.php b/include/validations/medals.inc.php index c308d4d..09c2520 100644 --- a/include/validations/medals.inc.php +++ b/include/validations/medals.inc.php @@ -1,6 +1,6 @@ Validate($_uid, false, 'medal', $_stamp); - $this->mid = $_idmedal; + parent::__construct($_user, $_profile, false, 'medal', $_stamp); + $this->mid = $_idmedal; $this->gid = $_subidmedal; + $this->level = $_level; + $this->has_levels = $has_levels; + if (is_null($this->gid)) { + $this->gid = 0; + } + if (!$this->has_levels) { + $this->level = ''; + } } // }}} // {{{ function formu() - function formu() - { - return 'include/form.valid.medals.tpl'; - } + public function formu() + { + return 'include/form.valid.medals.tpl'; + } // }}} // {{{ function _mail_subj - function _mail_subj() + 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(); } // }}} // {{{ function _mail_body - function _mail_body($isok) + 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.'; } } // }}} // {{{ function medal_name - function medal_name() + 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(); + $name = XDB::fetchOneCell('SELECT text + FROM profile_medal_enum + WHERE id = {?}', $this->mid); + $grade = XDB::fetchOneCell('SELECT text + FROM profile_medal_grade_enum + WHERE mid = {?} AND gid = {?}', + $this->mid, $this->gid); + if (is_null($grade)) { + return $name; + } + return $name . ' (' . $grade . ')'; } // }}} // {{{ function submit() - function submit() + public function submit() { - $res = XDB::query("SELECT FIND_IN_SET(flags, 'validation') - FROM profile_medals + $res = XDB::query("SELECT FIND_IN_SET('validation', flags) + FROM profile_medal_enum WHERE id = {?}", $this->mid); if ($res->fetchOneCell()) { parent::submit(); @@ -94,13 +108,31 @@ class MedalReq extends Validate $this->commit(); } } - + // }}} // {{{ function commit() - function commit () + 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, level) + VALUES ({?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE gid = VALUES(gid)', + $this->profile->id(), $this->mid, + is_null($this->gid) ? 0 : $this->gid, $this->level); + } + + // }}} + // {{{ function get_request($medal) + + static public function get_request($pid, $type, $grade, $level) + { + $reqs = parent::get_typed_requests($pid, 'medal'); + foreach ($reqs as &$req) { + if ($req->mid == $type && $req->gid == $grade && $req->level == $level) { + return $req; + } + } + return null; } // }}}