2 /***************************************************************************
3 * Copyright (C) 2003-2013 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
24 class MedalReq
extends ProfileValidate
36 public function __construct(User
$_user, Profile
$_profile, $_idmedal, $_subidmedal, $_level, $has_levels, $_stamp = 0)
38 parent
::__construct($_user, $_profile, false
, 'medal', $_stamp);
39 $this->mid
= $_idmedal;
40 $this->gid
= $_subidmedal;
41 $this->level
= $_level;
42 $this->has_levels
= $has_levels;
43 if (is_null($this->gid
)) {
46 if (!$this->has_levels
) {
52 // {{{ function formu()
54 public function formu()
56 return 'include/form.valid.medals.tpl';
60 // {{{ function _mail_subj
62 protected function _mail_subj()
64 return '[Polytechnique.org/Décoration] Demande de décoration : ' . $this->medal_name();
68 // {{{ function _mail_body
70 protected function _mail_body($isok)
73 return ' La décoration ' . $this->medal_name() . ' vient d\'être ajoutée à ta fiche.';
75 return ' La demande que tu avais faite pour la décoration ' . $this->medal_name() . ' a été refusée.';
80 // {{{ function medal_name
82 public function medal_name()
84 $name = XDB
::fetchOneCell('SELECT text
85 FROM profile_medal_enum
86 WHERE id = {?}', $this->mid
);
87 $grade = XDB
::fetchOneCell('SELECT text
88 FROM profile_medal_grade_enum
89 WHERE mid = {?} AND gid = {?}',
90 $this->mid
, $this->gid
);
91 if (is_null($grade)) {
94 return $name . ' (' . $grade . ')';
98 // {{{ function submit()
100 public function submit()
102 $res = XDB
::query("SELECT FIND_IN_SET('validation', flags)
103 FROM profile_medal_enum
104 WHERE id = {?}", $this->mid
);
105 if ($res->fetchOneCell()) {
113 // {{{ function commit()
115 public function commit ()
117 return XDB
::execute('INSERT INTO profile_medals (pid, mid, gid, level)
118 VALUES ({?}, {?}, {?}, {?})
119 ON DUPLICATE KEY UPDATE gid = VALUES(gid)',
120 $this->profile
->id(), $this->mid
,
121 is_null($this->gid
) ?
0 : $this->gid
, $this->level
);
125 // {{{ function get_request($medal)
127 static public function get_request($pid, $type, $grade, $level)
129 $reqs = parent
::get_typed_requests($pid, 'medal');
130 foreach ($reqs as &$req) {
131 if ($req->mid
== $type && $req->gid
== $grade && $req->level
== $level) {
143 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: