<?php
/***************************************************************************
- * Copyright (C) 2003-2010 Polytechnique.org *
+ * Copyright (C) 2003-2014 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
public $mid;
public $gid;
+ public $level;
+ public $has_levels;
// }}}
// {{{ constructor
- public function __construct(User &$_user, Profile &$_profile, $_idmedal, $_subidmedal, $_stamp = 0)
+ public function __construct(User $_user, Profile $_profile, $_idmedal, $_subidmedal, $_level, $has_levels, $_stamp = 0)
{
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 = '';
+ }
}
// }}}
public function medal_name()
{
- $res = XDB::query('SELECT m.text
- FROM profile_medal_enum AS m
- WHERE m.id = {?}', $this->mid);
- return $res->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 commit ()
{
- return XDB::execute('INSERT INTO profile_medals (pid, mid, gid)
- VALUES ({?}, {?}, {?})
+ 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);
+ is_null($this->gid) ? 0 : $this->gid, $this->level);
}
// }}}
// {{{ function get_request($medal)
- static public function get_request($pid, $type)
+ static public function get_request($pid, $type, $grade, $level)
{
$reqs = parent::get_typed_requests($pid, 'medal');
foreach ($reqs as &$req) {
- if ($req->mid == $type) {
+ if ($req->mid == $type && $req->gid == $grade && $req->level == $level) {
return $req;
}
}
// }}}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
?>