pid()); $value = array(); while (list($id, $grade) = $res->next()) { $value[$id] = array('grade' => $grade, 'valid' => '1'); } // Fetch not yet validated medals require_once 'validations.inc.php'; $medals = ProfileValidate::get_typed_requests($page->pid(), 'medal'); foreach ($medals as &$medal) { $value[$medal->mid] = array('grade' => $medal->gid, 'valid' => '0'); } } else if (!is_array($value)) { $value = array(); } ksort($value); return $value; } public function save(ProfilePage &$page, $field, $value) { require_once 'validations.inc.php'; $orig =& $page->orig[$field]; // Remove old ones foreach ($orig as $id=>&$val) { if (!isset($value[$id]) || $val['grade'] != $value[$id]['grade']) { if ($val['valid']) { XDB::execute("DELETE FROM profile_medals WHERE pid = {?} AND mid = {?}", $page->pid(), $id); } else { $req = MedalReq::get_request($page->pid(), $id); if ($req) { $req->clean(); } } } } // Add new ones foreach ($value as $id=>&$val) { if (!isset($orig[$id]) || $orig[$id]['grade'] != $val['grade']) { $req = new MedalReq(S::user(), $page->profile, $id, $val['grade']); $req->submit(); sleep(1); } } } public function getText($value) { $medalsList = DirEnum::getOptions(DirEnum::MEDALS); $medals = array(); foreach ($value as $id => $medal) { $medals[] = $medalsList[$id]; } return implode(', ', $medals); } } class ProfileSettingDecos extends ProfilePage { protected $pg_template = 'profile/deco.tpl'; public function __construct(PlWizard &$wiz) { parent::__construct($wiz); $this->settings['medals'] = new ProfileSettingDeco(); $this->settings['medals_pub'] = new ProfileSettingPub(); $this->watched['medals'] = true; } protected function _fetchData() { $res = XDB::query("SELECT medals_pub FROM profiles WHERE pid = {?}", $this->pid()); $this->values['medals_pub'] = $res->fetchOneCell(); } protected function _saveData() { if ($this->changed['medals_pub']) { XDB::execute("UPDATE profiles SET medals_pub = {?} WHERE pid = {?}", $this->values['medals_pub'], $this->pid()); } } public function _prepare(PlPage &$page, $id) { $res = XDB::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate FROM profile_medal_enum 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: ?>