Extended profile - make websites save

This commit is contained in:
Zach Copley 2011-03-15 10:10:18 -07:00
parent 4f217a3133
commit a6ae9ddd41
3 changed files with 125 additions and 7 deletions

View File

@ -98,6 +98,8 @@ class ExtendedProfile
}
}
// XXX: getPhones, getIms, and getWebsites pretty much do the same thing,
// so refactor.
function getPhones()
{
$phones = (isset($this->fields['phone'])) ? $this->fields['phone'] : null;
@ -155,6 +157,32 @@ class ExtendedProfile
return $iArrays;
}
function getWebsites()
{
$sites = (isset($this->fields['website'])) ? $this->fields['website'] : null;
$wArrays = array();
if (empty($sites)) {
$wArrays[] = array(
'label' => _m('Website'),
'type' => 'website'
);
} else {
for ($i = 0; $i < sizeof($sites); $i++) {
$wa = array(
'label' => _m('Website'),
'type' => 'website',
'index' => intval($sites[$i]->value_index),
'rel' => $sites[$i]->rel,
'value' => $sites[$i]->field_value,
);
$wArrays[] = $wa;
}
}
return $wArrays;
}
function getExperiences()
{
$companies = (isset($this->fields['company'])) ? $this->fields['company'] : null;
@ -273,13 +301,9 @@ class ExtendedProfile
'contact' => array(
'label' => _m('Contact'),
'fields' => array(
'phone' => $this->getPhones(),
'im' => $this->getIms(),
'website' => array(
'label' => _m('Websites'),
'type' => 'website',
'multi' => true,
),
'phone' => $this->getPhones(),
'im' => $this->getIms(),
'website' => $this->getWebsites()
),
),
'personal' => array(

View File

@ -107,6 +107,7 @@ class ExtendedProfileWidget extends Form
switch($fieldName) {
case 'phone':
case 'im':
case 'website':
case 'experience':
case 'education':
$this->showMultiple($fieldName, $field);
@ -147,6 +148,8 @@ class ExtendedProfileWidget extends Form
}
}
// XXX: showPhone, showIm and showWebsite all work the same, so
// combine
protected function showPhone($name, $field)
{
$this->out->elementStart('div', array('class' => 'phone-display'));
@ -167,6 +170,16 @@ class ExtendedProfileWidget extends Form
$this->out->elementEnd('div');
}
protected function showWebsite($name, $field)
{
$this->out->elementStart('div', array('class' => 'website-display'));
$this->out->text($field['value']);
if (!empty($field['rel'])) {
$this->out->text(' (' . $field['rel'] . ')');
}
$this->out->elementEnd('div');
}
protected function showEditableIm($name, $field)
{
$index = isset($field['index']) ? $field['index'] : 0;
@ -239,6 +252,44 @@ class ExtendedProfileWidget extends Form
$this->out->elementEnd('div');
}
protected function showEditableWebsite($name, $field)
{
$index = isset($field['index']) ? $field['index'] : 0;
$id = "extprofile-$name-$index";
$rel = $id . '-rel';
$this->out->elementStart(
'div', array(
'id' => $id . '-edit',
'class' => 'website-edit'
)
);
$this->out->input(
$id,
null,
isset($field['value']) ? $field['value'] : null
);
$this->out->dropdown(
$id . '-rel',
'Type',
array(
'blog' => 'Blog',
'homepage' => 'Homepage',
'facebook' => 'Facebook',
'linkedin' => 'LinkedIn',
'flickr' => 'Flickr',
'google' => 'Google Profile',
'other' => 'Other',
'twitter' => 'Twitter'
),
null,
false,
isset($field['rel']) ? $field['rel'] : null
);
$this->showMultiControls();
$this->out->elementEnd('div');
}
protected function showExperience($name, $field)
{
$this->out->elementStart('div', 'experience-item');
@ -421,6 +472,9 @@ class ExtendedProfileWidget extends Form
case 'phone':
$this->showPhone($name, $field);
break;
case 'website':
$this->showWebsite($name, $field);
break;
case 'im':
$this->showIm($name, $field);
break;
@ -467,6 +521,9 @@ class ExtendedProfileWidget extends Form
case 'im':
$this->showEditableIm($name, $field);
break;
case 'website':
$this->showEditableWebsite($name, $field);
break;
case 'experience':
$this->showEditableExperience($name, $field);
break;

View File

@ -110,6 +110,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
$this->savePhoneNumbers($user);
$this->saveIms($user);
$this->saveWebsites($user);
$this->saveExperiences($user);
$this->saveEducations($user);
@ -198,6 +199,42 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
}
}
function findWebsites() {
// Form vals look like this:
$sites = $this->sliceParams('website', 2);
$wsArray = array();
foreach ($sites as $site) {
list($id, $rel) = array_values($site);
$wsArray[] = array(
'value' => $id,
'rel' => $rel
);
}
return $wsArray;
}
function saveWebsites($user) {
$sites = $this->findWebsites();
$this->removeAll($user, 'website');
$i = 0;
foreach($sites as $site) {
if (!empty($site['value'])) {
++$i;
$this->saveField(
$user,
'website',
$site['value'],
$site['rel'],
$i
);
}
}
}
function findExperiences() {
// Form vals look like this: