public function FeedsUcAddressesProcessor::setTargetElement in Ubercart Addresses 7
Override setTargetElement to operate on a target item that is an address.
File
- feeds/
FeedsUcAddressesProcessor.inc, line 111 - Contains the FeedsUcAddressesProcessor class.
Class
- FeedsUcAddressesProcessor
- A processor for importing data belonging to an Ubercart Addresses address.
Code
public function setTargetElement(FeedsSource $source, $target_address, $target_element, $value) {
switch ($target_element) {
case 'aid':
// Don't set.
return;
case 'user_name':
$user = user_load_by_name($value);
if ($user) {
$target_address
->setOwner($user->uid);
}
return;
case 'user_mail':
$user = user_load_by_mail($value);
if ($user) {
$target_address
->setOwner($user->uid);
}
return;
case 'uid':
$target_address
->setOwner($value);
return;
}
// Set target through the field handlers.
$handler = NULL;
$fieldname = $target_element;
$format = NULL;
// Check if the target element represents a existing address field.
if (UcAddressesSchemaAddress::fieldExists($fieldname)) {
$handler = uc_addresses_get_address_field_handler($target_address, $fieldname, 'feeds');
}
else {
// Check if the target element represents a particular format of an existing address field.
$pieces = explode(':', $target_element);
if (count($pieces) >= 2) {
$fieldname = $pieces[0];
array_shift($pieces);
$format = implode(':', $pieces);
if (UcAddressesSchemaAddress::fieldExists($fieldname)) {
// Get the handler for the field.
$handler = uc_addresses_get_address_field_handler($target_address, $fieldname, 'feeds');
}
}
}
if ($handler instanceof UcAddressesFieldHandler) {
// Use the handler to set the right value.
$handler
->mapValue($value, $format);
}
else {
parent::setTargetElement($source, $target_address, $target_element, $value);
}
}