diff --git a/plugins/ExtendedProfile/extendedprofile.php b/plugins/ExtendedProfile/extendedprofile.php index 713d5c601a..09d010b090 100644 --- a/plugins/ExtendedProfile/extendedprofile.php +++ b/plugins/ExtendedProfile/extendedprofile.php @@ -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 diff --git a/plugins/ExtendedProfile/extendedprofilewidget.php b/plugins/ExtendedProfile/extendedprofilewidget.php index a4913eed12..03f70592fc 100644 --- a/plugins/ExtendedProfile/extendedprofilewidget.php +++ b/plugins/ExtendedProfile/extendedprofilewidget.php @@ -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 ); diff --git a/plugins/ExtendedProfile/profiledetailsettingsaction.php b/plugins/ExtendedProfile/profiledetailsettingsaction.php index 7870c273ba..3708f54d65 100644 --- a/plugins/ExtendedProfile/profiledetailsettingsaction.php +++ b/plugins/ExtendedProfile/profiledetailsettingsaction.php @@ -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); + + 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 + ); } - - $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), - '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) {