* 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;
}
}
{
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) {
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;
}
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);
}
}
}
}
+// Handles anonymity and network fields
class ProfileSettingManageursBool implements ProfileSetting
{
private $dbfield;
}
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
}
$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) {
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');
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)