From: Florent Bruneau Date: Sun, 2 Sep 2007 18:15:58 +0000 (+0200) Subject: Start working on the medals page X-Git-Tag: xorg/0.9.15~174^2~15 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=a7c28fffa54b53f05ef4245b73a8dfb9597be877;p=platal.git Start working on the medals page Signed-off-by: Florent Bruneau --- diff --git a/modules/profile.php b/modules/profile.php index 7e6b568..a4c2d57 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -319,7 +319,7 @@ class ProfileModule extends PLModule $wiz->addPage('ProfileGeneral', 'Général', 'general'); $wiz->addPage('ProfileAddresses', 'Adresses personnelles', 'adresses'); $wiz->addPage('ProfileGroups', 'Groupes X - Binets', 'poly'); - $wiz->addPage('ProfileDeco', 'Décorations - Medals', 'deco'); + $wiz->addPage('ProfileDecos', 'Décorations - Medailles', 'deco'); $wiz->addPage('ProfilePro', 'Informations professionnelles', 'emploi'); $wiz->addPage('ProfileSkills', 'Compétences diverses', 'skill'); $wiz->addPage('ProfileMentor', 'Mentoring', 'mentor'); diff --git a/modules/profile/decos.inc.php b/modules/profile/decos.inc.php new file mode 100644 index 0000000..ee000d9 --- /dev/null +++ b/modules/profile/decos.inc.php @@ -0,0 +1,146 @@ +next()) { + $value[$id] = array('grade' => $grade, + 'valid' => true); + } + + // Fetch not yet validated medals + require_once('validations.inc.php'); + $medals = Validate::get_typed_requests(S::i('uid'), 'medal'); + foreach ($medals as &$medal) { + $medals[$medal->mid] = array('grade' => $medal->gid, + 'valid' => false); + } + } else if (!is_array($value)) { + $value = array(); + } + ksort($value); + return $value; + } + + public function save(ProfilePage &$page, $field, $value) + { + require_once('validations.inc.php'); + + // Remove old ones + foreach ($page->orig as $id=>&$val) { + if (!isset($value[$id]) || $val['grade'] != $value[$id]['grade']) { + if ($val['valid']) { + XDB::execute("DELETE FROM profile_medals_sub + WHERE uid = {?} AND id = {?}", + S::i('uid'), $id); + } else { + $req = Validate::get_typed_request(S::i('uid'), 'medal', $id); + $req->clean(); + } + } + } + + // Add new ones + foreach ($value as $id=>&$val) { + if (!isset($this->orig[$id]) || $this->orig[$id]['grade'] != $val['grade']) { + $req = new MedalReq(S::i('uid'), $id, $val['grade']); + $req->submit(); + } + } + } +} + +class ProfileDecos extends ProfilePage +{ + protected $pg_template = 'profile/deco.tpl'; + + public function __construct(PlWizard &$wiz) + { + parent::__construct($wiz); + $this->settings['medals'] = new ProfileDeco(); + $this->settings['medals_pub'] = new ProfilePub(); + } + + protected function fetchData() + { + $res = XDB::query("SELECT profile_medals_pub + FROM auth_user_quick + WHERE user_id = {?}", + S::i('uid')); + $this->values['medals_pub'] = $res->fetchOneCell(); + parent::fetchData(); + } + + protected function saveData() + { + parent::saveData(); + if ($this->changed['medals_pub']) { + XDB::execute("UPDATE auth_user_quick + SET profile_medals_pub = {?} + WHERE user_id = {?}", + $this->values['medals_pub'], S::i('uid')); + } + } + + public function prepare(PlatalPage &$page) + { + parent::prepare($page); + $res = XDB::iterator("SELECT * + FROM profile_medals_grades + ORDER BY mid, pos"); + $grades = array(); + while ($tmp = $res->next()) { + $grades[$tmp['mid']][] = $tmp; + } + $page->assign('grades', $grades); + + $res = XDB::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate + FROM profile_medals + ORDER BY type, text"); + $mlist = array(); + while ($tmp = $res->next()) { + $mlist[$tmp['type']][] = $tmp; + } + $page->assign('medal_list', $mlist); + + $trad = Array('ordre' => 'Ordres', + 'croix' => 'Croix', + 'militaire' => 'Médailles militaires', + 'honneur' => 'Médailles d\'honneur', + 'resistance' => 'Médailles de la résistance', + 'prix' => 'Prix'); + $page->assign('trad', $trad); + } +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 9781828..3e66990 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -168,7 +168,8 @@ class ProfileGeneral extends ProfilePage parent::saveData(); if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom']) { XDB::execute("UPDATE auth_user_md5 - SET nationalite = {?}, nom={?}, prenom={?} WHERE user_id = {?}", + SET nationalite = {?}, nom={?}, prenom={?} + WHERE user_id = {?}", $this->values['nationalite'], $this->values['nom'], $this->values['prenom'], S::v('uid')); } if ($this->changed['nick'] || $this->changed['mobile'] || $this->changed['mobile_pub'] @@ -188,7 +189,12 @@ class ProfileGeneral extends ProfilePage require_once('user.func.inc.php'); user_reindex(S::v('uid')); } - XDB::execute("UPDATE photo SET pub = {?} WHERE uid = {?}", $this->values['photo_pub'], S::v('uid')); + if ($this->changed['photo_pub']) { + XDB::execute("UPDATE photo + SET pub = {?} + WHERE uid = {?}", + $this->values['photo_pub'], S::v('uid')); + } } public function prepare(PlatalPage &$page) diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 4566a10..233a514 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -226,6 +226,7 @@ abstract class ProfilePage implements PlWizardPage require_once dirname(__FILE__) . '/general.inc.php'; require_once dirname(__FILE__) . '/addresses.inc.php'; require_once dirname(__FILE__) . '/groups.inc.php'; +require_once dirname(__FILE__) . '/decos.inc.php'; // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/templates/profile/deco.tpl b/templates/profile/deco.tpl index ae09bea..1dd1f24 100644 --- a/templates/profile/deco.tpl +++ b/templates/profile/deco.tpl @@ -23,6 +23,16 @@ {literal} -{if $smarty.request.medal_op eq "ajouter"} -
- Ta demande a bien été prise en compte, elle sera validée prochainement par un administrateur. -
-{/if} -
- - - - - - - - - - - {foreach from=$medals item=m} - - - - - - {/foreach} - {foreach from=$medals_valid item=v} - - - - - {/foreach} - - - + +
- Médailles, Décorations, Prix, ... -
- - - - - -
- - - ces informations sont normalement publiques (JO, ...) mais tu peux choisir de les associer a ta fiche publique -
-
- {$m.medal} - - {$m.medal}
- {if $grades[$m.id]|@count} - {foreach from=$grades[$m.id] item=g} - {if $g.gid eq $m.gid}{$g.text}{/if} - {/foreach} - {/if} -
- - retirer - -
- mid}src="images/medals/{$m.img}"{/if} - {/foreach} - {/foreach} - title="Validation" alt="Validation" width="32" /> - - - {foreach from=$medal_list item=list} - {foreach from=$list item=m} - {if $m.id eq $v->mid}{$m.text} (en attente de validation){/if} - {/foreach} - {/foreach} -
- {foreach from=$grades key=mid item=grd} - {if $mid eq $v->mid} - {foreach from=$grd item=g} - {if $g.gid eq $v->gid}{$g.text}{/if} - {/foreach} - {/if} - {/foreach} -
- - annuler - -
-   - - + + + + + - - -
+ Médailles, Décorations, Prix, ... +
+
+
+ +
+
+ ces informations sont normalement publiques (JO, ...) mais tu peux choisir de les associer a ta fiche publique +
+
+
+ - -
- - ajouter + + {icon name=add title="Ajouter cette médaille"} -
- + + {foreach from=$medals item=medal key=id} + {include file="profile/deco.medal.tpl" medal=$medal id=$id} + {/foreach} +
+ + {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}