$this->out->elementStart('table', array('class' => 'extended-profile'));
foreach ($section['fields'] as $fieldName => $field) {
- if ($fieldName == 'phone') {
- $this->showPhones($fieldName, $field);
- } else {
+
+ switch($fieldName) {
+ case 'phone':
+ case 'experience':
+ $this->showMultiple($fieldName, $field);
+ break;
+ default:
$this->showExtendedProfileField($fieldName, $field);
}
}
$this->out->elementEnd('tr');
}
- /**
- * Outputs the value of a field
- *
- * @param string $name name of the field
- * @param array $field set of key/value pairs for the field
- */
- protected function showFieldValue($name, $field)
- {
- $type = strval(@$field['type']);
-
- switch($type)
- {
- case '':
- case 'text':
- case 'textarea':
- $this->out->text($this->ext->getTextValue($name));
- break;
- case 'tags':
- $this->out->text($this->ext->getTags());
- break;
- case 'phone':
- $this->showPhone($name, $field);
- break;
- default:
- $this->out->text("TYPE: $type");
- }
- }
-
- protected function showPhones($name, $field) {
- foreach ($field as $phone) {
- $this->showExtendedProfileField($name, $phone);
+ protected function showMultiple($name, $fields) {
+ foreach ($fields as $field) {
+ $this->showExtendedProfileField($name, $field);
}
}
isset($field['rel']) ? $field['rel'] : null
);
+ $this->showMultiControls();
+ $this->out->elementEnd('div');
+ }
+
+ protected function showExperience($name, $field)
+ {
+ $this->out->elementStart('div', array('class' => 'experience-display'));
+ $this->out->text($field['company']);
+ $this->out->elementStart('dl', 'experience-start-and-end');
+ $this->out->element('dt', null, _m('Start'));
+ $this->out->element('dd', null, $field['start']);
+ $this->out->element('dt', null, _m('End'));
+ if ($field['current']) {
+ $this->out->element('dd', null, '(' . _m('Current') . ')');
+ } else {
+ $this->out->element('dd', null, $field['end']);
+ }
+ $this->out->elementEnd('dl');
+ $this->out->elementEnd('div');
+ }
+
+ protected function showEditableExperience($name, $field)
+ {
+ $index = isset($field['index']) ? $field['index'] : 0;
+ $id = "extprofile-$name-$index";
+ $this->out->elementStart(
+ 'div', array(
+ 'id' => $id . '-edit',
+ 'class' => 'experience-edit'
+ )
+ );
+
+ $this->out->input(
+ $id,
+ null,
+ isset($field['company']) ? $field['company'] : null
+ );
+
+ $this->out->elementStart('ul', 'experience-start-and-end');
+ $this->out->elementStart('li');
+ $this->out->input(
+ $id . '-start',
+ _m('Start'),
+ isset($field['start']) ? $field['start'] : null
+ );
+ $this->out->elementEnd('li');
+
+ $this->out->elementStart('li');
+ $this->out->input(
+ $id . '-end',
+ _m('End'),
+ isset($field['end']) ? $field['end'] : null
+ );
+ $this->out->elementEnd('li');
+ $this->out->elementStart('li');
+ $this->out->checkbox(
+ $id . '-current',
+ _m('Current'),
+ $field['current']
+ );
+ $this->out->elementEnd('li');
+ $this->out->elementEnd('ul');
+ $this->showMultiControls();
+ $this->out->elementEnd('div');
+ }
+
+ function showMultiControls()
+ {
$this->out->element(
'a',
array(
),
'-'
);
+ }
- $this->out->elementEnd('div');
+ /**
+ * Outputs the value of a field
+ *
+ * @param string $name name of the field
+ * @param array $field set of key/value pairs for the field
+ */
+ protected function showFieldValue($name, $field)
+ {
+ $type = strval(@$field['type']);
+
+ switch($type)
+ {
+ case '':
+ case 'text':
+ case 'textarea':
+ $this->out->text($this->ext->getTextValue($name));
+ break;
+ case 'tags':
+ $this->out->text($this->ext->getTags());
+ break;
+ case 'phone':
+ $this->showPhone($name, $field);
+ break;
+ case 'experience':
+ $this->showExperience($name, $field);
+ break;
+ default:
+ $this->out->text("TYPE: $type");
+ }
}
/**
case 'phone':
$this->showEditablePhone($name, $field);
break;
+ case 'experience':
+ $this->showEditableExperience($name, $field);
+ break;
default:
$out->input($id, null, "TYPE: $type");
}
}
$this->savePhoneNumbers($user);
+ $this->saveExperiences($user);
$this->showForm(_('Details saved.'), true);
$phoneParams = $this->findMultiParams('phone');
ksort($phoneParams); // this sorts them into pairs
$phones = $this->arraySplit($phoneParams, sizeof($phoneParams) / 2);
-
$phoneTuples = array();
- foreach($phones as $phone) {
- $firstkey = current(array_keys($phone));
- $index = substr($firstkey, strrpos($firstkey, '-') + 1);
+ foreach ($phones as $phone) {
list($number, $rel) = array_values($phone);
-
$phoneTuples[] = array(
'value' => $number,
- 'index' => $index,
'rel' => $rel
);
}
return $phoneTuples;
}
+ function findExperiences() {
+
+ // Form vals look like this:
+ // 'extprofile-experience-0' => 'Bozotronix',
+ // 'extprofile-experience-0-current' => 'true'
+ // 'extprofile-experience-0-start' => '1/5/10',
+ // 'extprofile-experience-0-end' => '2/3/11',
+
+ $experiences = array();
+ $expParams = $this->findMultiParams('experience');
+ ksort($expParams);
+ $experiences = $this->arraySplit($expParams, sizeof($expParams) / 4);
+ $expArray = array();
+
+ foreach ($experiences as $exp) {
+ list($company, $current, $start, $end) = array_values($exp);
+ $expArray[] = array(
+ 'company' => $company,
+ 'start' => $start,
+ 'end' => $end,
+ 'current' => $current,
+ );
+ }
+
+ return $expArray;
+ }
+
+ function saveExperiences($user) {
+ common_debug('save experiences');
+ $experiences = $this->findExperiences();
+
+ $this->removeAll($user, 'company');
+ $this->removeAll($user, 'start');
+ $this->removeAll($user, 'end'); // also stores 'current'
+
+ $i = 0;
+ foreach($experiences as $experience) {
+ if (!empty($experience['company'])) {
+ ++$i;
+ $this->saveField(
+ $user,
+ 'company',
+ $experience['company'],
+ null,
+ $i
+ );
+ /*
+ $this->saveField(
+ $user,
+ 'start',
+ null,
+ null,
+ $i,
+ $experience['start']
+ );
+
+ // Save "current" employer indicator in rel
+ if ($experience['current']) {
+ $this->saveField(
+ $user,
+ 'end',
+ null,
+ 'current', // rel
+ $i
+ );
+ } else {
+ $this->saveField(
+ $user,
+ 'end',
+ null,
+ null,
+ $i,
+ $experience['end']
+ );
+ }
+ */
+ }
+ }
+ }
+
function arraySplit($array, $pieces)
{
if ($pieces < 2) {
* @param string $value field value
* @param string $rel field rel (type)
* @param int $index index (fields can have multiple values)
+ * @param date $date related date
*/
- function saveField($user, $name, $value, $rel = null, $index = null)
+ function saveField($user, $name, $value, $rel = null, $index = null, $date = null)
{
$profile = $user->getProfile();
$detail = new Profile_detail();
$detial->value_index = $index;
$detail->rel = $rel;
$detail->field_value = $value;
+ $detail->date = $date;
$detail->created = common_sql_now();
$result = $detail->insert();
if (empty($result)) {
$detail->field_value = $value;
$detail->rel = $rel;
+ $detail->date = $date;
$result = $detail->update($orig);
if (empty($result)) {