2011-02-03 00:23:24 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2011, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Class for outputting a widget to display or edit
|
|
|
|
* extended profiles
|
|
|
|
*/
|
|
|
|
class ExtendedProfileWidget extends Form
|
2011-02-03 00:23:24 +00:00
|
|
|
{
|
2011-03-09 03:20:43 +00:00
|
|
|
const EDITABLE = true;
|
2011-02-03 00:23:24 +00:00
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* The parent profile
|
|
|
|
*
|
|
|
|
* @var Profile
|
|
|
|
*/
|
2011-02-03 00:23:24 +00:00
|
|
|
protected $profile;
|
2011-03-09 03:20:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The extended profile
|
|
|
|
*
|
|
|
|
* @var Extended_profile
|
|
|
|
*/
|
2011-02-03 00:23:24 +00:00
|
|
|
protected $ext;
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param XMLOutputter $out
|
|
|
|
* @param Profile $profile
|
|
|
|
* @param boolean $editable
|
|
|
|
*/
|
2011-02-03 00:23:24 +00:00
|
|
|
public function __construct(XMLOutputter $out=null, Profile $profile=null, $editable=false)
|
|
|
|
{
|
|
|
|
parent::__construct($out);
|
|
|
|
|
|
|
|
$this->profile = $profile;
|
|
|
|
$this->ext = new ExtendedProfile($this->profile);
|
|
|
|
|
|
|
|
$this->editable = $editable;
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Show the extended profile, or the edit form
|
|
|
|
*/
|
2011-02-03 00:23:24 +00:00
|
|
|
public function show()
|
2011-03-09 03:20:43 +00:00
|
|
|
{
|
|
|
|
if ($this->editable) {
|
|
|
|
parent::show();
|
|
|
|
} else {
|
|
|
|
$this->showSections();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show form data
|
|
|
|
*/
|
|
|
|
public function formData()
|
|
|
|
{
|
|
|
|
$this->showSections();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show each section of the extended profile
|
|
|
|
*/
|
|
|
|
public function showSections()
|
2011-02-03 00:23:24 +00:00
|
|
|
{
|
|
|
|
$sections = $this->ext->getSections();
|
|
|
|
foreach ($sections as $name => $section) {
|
|
|
|
$this->showExtendedProfileSection($name, $section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Show an extended profile section
|
|
|
|
*
|
|
|
|
* @param string $name name of the section
|
|
|
|
* @param array $section array of fields for the section
|
|
|
|
*/
|
2011-02-03 00:23:24 +00:00
|
|
|
protected function showExtendedProfileSection($name, $section)
|
|
|
|
{
|
|
|
|
$this->out->element('h3', null, $section['label']);
|
|
|
|
$this->out->elementStart('table', array('class' => 'extended-profile'));
|
2011-03-11 00:57:41 +00:00
|
|
|
|
2011-02-03 00:23:24 +00:00
|
|
|
foreach ($section['fields'] as $fieldName => $field) {
|
2011-03-14 22:29:11 +00:00
|
|
|
|
|
|
|
switch($fieldName) {
|
|
|
|
case 'phone':
|
|
|
|
case 'experience':
|
2011-03-15 03:58:35 +00:00
|
|
|
case 'education':
|
2011-03-14 22:29:11 +00:00
|
|
|
$this->showMultiple($fieldName, $field);
|
|
|
|
break;
|
|
|
|
default:
|
2011-03-11 00:57:41 +00:00
|
|
|
$this->showExtendedProfileField($fieldName, $field);
|
|
|
|
}
|
2011-02-03 00:23:24 +00:00
|
|
|
}
|
|
|
|
$this->out->elementEnd('table');
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Show an extended profile field
|
|
|
|
*
|
|
|
|
* @param string $name name of the field
|
|
|
|
* @param array $field set of key/value pairs for the field
|
|
|
|
*/
|
2011-02-03 00:23:24 +00:00
|
|
|
protected function showExtendedProfileField($name, $field)
|
|
|
|
{
|
|
|
|
$this->out->elementStart('tr');
|
|
|
|
|
|
|
|
$this->out->element('th', null, $field['label']);
|
|
|
|
|
|
|
|
$this->out->elementStart('td');
|
2011-02-03 00:38:01 +00:00
|
|
|
if ($this->editable) {
|
|
|
|
$this->showEditableField($name, $field);
|
|
|
|
} else {
|
|
|
|
$this->showFieldValue($name, $field);
|
|
|
|
}
|
2011-02-03 00:23:24 +00:00
|
|
|
$this->out->elementEnd('td');
|
|
|
|
|
|
|
|
$this->out->elementEnd('tr');
|
|
|
|
}
|
2011-02-03 00:38:01 +00:00
|
|
|
|
2011-03-14 22:29:11 +00:00
|
|
|
protected function showMultiple($name, $fields) {
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$this->showExtendedProfileField($name, $field);
|
2011-03-11 00:57:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-14 08:49:46 +00:00
|
|
|
protected function showPhone($name, $field)
|
2011-03-10 22:14:21 +00:00
|
|
|
{
|
|
|
|
$this->out->elementStart('div', array('class' => 'phone-display'));
|
|
|
|
$this->out->text($field['value']);
|
2011-03-11 00:57:41 +00:00
|
|
|
if (!empty($field['rel'])) {
|
|
|
|
$this->out->text(' (' . $field['rel'] . ')');
|
|
|
|
}
|
2011-03-10 22:14:21 +00:00
|
|
|
$this->out->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function showEditablePhone($name, $field)
|
|
|
|
{
|
2011-03-14 08:49:46 +00:00
|
|
|
$index = isset($field['index']) ? $field['index'] : 0;
|
2011-03-10 22:14:21 +00:00
|
|
|
$id = "extprofile-$name-$index";
|
|
|
|
$rel = $id . '-rel';
|
2011-03-13 23:32:13 +00:00
|
|
|
$this->out->elementStart(
|
|
|
|
'div', array(
|
|
|
|
'id' => $id . '-edit',
|
|
|
|
'class' => 'phone-edit'
|
|
|
|
)
|
|
|
|
);
|
2011-03-14 08:49:46 +00:00
|
|
|
$this->out->input(
|
|
|
|
$id,
|
|
|
|
null,
|
|
|
|
isset($field['value']) ? $field['value'] : null
|
|
|
|
);
|
2011-03-10 22:14:21 +00:00
|
|
|
$this->out->dropdown(
|
|
|
|
$id . '-rel',
|
|
|
|
'Type',
|
|
|
|
array(
|
|
|
|
'office' => 'Office',
|
|
|
|
'mobile' => 'Mobile',
|
|
|
|
'home' => 'Home',
|
|
|
|
'pager' => 'Pager',
|
|
|
|
'other' => 'Other'
|
|
|
|
),
|
|
|
|
null,
|
|
|
|
false,
|
2011-03-14 08:49:46 +00:00
|
|
|
isset($field['rel']) ? $field['rel'] : null
|
2011-03-10 22:14:21 +00:00
|
|
|
);
|
2011-03-14 08:49:46 +00:00
|
|
|
|
2011-03-14 22:29:11 +00:00
|
|
|
$this->showMultiControls();
|
|
|
|
$this->out->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function showExperience($name, $field)
|
|
|
|
{
|
2011-03-15 02:09:22 +00:00
|
|
|
$this->out->elementStart('div', 'experience-item');
|
|
|
|
$this->out->element('div', 'field', $field['company']);
|
|
|
|
$this->out->element('div', 'label', _m('Start'));
|
|
|
|
$this->out->element('div', array('class' => 'field date'), $field['start']);
|
|
|
|
$this->out->element('div', 'label', _m('End'));
|
|
|
|
$this->out->element('div', array('class' => 'field date'), $field['end']);
|
2011-03-14 22:29:11 +00:00
|
|
|
if ($field['current']) {
|
2011-03-15 02:09:22 +00:00
|
|
|
$this->out->element(
|
|
|
|
'div',
|
|
|
|
array('class' => 'field current'),
|
|
|
|
'(' . _m('Current') . ')'
|
|
|
|
);
|
2011-03-14 22:29:11 +00:00
|
|
|
}
|
|
|
|
$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');
|
2011-03-15 00:27:50 +00:00
|
|
|
$this->out->hidden(
|
|
|
|
$id . '-current',
|
|
|
|
'false'
|
|
|
|
);
|
2011-03-14 22:29:11 +00:00
|
|
|
$this->out->checkbox(
|
|
|
|
$id . '-current',
|
|
|
|
_m('Current'),
|
|
|
|
$field['current']
|
|
|
|
);
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
$this->out->elementEnd('ul');
|
|
|
|
$this->showMultiControls();
|
|
|
|
$this->out->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
2011-03-15 03:58:35 +00:00
|
|
|
protected function showEducation($name, $field)
|
|
|
|
{
|
|
|
|
$this->out->elementStart('div', 'education-item');
|
|
|
|
$this->out->element('div', 'field', $field['school']);
|
|
|
|
$this->out->element('div', 'label', _m('Degree'));
|
|
|
|
$this->out->element('div', 'field', $field['degree']);
|
|
|
|
$this->out->element('div', 'label', _m('Description'));
|
|
|
|
$this->out->element('div', 'field', $field['description']);
|
|
|
|
$this->out->element('div', 'label', _m('Start'));
|
|
|
|
$this->out->element('div', array('class' => 'field date'), $field['start']);
|
|
|
|
$this->out->element('div', 'label', _m('End'));
|
|
|
|
$this->out->element('div', array('class' => 'field date'), $field['end']);
|
|
|
|
$this->out->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function showEditableEducation($name, $field)
|
|
|
|
{
|
|
|
|
$index = isset($field['index']) ? $field['index'] : 0;
|
|
|
|
$id = "extprofile-$name-$index";
|
|
|
|
$this->out->elementStart(
|
|
|
|
'div', array(
|
|
|
|
'id' => $id . '-edit',
|
|
|
|
'class' => 'education-edit'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->out->input(
|
|
|
|
$id,
|
|
|
|
null,
|
|
|
|
isset($field['school']) ? $field['school'] : null
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->out->element('div', 'label', _m('Degree'));
|
|
|
|
$this->out->input(
|
2011-03-15 05:02:24 +00:00
|
|
|
$id . '-degree',
|
2011-03-15 03:58:35 +00:00
|
|
|
null,
|
|
|
|
isset($field['degree']) ? $field['degree'] : null
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->out->element('div', 'label', _m('Description'));
|
|
|
|
$this->out->element('div', 'field', $field['description']);
|
|
|
|
|
|
|
|
$this->out->input(
|
2011-03-15 05:02:24 +00:00
|
|
|
$id . '-description',
|
2011-03-15 03:58:35 +00:00
|
|
|
null,
|
|
|
|
isset($field['description']) ? $field['description'] : null
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->out->elementStart('ul', 'education-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
|
|
|
|
);
|
2011-03-15 04:07:14 +00:00
|
|
|
$this->out->elementEnd('li');
|
2011-03-15 03:58:35 +00:00
|
|
|
$this->out->elementEnd('ul');
|
|
|
|
|
|
|
|
$this->showMultiControls();
|
|
|
|
$this->out->elementEnd('div');
|
|
|
|
}
|
|
|
|
|
2011-03-14 22:29:11 +00:00
|
|
|
function showMultiControls()
|
|
|
|
{
|
2011-03-14 08:49:46 +00:00
|
|
|
$this->out->element(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'class' => 'add_row',
|
|
|
|
'href' => 'javascript://',
|
|
|
|
'style' => 'display: none; '
|
|
|
|
),
|
|
|
|
'+'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->out->element(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'class' => 'remove_row',
|
|
|
|
'href' => 'javascript://',
|
|
|
|
'style' => 'display: none; '
|
|
|
|
),
|
|
|
|
'-'
|
|
|
|
);
|
2011-03-14 22:29:11 +00:00
|
|
|
}
|
2011-03-14 08:49:46 +00:00
|
|
|
|
2011-03-14 22:29:11 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2011-03-15 03:58:35 +00:00
|
|
|
case 'education':
|
|
|
|
$this->showEducation($name, $field);
|
|
|
|
break;
|
2011-03-14 22:29:11 +00:00
|
|
|
default:
|
|
|
|
$this->out->text("TYPE: $type");
|
|
|
|
}
|
2011-02-03 00:38:01 +00:00
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Show an editable version of the field
|
|
|
|
*
|
|
|
|
* @param string $name name fo the field
|
|
|
|
* @param array $field array of key/value pairs for the field
|
|
|
|
*/
|
2011-02-03 00:38:01 +00:00
|
|
|
protected function showEditableField($name, $field)
|
|
|
|
{
|
|
|
|
$out = $this->out;
|
2011-03-09 03:20:43 +00:00
|
|
|
|
2011-02-03 00:38:01 +00:00
|
|
|
$type = strval(@$field['type']);
|
|
|
|
$id = "extprofile-" . $name;
|
2011-03-09 03:20:43 +00:00
|
|
|
|
2011-02-03 00:38:01 +00:00
|
|
|
$value = 'placeholder';
|
|
|
|
|
|
|
|
switch ($type) {
|
2011-03-09 03:20:43 +00:00
|
|
|
case '':
|
|
|
|
case 'text':
|
|
|
|
$out->input($id, null, $this->ext->getTextValue($name));
|
|
|
|
break;
|
|
|
|
case 'textarea':
|
|
|
|
$out->textarea($id, null, $this->ext->getTextValue($name));
|
|
|
|
break;
|
|
|
|
case 'tags':
|
|
|
|
$out->input($id, null, $this->ext->getTags());
|
|
|
|
break;
|
2011-03-10 22:14:21 +00:00
|
|
|
case 'phone':
|
|
|
|
$this->showEditablePhone($name, $field);
|
|
|
|
break;
|
2011-03-14 22:29:11 +00:00
|
|
|
case 'experience':
|
|
|
|
$this->showEditableExperience($name, $field);
|
|
|
|
break;
|
2011-03-15 03:58:35 +00:00
|
|
|
case 'education':
|
|
|
|
$this->showEditableEducation($name, $field);
|
|
|
|
break;
|
2011-03-09 03:20:43 +00:00
|
|
|
default:
|
|
|
|
$out->input($id, null, "TYPE: $type");
|
2011-02-03 00:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-09 03:20:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Action elements
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
|
|
|
function formActions()
|
|
|
|
{
|
|
|
|
$this->out->submit(
|
|
|
|
'save',
|
|
|
|
_m('BUTTON','Save'),
|
|
|
|
'submit form_action-secondary',
|
|
|
|
'save',
|
|
|
|
_('Save details')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ID of the form
|
|
|
|
*
|
|
|
|
* @return string ID of the form
|
|
|
|
*/
|
|
|
|
|
|
|
|
function id()
|
|
|
|
{
|
|
|
|
return 'profile-details-' . $this->profile->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class of the form
|
|
|
|
*
|
|
|
|
* @return string of the form class
|
|
|
|
*/
|
|
|
|
|
|
|
|
function formClass()
|
|
|
|
{
|
|
|
|
return 'form_profile_details';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action of the form
|
|
|
|
*
|
|
|
|
* @return string URL of the action
|
|
|
|
*/
|
|
|
|
|
|
|
|
function action()
|
|
|
|
{
|
|
|
|
return common_local_url('profiledetailsettings');
|
|
|
|
}
|
2011-02-03 00:23:24 +00:00
|
|
|
}
|