本文整理汇总了PHP中ExtraField::extra_field_double_select_convert_string_to_array方法的典型用法代码示例。如果您正苦于以下问题:PHP ExtraField::extra_field_double_select_convert_string_to_array方法的具体用法?PHP ExtraField::extra_field_double_select_convert_string_to_array怎么用?PHP ExtraField::extra_field_double_select_convert_string_to_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExtraField
的用法示例。
在下文中一共展示了ExtraField::extra_field_double_select_convert_string_to_array方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Saves an option into the corresponding *_field_options table
* @param array $params Parameters to be considered for the insertion
* @param bool $show_query Whether to show the query (sent to the parent save() method)
* @return bool True on success, false on error
* @assert (array('field_id'=>0), false) === false
* @assert (array('field_id'=>1), false) === true
*/
public function save($params, $show_query = false)
{
$field_id = intval($params['field_id']);
if (empty($field_id)) {
return false;
}
$time = api_get_utc_datetime();
if (!empty($params['field_options']) && in_array($params['field_type'], array(ExtraField::FIELD_TYPE_RADIO, ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_SELECT_MULTIPLE, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) {
if ($params['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
//$params['field_options'] = France:Paris;Bretagne;Marseilles;Lyon|Belgique:Bruxelles;Namur;Liège;Bruges|Peru:Lima;Piura;
$options_parsed = ExtraField::extra_field_double_select_convert_string_to_array($params['field_options']);
if (!empty($options_parsed)) {
foreach ($options_parsed as $key => $option) {
$sub_options = $option['options'];
$new_params = array('field_id' => $field_id, 'option_value' => 0, 'option_display_text' => $option['label'], 'option_order' => 0, 'tms' => $time);
// Looking if option already exists:
$option_info = self::get_field_option_by_field_id_and_option_display_text($field_id, $option['label']);
if (empty($option_info)) {
$sub_id = parent::save($new_params, $show_query);
} else {
$sub_id = $option_info['id'];
$new_params['id'] = $sub_id;
parent::update($new_params, $show_query);
}
foreach ($sub_options as $sub_option) {
if (!empty($sub_option)) {
$new_params = array('field_id' => $field_id, 'option_value' => $sub_id, 'option_display_text' => $sub_option, 'option_order' => 0, 'tms' => $time);
$option_info = self::get_field_option_by_field_id_and_option_display_text_and_option_value($field_id, $sub_option, $sub_id);
if (empty($option_info)) {
parent::save($new_params, $show_query);
} else {
$new_params['id'] = $option_info['id'];
parent::update($new_params, $show_query);
}
}
}
}
}
$list = array();
} else {
$list = explode(';', $params['field_options']);
}
if (!empty($list)) {
foreach ($list as $option) {
$option_info = self::get_field_option_by_field_and_option($field_id, $option);
// Use URLify only for new items
$optionValue = URLify::filter($option);
$option = trim($option);
if ($option_info == false) {
$order = self::get_max_order($field_id);
$new_params = array('field_id' => $field_id, 'option_value' => trim($optionValue), 'option_display_text' => trim($option), 'option_order' => $order, 'tms' => $time);
parent::save($new_params, $show_query);
}
}
}
}
return true;
}