show statistics in event overview
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 14 Nov 2008 13:27:19 +0000 (13:27 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 14 Nov 2008 13:27:19 +0000 (13:27 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@180 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

doc/prog_protocol.html
src/event.cpp
src/event.h
src/overview.cpp
src/webrequest.cpp
www/inc/classes/event.php
www/inc/classes/ticket.php

index 7c04ecf..7c22d4b 100644 (file)
@@ -148,13 +148,15 @@ The <tt>geteventlist</tt> transaction requests all events from the server. The r
 
 <pre>
 &lt;EventList>
-  &lt;Event id="0" start="1190543432">blechsalat&lt;/Event>
-  &lt;Event id="1" start="1191419769">stringsalat&lt;/Event>
+  &lt;Event id="0" start="1190543432" sold="11" capacity="20" reserved="2">blechsalat&lt;/Event>
+  &lt;Event id="1" start="1191419769" sold="11" capacity="20" reserved="2">stringsalat&lt;/Event>
 &lt;/EventList>
 </pre>
 
 Each event is encapsulated in an <tt>Event</tt> tag. The events have no specific order. The <tt>id</tt> attribute contains the internal ID of the event that can be used to reference it in other requests. The <tt>start</tt> attribute contains the start time of the event as Unix timestamp. The text of the <tt>Event</tt> tag contains the title of the event.<p>
 
+There are 3 optional attributes: <tt>capacity</tt> contains the maximum number of seats for this event, <tt>sold</tt> the number of tickets that have been sold and <tt>reserved</tt> the number of tickets that have been reserved.<p>
+
 <h3>Getting Detailed Event Data</h3>
 
 The <tt>geteventdata</tt> transaction returns detailed data about the event. The request body contains a space separated list of event IDs. The response looks like:<p>
index cfafa97..ba75490 100644 (file)
@@ -29,6 +29,7 @@ MEvent::MEvent()
        req=0;
        eventid=-1;
        m_starttime=m_endtime=m_capacity=m_defaultprice=0;
+       m_sold=m_reserved=-1;
        m_valid=m_complete=false;
 }
 
@@ -38,6 +39,7 @@ MEvent::MEvent(MWebRequest*r,QDomElement&el)
        m_starttime=QDateTime::currentDateTime().toTime_t();
        m_endtime=m_starttime+3600;
        m_capacity=10;
+       m_sold=m_reserved=-1;
        m_defaultprice=100;
        m_valid=false;
        m_roomid=m_title=m_artist=m_description=m_cancelreason="";
@@ -65,6 +67,8 @@ MEvent& MEvent::operator=(const MEvent&e)
        m_endtime=e.m_endtime;
        m_roomid=e.m_roomid;
        m_capacity=e.m_capacity;
+       m_sold=e.m_sold;
+       m_reserved=e.m_reserved;
        m_defaultprice=e.m_defaultprice;
        m_cancelreason=e.m_cancelreason;
        m_valid=e.m_valid;
@@ -77,6 +81,7 @@ void MEvent::refresh()
        m_starttime=QDateTime::currentDateTime().toTime_t();
        m_endtime=m_starttime+3600;
        m_capacity=10;
+       m_sold=m_reserved=-1;
        m_defaultprice=100;
        m_valid=false;
        m_roomid=m_title=m_artist=m_description=m_cancelreason="";
@@ -120,6 +125,8 @@ void MEvent::initFromElement(QDomElement&el)
        m_starttime=el.attribute("start","0").toInt();
        m_endtime=el.attribute("end","0").toInt();
        m_capacity=el.attribute("capacity","0").toInt();
+       m_sold=el.attribute("sold","-1").toInt();
+       m_reserved=el.attribute("reserved","-1").toInt();
        m_defaultprice=el.attribute("defaultprice","0").toInt();
        bool iscancel=el.attribute("cancelled","false")=="true";
        //get title (if element exists this is a complete list, otherwise only preview)
index aec7360..64d019e 100644 (file)
@@ -65,6 +65,10 @@ class MEvent
                QString room()const{return m_roomid;}
                /**returns the amount of tickets than can be sold for this event, initially this should be a copy of the rooms capacity*/
                int capacity()const{return m_capacity;}
+               /**returns how many tickets have been sold (if not available: -1)*/
+               int amountSold()const{return m_sold;}
+               /**returns how many tickets have been reserved (if not available: -1)*/
+               int amountReserved()const{return m_reserved;}
                /**returns the normal price of tickets in cent*/
                int price()const{return m_defaultprice;}
                /**returns whether the event is cancelled*/
@@ -110,6 +114,8 @@ class MEvent
                QString m_roomid;
                //initially a copy from room, can be adjusted
                int m_capacity;
+               //contains amount of sold/reserved tickets if available; -1 otherwise
+               int m_sold,m_reserved;
                //default pricing in cents
                int m_defaultprice;
                //if not null/empty: event has been cancelled
index 278a732..68e3e6d 100644 (file)
@@ -313,16 +313,19 @@ void MOverview::updateEvents()
 {
        QList<MEvent>evl=req->getAllEvents();
        eventmodel->clear();
-       eventmodel->insertColumns(0,2);
+       eventmodel->insertColumns(0,6);
        eventmodel->insertRows(0,evl.size());
-       eventmodel->setHorizontalHeaderLabels(QStringList()<<tr("Start Time")<<tr("Title"));
+       eventmodel->setHorizontalHeaderLabels(QStringList()<<tr("Start Time")<<tr("Title")<<tr("Capacity")<<tr("Sold")<<tr("Reserved")<<tr("Free"));
        for(int i=0;i<evl.size();i++){
                eventmodel->setData(eventmodel->index(i,0),evl[i].eventId(),Qt::UserRole);
                eventmodel->setData(eventmodel->index(i,0),QDateTime::fromTime_t(evl[i].startTime()).toString(tr("ddd MMMM d yyyy, h:mm ap","time format")));
                eventmodel->setData(eventmodel->index(i,1),evl[i].title());
+               eventmodel->setData(eventmodel->index(i,2),evl[i].capacity());
+               eventmodel->setData(eventmodel->index(i,3),evl[i].amountSold());
+               eventmodel->setData(eventmodel->index(i,4),evl[i].amountReserved());
+               eventmodel->setData(eventmodel->index(i,5),evl[i].capacity()-evl[i].amountSold()-evl[i].amountReserved());
        }
-       eventtable->resizeColumnToContents(0);
-       eventtable->resizeColumnToContents(1);
+       eventtable->resizeColumnsToContents();
 }
 
 void MOverview::closeEvent(QCloseEvent*ce)
index 11c7b79..2a80131 100644 (file)
@@ -547,12 +547,13 @@ QString MWebRequest::getTemplate(QString f)
        f=f.toLower();
        QRegExp fregexp("[a-z0-9_\\.]+");
        if(!fregexp.exactMatch(f))return "";
-       //do we need an update?
+       //basics
        QString dname=dataDir()+"/templates/";
        QSettings set;
        set.beginGroup("templates/"+profileid);
+       //do we need an update?
        QDateTime last=QDateTime::fromTime_t(set.value("lastupdate",0).toInt()+300);
-       if(last<QDateTime::currentDateTime()){do{
+       if(last<QDateTime::currentDateTime()){do{//pseudo-loop, so we can use break instead of goto
                //get local info
                set.beginGroup("checksum");
                QStringList files=set.childKeys();
@@ -560,9 +561,12 @@ QString MWebRequest::getTemplate(QString f)
                for(int i=0;i<files.size();i++)
                        fmap.insert(files[i],set.value(files[i]).toString());
                set.endGroup();
-               //get remote info
+               //get remote info, assume it is still valid if unable to retrieve it
                if(!request("gettemplatelist",""))break;
                if(responseStatus()!=Ok)break;
+               //remember update time
+               set.setValue("lastupdate",QDateTime::currentDateTime().toTime_t());
+               //parse info
                QDomDocument doc;
                if(!doc.setContent(responseBody()))break;
                //prune old stuff
@@ -625,5 +629,9 @@ bool MWebRequest::setTemplate(QString n,QString f)
                return false;
        if(responseStatus()!=Ok)
                return false;
+       //delete it from cache, so it is retrieved again
+       QSettings().remove("templates/"+profileid+"/checksum/"+n);
+       QFile(dataDir()+"/templates/"+n).remove();
+       //return success
        return true;
 }
index 6eb2f35..b77b9d2 100644 (file)
@@ -17,7 +17,7 @@ returns an array of array("eventid"=>int, "title"=>string,"starttime"=>int)*/
 function getAllEvents()
 {
        global $db;
-       return $db->select("event","eventid,title,starttime","","ORDER BY starttime");
+       return $db->select("event","eventid,title,starttime,capacity","","ORDER BY starttime");
 }
 
 /**Get an overview of events: returns an array of array("eventid"=>int); used by createEventList; returns only events in the future  and ordered*/
@@ -30,6 +30,7 @@ function getAllEventsForListing()
 /**Machine-wrapper for getAllEvents() */
 function getAllEventsXml()
 {
+       global $db;
        $all=getAllEvents();
        if($all===false){
                header("X-MagicSmoke-Status: Error");
@@ -42,8 +43,25 @@ function getAllEventsXml()
        if(count($all)>0)
        foreach($all as $k => $ev){
                $nod=$xml->createElement("Event",$ev["title"]);
+               //set direct attributes
                $nod->setAttribute("id",$ev["eventid"]);
                $nod->setAttribute("start",$ev["starttime"]);
+               $nod->setAttribute("capacity",$ev["capacity"]);
+               //find out how many tickets are sold/reserved
+               $res=$db->select("ticket","status","eventid=".$db->escapeInt($ev["eventid"]));
+               if($res===false){
+                       $nod->setAttribute("sold",0);
+                       $nod->setAttribute("reserved",0);
+               }else{
+                       $cnt=0;
+                       $rsv=0;
+                       foreach($res as $tc){
+                               if(($tc["status"] & TICKET_USABLE) == TICKET_USABLE)$cnt++;
+                               if($tc["status"]==TICKET_RESERVED)$rsv++;
+                       }
+                       $nod->setAttribute("sold",$cnt);
+                       $nod->setAttribute("reserved",$rsv);
+               }
                $root->appendChild($nod);
        }
        $xml->appendChild($root);
index a6b9979..fa06caf 100644 (file)
 //
 
 //masks
-/**mask: ticket is blocked (can be used or is used)*/
+/**mask: ticket is blocked (is blocking a seat)*/
 define("TICKET_MBLOCK",0x100); //dec: 256
 /**mask: ticket must be paid or is paid*/
 define("TICKET_MPAY",0x200); //dec: 512
+/**mask: ticket is usable by a customer (blocking plus (to be) paid)*/
+define("TICKET_USABLE",0x300); //dec: 768
 
 
 /**ticket has been reserved by a seller*/
-define("TICKET_RESERVED",0x101); //dec: 257
+define("TICKET_RESERVED",0x301); //dec: 769
 /**ticket is part of an order or has been sold independently*/
 define("TICKET_BOUGHT",0x302); //dec: 770
 /**ticket has been used*/