From e4eb6719a5e270430b57425bcb344f0c7971254b Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 15 Mar 2011 15:35:00 -0700 Subject: [PATCH] Extended profile - make birthday save --- .../ExtendedProfile/extendedprofilewidget.php | 8 +- .../profiledetailsettingsaction.php | 76 +++++++++---------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/plugins/ExtendedProfile/extendedprofilewidget.php b/plugins/ExtendedProfile/extendedprofilewidget.php index 05cfadacc3..fc3d7ca51d 100644 --- a/plugins/ExtendedProfile/extendedprofilewidget.php +++ b/plugins/ExtendedProfile/extendedprofilewidget.php @@ -399,7 +399,7 @@ class ExtendedProfileWidget extends Form $this->out->element('div', 'label', _m('Description')); $this->out->element('div', 'field', $field['description']); - $this->out->input( + $this->out->textarea( $id . '-description', null, isset($field['description']) ? $field['description'] : null @@ -463,6 +463,9 @@ class ExtendedProfileWidget extends Form case 'textarea': $this->out->text($this->ext->getTextValue($name)); break; + case 'date': + $this->out->text($this->ext->getTextValue($name)); + break; case 'tags': $this->out->text($this->ext->getTags()); break; @@ -506,6 +509,9 @@ class ExtendedProfileWidget extends Form case 'text': $out->input($id, null, $this->ext->getTextValue($name)); break; + case 'date': + $out->input($id, null, $this->ext->getTextValue($name)); + break; case 'textarea': $out->textarea($id, null, $this->ext->getTextValue($name)); break; diff --git a/plugins/ExtendedProfile/profiledetailsettingsaction.php b/plugins/ExtendedProfile/profiledetailsettingsaction.php index 2357860884..d3b653bad2 100644 --- a/plugins/ExtendedProfile/profiledetailsettingsaction.php +++ b/plugins/ExtendedProfile/profiledetailsettingsaction.php @@ -100,6 +100,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction $profile = $user->getProfile(); $simpleFieldNames = array('title', 'spouse', 'kids'); + $dateFieldNames = array('birthday'); foreach ($simpleFieldNames as $name) { $value = $this->trimmed('extprofile-' . $name); @@ -108,6 +109,15 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction } } + foreach ($dateFieldNames as $name) { + $value = $this->trimmed('extprofile-' . $name); + $this->saveField( + $user, + $name, + $this->parseDate($name, $value) + ); + } + $this->savePhoneNumbers($user); $this->saveIms($user); $this->saveWebsites($user); @@ -123,6 +133,30 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction } + function parseDate($fieldname, $datestr, $required = false) + { + if (empty($datestr) && $required) { + $msg = sprintf( + _m('You must supply a date for "%s".'), + $fieldname + ); + throw new Exception($msg); + } else { + $ts = strtotime($datestr); + if ($ts === false) { + throw new Exception( + sprintf( + _m('Invalid date entered for "%s": %s'), + $fieldname, + $ts + ) + ); + } + return common_sql_date($ts); + } + return null; + } + function savePhoneNumbers($user) { $phones = $this->findPhoneNumbers(); $this->removeAll($user, 'phone'); @@ -249,26 +283,10 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction foreach ($experiences as $exp) { list($company, $current, $end, $start) = array_values($exp); if (!empty($company)) { - $startTs = strtotime($start); - - if ($startTs === false) { - $msg = empty($start) ? _m('You must supply a start date.') - : sprintf(_m("Invalid start date: %s"), $start); - throw new Exception($msg); - } - - $endTs = strtotime($end); - - if ($current === 'false' && $endTs === false) { - $msg = empty($end) ? _m('You must supply an end date.') - : sprintf(_m("Invalid end date: %s"), $end); - throw new Exception($msg); - } - $expArray[] = array( 'company' => $company, - 'start' => common_sql_date($startTs), - 'end' => common_sql_date($endTs), + 'start' => $this->parseDate('Start', $start, true), + 'end' => $this->parseDate('End', $end, true), 'current' => ($current == 'false') ? false : true ); } @@ -344,31 +362,13 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction foreach ($edus as $edu) { list($school, $degree, $description, $end, $start) = array_values($edu); - if (!empty($school)) { - - $startTs = strtotime($start); - - if ($startTs === false) { - $msg = empty($start) ? _m('You must supply a start date.') - : sprintf(_m("Invalid start date: %s"), $start); - throw new Exception($msg); - } - - $endTs = strtotime($end); - - if ($endTs === false) { - $msg = empty($end) ? _m('You must supply an end date.') - : sprintf(_m("Invalid end date: %s"), $end); - throw new Exception($msg); - } - $eduArray[] = array( 'school' => $school, 'degree' => $degree, 'description' => $description, - 'start' => common_sql_date($startTs), - 'end' => common_sql_date($endTs) + 'start' => $this->parseDate('Start', $start, true), + 'end' => $this->parseDate('End', $end, true) ); } } -- 2.39.5