return date(i18n("Y-m-d"), $date);
}
+ /** returns date in current language, default: ISO-date */
+ public function getDateTime($date)
+ {
+ return date(i18n("Y-m-d h:i a"), $date);
+ }
+
/** returns time in current language */
public function getTime($time)
{
$d=dirname(__FILE__);
wob_autoclass("EventRender",$d.'/event_listing.php');
wob_autoclass("WebCart",$d.'/cart_listing.php');
+wob_autoclass("LangFilterExtension",$d.'/twig_extensions.php');
?>
/**contains the name of the cookie and the HTTP parameter for the cart ID*/
const cartIdName = "smoke_cartid";
+/**contains the name for the web UI field that is supposed to contain the amount of tickets*/
+const TicketAmountField = "amountTickets";
+
/**called from index.php - add tickets to cart*/
static public function addTickets(){
global $HTTPARGS;
//get the cart
$cartid=self::getOrCreateCart();
//find event
- if(!isset($HTTPARGS['event']) || !isset($HTTPARGS['amountTickets']))
+ if(!isset($HTTPARGS['event']) || !isset($HTTPARGS[self::TicketAmountField]))
redirectHome();
$evid=$HTTPARGS['event']+0;
//find price categories
- $pcs=$HTTPARGS['amountTickets'];
+ $pcs=$HTTPARGS[self::TicketAmountField];
if(!is_array($pcs) || count($pcs)==0)
redirectHome();
//go through them
/**return existing cart or create a new one*/
static public function getOrCreateCart(){
- global $CartTimeout;
+ global $CartTimeout,$WebDefaultShipping;
//try to find it, if found update it
self::getCart();
//found?
$c=WTcart::newRow();
$exp=time()+$CartTimeout;
$c->timeout=$exp;
+ if($WebDefaultShipping>=0)
+ $c->shippingtype=$WebDefaultShipping;
$c->insert();
//set cookies
setCookie(self::cartIdName,$c->cartid,0);
$p = $twig->loadTemplate("cart.html");
$list=$basevars;
- $list["cart"]=$cart->getParserData();
+ $list["cart"]=$cart;
// create page
return $p->render($list);
//only show those available via web
if(!$session->checkFlags($event->getflags()))continue;
//encode as array
- $list['events'][]=$event->getParserData();
+ $list['events'][]=$event;
}
//pass 2: create page
// set event details
$list=$basevars;
- $list['event']=$event->getParserData();
+ $list['event']=$event;
// create page
return $p->render($list);
--- /dev/null
+<?
+//
+// PHP Implementation: additional Twig Filters
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2010
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+class LangFilterExtension extends Twig_Extension
+{
+ private $lang;
+
+ public function getFilters()
+ {
+ $this->lang=LanguageManager::singleton();
+ return array(
+ 'asMoney' => new Twig_Filter_Method($this, 'getPrice'),
+ 'asDate' => new Twig_Filter_Method($this, 'getDate'),
+ 'asTime' => new Twig_Filter_Method($this, 'getTime'),
+ 'asDateTime' => new Twig_Filter_Method($this, 'getDateTime'),
+ );
+ }
+
+ public function getPrice($i){return $this->lang->getPrice($i);}
+ public function getDate($i){return $this->lang->getDate($i);}
+ public function getTime($i){return $this->lang->getTime($i);}
+ public function getDateTime($i){return $this->lang->getDateTime($i);}
+
+ public function getName()
+ {
+ return 'LangFilter';
+ }
+
+}
+
+?>
\ No newline at end of file
$cnt++;
return $cnt;
}
+
+ /**helper for web UI: returns the name of the field for this event price*/
+ public function getAmountinputfield()
+ {
+ return WebCart::TicketAmountField."[".$this->prop_pricecategoryid."]";
+ }
};
class WOEvent extends WOEventAbstract
global $db;
$trans->setevents(WOEvent::fromTableArrayevent(WTevent::selectFromDB("starttime<=".$db->escapeInt($start)." AND endtime>=".$db->escapeInt($end))));
}
-
- /**returns the data in an array suitable for the web-page-renderer*/
- public function getParserData()
- {
- global $session,$basevars;
- $lang = LanguageManager::singleton();
- $ret= $this->propertyArray();
- $ret["date"]=$lang->getDate($this->getstart());
- $ret["time"]=$lang->getTime($this->getstart());
- $ret["place"]=$this->getroom();
- $ret["name"]=$this->gettitle();
- $ret["artistname"]=$this->getartist()->getname();
- $ret["ID"]=$this->getid();
- $ret["availabletickets"]=$this->getamountFree();
- //list all available prices
- $ret["prices"] = array();
- foreach($this->getprice() as $price){
- //not those unavailable via web
- if(!$session->checkFlags($price->getflags()))continue;
- //fill in data
- $p=$price->propertyArray();
- $p["price"]=$lang->getPrice($price->getprice());
- $p["pricecents"]=$price->getprice();
- $p["categoryid"]=$price->getpricecategoryid();
- $p["categoryname"]=$price->getpricecategory()->getname();
- //get max tickets, current amount, amount free
- $p["maxtickets"]=$price->getmaxavailable();
- $p["ticketsblock"]=$price->getamountticketsblock();
- $p["ticketsavailable"]=($price->getmaxavailable()-$price->getamountticketsblock());
- //little helper for forms
- $p["amountinputfield"]=($basevars['inputnames']['amountTickets']."[".$price->getpricecategoryid()."]");
- //copy to my own array
- $ret['prices'][]=$p;
- }
- //return result
- return $ret;
- }
};
?>
\ No newline at end of file
class WOWebCart extends WOWebCartAbstract
{
- /**returns array data for twig*/
- public function getParserData()
+ /**returns is empty attribute for twig*/
+ public function getIsempty()
{
- $ret=$this->propertyArray();
- //check whether it is empty
- $ret['isempty']=count($this->prop_tickets)==0 && count($this->prop_vouchers)==0 && count($this->prop_items)==0;
+ return count($this->prop_tickets)==0 && count($this->prop_vouchers)==0 && count($this->prop_items)==0;
$prc=0;
- //go through tickets and add some data
- $lang=LanguageManager::singleton();
- foreach($ret['tickets'] as $id=>$tck){
- $ev=WOEvent::fromTableevent(WTevent::getFromDB($tck['eventid']));
- $ret['tickets'][$id]['event']=$ev->propertyArray();
- $pc=WOEventPrice::fromTableeventprice(WTeventprice::getFromDB($tck['eventid'],$tck['pricecategoryid']));
- $ret['tickets'][$id]['pricecategory']=$pc->propertyArray();
- $p=$pc->getprice();
- $ret['tickets'][$id]['price']=$lang->getPrice($p);
- $ret['tickets'][$id]['pricecents']=$p;
- $p*=$tck['amount'];
- $ret['tickets'][$id]['pricesum']=$lang->getPrice($p);
- $ret['tickets'][$id]['pricesumcents']=$p;
- $prc+=$p;
+ }
+
+ /**returns the overall sum for twig*/
+ public function getTotalsum()
+ {
+ $prc=0;
+ //go through tickets
+ foreach($this->gettickets() as $tck){
+ $prc+=$tck->getprice()*$tck->getamount();
}
//go through vouchers add to sum
- foreach($ret['vouchers'] as $id=>$vou){
- $prc+=$vou['value'];
- $ret['vouchers'][$id]['valuecents']=$vou['value'];
- $ret['vouchers'][$id]['value']=$lang->getPrice($vou['value']);
+ foreach($this->getvouchers() as $id=>$vou){
+ $prc+=$vou->getvalue();
}
//TODO: go through items add to sum
- //TODO: add shipping option
- $ret["shippingid"]=false;
- //add sum to return value
- $ret['sumcents']=$prc;
- $ret['sum']=$lang->getPrice($prc);
+ //add shipping option
+ $ship=$this->getshipping();
+ if(is_a($ship,"WOShipping"))
+ $prc+=$ship->getcost();
//return...
- return $ret;
+ return $prc;
}
/**transaction to add tickets to cart*/
$itm=WTcartticket::getFromDB($cartid,$evid,$pcid);
if(is_a($itm,"WTcartticket")){
//yes: add to it
+// echo "add".$amount;
$itm->amount+=$amount;
$itm->update();
}else{
//no: add new item
+// echo "ins".$amount;
$itm=WTcartticket::newRow();
$itm->cartid=$cartid;
$itm->eventid=$evid;
$itm->amount=$amount;
$itm->insert();
}
+// die ("hallo");
}
};
//initialize TWIG
$loader = new Twig_Loader_Filesystem(LanguageManager::singleton()->templateFolder());
$twig = new Twig_Environment($loader, $twigoptions );
-foreach($twigextensions as $te)$twig->addExtension($te);
+foreach($twigextensions as $te){
+ $t='Twig_Extension_'.$te;
+ $twig->addExtension(new $t());
+}
+$twig->addExtension(new LangFilterExtension);
//basic variables shared by all templates
// script URLs
$basevars['inputnames']['cartid']=WebCart::cartIdName;
$basevars['cartcookie']=WebCart::cartIdName;
// other info
-$basevars['languages']=LanguageManager::getLanguages();
+$basevars['lang']=LanguageManager::singleton();
//strings that are used to compose the overall layout
$page="(internal error: no page text yet, probably no template defined)";
<table frame="1" border="1">
<tr><td><b>Item</b></td><td><b>Item Price</b></td><td><b>Amount</b></td><td><b>Sum</b></td></tr>
{% for ticket in cart.tickets %}
- <tr><td>Ticket: {{ticket.event.title}}</td><td>{{ticket.price}}</td><td>{{ticket.amount}}</td><td>{{ticket.pricesum}}</td></tr>
+ {% set pricesum=ticket.price * ticket.amount %}
+ <tr><td>Ticket: {{ticket.event.title}}</td><td align="right">{{ticket.price|asMoney}}</td><td align="right">{{ticket.amount}}</td><td align="right">{{pricesum|asMoney}}</td></tr>
{% endfor %}
{% for voucher in cart.vouchers %}
- <tr><td>Voucher</td><td>{{voucher.value}}</td><td>1</td><td>{{voucher.value}}</td></tr>
+ <tr><td>Voucher</td><td align="right">{{voucher.value}}</td><td align="right">1</td><td align="right">{{voucher.value}}</td></tr>
{% endfor %}
- <tr><td>Shipping: {{cart.shipping.name}}</td><td>{{cart.shipping.price}}</td><td>1</td><td>{{cart.shippingprice}}</td></tr>
- <tr><td colspan="3" align="right"><b>Sum:</b></td><td>{{cart.sum}}</td></tr>
+ <tr><td>Shipping: {{cart.shipping.description}}</td><td align="right">{{cart.shipping.cost|asMoney}}</td><td align="right">1</td><td align="right">{{cart.shipping.cost|asMoney}}</td></tr>
+ <tr><td colspan="3" align="right"><b>Sum:</b></td><td>{{cart.totalsum|asMoney}}</td></tr>
</table>
<p><a href="{{script.checkout}}">Checkout</a></p>
{% endif %}
{% extends 'layout.html' %}
-{% block title %}{{event.name}}{% endblock %}
+{% block title %}{{event.title}}{% endblock %}
{% block page %}
- <h2>{{event.name}}</h2>
- {{event.date}} {{event.time}}, {{event.place}}<br/>
- Artist: {{event.artistname}}<br/>
+ {{event.start|asDateTime}}, {{event.room|e}}<br/>
+ Artist: {{event.artist.name|e}}<br/>
{{event.description}}<br/>
- <form action="{{script.eventOrder}}{{event.ID}}" method="POST">
+ <form action="{{script.eventOrder|safe}}{{event.ID|safe}}" method="POST">
<table>
<tr><td>Price:</td><td>Amount:</td></tr>
- {% for price in event.prices %}
- <tr><td>{{price.price}} ({{price.categoryname}})</td>
+ {% for price in event.price %}
+ {% if price.canuse %}
+ <tr><td>{{price.price|asMoney}} ({{price.pricecategory.name}})</td>
<td><select name="{{price.amountinputfield}}">
- {% for i in 0 .. price.ticketsavailable %}
+ {% set ticketsavailable=price.maxavailable - price.amountticketsblock %}
+ {% for i in 0 .. ticketsavailable %}
<option>{{i}}</option>
{% endfor %}
</select></td></tr>
+ {% endif %}
{% endfor %}</table><br/>
<input type="submit" value="add to cart" />
</form>
{% for event in events %}
<h2>{{event.name}}</h2>
- {{event.date}} {{event.time}}, {{event.place}}<br/>
- Artist: {{event.artistname}}<br/>
+ {{event.start|asDate}} {{event.start|asTime}}, {{event.room}}<br/>
+ Artist: {{event.artist.name}}<br/>
{{event.description}}<br/>
Price:
- {% for price in event.prices %}
- {{price.price}} ({{price.categoryname}})
+ {% for price in event.price %}
+ {{price.price|asMoney}} ({{price.pricecategory.name}})
{% endfor %}<br/>
<a href="{{script.eventDetails}}{{event.ID}}">details/order tickets</a>
{% endfor %}
<!-- Begin Menu -->
<p align="right">
<a href="{{script.root}}">Ticket Shop</a> |
-<a href="{{script.mycart}}">My Shoping Cart</a> |
-Language:
-{% for lang in languages %}
- <a href="{{script.setlanguage}}{{lang}}"><img src="images/{{lang}}.png" alt="{{lang}}"/></a>
+<a href="{{script.mycart}}">My Shoping Cart</a>
+{% if lang.languages|length > 1 %}
+| Language:
+{% for lng in lang.languages %}
+ <a href="{{script.setlanguage}}{{lng}}"><img src="images/{{lng}}.png" alt="{{lng}}"/></a>
{% endfor %}
+{% endif %}
</p>
<!-- End Menu -->