]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Extended profile - make birthday save
authorZach Copley <zach@status.net>
Tue, 15 Mar 2011 22:35:00 +0000 (15:35 -0700)
committerZach Copley <zach@status.net>
Tue, 15 Mar 2011 22:35:00 +0000 (15:35 -0700)
plugins/ExtendedProfile/extendedprofilewidget.php
plugins/ExtendedProfile/profiledetailsettingsaction.php

index 05cfadacc3ed232840cba0afa72d4548ba8c18d7..fc3d7ca51da232615f88f6667cf43afa85a1687e 100644 (file)
@@ -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;
index 235786088458491c37eecc6c3684daac27392815..d3b653bad2037e3925c679e8e5cf69745b5f528a 100644 (file)
@@ -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)
                 );
             }
         }