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

index 713d5c601ab822537a4dd954a3f31a9154e948d3..09d010b090bc86ae6dd7ff91d90f25d16ad45a43 100644 (file)
@@ -168,7 +168,7 @@ class ExtendedProfile
     {
         $schools = (isset($this->fields['school'])) ? $this->fields['school'] : null;
         $degrees = (isset($this->fields['degree'])) ? $this->fields['degree'] : null;
-        $descs = (isset($this->fields['degree_description'])) ? $this->fields['degree_description'] : null;
+        $descs = (isset($this->fields['degree_descr'])) ? $this->fields['degree_descr'] : null;
         $start = (isset($this->fields['school_start'])) ? $this->fields['school_start'] : null;
         $end = (isset($this->fields['school_end'])) ? $this->fields['school_end'] : null;
         $iArrays = array();
@@ -190,8 +190,8 @@ class ExtendedProfile
                     'type'    => 'education',
                     'label'   => _m('Institution'),
                     'school'  => $schools[$i]->field_value,
-                    'degree'  => $degrees[$i]->field_value,
-                    'description' => $descs[$i]->field_value,
+                    'degree'  => isset($degrees[$i]->field_value) ? $degrees[$i]->field_value : null,
+                    'description' => isset($descs[$i]->field_value) ? $descs[$i]->field_value : null,
                     'index'   => intval($schools[$i]->value_index),
                     'start'   => $start[$i]->date,
                     'end'     => $end[$i]->date
index a4913eed12639af781343adf2e117b470f49aef7..03f70592fc7dfec691b374e9b468fb5f95460b67 100644 (file)
@@ -291,7 +291,7 @@ class ExtendedProfileWidget extends Form
 
         $this->out->element('div', 'label', _m('Degree'));
         $this->out->input(
-            $id,
+            $id . '-degree',
             null,
             isset($field['degree']) ? $field['degree'] : null
         );
@@ -300,7 +300,7 @@ class ExtendedProfileWidget extends Form
         $this->out->element('div', 'field', $field['description']);
 
         $this->out->input(
-            $id,
+            $id . '-description',
             null,
             isset($field['description']) ? $field['description'] : null
         );
index 7870c273ba761a489295fb06c16120d97fe0d284..3708f54d65027ab14fdb9930b53a831e900b6ef5 100644 (file)
@@ -110,6 +110,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
 
             $this->savePhoneNumbers($user);
             $this->saveExperiences($user);
+            $this->saveEducations($user);
 
         } catch (Exception $e) {
             $this->showForm($e->getMessage(), false);
@@ -171,28 +172,30 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
 
         foreach ($experiences as $exp) {
             list($company, $current, $end, $start) = array_values($exp);
-            $startTs = strtotime($start);
+            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);
-            }
+                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);
+                $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);
-            }
+                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),
-                'current' => ($current == 'false') ? false : true
-            );
+                $expArray[] = array(
+                    'company' => $company,
+                    'start'   => common_sql_date($startTs),
+                    'end'     => common_sql_date($endTs),
+                    'current' => ($current == 'false') ? false : true
+                );
+            }
         }
 
         return $expArray;
@@ -251,6 +254,110 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
         }
     }
 
+    function findEducations() {
+
+        // Form vals look like this:
+        // 'extprofile-education-0-school' => 'Pigdog',
+        // 'extprofile-education-0-degree' => 'BA',
+        // 'extprofile-education-0-description' => 'Blar',
+        // 'extprofile-education-0-start' => '05/22/99',
+        // 'extprofile-education-0-end' => '05/22/05',
+
+        $edus = $this->sliceParams('education', 5);
+        $eduArray = array();
+
+        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)
+                );
+            }
+        }
+
+        return $eduArray;
+    }
+
+
+    function saveEducations($user) {
+         common_debug('save education');
+         $edus = $this->findEducations();
+         common_debug(var_export($edus, true));
+
+         $this->removeAll($user, 'school');
+         $this->removeAll($user, 'degree');
+         $this->removeAll($user, 'degree_descr');
+         $this->removeAll($user, 'school_start');
+         $this->removeAll($user, 'school_end');
+
+         $i = 0;
+         foreach($edus as $edu) {
+             if (!empty($edu['school'])) {
+                 ++$i;
+                 $this->saveField(
+                     $user,
+                     'school',
+                     $edu['school'],
+                     null,
+                     $i
+                 );
+                 $this->saveField(
+                     $user,
+                     'degree',
+                     $edu['degree'],
+                     null,
+                     $i
+                 );
+                 $this->saveField(
+                     $user,
+                     'degree_descr',
+                     $edu['description'],
+                     null,
+                     $i
+                 );
+                 $this->saveField(
+                     $user,
+                     'school_start',
+                     null,
+                     null,
+                     $i,
+                     $edu['start']
+                 );
+
+                 $this->saveField(
+                     $user,
+                     'school_end',
+                     null,
+                     null,
+                     $i,
+                     $edu['end']
+                 );
+            }
+         }
+     }
+
     function arraySplit($array, $pieces)
     {
         if ($pieces < 2) {