Sélectionner une révision Git
functions.php 3,10 Kio
<?php
function commande_to_string($commande_formatee, $show_price = true) {
global $foods;
global $food_types;
global $sauces;
global $meats;
global $sizes;
$current_commande = unformat_commande_new($commande_formatee);
$commande = $food_types[$current_commande['food_type_id']].' : ';
$commande .= $foods[$current_commande['food_id']]['food_title'];
$commande .= (isset($current_commande['size_id'])) ? ' ('.$sizes[$current_commande['size_id']]['title'].')' : '';
if (sizeof($current_commande['sauces_ids']) > 0) {
$commande .= ' (Sauce'.ngettext('', 's', sizeof($current_commande['sauces_ids']));
$commande .= ' : '.implode(', ', array_map(function($sauce_id) use($sauces) { return $sauces[$sauce_id]; }, $current_commande['sauces_ids'])).')';
}
if (sizeof($current_commande['meats_ids']) > 0) {
$commande .= ' (Viande'.ngettext('', 's', sizeof($current_commande['meats_ids']));
$commande .= ' : '.implode(', ', array_map(function($sauce_id) use($meats) { return $meats[$sauce_id]; }, $current_commande['meats_ids'])).')';
}
if ($show_price)
$commande .= ' <strong>('.$current_commande['price'].'€)</strong>';
else
$commande .= ' ['.$current_commande['price'].'€]';
return $commande;
}
function commande_to_string_no_price($commande_formatee) {
return commande_to_string($commande_formatee, false);
}
function format_commande($current_commande) {
$commande_full = 'food_type_id:'.$current_commande['food_type_id'];
$commande_full .= '-food_id:'.$current_commande['food_id'];
$commande_full .= (isset($current_commande['size_id'])) ? '-size_id:'.$current_commande['size_id'] : '';
if (sizeof($current_commande['sauces_ids']) > 0)
$commande_full .= '-sauces_ids:'.implode(',', $current_commande['sauces_ids']);
if (sizeof($current_commande['meats_ids']) > 0)
$commande_full .= '-meats_ids:'.implode(',', $current_commande['meats_ids']);
$commande_full .= '-price:'.$current_commande['price'];
$commande_full .= '-price_obig:'.$current_commande['price_obig'];
return $commande_full;
}
function unformat_commande_new($commande_formatee) {
$commande_array = split("-", $commande_formatee);
$current_commande['food_id'] = 0;
$current_commande['food_type_id'] = 0;
$current_commande['sauces_ids'] = array();
$current_commande['meats_ids'] = array();
foreach ($commande_array as $commande_element_infos) {
$commande_element_infos_split = split(":", $commande_element_infos);
$commande_element = $commande_element_infos_split[0];
$commande_element_value = $commande_element_infos_split[1];
switch ($commande_element) {
case 'sauces_ids':
$current_commande['sauces_ids'] = split(",", $commande_element_value);
break;
case 'meats_ids':
$current_commande['meats_ids'] = split(",", $commande_element_value);
break;
default:
$current_commande[$commande_element] = $commande_element_value;
}
}
return $current_commande;
}
?>