From 6b3d8229a4edbbda570b6049a6f546a4a6c47c71 Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 5 Jul 2010 19:53:59 +0000 Subject: [PATCH] docu for templates make eventOrder more robust make cart table defs more robust git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@529 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- wob/cart.wolf | 12 ++++--- wob/user.wolf | 2 +- www/inc/rendering/autoload.php | 2 + www/inc/rendering/cart_listing.php | 28 ++++++++++++----- www/inc/rendering/twig_extensions.php | 21 ++++++++++++ www/inc/wext/event.php | 20 ++++++++++- www/index.php | 3 +- www/template/en/cart.html | 43 +++++++++++++++++++++---- www/template/en/eventdetails.html | 45 ++++++++++++++++---------- www/template/en/index.html | 56 ++++++++++++++++++++++++++------- www/template/en/layout.html | 2 +- 11 files changed, 179 insertions(+), 55 deletions(-) diff --git a/wob/cart.wolf b/wob/cart.wolf index aae1f75..ca8afb4 100644 --- a/wob/cart.wolf +++ b/wob/cart.wolf @@ -7,7 +7,7 @@ - see COPYING.AGPL for details --> - +
the cookie for this cart @@ -28,7 +28,7 @@ pointer to shipping type (none per default, programmatic default is in config)
- +
@@ -36,19 +36,19 @@
- +
voucher value in cents
- +
- +
@@ -149,6 +149,7 @@ The cart as used by the web user interface, this maps into the cart tables. This class is never used by the The cart ID of this session + When the cart will be automatically deleted The customer of this cart The address to deliver to (mandatory) The address to send the invoice to if different from the delivery address (optional) @@ -168,6 +169,7 @@ + diff --git a/wob/user.wolf b/wob/user.wolf index 8320696..5f0971d 100644 --- a/wob/user.wolf +++ b/wob/user.wolf @@ -58,7 +58,7 @@
- +
diff --git a/www/inc/rendering/autoload.php b/www/inc/rendering/autoload.php index 256c4e4..f42aed8 100644 --- a/www/inc/rendering/autoload.php +++ b/www/inc/rendering/autoload.php @@ -11,6 +11,8 @@ $d=dirname(__FILE__); wob_autoclass("EventRender",$d.'/event_listing.php'); wob_autoclass("WebCart",$d.'/cart_listing.php'); + wob_autoclass("LangFilterExtension",$d.'/twig_extensions.php'); +wob_autoclass("SmokeFilterExtension",$d.'/twig_extensions.php'); ?> diff --git a/www/inc/rendering/cart_listing.php b/www/inc/rendering/cart_listing.php index 7610d96..2dde2a2 100644 --- a/www/inc/rendering/cart_listing.php +++ b/www/inc/rendering/cart_listing.php @@ -25,16 +25,21 @@ static public function addTickets(){ //get the cart $cartid=self::getOrCreateCart(); //find event - if(!isset($HTTPARGS['event']) || !isset($HTTPARGS[self::TicketAmountField])) + if(!isset($HTTPARGS[self::TicketAmountField])) redirectHome(); - $evid=$HTTPARGS['event']+0; //find price categories $pcs=$HTTPARGS[self::TicketAmountField]; if(!is_array($pcs) || count($pcs)==0) redirectHome(); //go through them foreach($pcs as $pcid => $amount){ - $pcid=$pcid+0;$amount=$amount+0; + //extract event ID from pcid + $evid=WOEventPrice::getEventIdFromAmountIndex($pcid); + //convert pcid to int + $pcid=WOEventPrice::getCategoryIdFromAmountIndex($pcid); + //convert amount to int + $amount=$amount+0; + //actually add WTrWebCartAddTicket::execute($cartid,$evid,$pcid,$amount); } //go to the cart @@ -126,7 +131,7 @@ static public function getNewCartId(){ /** creates the cart overview */ static public function createCartOverview() { - global $twig,$basevars; + global $twig,$basevars,$WebForceShipping; //get cart id and check it $cartid=self::getCart(); @@ -135,19 +140,26 @@ static public function createCartOverview() return $p->render($basevars); } - //cart is ok, now display it + //cart is ok, now get the object $cart = WOWebCart::fromTablecart(WTcart::getFromDB($cartid)); if(!is_a($cart,"WOWebCart")){ //ooops. internal problem $p=$twig->loadTemplate("carterror.html"); return $p->render($basevars); } - - $p = $twig->loadTemplate("cart.html"); $list=$basevars; $list["cart"]=$cart; - // create page + //additional info: available shipping types + $list["shipping"]=array(); + $list["forceshipping"]=$WebForceShipping; + $sl=WOShipping::fromTableArrayshipping(WTshipping::selectFromDB()); + foreach($sl as $s) + if($s->getcanuse()) + $list["shipping"][]=$s; + + //display + $p = $twig->loadTemplate("cart.html"); return $p->render($list); } diff --git a/www/inc/rendering/twig_extensions.php b/www/inc/rendering/twig_extensions.php index d10644b..acfb95f 100644 --- a/www/inc/rendering/twig_extensions.php +++ b/www/inc/rendering/twig_extensions.php @@ -31,11 +31,32 @@ class LangFilterExtension extends Twig_Extension public function getTime($i){return $this->lang->getTime($i);} public function getDateTime($i){return $this->lang->getDateTime($i);} + public function formatDate($i,$f){return $this->lang->formatDate($i,$f);} + public function getName() { return 'LangFilter'; } +} +class SmokeFilterExtension extends Twig_Extension +{ + public function getFilters() + { + $this->lang=LanguageManager::singleton(); + return array( + 'isObject' => new Twig_Filter_Method($this, 'isObject'), + 'isFalse' => new Twig_Filter_Method($this, 'isFalse'), + ); + } + + public function isObject($i){return is_a($i,"WObject");} + public function isFalse($i){return $i===false || $i === null;} + + public function getName() + { + return 'SmokeFilter'; + } } ?> \ No newline at end of file diff --git a/www/inc/wext/event.php b/www/inc/wext/event.php index 92688a7..746ea17 100644 --- a/www/inc/wext/event.php +++ b/www/inc/wext/event.php @@ -34,10 +34,26 @@ class WOEventPrice extends WOEventPriceAbstract return $cnt; } - /**helper for web UI: returns the name of the field for this event price*/ + /**helper for web UI: returns the name of the field for this event price, always the configured amount field from WebCart plus an index indicating category and event IDs*/ public function getAmountinputfield() { - return WebCart::TicketAmountField."[".$this->prop_pricecategoryid."]"; + return WebCart::TicketAmountField."[".$this->prop_pricecategoryid.":".$this->prop_eventid."]"; + } + + /**helper function for web UI: returns the event ID from an amount field index */ + static public function getEventIdFromAmountIndex($idx) + { + $sl=explode(":",$idx); + if(count($sl==2))return $sl[1]+0; + else return null; + } + + /**helper function for web UI: returns the event ID from an amount field index */ + static public function getCategoryIdFromAmountIndex($idx) + { + $sl=explode(":",$idx); + if(count($sl==2))return $sl[0]+0; + else return null; } }; diff --git a/www/index.php b/www/index.php index f072ca9..a025efd 100644 --- a/www/index.php +++ b/www/index.php @@ -32,6 +32,7 @@ foreach($twigextensions as $te){ $twig->addExtension(new $t()); } $twig->addExtension(new LangFilterExtension); +$twig->addExtension(new SmokeFilterExtension); //basic variables shared by all templates // script URLs @@ -39,7 +40,7 @@ $basevars['script']['root']=$_SERVER['SCRIPT_NAME']; $basevars['script']['this']=$_SERVER['REQUEST_URI']; $basevars['script']['index']=$_SERVER['SCRIPT_NAME']."?mode=index"; $basevars['script']['eventDetails']=$_SERVER['SCRIPT_NAME']."?mode=eventDetails&event="; -$basevars['script']['eventOrder']=$_SERVER['SCRIPT_NAME']."?mode=eventOrder&event="; +$basevars['script']['eventOrder']=$_SERVER['SCRIPT_NAME']."?mode=eventOrder"; $basevars['script']['cart']=$_SERVER['SCRIPT_NAME']."?mode=cart"; $basevars['script']['mycart']=$_SERVER['SCRIPT_NAME']."?mode=mycart"; $basevars['script']['checkout']=$_SERVER['SCRIPT_NAME']."?mode=checkout"; diff --git a/www/template/en/cart.html b/www/template/en/cart.html index 8934ac4..70abf5c 100644 --- a/www/template/en/cart.html +++ b/www/template/en/cart.html @@ -2,33 +2,62 @@ ================================ this one is called to show the cart #} - {% extends 'layout.html' %} {% block title %}Cart{% endblock %} {% block page %} -

This is cart {{cart.cartid}}

+ {# this just shows what is possible, we do not actually need to tell the user how secury it is...#} +

This is cart {{cart.cartid}}. It will expire {{cart.timeout|asDateTime}}.

+ {# the isempty flag tells us whether we need to bother with the rest... #} {% if cart.isempty %} This cart is empty. {% else %} + {# build a table with all the items of this shopping cart: + this is the headline: #}
+ + {# go through tickets and render them #} {% for ticket in cart.tickets %} - {% set pricesum=ticket.price * ticket.amount %} - + {% set pricesum=ticket.price * ticket.amount %} + + + + {% endfor %} + + {# now go through vouchers #} {% for voucher in cart.vouchers %} {% endfor %} - - + {# TODO: go through product items #} + + {# render the shipping option #} + {% if cart.shipping|isObject %} + + + + + {% else %} + + {% endif %} + + {# the overall sum of the above items... #} + + + {# end of the table #}
ItemItem PriceAmountSum
Ticket: {{ticket.event.title}}{{ticket.price|asMoney}}{{ticket.amount}}{{pricesum|asMoney}}
Ticket: {{ticket.event.title}}{{ticket.price|asMoney}}{{ticket.amount}}{{pricesum|asMoney}}
Voucher{{voucher.value}}1{{voucher.value}}
Shipping: {{cart.shipping.description}}{{cart.shipping.cost|asMoney}}1{{cart.shipping.cost|asMoney}}
Sum:{{cart.totalsum|asMoney}}
Shipping: {{cart.shipping.description}}{{cart.shipping.cost|asMoney}}1{{cart.shipping.cost|asMoney}}
No Shipping{{0|asMoney}}
Sum:{{cart.totalsum|asMoney}}
+ + {# actions the user may want to take #}

Checkout

+ + {# end of the non-empty cart... #} {% endif %} + {# in any case: allow the user to shop some more... #}

Continue Shopping

-{% endblock %} +{% endblock page %} diff --git a/www/template/en/eventdetails.html b/www/template/en/eventdetails.html index 8bec38f..0d5a6bd 100644 --- a/www/template/en/eventdetails.html +++ b/www/template/en/eventdetails.html @@ -2,31 +2,40 @@ ================================ this one is called to create the event detail/order page #} - {% extends 'layout.html' %} {% block title %}{{event.title}}{% endblock %} {% block page %} - + {# show basic information about the event #} {{event.start|asDateTime}}, {{event.room|e}}
Artist: {{event.artist.name|e}}
{{event.description}}
-
- - - {% for price in event.price %} - {% if price.canuse %} - - - {% endif %} - {% endfor %}
Price:Amount:
{{price.price|asMoney}} ({{price.pricecategory.name}})

- + + {# start the form that allows users to order for an event, the |safe filter tells the Twig parser that the URL should not be mangled #} + + + {# listing pricing options... #} + + {% for price in event.price %} + {# the objects handed over from MagicSmoke are not filtered, so it is important to check whether it makes sense to offer a specific price category #} + {% if price.canuse %} + {# if usable: show the details of the price category #} + + {# the amountinputfield property of the price contains the name for the form element to be used for each options amount - please use this property instead of hard coded values! #} + + {% endif %} + {% endfor %} +
Price:Amount:
{{price.price|asMoney}} ({{price.pricecategory.name}})

+ + {# end of the form... just add a button... #} +
-{% endblock %} +{% endblock page %} diff --git a/www/template/en/index.html b/www/template/en/index.html index f699354..4ab49e5 100644 --- a/www/template/en/index.html +++ b/www/template/en/index.html @@ -9,16 +9,48 @@ {% block page %} - {% for event in events %} -

{{event.name}}

- {{event.start|asDate}} {{event.start|asTime}}, {{event.room}}
- Artist: {{event.artist.name}}
- {{event.description}}
- Price: - {% for price in event.price %} - {{price.price|asMoney}} ({{price.pricecategory.name}}) - {% endfor %}
- details/order tickets - {% endfor %} + {# we use this to show monthly date lines #} + {% set olddate = '00' %} + + {# go through all events that MagicSmoke gave us #} + {% for event in events %} + {# check whether it actually makes sense to show this event, we do not show any events that the user cannot get tickets for (however, we do show those which are sold out) #} + {% if event.canuse %} + {# show the monthly date line #} + {% set newdate = event.start|date('Y.m') %} + {% if newdate != olddate %} + + +

{{ event.start|date('F - Y') }}
+ {% endif %} + {% set olddate = newdate %} + + {# show basic data about the event #} +

{{event.name}}

+ {{event.start|asDateTime}}, {{event.room}}
+ Artist: {{event.artist.name}}
+ {{event.description}}
+ + {# show pricing options #} + Price: + {% for price in event.price %} + {% if loop.index > 1 %},{% endif %} + {{price.price|asMoney}} ({{price.pricecategory.name}}) + {% endfor %}
+ + {# is it sold out? #} + {% if event.amountFree == 0 %} + Event sold out.
+ {% else %} + {# only very few tickets left? #} + {% if event.amountFree <= 5 %} + Event almost sold out.
+ {% endif %} + details/order tickets + {% endif %} + + {# end of event... #} + {% endif %} + {% endfor %} -{% endblock %} +{% endblock page %} diff --git a/www/template/en/layout.html b/www/template/en/layout.html index be1e036..bd38368 100644 --- a/www/template/en/layout.html +++ b/www/template/en/layout.html @@ -2,7 +2,7 @@ {% block title %}{% endblock %} - Magic Smoke Example Layout - + -- 1.7.2.5