From: Iain Patterson Date: Wed, 10 Apr 2013 21:52:25 +0000 (-0400) Subject: Describe parcels with more detail. X-Git-Tag: 2013-04-10^0 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=5f50c624101d671ec4147b3ad974c15178c6ebe5;p=readifood.git Describe parcels with more detail. Specify family unit size and allow multiple types of parcel contents. --- diff --git a/lib/constants.php b/lib/constants.php index 10fafd6..dcffda2 100644 --- a/lib/constants.php +++ b/lib/constants.php @@ -27,4 +27,18 @@ $STATE_CANCELLED = 1 << 5; $STATE_ANY = $all_states; + /* Parcel types. */ + $parcel_sizes = array("Single", "Couple", "Family"); + $PARCEL_SINGLE = 1 << 0; + $PARCEL_COUPLE = 1 << 1; + $PARCEL_FAMILY = 1 << 2; + + $parcel_contents = array(null, null, null, "Vegetarian", "Halal", "Diabetic", "Baby 0-6 months", "Baby 6-12 months", "Toiletry bag"); + $PARCEL_VEGETARIAN = 1 << 3; + $PARCEL_HALAL = 1 << 4; + $PARCEL_DIABETIC = 1 << 5; + $PARCEL_BABY6 = 1 << 6; + $PARCEL_BABY12 = 1 << 7; + $PARCEL_TOILETRY = 1 << 8; + ?> diff --git a/lib/delivery.php b/lib/delivery.php index 03495df..dddf2a2 100644 --- a/lib/delivery.php +++ b/lib/delivery.php @@ -88,7 +88,7 @@ if (! $contact) continue; $area = get_contact_area($contact); - echo "

Order of " . $order->getQuantity() . "kg for " . htmlspecialchars($contact->getDisplayname()) . " in " . htmlspecialchars(get_area_displayname($area)) . ".

\n"; + echo "

Order of " . get_order_parcel_string($order) . " for " . htmlspecialchars($contact->getDisplayname()) . " in " . htmlspecialchars(get_area_displayname($area)) . ".

\n"; $hub = get_hub_by_id($order->getHubId(), false); if ($hub) { echo "

Deliver to hub " . htmlspecialchars($hub->getName()) . ""; diff --git a/lib/functions.php b/lib/functions.php index f9da713..3727a65 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -199,8 +199,27 @@ return sprintf("%0.2fkg on %s", $donation->getQuantity() / 1000, $donation->getDate()); } + function get_order_parcel_string($order) { + global $parcel_sizes, $parcel_contents; + + $parcel_size = ""; + for ($i = 0 ; $i < count($parcel_sizes); $i++) { + if ($order->getParcel() & (1 << $i)) { + $parcel_size = $parcel_sizes[$i]; + break; + } + } + + $selected = array(); + for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) { + if ($order->getParcel() & (1 << $i)) $selected[] = $parcel_contents[$i]; + } + + return implode(": ", array($parcel_size, implode(", ", $selected))); + } + function get_order_displayname($order) { - return sprintf("%0.2fkg on %s", $order->getQuantity() / 1000, $order->getDate()); + return sprintf("%s on %s", get_order_parcel_string($order), $order->getDate()); } function get_address_area($address) { diff --git a/lib/order.php b/lib/order.php index a392f6e..cb40f63 100644 --- a/lib/order.php +++ b/lib/order.php @@ -230,7 +230,7 @@ } function show_order_form($order = null, $area_id = null) { - global $states; + global $states, $parcel_sizes, $parcel_contents; if ($order) { $q = new OrderStateQuery; @@ -299,6 +299,29 @@ echo " "; input("quantity", sprintf("%0.2f", $order->getQuantity() / 1000)); echo "\n"; echo "\n"; + /* Parcel type. */ + echo "\n"; + echo " Parcel size\n"; + echo " \n"; + echo "\n"; + + /* Parcel contents. */ + echo "\n"; + echo " Parcel contents\n"; + echo " "; + for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) { + echo " getParcel() & (1 << $i)) echo " checked"; + echo ">$parcel_contents[$i]\n"; + } + echo "\n"; + echo "\n"; + /* Driver. */ echo "\n"; echo " Driver\n"; @@ -371,7 +394,7 @@ } function update_order(&$order, $new = false) { - global $user_id; + global $user_id, $parcel_sizes, $parcel_contents; #$date = ymd_to_iso8601("date"); $date = $_POST['date']; @@ -383,6 +406,10 @@ if (! $driver_id) $driver_id = null; $state = $_POST['state']; if (! $state) $state = $GLOBALS['STATE_PLACED']; + $parcel = $_POST['parcel_size']; + for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) { + if ($_POST['parcel_' . $i] == "on") $parcel |= (1 << $i); + } if ($date) { list($y, $m, $d) = explode('-', $date); @@ -432,6 +459,7 @@ $order->setBeneficiaryId($beneficiary_id); $order->setHubId($hub_id); $order->setQuantity($quantity * 1000); + $order->setParcel($parcel); /* XXX: begin/commit */ try { diff --git a/propel/schema.xml b/propel/schema.xml index 7c801b4..0c35e97 100644 --- a/propel/schema.xml +++ b/propel/schema.xml @@ -132,6 +132,7 @@ +