2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 ***************************************************************************/
22 class ProfileDeco
implements ProfileSetting
24 public function value(ProfilePage
&$page, $field, $value, &$success)
27 if (is_null($value)) {
28 // Fetch already attributed medals
29 $res = XDB
::iterRow("SELECT m.id AS id, s.gid AS grade
30 FROM profile_medals_sub AS s
31 INNER JOIN profile_medals AS m ON ( s.mid = m.id )
35 while (list($id, $grade) = $res->next()) {
36 $value[$id] = array('grade' => $grade,
40 // Fetch not yet validated medals
41 require_once('validations.inc.php');
42 $medals = Validate
::get_typed_requests(S
::i('uid'), 'medal');
43 foreach ($medals as &$medal) {
44 $value[$medal->mid
] = array('grade' => $medal->gid
,
47 } else if (!is_array($value)) {
54 public function save(ProfilePage
&$page, $field, $value)
56 require_once('validations.inc.php');
58 $orig =& $page->orig
[$field];
61 foreach ($orig as $id=>&$val) {
62 if (!isset($value[$id]) ||
$val['grade'] != $value[$id]['grade']) {
64 XDB
::execute("DELETE FROM profile_medals_sub
65 WHERE uid = {?} AND mid = {?}",
68 $req = MedalReq
::get_request(S
::i('uid'), $id);
77 foreach ($value as $id=>&$val) {
78 if (!isset($orig[$id]) ||
$orig[$id]['grade'] != $val['grade']) {
79 $req = new MedalReq(S
::user(), $id, $val['grade']);
86 class ProfileDecos
extends ProfilePage
88 protected $pg_template = 'profile/deco.tpl';
90 public function __construct(PlWizard
&$wiz)
92 parent
::__construct($wiz);
93 $this->settings
['medals'] = new ProfileDeco();
94 $this->settings
['medals_pub'] = new ProfilePub();
95 $this->watched
['medals'] = true
;
98 protected function _fetchData()
100 $res = XDB
::query("SELECT profile_medals_pub
102 WHERE user_id = {?}",
104 $this->values
['medals_pub'] = $res->fetchOneCell();
107 protected function _saveData()
109 if ($this->changed
['medals_pub']) {
110 XDB
::execute("UPDATE auth_user_quick
111 SET profile_medals_pub = {?}
112 WHERE user_id = {?}",
113 $this->values
['medals_pub'], S
::i('uid'));
117 public function _prepare(PlPage
&$page, $id)
119 $res = XDB
::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate
121 ORDER BY type, text");
123 while ($tmp = $res->next()) {
124 $mlist[$tmp['type']][] = $tmp;
126 $page->assign('medal_list', $mlist);
127 $trad = Array('ordre' => 'Ordres',
129 'militaire' => 'Médailles militaires',
130 'honneur' => 'Médailles d\'honneur',
131 'resistance' => 'Médailles de la résistance',
133 $page->assign('trad', $trad);
137 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: