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

index 2277e4d7697244a7f8db13307c8e7f69f993a45c..b6844e205f64c078c38e360d11fa117a13aa2a8e 100644 (file)
@@ -131,24 +131,36 @@ class ExtendedProfile
 
     function getExperiences()
     {
-        $companies = (isset($this->fields['companies'])) ? $this->fields['company'] : null;
+        $companies = (isset($this->fields['company'])) ? $this->fields['company'] : null;
         $start = (isset($this->fields['start'])) ? $this->fields['start'] : null;
         $end   = (isset($this->fields['end'])) ? $this->fields['end'] : null;
 
-        $cArrays = array();
+        $eArrays = array();
 
-        if (empty($experiences)) {
+        if (empty($companies)) {
             $eArrays[] = array(
                 'label'   => _m('Employer'),
                 'type'    => 'experience',
-                'company' => "Bozotronix",
-                'start'   => '1/5/10',
-                'end'     => '2/3/11',
-                'current' => true,
+                'company' => null,
+                'start'   => null,
+                'end'     => null,
+                'current' => false,
                 'index'   => 0
             );
+        } else {
+            for ($i = 0; $i < sizeof($companies); $i++) {
+                $ea = array(
+                    'label'   => _m('Employer'),
+                    'type'    => 'experience',
+                    'company' => $companies[$i]->field_value,
+                    'index'   => intval($companies[$i]->value_index),
+                    'current' => $end[$i]->rel,
+                    'start'   => $start[$i]->date,
+                    'end'     => $end[$i]->date
+                );
+               $eArrays[] = $ea;
+            }
         }
-
         return $eArrays;
     }
 
index 9dfbaa716e23a39d6efa6eae29a44e987ff3173a..478990ac630692b235d8fc6ad613fc5d9ea79791 100644 (file)
@@ -241,6 +241,10 @@ class ExtendedProfileWidget extends Form
         );
         $this->out->elementEnd('li');
         $this->out->elementStart('li');
+        $this->out->hidden(
+            $id . '-current',
+            'false'
+        );
         $this->out->checkbox(
             $id . '-current',
             _m('Current'),
index 5e505f6c28588d59fdaedd137675251df99b295c..56f81d7a2d7c6771b82978a84dacc8ff525757b9 100644 (file)
@@ -95,25 +95,26 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
         $user = common_current_user();
 
         try {
-           $this->saveStandardProfileDetails($user);
-        } catch (Exception $e) {
-            $this->showForm($e->getMessage(), false);
-            return;
-        }
+            $this->saveStandardProfileDetails($user);
 
-        $profile = $user->getProfile();
+            $profile = $user->getProfile();
 
-        $simpleFieldNames = array('title', 'spouse', 'kids');
+            $simpleFieldNames = array('title', 'spouse', 'kids');
 
-        foreach ($simpleFieldNames as $name) {
-            $value = $this->trimmed('extprofile-' . $name);
-            if (!empty($value)) {
-                $this->saveField($user, $name, $value);
+            foreach ($simpleFieldNames as $name) {
+                $value = $this->trimmed('extprofile-' . $name);
+                if (!empty($value)) {
+                    $this->saveField($user, $name, $value);
+                }
             }
-        }
 
-        $this->savePhoneNumbers($user);
-        $this->saveExperiences($user);
+            $this->savePhoneNumbers($user);
+            $this->saveExperiences($user);
+
+        } catch (Exception $e) {
+            $this->showForm($e->getMessage(), false);
+            return;
+        }
 
         $this->showForm(_('Details saved.'), true);
 
@@ -170,11 +171,31 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
         $expArray = array();
 
         foreach ($experiences as $exp) {
-            list($company, $current, $start, $end) = array_values($exp);
+
+            common_debug('Experience: ' . var_export($exp, true));
+
+            list($company, $current, $end, $start) = array_values($exp);
+
+            $startTs = strtotime($start);
+
+            if ($startTs === false) {
+                throw new Exception(
+                    sprintf(_m("Invalid start date: %s"), $start)
+                );
+            }
+
+            $endTs = strtotime($end);
+
+            if ($current === 'false' && $endTs === false) {
+                throw new Exception(
+                    sprintf(_m("Invalid end date: %s"), $start)
+                );
+            }
+
             $expArray[] = array(
                 'company' => $company,
-                'start'   => $start,
-                'end'     => $end,
+                'start'   => common_sql_date($startTs),
+                'end'     => common_sql_date($endTs),
                 'current' => $current,
             );
         }
@@ -201,7 +222,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
                     null,
                     $i
                 );
-           /*
+
                 $this->saveField(
                     $user,
                     'start',
@@ -230,7 +251,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
                         $experience['end']
                     );
                 }
-                */
+
             }
         }
     }