// merge 1.4 => 6117

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@6118 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
fBrignoli
2011-04-29 09:09:38 +00:00
parent e60a8b9203
commit 56099fa735
29 changed files with 199 additions and 217 deletions
-91
View File
@@ -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();