}
code+="\");\n\tif($res!==false && count($res)<1)return false;\n\telse return new WT"+tbl.name()+"($res[0],true);\n}\n\n";
//static get selection
- code+="public static function selectFromDB($where){\n\tglobal "+dbi+";\n\t$res="+dbi+"->select(\""+tbl.name()+"\",\"*\",$where);\n\tif($res===false || count($res)<1)return array();\n\t";
+ code+="public static function selectFromDB($where=\"\",$orderby=\"\"){\n\tglobal "+dbi+";\n\t$res="+dbi+"->select(\""+tbl.name()+"\",\"*\",$where,$orderby);\n\tif($res===false || count($res)<1)return array();\n\t";
code+="$r=array();\n\tforeach($res as $row)\n\t\t$r[]=new WT"+tbl.name()+"($row,true);\n\treturn $r;\n}\n\n";
//go through columns, generate specific code
return $db->select("event","eventid","starttime>=".time()." ORDER BY starttime");
}
-/**Machine-wrapper for getAllEvents() */
-function getAllEventsXml()
-{
- global $db;
- $all=getAllEvents();
- if($all===false){
- header("X-MagicSmoke-Status: Error");
- echo "Database Error.";
- return;
- }
- header("X-MagicSmoke-Status: Ok");
- $xml=new DOMDocument;
- $root=$xml->createElement("EventList");
- if(count($all)>0)
- foreach($all as $k => $ev){
- $nod=$xml->createElement("Event",xq($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);
- echo $xml->saveXml();
-}
/**Wrapper around event table*/
class Event
/**XML iface: get all events*/
public static function getAllEvents($trans)
{
- $evlst=WOEvent::fromTableArrayevent(WTevent::selectFromDB(""));
+ $evlst=WOEvent::fromTableArrayevent(WTevent::selectFromDB("","ORDER BY starttime"));
$trans->setevents($evlst);
}
};