// merge 1.4 => 6117
This commit is contained in:
@@ -216,97 +216,6 @@ class AddressCore extends ObjectModel
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns values ordered in an array according to given fields
|
||||
* @param array $config set options for the method formated as
|
||||
$config = array(
|
||||
'spacer' => ' '
|
||||
, 'optional' => array(
|
||||
'company' => 1
|
||||
,'phone' => 1
|
||||
)
|
||||
, 'ignore' => array(
|
||||
'phone_mobile' => 1
|
||||
)
|
||||
, 'return_set' => true (true: hash return, false: String array)
|
||||
)
|
||||
* @param String $pattern lines of each needed fields \n splitted
|
||||
* @param array $values optionnal given values
|
||||
* @return array field values or hash values
|
||||
*/
|
||||
public static function getOrderedValuesFromArray($config, $pattern, array $values = null)
|
||||
{
|
||||
$tmp_address = new Address();
|
||||
$out = $tmp_address->getOrderedValues($config, $pattern, $values);
|
||||
unset($tmp_address);
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns values ordered in an array according to given fields
|
||||
* @param array $config set options for the method formated as
|
||||
$config = array(
|
||||
'spacer' => ' '
|
||||
, 'optional' => array(
|
||||
'company' => 1
|
||||
,'phone' => 1
|
||||
,'phone_mobile' => 1
|
||||
)
|
||||
, 'return_set' => true
|
||||
)
|
||||
* @param String $address_datas lines of each needed fields \n splitted
|
||||
* @param array $given_values optionnal given values
|
||||
* @return array field values or values in a hash
|
||||
*/
|
||||
|
||||
public function getOrderedValues(array $config, $address_datas, array $given_values = null)
|
||||
{
|
||||
|
||||
$spacer = $config["spacer"]; // String used for joining lines_out
|
||||
$optional_fields = (isset($config["optional"]))? $config["optional"] : array(); // array hash tells which fields are optional
|
||||
|
||||
$ignore = (isset($config["ignore"]))? $config["ignore"] : array(); // array hash tells which fields are ignored
|
||||
|
||||
|
||||
$return_set = (!empty($config["return_set"])) ? $config["return_set"] : false;
|
||||
|
||||
$line_breaker = "\n"; // used in address_datas format
|
||||
|
||||
|
||||
$lines_out = array();
|
||||
$fields_lines = explode($line_breaker, $address_datas);
|
||||
|
||||
foreach ($fields_lines as $one_line)
|
||||
if(!empty($one_line) && $one_line!= '')
|
||||
{
|
||||
$tmp_values = array();
|
||||
$val_added = false;
|
||||
|
||||
$words = explode(' ', trim($one_line));
|
||||
$tmp_words = array();
|
||||
|
||||
foreach ($words as $one_word)
|
||||
{
|
||||
if (!isset($ignore[$one_word]))
|
||||
{
|
||||
$one_word = trim($one_word);
|
||||
$val = (is_null($given_values)) ? $this->{$one_word} : $given_values[$one_word];
|
||||
if ((!empty($val) && $val != '') || ((empty($val) || $val == '') && (isset($optional_fields[$one_word]) != 1)))
|
||||
{
|
||||
$tmp_values[$one_word] = $val;
|
||||
$val_added = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($val_added)
|
||||
$lines_out[] = ($return_set) ? $tmp_values : implode($spacer, $tmp_values);
|
||||
}
|
||||
return $lines_out;
|
||||
}
|
||||
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
parent::validateFields();
|
||||
|
||||
Reference in New Issue
Block a user