Extended profile - make education entries save

This commit is contained in:
Zach Copley 2011-03-14 22:02:24 -07:00
parent 8559fbb2ca
commit 6d34818b5d
3 changed files with 132 additions and 25 deletions

View 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

View 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
);

View 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,6 +172,7 @@ 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) {
@ -194,6 +196,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
'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) {