From 2a43ddaa132cf8474ca51ddd87321d002cf4a15a Mon Sep 17 00:00:00 2001 From: Thomas Minvielle Date: Sun, 18 May 2014 09:52:14 +0200 Subject: [PATCH] Insert or update profile_manageurs when the user validates. --- modules/profile/manageurs.inc.php | 202 ++++++++++++++++++++++---------------- templates/profile/manageurs.tpl | 28 +++--- 2 files changed, 130 insertions(+), 100 deletions(-) diff --git a/modules/profile/manageurs.inc.php b/modules/profile/manageurs.inc.php index 5faaa64..428e8f2 100644 --- a/modules/profile/manageurs.inc.php +++ b/modules/profile/manageurs.inc.php @@ -19,19 +19,110 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -class ProfileSettingManageurs implements ProfileSetting +class ProfileSettingManageursYear implements ProfileSetting { public function value(ProfilePage $page, $field, $value, &$success) { $success = true; + if (is_null($value)) { + $value = XDB::fetchOneCell("SELECT m.entry_year + FROM profile_manageurs AS m + WHERE pid = {?}", + $page->pid()); + } else { + if (($value < 1921) || ($value > (date('Y') + 4))) { + Platal::page()->trigWarning('L\'année de début d\'activité professionnelle est mal ou non renseignée, elle doit être du type : 2004.'); + $success = (is_null($value) || ($value == '')); // Even if it triggers a warning, the null value is valid. + $value = null; + } + } + + return $value; + } + + public function save(ProfilePage $page, $field, $value) + { + XDB::execute("INSERT INTO profile_manageurs (pid, title, entry_year, project, anonymity, visibility, email, communication, push, network) + VALUES ({?},{?},{?},{?},{?},{?},{?},{?},{?},{?}) + ON DUPLICATE KEY UPDATE entry_year = VALUES(entry_year)", + $page->pid(), '', $value, '', 0, 'blocked', '', '', 'never', 0); + } + + public function getText($value) { + } +} + +// Handles title, project and email fields +class ProfileSettingManageursText implements ProfileSetting +{ + private $dbfield; + + public function __construct($dbfield) + { + $this->dbfield = $dbfield; + } + + public function value(ProfilePage $page, $field, $value, &$success) + { + if (is_null($value)) { + $value = XDB::fetchOneCell("SELECT m." . $this->dbfield . + " FROM profile_manageurs AS m + WHERE m.pid = {?}", + $page->pid()); + } + else if ($this->dbfield == 'email') { + $success = (($value == '') || isvalid_email($value)); + if (!isvalid_email($value)) { + Platal::page()->trigWarning('Le champ email n\'est pas correctement renseigné.'); + } + } else { + $success = true; + } + return $value; + } + + public function save(ProfilePage $page, $field, $value) + { + $default = array('title' => '', 'project' => '', 'email' => ''); + $default[$this->dbfield] = $value; + XDB::execute("INSERT INTO profile_manageurs (pid, title, entry_year, project, anonymity, visibility, email, communication, push, network) + VALUES ({?},{?},{?},{?},{?},{?},{?},{?},{?},{?}) + ON DUPLICATE KEY UPDATE " . $this-> dbfield . " = VALUES(" . $this->dbfield .")", + $page->pid(), $default['title'], null, $default['project'], 0, 'blocked', $default['email'], '', 'never', 0); + } + + public function getText($value) { + return $value; + } +} + +class ProfileSettingManageursVisibility implements ProfileSetting +{ + public function value(ProfilePage $page, $field, $value, &$success) + { + if (is_null($value)) { + $value = XDB::fetchOneCell("SELECT m.visibility + FROM profile_manageurs AS m + WHERE m.pid = {?}", + $page->pid()); + if (is_null($value)) { + $value = 'blocked'; + } + } + $success = in_array($value, array('visible', 'visible_exceptions', 'blocked')); return $value; } public function save(ProfilePage $page, $field, $value) { + XDB::execute("INSERT INTO profile_manageurs (pid, title, entry_year, project, anonymity, visibility, email, communication, push, network) + VALUES ({?},{?},{?},{?},{?},{?},{?},{?},{?},{?}) + ON DUPLICATE KEY UPDATE visibility = VALUES(visibility)", + $page->pid(), '', null, '', 0, $value, '', '', 'never', 0); } public function getText($value) { + return $value; } } @@ -39,40 +130,25 @@ class ProfileSettingManageursPush implements ProfileSetting { public function value(ProfilePage $page, $field, $value, &$success) { - $success = true; if (is_null($value)) { $value = XDB::fetchOneCell("SELECT m.push FROM profile_manageurs AS m WHERE m.pid = {?}", $page->pid()); - } - else { - switch ($value) { - case 'unique': - break; - case 'weekly': - break; - case 'never': - break; - case 0: - $value = 'unique'; - break; - case 1: - $value = 'weekly'; - break; - default: + if (is_null($value)) { $value = 'never'; } } + $success = in_array($value, array('unique', 'weekly', 'never')); return $value; } public function save(ProfilePage $page, $field, $value) { - XDB::execute("UPDATE profile_manageurs AS m - SET m.push = {?} - WHERE m.pid = {?}", - $value, $page->pid()); + XDB::execute("INSERT INTO profile_manageurs (pid, title, entry_year, project, anonymity, visibility, email, communication, push, network) + VALUES ({?},{?},{?},{?},{?},{?},{?},{?},{?},{?}) + ON DUPLICATE KEY UPDATE push = VALUES(push)", + $page->pid(), '', null, '', 0, 'blocked', '', '', $value, 0); } public function getText($value) { @@ -91,15 +167,14 @@ class ProfileSettingManageursCommunication implements ProfileSetting public function value(ProfilePage $page, $field, $value, &$success) { - $success = true; if (is_null($value)) { $value = XDB::fetchOneCell("SELECT FIND_IN_SET({?}, m.communication) FROM profile_manageurs AS m WHERE m.pid = {?}", $this->communication_field, $page->pid()); } - $value = (bool) $value; + $success = true; return $value; } @@ -125,10 +200,10 @@ class ProfileSettingManageursCommunication implements ProfileSetting if ($modified) { $res = implode(',', $res); - XDB::execute("UPDATE profile_manageurs AS m - SET m.communication = {?} - WHERE m.pid = {?}", - $res, $page->pid()); + XDB::execute("INSERT INTO profile_manageurs (pid, title, entry_year, project, anonymity, visibility, email, communication, push, network) + VALUES ({?},{?},{?},{?},{?},{?},{?},{?},{?},{?}) + ON DUPLICATE KEY UPDATE communication = VALUES(communication)", + $page->pid(), '', null, '', 0, 'blocked', '', $res, 'never', 0); } } @@ -142,6 +217,7 @@ class ProfileSettingManageursCommunication implements ProfileSetting } } +// Handles anonymity and network fields class ProfileSettingManageursBool implements ProfileSetting { private $dbfield; @@ -152,7 +228,6 @@ class ProfileSettingManageursBool implements ProfileSetting } public function value(ProfilePage $page, $field, $value, &$success) { - $success = true; if (is_null($value)) { $value = XDB::fetchOneCell("SELECT m." . $this->dbfield . " FROM profile_manageurs AS m @@ -162,23 +237,18 @@ class ProfileSettingManageursBool implements ProfileSetting } $value = (bool) $value; + $success = true; return $value; } public function save(ProfilePage $page, $field, $value) { - if ($value) { - XDB::execute("UPDATE profile_manageurs AS m - SET m." . $this->dbfield . " = 1 - WHERE m.pid = {?}", - $page->pid()); - } - else { - XDB::execute("UPDATE profile_manageurs AS m - SET m." . $this->dbfield . " = 0 - WHERE m.pid = {?}", - $page->pid()); - } + $default = array('anonymity' => 0, 'network' => 0); + $default[$this->dbfield] = (($value) ? 1 : 0); + XDB::execute("INSERT INTO profile_manageurs (pid, title, entry_year, project, anonymity, visibility, email, communication, push, network) + VALUES ({?},{?},{?},{?},{?},{?},{?},{?},{?},{?}) + ON DUPLICATE KEY UPDATE " . $this->dbfield . " = VALUES(" . $this->dbfield . ")", + $page->pid(), '', null, '', $default['anonymity'], 'blocked', '', '', 'never', $default['network']); } public function getText($value) { @@ -198,11 +268,11 @@ class ProfilePageManageurs extends ProfilePage public function __construct(PlWizard $wiz) { parent::__construct($wiz); - $this->settings['manageurs_title'] = null; - $this->settings['manageurs_entry_year'] = null; - $this->settings['manageurs_project'] = null; - $this->settings['manageurs_visibility'] = null; - $this->settings['manageurs_email'] = null; + $this->settings['manageurs_title'] = new ProfileSettingManageursText('title'); + $this->settings['manageurs_entry_year'] = new ProfileSettingManageursYear(); + $this->settings['manageurs_project'] = new ProfileSettingManageursText('project'); + $this->settings['manageurs_visibility'] = new ProfileSettingManageursVisibility(); + $this->settings['manageurs_email'] = new ProfileSettingManageursText('email'); $this->settings['manageurs_push'] = new ProfileSettingManageursPush(); $this->settings['manageurs_anonymity'] = new ProfileSettingManageursBool('anonymity'); $this->settings['manageurs_novelty'] = new ProfileSettingManageursCommunication('novelty'); @@ -213,50 +283,10 @@ class ProfilePageManageurs extends ProfilePage protected function _fetchData() { - $res = XDB::query("SELECT title AS manageurs_title, entry_year AS manageurs_entry_year, project AS manageurs_project, - visibility AS manageurs_visibility, email AS manageurs_email - FROM profile_manageurs - WHERE pid = {?}", - $this->pid()); - $this->values = $res->fetchOneAssoc(); } protected function _saveData() { - if ($this->changed['manageurs_title']) { - XDB::execute('UPDATE profile_manageurs - SET title = {?} - WHERE pid = {?}', - $this->values['manageurs_title'], $this->pid()); - } - - if ($this->changed['manageurs_entry_year']) { - XDB::execute('UPDATE profile_manageurs - SET entry_year = {?} - WHERE pid = {?}', - $this->values['manageurs_entry_year'], $this->pid()); - } - - if ($this->changed['manageurs_project']) { - XDB::execute('UPDATE profile_manageurs - SET project = {?} - WHERE pid = {?}', - $this->values['manageurs_project'], $this->pid()); - } - - if ($this->changed['manageurs_visibility']) { - XDB::execute('UPDATE profile_manageurs - SET visibility = {?} - WHERE pid = {?}', - $this->values['manageurs_visibility'], $this->pid()); - } - - if ($this->changed['manageurs_email']) { - XDB::execute('UPDATE profile_manageurs - SET email = {?} - WHERE pid = {?}', - $this->values['manageurs_email'], $this->pid()); - } } public function _prepare(PlPage $page, $id) diff --git a/templates/profile/manageurs.tpl b/templates/profile/manageurs.tpl index 090fed9..5018ef9 100644 --- a/templates/profile/manageurs.tpl +++ b/templates/profile/manageurs.tpl @@ -37,7 +37,7 @@ Intitulé du profil : - + @@ -94,22 +94,22 @@

@@ -121,7 +121,7 @@ Les offres d'entreprises, les messages de diplômés et la communication Manageurs seront envoyés à cette adresse. - + @@ -154,20 +154,20 @@


-- 2.1.4