From: Stéphane Jacob Date: Sun, 25 Sep 2011 21:23:47 +0000 (+0200) Subject: Adds levels to medals (Closes #1381). X-Git-Tag: xorg/1.1.4~133 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=15d26d450f109e27b8fad7839d98ebae788147e7;p=platal.git Adds levels to medals (Closes #1381). Signed-off-by: Stéphane Jacob --- diff --git a/ChangeLog b/ChangeLog index 5dbf04f..eafa66a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,6 +27,7 @@ Bug/Wish: - #1537: Replaces payments page on main site by a donation page -JAC * Profile: + - #1381: Adds levels to medals -JAC - #1535: Moves and displays skills with mentoring informations -JAC * XnetGrp: diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index 96502f8..ef574c0 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -376,7 +376,7 @@ class ProfileMedals extends ProfileField public static function fetchData(array $pids, Visibility $visibility) { - $data = XDB::iterator('SELECT pm.pid, pm.mid, pm.gid, pme.text, pme.img, pmge.text AS grade + $data = XDB::iterator('SELECT pm.pid, pm.mid, pm.gid, pme.text, pme.img, pmge.text AS grade, pm.level FROM profile_medals AS pm LEFT JOIN profiles AS p ON (pm.pid = p.pid) LEFT JOIN profile_medal_enum AS pme ON (pme.id = pm.mid) diff --git a/include/validations/medals.inc.php b/include/validations/medals.inc.php index fc77918..09c2520 100644 --- a/include/validations/medals.inc.php +++ b/include/validations/medals.inc.php @@ -27,18 +27,25 @@ class MedalReq extends ProfileValidate 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 = ''; + } } // }}} @@ -107,21 +114,21 @@ class MedalReq extends ProfileValidate 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, $grade) + 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) { + if ($req->mid == $type && $req->gid == $grade && $req->level == $level) { return $req; } } diff --git a/modules/profile.php b/modules/profile.php index 3e4795b..e200bd5 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -426,12 +426,12 @@ class ProfileModule extends PLModule { pl_content_headers("text/html"); $page->changeTpl('profile/deco.medal.tpl', NO_SKIN); - $valid = XDB::fetchOneCell("SELECT NOT FIND_IN_SET('validation', flags) - FROM profile_medal_enum - WHERE id = {?}", - $id); + list($valid, $has_levels) = XDB::fetchOneRow("SELECT NOT FIND_IN_SET('validation', flags), FIND_IN_SET('has_levels', flags) + FROM profile_medal_enum + WHERE id = {?}", + $id); $page->assign('id', $i); - $page->assign('medal', array('id' => $id, 'grade' => 0, 'valid' => $valid)); + $page->assign('medal', array('id' => $id, 'grade' => 0, 'valid' => $valid, 'has_levels' => $has_levels)); } function handler_ajax_job($page, $id, $pid) diff --git a/modules/profile/decos.inc.php b/modules/profile/decos.inc.php index 3adbafa..dcdffe5 100644 --- a/modules/profile/decos.inc.php +++ b/modules/profile/decos.inc.php @@ -24,6 +24,9 @@ class ProfileSettingDeco implements ProfileSetting private static function compareMedals(array $a, array $b) { if ($a['id'] == $b['id']) { + if ($a['grade'] == $b['grade']) { + return $a['level'] > $b['level']; + } return $a['grade'] > $b['grade']; } return $a['id'] > $b['id']; @@ -34,18 +37,21 @@ class ProfileSettingDeco implements ProfileSetting $success = true; if (is_null($value)) { // Fetch already attributed medals - $value = XDB::fetchAllAssoc('SELECT mid AS id, gid AS grade, 1 AS valid - FROM profile_medals - WHERE pid = {?}', + $value = XDB::fetchAllAssoc("SELECT m.mid AS id, m.gid AS grade, 1 AS valid, FIND_IN_SET('has_levels', e.flags) AS has_levels, m.level + FROM profile_medals AS m + INNER JOIN profile_medal_enum AS e ON (m.mid = e.id) + WHERE m.pid = {?}", $page->pid()); // Fetch not yet validated medals $medals = ProfileValidate::get_typed_requests($page->pid(), 'medal'); foreach ($medals as &$medal) { $value[] = array( - 'id' => $medal->mid, - 'grade' => $medal->gid, - 'valid' => '0' + 'id' => $medal->mid, + 'grade' => $medal->gid, + 'level' => $medal->level, + 'has_levels' => $medal->has_levels, + 'valid' => '0' ); } } elseif (!is_array($value)) { @@ -65,7 +71,7 @@ class ProfileSettingDeco implements ProfileSetting while ($i < $total_original || $j < $total_value) { if (isset($value[$j]) && (!isset($original[$i]) || self::compareMedals($original[$i], $value[$j]))) { - $req = new MedalReq(S::user(), $page->profile, $value[$j]['id'], $value[$j]['grade']); + $req = new MedalReq(S::user(), $page->profile, $value[$j]['id'], $value[$j]['grade'], $value[$j]['level'], $value[$j]['has_levels']); $req->submit(); sleep(1); ++$j; @@ -75,7 +81,7 @@ class ProfileSettingDeco implements ProfileSetting WHERE pid = {?} AND mid = {?} AND gid = {?}', $page->pid(), $original[$i]['id'], $original[$i]['grade']); } else { - $req = MedalReq::get_request($page->pid(), $original[$i]['id'], $original[$i]['grade']); + $req = MedalReq::get_request($page->pid(), $original[$i]['id'], $original[$i]['grade'], $value[$j]['level']); if ($req) { $req->clean(); } diff --git a/templates/profile/deco.medal.tpl b/templates/profile/deco.medal.tpl index 0c99ea0..b206319 100644 --- a/templates/profile/deco.medal.tpl +++ b/templates/profile/deco.medal.tpl @@ -33,6 +33,19 @@ + + +
+ {if $medal.has_levels} + Niveau / Échelon : + + {else} + + {/if}
diff --git a/templates/profile/deco.tpl b/templates/profile/deco.tpl index 4c27f5f..334ca32 100644 --- a/templates/profile/deco.tpl +++ b/templates/profile/deco.tpl @@ -50,7 +50,7 @@ {foreach from=$medals item=medal key=id} {include file="profile/deco.medal.tpl" medal=$medal id=$id} {/foreach} -

+

Si {if $isMe}ta{else}la{/if} décoration ou {if $isMe}ta{else}la{/if} médaille ne figure pas dans la liste, diff --git a/templates/profile/profile.tpl b/templates/profile/profile.tpl index ea76a36..f005f45 100644 --- a/templates/profile/profile.tpl +++ b/templates/profile/profile.tpl @@ -257,7 +257,7 @@ $($.closeOnEsc);

{$m.text}
- {$m.text}
{$m.grade} + {$m.text}{if $m.level} ({$m.level}){/if}
{$m.grade}
{/foreach} diff --git a/upgrade/1.1.4/05_medals.sql b/upgrade/1.1.4/05_medals.sql new file mode 100644 index 0000000..00d7298 --- /dev/null +++ b/upgrade/1.1.4/05_medals.sql @@ -0,0 +1,7 @@ +ALTER TABLE profile_medals ADD COLUMN level ENUM('', 'Or', 'Argent', 'Bronze') NOT NULL DEFAULT ''; +ALTER TABLE profile_medal_enum MODIFY COLUMN flags SET('validation', 'has_levels') NOT NULL DEFAULT ''; +UPDATE profile_medal_enum SET flags = 'has_levels' WHERE id = 20; -- Médaille de la Défense Nationale +UPDATE profile_medal_enum SET flags = 'validation,has_levels' WHERE id IN (61, 62, 63); -- sports +DELETE FROM profile_medal_grade_enum WHERE mid IN (61, 62, 63); -- Not used in prod yet, thus no need to update. + +-- vim:set syntax=mysql: