<?php
/***************************************************************************
- * Copyright (C) 2003-2008 Polytechnique.org *
+ * Copyright (C) 2003-2011 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
// {{{ class MedalReq
-class MedalReq extends Validate
+class MedalReq extends ProfileValidate
{
// {{{ properties
// }}}
// {{{ constructor
- public function __construct($_uid, $_idmedal, $_subidmedal, $_stamp=0)
+ public function __construct(User $_user, Profile $_profile, $_idmedal, $_subidmedal, $_stamp = 0)
{
- parent::__construct($_uid, false, 'medal', $_stamp);
- $this->mid = $_idmedal;
+ parent::__construct($_user, $_profile, false, 'medal', $_stamp);
+ $this->mid = $_idmedal;
$this->gid = $_subidmedal;
+ if (is_null($this->gid)) {
+ $this->gid = 0;
+ }
}
// }}}
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();
}
// }}}
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.';
}
}
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 . ')';
}
// }}}
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();
public function commit ()
{
- require_once 'notifs.inc.php';
- register_watch_op($this->uid, WATCH_FICHE, 'medals');
- 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($uid, $type)
+ static public function get_request($pid, $type, $grade)
{
- $reqs = Validate::get_typed_requests($uid, 'medal');
+ $reqs = parent::get_typed_requests($pid, 'medal');
foreach ($reqs as &$req) {
- if ($req->mid == $type) {
+ if ($req->mid == $type && $req->gid == $grade) {
return $req;
}
}