Extended profile - finished basic pattern for adding/removing/saving multiple complex fields

This commit is contained in:
Zach Copley
2011-03-14 01:49:46 -07:00
parent deb40602d2
commit 04c8bf2743
4 changed files with 107 additions and 74 deletions

View File

@@ -107,7 +107,9 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
foreach ($simpleFieldNames as $name) {
$value = $this->trimmed('extprofile-' . $name);
$this->saveField($user, $name, $value);
if (!empty($value)) {
$this->saveField($user, $name, $value);
}
}
$this->savePhoneNumbers($user);
@@ -118,15 +120,19 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
function savePhoneNumbers($user) {
$phones = $this->findPhoneNumbers();
foreach ($phones as $phone) {
$this->saveField(
$user,
'phone',
$phone['value'],
$phone['rel'],
$phone['index']
);
$this->removeAll($user, 'phone');
$i = 0;
foreach($phones as $phone) {
if (!empty($phone['value'])) {
++$i;
$this->saveField(
$user,
'phone',
$phone['value'],
$phone['rel'],
$i
);
}
}
}
@@ -223,6 +229,16 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
$detail->free();
}
function removeAll($user, $name)
{
$profile = $user->getProfile();
$detail = new Profile_detail();
$detail->profile_id = $profile->id;
$detail->field_name = $name;
$detail->delete();
$detail->free();
}
/**
* Save fields that should be stored in the main profile object
*