From 7c2e0f0db1940d4d52d282ddd06d22706ee35a54 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 23 Sep 2007 14:30:38 +0200 Subject: [PATCH] Remove duplicated code Signed-off-by: Florent Bruneau --- modules/profile/addresses.inc.php | 7 +------ modules/profile/decos.inc.php | 9 +++------ modules/profile/general.inc.php | 14 +++----------- modules/profile/groups.inc.php | 3 +-- modules/profile/jobs.inc.php | 13 +++---------- modules/profile/mentor.inc.php | 13 +++---------- modules/profile/page.inc.php | 16 ++++++++++++++++ modules/profile/skills.inc.php | 3 +-- 8 files changed, 31 insertions(+), 47 deletions(-) diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index 89a3de1..9c4aec9 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -174,12 +174,8 @@ class ProfileAddresses extends ProfilePage $this->settings['addresses'] = new ProfileAddress(); } - protected function fetchData() + protected function _fetchData() { - if (count($this->orig) > 0) { - $this->values = $this->orig; - return; - } // Build the addresses tree $res = XDB::query("SELECT a.adrid AS id, a.adr1, a.adr2, a.adr3, UNIX_TIMESTAMP(a.datemaj) AS datemaj, @@ -231,7 +227,6 @@ class ProfileAddresses extends ProfilePage } unset($address['id']); } - parent::fetchData(); } } diff --git a/modules/profile/decos.inc.php b/modules/profile/decos.inc.php index 1018e9b..ab1d9fd 100644 --- a/modules/profile/decos.inc.php +++ b/modules/profile/decos.inc.php @@ -94,19 +94,17 @@ class ProfileDecos extends ProfilePage $this->settings['medals_pub'] = new ProfilePub(); } - protected function fetchData() + 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() + protected function _saveData() { - parent::saveData(); if ($this->changed['medals_pub']) { XDB::execute("UPDATE auth_user_quick SET profile_medals_pub = {?} @@ -115,9 +113,8 @@ class ProfileDecos extends ProfilePage } } - public function prepare(PlatalPage &$page, $id) + public function _prepare(PlatalPage &$page, $id) { - parent::prepare($page, $id); $res = XDB::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate FROM profile_medals ORDER BY type, text"); diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 3cd19e4..9c2590a 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -117,13 +117,8 @@ class ProfileGeneral extends ProfilePage = new ProfileAppli(); } - protected function fetchData() + protected function _fetchData() { - if (count($this->orig) > 0) { - $this->values = $this->orig; - return; - } - // Checkout all data... $res = XDB::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite, q.profile_mobile as mobile, q.profile_mobile_pub as mobile_pub, @@ -160,12 +155,10 @@ class ProfileGeneral extends ProfilePage WHERE type='photo' AND user_id = {?}", S::v('uid')); $this->values['nouvellephoto'] = $res->fetchOneCell(); - parent::fetchData(); } - protected function saveData() + protected function _saveData() { - parent::saveData(); if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom']) { XDB::execute("UPDATE auth_user_md5 SET nationalite = {?}, nom={?}, prenom={?} @@ -197,9 +190,8 @@ class ProfileGeneral extends ProfilePage } } - public function prepare(PlatalPage &$page, $id) + public function _prepare(PlatalPage &$page, $id) { - parent::prepare($page, $id); require_once "applis.func.inc.php"; } } diff --git a/modules/profile/groups.inc.php b/modules/profile/groups.inc.php index 9a14ad8..83d89f3 100644 --- a/modules/profile/groups.inc.php +++ b/modules/profile/groups.inc.php @@ -105,9 +105,8 @@ class ProfileGroups extends ProfilePage $this->settings['binets'] = new ProfileGroup('binets', 'user_id', 'binet_id'); } - public function prepare(PlatalPage &$page, $id) + public function _prepare(PlatalPage &$page, $id) { - parent::prepare($page, $id); $page->assign('mygroups', XDB::iterator("SELECT a.nom, a.site, a.diminutif, a.unsub_url, a.pub, m.perms FROM groupex.asso AS a INNER JOIN groupex.membres AS m ON (m.asso_id = a.id) diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index 4f79328..64b96b6 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -129,12 +129,8 @@ class ProfileJobs extends ProfilePage $this->settings['jobs'] = new ProfileJob(); } - protected function fetchData() + protected function _fetchData() { - if (count($this->orig) > 0) { - $this->values = $this->orig; - return; - } // Checkout the CV $res = XDB::query("SELECT cv FROM auth_user_md5 @@ -188,10 +184,9 @@ class ProfileJobs extends ProfilePage 'tel_pub' => $tel_pub, 'email_pub' => $email_pub); } - parent::fetchData(); } - protected function saveData() + protected function _saveData() { if ($this->changed['cv']) { XDB::execute("UPDATE auth_user_md5 @@ -199,12 +194,10 @@ class ProfileJobs extends ProfilePage WHERE user_id = {?}", $this->values['cv'], S::i('uid')); } - parent::saveData(); } - public function prepare(PlatalPage &$page, $id) + public function _prepare(PlatalPage &$page, $id) { - parent::prepare($page, $id); $page->assign('secteurs', XDB::iterator("SELECT id, label FROM emploi_secteur")); $page->assign('fonctions', XDB::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title diff --git a/modules/profile/mentor.inc.php b/modules/profile/mentor.inc.php index fbc06ec..5ab9095 100644 --- a/modules/profile/mentor.inc.php +++ b/modules/profile/mentor.inc.php @@ -124,23 +124,17 @@ class ProfileMentor extends ProfilePage $this->settings['countries'] = new ProfileCountry(); } - protected function fetchData() + protected function _fetchData() { - if (count($this->orig) > 0) { - $this->values = $this->orig; - return; - } $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", S::i('uid')); $this->value['expertise'] = $res->fetchOneCell(); - parent::fetchData(); } - protected function saveData() + protected function _saveData() { - parent::saveData(); if ($this->changed['expertise']) { XDB::execute("REPLACE INTO mentor (uid, expertise) VALUES ({?}, {?})", @@ -148,9 +142,8 @@ class ProfileMentor extends ProfilePage } } - public function prepare(PlatalPage &$page, $id) + public function _prepare(PlatalPage &$page, $id) { - parent::prepare($page, $id); $page->assign('secteurs_sel', XDB::iterator("SELECT id, label FROM emploi_secteur")); } diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index e30023d..4f44024 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -181,12 +181,18 @@ abstract class ProfilePage implements PlWizardPage $this->wizard =& $wiz; } + protected function _fetchData() + { + } + protected function fetchData() { if (count($this->orig) > 0) { $this->values = $this->orig; return; } + + $this->_fetchData(); foreach ($this->settings as $field=>&$setting) { $success = false; if (!is_null($setting)) { @@ -199,6 +205,10 @@ abstract class ProfilePage implements PlWizardPage $this->orig = $this->values; } + protected function _saveData() + { + } + protected function saveData() { foreach ($this->settings as $field=>&$setting) { @@ -206,6 +216,7 @@ abstract class ProfilePage implements PlWizardPage $setting->save($this, $field, $this->values[$field]); } } + $this->_saveData(); // Update the last modification date XDB::execute('REPLACE INTO user_changes @@ -242,6 +253,10 @@ abstract class ProfilePage implements PlWizardPage return 'profile/base.tpl'; } + protected function _prepare(PlatalPage &$page, $id) + { + } + public function prepare(PlatalPage &$page, $id) { if (count($this->values) == 0) { @@ -250,6 +265,7 @@ abstract class ProfilePage implements PlWizardPage foreach ($this->values as $field=>&$value) { $page->assign($field, $value); } + $this->_prepare($page, $id); $page->assign('profile_page', $this->pg_template); $page->assign('errors', $this->errors); } diff --git a/modules/profile/skills.inc.php b/modules/profile/skills.inc.php index 17444eb..bfaa7fb 100644 --- a/modules/profile/skills.inc.php +++ b/modules/profile/skills.inc.php @@ -89,9 +89,8 @@ class ProfileSkills extends ProfilePage $this->settings['langues'] = new ProfileSkill('langues', 'lid', 'langue_fr'); } - public function prepare(PlatalPage &$page, $id) + public function _prepare(PlatalPage &$page, $id) { - parent::prepare($page, $id); $page->assign('comp_list', XDB::iterator("SELECT id, text_fr, FIND_IN_SET('titre',flags) AS title FROM competences_def")); $page->assign('comp_level', array('initié' => 'initié', -- 2.1.4