From: Iain Patterson Date: Tue, 9 Apr 2013 22:26:57 +0000 (-0400) Subject: Split hub roles. X-Git-Tag: 2013-04-10~8 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=8549c1776033e924ea50328bd2434529d85b5669;p=readifood.git Split hub roles. Differentiate between hubs which take donations (ROLE_COLLECTION) and those which receive orders on behalf of beneficiaries (ROLE_DISTRIBUTION). --- diff --git a/lib/constants.php b/lib/constants.php index 375fe47..10fafd6 100644 --- a/lib/constants.php +++ b/lib/constants.php @@ -4,13 +4,18 @@ $week = array("Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat"); /* Contact roles. */ - $roles = array("Staff", "Driver", "Referrer", "Beneficiary", "Donor"); + $contact_roles = array("Staff", "Driver", "Referrer", "Beneficiary", "Donor"); $ROLE_STAFF = 1 << 0; $ROLE_DRIVER = 1 << 1; $ROLE_REQUESTER = 1 << 2; $ROLE_BENEFICIARY = 1 << 3; $ROLE_DONOR = 1 << 4; + /* Hub types. */ + $hub_roles = array("Collection", "Distribution"); + $ROLE_COLLECTION = 1 << 0; + $ROLE_DISTRIBUTION = 1 << 1; + /* Order states. */ $states = array("placed", "picked", "despatched", "undelivered", "delivered", "cancelled"); $all_states = (1 << count($states)) - 1; diff --git a/lib/contact.php b/lib/contact.php index ccfcd48..166fd97 100644 --- a/lib/contact.php +++ b/lib/contact.php @@ -167,17 +167,11 @@ } function show_contact_role_form($role) { - global $roles; - - for ($i = 0; $i < count($roles); $i++) { - echo " $roles[$i]\n"; - } + return show_role_form($role, $GLOBALS['contact_roles']); } function show_contact_form($contact = null) { - global $roles; + global $contact_roles; if (! $contact) $contact = new Contact; @@ -299,10 +293,10 @@ } function update_contact(&$contact, $area_id, $new = false) { - global $roles; + global $contact_roles; $role = 0; - for ($i = 0; $i < count($roles); $i++) { + for ($i = 0; $i < count($contact_roles); $i++) { if ($_POST['role_' . $i] == "on") $role |= (1 << $i); } diff --git a/lib/functions.php b/lib/functions.php index b019e93..86c8140 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -285,10 +285,8 @@ return get_city_contacts($city_id, $GLOBALS['ROLE_DRIVER']); } - function get_contact_role_string($contact) { - global $roles; - - $role = $contact->getRole(); + function get_role_string($object, $roles) { + $role = $object->getRole(); $selected = array(); @@ -299,6 +297,22 @@ return implode(", ", $selected); } + function get_contact_role_string($contact) { + return get_role_string($contact, $GLOBALS['contact_roles']); + } + + function get_hub_role_string($hub) { + return get_role_string($hub, $GLOBALS['hub_roles']); + } + + function show_role_form($role, $roles) { + for ($i = 0; $i < count($roles); $i++) { + echo " $roles[$i]\n"; + } + } + function get_area_hubs($area_id = null) { $q = new HubQuery; if (isset($area_id)) $q->useAddressQuery()->filterByAreaId($area_id)->endUse(); diff --git a/lib/hub.php b/lib/hub.php index 48b45ae..a3a1121 100644 --- a/lib/hub.php +++ b/lib/hub.php @@ -40,18 +40,28 @@ exit; } + function show_hub_summary(&$hub, $editing = false) { + if ($editing) echo "

Hub: " . htmlspecialchars($hub->getName()) . ""; + else echo "
\nHub " . $hub->getStrongLink(); + $role = $hub->getRole(); + $role_string = get_hub_role_string($hub); + if ($role_string) echo " $role_string"; + if ($role & $GLOBALS['ROLE_COLLECTION']) printf(" Donations", urlencode($hub->getName()), $hub->getId()); + if ($role & $GLOBALS['ROLE_DISTRIBUTION']) printf(" Orders", urlencode($hub->getName()), $hub->getId()); + if (check_admin(1)) { + echo " " . $hub->getDeleteLink(); + } + $area = get_hub_area($hub); + if ($area) echo " in " . $area->getLink(); + $city = get_hub_city($hub); + if ($city) echo ", " . $city->getLink(get_city_displayname($city)); + } + function show_hubs($offset, $per_page, $address_ids) { $q = new HubQuery; $hubs = $q->filterByAddressId($address_ids)->find(); if (count($hubs)) { - foreach ($hubs as $hub) { - echo "
\nhub " . $hub->getLink(); - if (check_admin(1)) { - echo " " . $hub->getDeleteLink(); - } - $area = get_hub_area($hub); - echo " in " . $area->getLink(); - } + foreach ($hubs as $hub) show_hub_summary($hub); } else echo " none"; } @@ -70,7 +80,7 @@ $address_ids = array(); foreach ($addresses as $address) $address_ids[] = $address->getId(); - echo "

hubs in city " . $city->getLink(get_city_displayname($city)) . ":"; + echo "

Hubs in city " . $city->getLink(get_city_displayname($city)) . ":"; return show_hubs($offset, $per_page, $address_ids); } else echo "

No such city!

\n"; @@ -134,9 +144,19 @@ show_hub_cities_form($city_id); } + function show_hub_role_form($role) { + return show_role_form($role, $GLOBALS['hub_roles']); + } + function show_hub_form($hub = null, $area_id = null) { if (! $hub) $hub = new Hub; + /* Role. */ + echo "\n"; + echo " Role\n"; + echo " "; show_hub_role_form($hub->getRole()); echo "\n"; + echo "\n"; + /* Display name. */ echo "\n"; echo " Hub name\n"; @@ -230,6 +250,13 @@ } function update_hub(&$hub, $area_id, $new = false) { + global $hub_roles; + + $role = 0; + for ($i = 0; $i < count($hub_roles); $i++) { + if ($_POST['role_' . $i] == "on") $role |= (1 << $i); + } + $displayname = $_POST['displayname']; if (! $displayname) { @@ -264,6 +291,7 @@ $telephone2 = $_POST['telephone2']; $email = $_POST['email']; + $hub->setRole($role); $hub->setDisplayname($displayname); $hub->setTelephone1($telephone1); $hub->setTelephone2($telephone2); @@ -330,12 +358,7 @@ if (! $hub) return; echo "
\n"; - echo "

Hub: " . $hub->getDisplayname() . ""; - if (check_admin(1)) { - echo " " . $hub->getDeleteLink(); - } - $city = get_hub_city($hub); - if ($city) echo " in " . $city->getLink(get_city_displayname($city)); + show_hub_summary($hub, true); echo ": "; echo "\n

"; diff --git a/propel/schema.xml b/propel/schema.xml index 78516d8..445574d 100644 --- a/propel/schema.xml +++ b/propel/schema.xml @@ -93,6 +93,7 @@ +