Remove duplicated code
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 23 Sep 2007 12:30:38 +0000 (14:30 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 23 Sep 2007 12:30:38 +0000 (14:30 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
modules/profile/addresses.inc.php
modules/profile/decos.inc.php
modules/profile/general.inc.php
modules/profile/groups.inc.php
modules/profile/jobs.inc.php
modules/profile/mentor.inc.php
modules/profile/page.inc.php
modules/profile/skills.inc.php

index 89a3de1..9c4aec9 100644 (file)
@@ -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();
     }
 }
 
index 1018e9b..ab1d9fd 100644 (file)
@@ -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");
index 3cd19e4..9c2590a 100644 (file)
@@ -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";
     }
 }
index 9a14ad8..83d89f3 100644 (file)
@@ -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)
index 4f79328..64b96b6 100644 (file)
@@ -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
index fbc06ec..5ab9095 100644 (file)
@@ -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"));
     }
index e30023d..4f44024 100644 (file)
@@ -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);
     }
index 17444eb..bfaa7fb 100644 (file)
@@ -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Ć©',