forked from GNUsocial/gnu-social
		
	Extended profile - make education entries save
This commit is contained in:
		| @@ -168,7 +168,7 @@ class ExtendedProfile | |||||||
|     { |     { | ||||||
|         $schools = (isset($this->fields['school'])) ? $this->fields['school'] : null; |         $schools = (isset($this->fields['school'])) ? $this->fields['school'] : null; | ||||||
|         $degrees = (isset($this->fields['degree'])) ? $this->fields['degree'] : 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; |         $start = (isset($this->fields['school_start'])) ? $this->fields['school_start'] : null; | ||||||
|         $end = (isset($this->fields['school_end'])) ? $this->fields['school_end'] : null; |         $end = (isset($this->fields['school_end'])) ? $this->fields['school_end'] : null; | ||||||
|         $iArrays = array(); |         $iArrays = array(); | ||||||
| @@ -190,8 +190,8 @@ class ExtendedProfile | |||||||
|                     'type'    => 'education', |                     'type'    => 'education', | ||||||
|                     'label'   => _m('Institution'), |                     'label'   => _m('Institution'), | ||||||
|                     'school'  => $schools[$i]->field_value, |                     'school'  => $schools[$i]->field_value, | ||||||
|                     'degree'  => $degrees[$i]->field_value, |                     'degree'  => isset($degrees[$i]->field_value) ? $degrees[$i]->field_value : null, | ||||||
|                     'description' => $descs[$i]->field_value, |                     'description' => isset($descs[$i]->field_value) ? $descs[$i]->field_value : null, | ||||||
|                     'index'   => intval($schools[$i]->value_index), |                     'index'   => intval($schools[$i]->value_index), | ||||||
|                     'start'   => $start[$i]->date, |                     'start'   => $start[$i]->date, | ||||||
|                     'end'     => $end[$i]->date |                     'end'     => $end[$i]->date | ||||||
|   | |||||||
| @@ -291,7 +291,7 @@ class ExtendedProfileWidget extends Form | |||||||
|  |  | ||||||
|         $this->out->element('div', 'label', _m('Degree')); |         $this->out->element('div', 'label', _m('Degree')); | ||||||
|         $this->out->input( |         $this->out->input( | ||||||
|             $id, |             $id . '-degree', | ||||||
|             null, |             null, | ||||||
|             isset($field['degree']) ? $field['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->element('div', 'field', $field['description']); | ||||||
|  |  | ||||||
|         $this->out->input( |         $this->out->input( | ||||||
|             $id, |             $id . '-description', | ||||||
|             null, |             null, | ||||||
|             isset($field['description']) ? $field['description'] : null |             isset($field['description']) ? $field['description'] : null | ||||||
|         ); |         ); | ||||||
|   | |||||||
| @@ -110,6 +110,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction | |||||||
|  |  | ||||||
|             $this->savePhoneNumbers($user); |             $this->savePhoneNumbers($user); | ||||||
|             $this->saveExperiences($user); |             $this->saveExperiences($user); | ||||||
|  |             $this->saveEducations($user); | ||||||
|  |  | ||||||
|         } catch (Exception $e) { |         } catch (Exception $e) { | ||||||
|             $this->showForm($e->getMessage(), false); |             $this->showForm($e->getMessage(), false); | ||||||
| @@ -171,28 +172,30 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction | |||||||
|  |  | ||||||
|         foreach ($experiences as $exp) { |         foreach ($experiences as $exp) { | ||||||
|             list($company, $current, $end, $start) = array_values($exp); |             list($company, $current, $end, $start) = array_values($exp); | ||||||
|             $startTs = strtotime($start); |             if (!empty($company)) { | ||||||
|  |                 $startTs = strtotime($start); | ||||||
|  |  | ||||||
|             if ($startTs === false) { |                 if ($startTs === false) { | ||||||
|                 $msg = empty($start) ? _m('You must supply a start date.') |                     $msg = empty($start) ? _m('You must supply a start date.') | ||||||
|                     : sprintf(_m("Invalid start date: %s"), $start); |                         : sprintf(_m("Invalid start date: %s"), $start); | ||||||
|                 throw new Exception($msg); |                     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; |         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) |     function arraySplit($array, $pieces) | ||||||
|     { |     { | ||||||
|         if ($pieces < 2) { |         if ($pieces < 2) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user