getallevents works again
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 9 Aug 2009 15:38:20 +0000 (15:38 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 9 Aug 2009 15:38:20 +0000 (15:38 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@326 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/event.cpp
src/event.h
src/eventedit.cpp
src/eventsummary.cpp
src/orderwin.cpp
src/ticketrender.cpp
src/wbase/nullable.h
wob/event.wolf
woc/phpout.cpp
woc/phpout.h
www/inc/wbase/object.php

index fe1a8a6..e81f4a6 100644 (file)
@@ -33,7 +33,7 @@ QRegExp MEvent::priceRegExp()const
 
 QString MEvent::priceString()const
 {
-       qint64 dp=defaultprice();
+       qint64 dp=/*defaultprice()*/0;
        QString ret=QString::number(dp/100);
        ret+=QCoreApplication::translate("MEvent",".","price decimal dot");
        ret+=QString::number((dp/10)%10);
index c684946..e5b9f7b 100644 (file)
@@ -57,7 +57,7 @@ class MEvent:public MOEvent
                void setdefaultprice(QString);
                
                //inherit alternative definition
-               inline void setdefaultprice(qint64 p){MOEvent::setdefaultprice(p);}
+               inline void setdefaultprice(qint64 p){/*MOEvent::setdefaultprice(p);*/}
                
                /**returns whether the event is valid. an event can be invalid if it is uninitialized (negative ID) or the server request failed*/
                //bool isValid()const{return m_valid;}
index 3c4b663..2b73b75 100644 (file)
@@ -68,7 +68,7 @@ MEventEditor::MEventEditor(QWidget*w,qint64 id)
        gl->addWidget(lab=new QLabel(tr("Artist:")),++lctr,0);
        lab->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
        gl->addWidget(artist=new QLineEdit,lctr,1);
-       artist->setText(event.artist());
+       artist->setText(event.artist().value().name());
        
        gl->addWidget(lab=new QLabel(tr("Description:")),++lctr,0);
        lab->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
@@ -113,10 +113,10 @@ MEventEditor::MEventEditor(QWidget*w,qint64 id)
        price->setText(event.priceString());
        
        gl->addWidget(cancelcheck=new QCheckBox(tr("Event Cancelled:")),++lctr,0);
-       cancelcheck->setChecked(event.cancelled());
+       cancelcheck->setChecked(event.iscancelled());
        cancelcheck->setEnabled(false);
        gl->addWidget(cancelreason=new QLineEdit,lctr,1);
-       cancelreason->setEnabled(event.cancelled());
+       cancelreason->setEnabled(event.iscancelled());
        cancelreason->setText(event.cancelreason());
        connect(cancelcheck,SIGNAL(toggled(bool)),cancelreason,SLOT(setEnabled(bool)));
        
@@ -137,10 +137,10 @@ void MEventEditor::writeBack()
        event.settitle(title->text());
        event.setstart(starttime->dateTime().toTime_t());
        event.setend(endtime->dateTime().toTime_t());
-       event.setartist(artist->text());
+//     event.setartist(artist->text());
        event.setroom(room->text());
        event.setdefaultprice(price->text());
-       event.setcancelled(cancelcheck->isChecked());
+       event.setiscancelled(cancelcheck->isChecked());
        event.setcancelreason(cancelreason->text());
        event.setdescription(description->toPlainText());
        event.setcapacity(capacity->value());
index ba5206c..70caf5a 100644 (file)
@@ -49,7 +49,7 @@ MEventSummary::MEventSummary(QWidget*par,qint64 eid)
        gl->addWidget(new QLabel(tr("Title:")),rc,0);
        gl->addWidget(new QLabel(event.title()),rc,1);
        gl->addWidget(new QLabel(tr("Artist:")),++rc,0);
-       gl->addWidget(new QLabel(event.artist()),rc,1);
+       gl->addWidget(new QLabel(event.artist().value().name()),rc,1);
        gl->addWidget(new QLabel(tr("Start:")),++rc,0);
        gl->addWidget(new QLabel(event.startTimeString()),rc,1);
        gl->addWidget(new QLabel(tr("Capacity:")),++rc,0);
@@ -212,7 +212,7 @@ void MEventSummary::getVariable(QString varname,MOdtRenderer::VarType&av,QVarian
                value=event.title().value();
        else
        if(varname=="ARTIST")
-               value=event.artist().value();
+               value=event.artist().value().name().value();
        else
        if(varname=="ROOM")
                value=event.room().value();
@@ -266,7 +266,7 @@ void MEventSummary::getVariable(QString varname,MOdtRenderer::VarType&av,QVarian
                av=MOdtRenderer::IntVar;
        }else
        if(varname=="EVENTPRICE"){
-               value=event.defaultprice().value();
+               value=/*event.defaultprice().value()*/(int)1;
                av=MOdtRenderer::MoneyVar;
        }
 }
index 945b9e5..04e4d91 100644 (file)
@@ -540,7 +540,7 @@ void MOrderWindow::getLoopVariable(QString loopname,int it,QString vn,MOdtRender
                }else
                if(vn=="ID")value=tickets[it].ticketid().value();else
                if(vn=="TITLE")value=tickets[it].event().title().value();else
-               if(vn=="ARTIST")value=tickets[it].event().artist().value();else
+               if(vn=="ARTIST")value=tickets[it].event().artist().value().name().value();else
                if(vn=="DATE"){
                        value=tickets[it].event().start().value();
                        av=MOdtRenderer::DateVar;
@@ -567,7 +567,7 @@ void MOrderWindow::getLoopVariable(QString loopname,int it,QString vn,MOdtRender
                        av=MOdtRenderer::MoneyVar;
                }else
                if(vn=="TITLE")value=tickets[it].proto.event().title().value();else
-               if(vn=="ARTIST")value=tickets[it].proto.event().artist().value();else
+               if(vn=="ARTIST")value=tickets[it].proto.event().artist().value().name().value();else
                if(vn=="DATE"){
                        value=tickets[it].proto.event().start().value();
                        av=MOdtRenderer::DateVar;
index 5fb3db8..8e5b9d4 100644 (file)
@@ -527,7 +527,7 @@ QString MTicketLabel::getVariable(QString var)const
        if(var=="DATETIME")return tick.event().startTimeString();
        if(var=="ROOM")return tick.event().room();
        if(var=="TITLE")return tick.event().title();
-       if(var=="ARTIST")return tick.event().artist();
+       if(var=="ARTIST")return tick.event().artist().value().name();
        return "";
 }
 
index 3b90ed3..ec11c9d 100644 (file)
@@ -17,7 +17,7 @@
 template<class T>class Nullable
 {
        public:
-               Nullable(){isnull=true;}
+               Nullable(){isnull=true;elem=T();}
                Nullable(const T&t){isnull=false;elem=t;}
                Nullable(const Nullable<T>&t){isnull=t.isnull;elem=t.elem;}
                
index 615584d..dd11253 100644 (file)
@@ -42,7 +42,7 @@
                <Column name="eventid" type="seq32" primarykey="yes"/>
                <!--display data-->
                <Column name="title" type="string" notnull="yes"/>
-               <Column name="artist" type="string" notnull="yes"/>
+               <Column name="artistid" type="int32" foreignkey="artist:artistid"/>
                <Column name="description" type="text"/><!-- web visible -->
                <Column name="comment" type="text"/><!-- internal -->
                <!--timing and location-->
                <Column name="flags" type="string"/>
        </Table>
        
+       <Class name="Artist">
+               <Property name="id" type="int" id="yes"/>
+               <Property name="name" type="string"/>
+               <Property name="description" type="string"/>
+               <Property name="comment" type="string"/>
+       </Class>
+       
+       <Class name="Price">
+               <Property name="eventid" type="int"/>
+               <Property name="pricecategoryid" type="int"/>
+               <Property name="maxavailable" type="int32"/>
+               <Property name="price" type="int32"/>
+               <Property name="flags" type="string"/>
+       </Class>
+       
        <Class name="Event">
                <Property name="id" type="int" id="yes"/>
                <Property name="start" type="int64"/>
                <Property name="end" type="int64"/>
                <Property name="capacity" type="int"/>
-               <Property name="defaultprice" type="int"/>
+               <Property name="price" type="List:Price"/>
                <Property name="title" type="string"/>
-               <Property name="artist" type="string"/>
+               <Property name="artist" type="Artist"/>
                <Property name="room" type="string"/>
                <Property name="iscancelled" type="bool"/>
                <Property name="cancelreason" type="string"/>
                        <Map column="description"/>
                        <Map column="comment"/>
                        <!--timing and location-->
-                       <Map column="starttime"/>
-                       <Map column="endtime"/>
+                       <Map column="starttime" property="start"/>
+                       <Map column="endtime" property="end"/>
                        <Map column="roomid" property="room"/>
                        <!--Map column="seatplanid"/-->
                        <!--initially a copy from room, can be adjusted-->
index dd55d22..2de7e4a 100644 (file)
@@ -268,6 +268,9 @@ void WocPHPServerOut::newClass(const WocClass&cls)
        QString code="class "+cna+" extends "+cls.serverBaseClass()+"{\n\n";
        tf.write(code.toAscii());
        
+       //property declaration and constructor
+       tf.write(classConstruct(cls).toAscii());
+       
        //enums
        tf.write(classEnums(cls).toAscii());
        
@@ -291,6 +294,23 @@ void WocPHPServerOut::newClass(const WocClass&cls)
        tf.close();
 }
 
+QString WocPHPServerOut::classConstruct(const WocClass&cls)
+{
+       QString code;
+       QStringList k=cls.propertyNames();
+       for(int i=0;i<k.size();i++){
+               code+="protected $prop_"+k[i];
+               if(!cls.propertyIsList(k[i]))code+="=null";
+               code+=";\n";
+       }
+       code+="public function __construct()\n{\n";
+       for(int i=0;i<k.size();i++)
+               if(cls.propertyIsList(k[i]))
+                       code+="\t$this->prop_"+k[i]+"=array();";
+       code+="}\n";
+       return code;
+}
+
 QString WocPHPServerOut::classEnums(const WocClass&cls)
 {
        QString code;
@@ -309,7 +329,7 @@ QString WocPHPServerOut::classProperties(const WocClass&cls)
        QString code;
        QStringList k=cls.propertyNames();
        for(int i=0;i<k.size();i++){
-               code+="\nprotected $prop_"+k[i]+";\n";
+               code+="\n";
                //generate validator
                code+=classPropertyValidator(cls,k[i]);
                //generic getter
@@ -533,7 +553,7 @@ QString WocPHPServerOut::classPropertyScalarSetters(const WocClass&cls,QString p
        if(cls.propertyIsObject(prop)){
                code+="\tif(is_a($value,\"WO"+cls.propertyPlainType(prop)+"\")){\n";
                code+="\t\t$this->prop_"+prop+"=$value;\n";
-               code+="\t\treturn true;\n";
+               code+="\t\treturn true;\n\t}\n";
        }else{
                qDebug("Warning: unable to generate setter for class %s property %s: unknown type.",cls.name().toAscii().data(),prop.toAscii().data());
                code+="\treturn false;\n";
@@ -609,12 +629,13 @@ QString WocPHPServerOut::classMappings(const WocClass&cls)
        QString code;
        QStringList k=cls.mappingTables();
        for(int i=0;i<k.size();i++){
-               code+="\nstatic public function fromTable"+k[i]+"($table){\n\t$data=array();\n";
+               code+="\nstatic public function fromTable"+k[i]+"($table){\n";
+               code+="\t$data=new WO"+cls.name()+"();\n";
                QList<QPair<QString,QString> >map=cls.mapping(k[i]);
                for(int j=0;j<map.size();j++){
-                       code+="\t$data[\""+map[j].second+"\"]=$table->"+map[j].first+";\n";
+                       code+="\t$data->prop_"+map[j].second+"=$table->"+map[j].first+";\n";
                }
-               code+="\treturn new WO"+cls.name()+"($data);\n}\n";
+               code+="\treturn $data;\n}\n";
                code+="static public function fromTableArray"+k[i]+"(array $table){\n\t$ret=array();\n";
                code+="\tfor($i=0;$i<count($table);$i++)$ret[]=self::fromTable"+k[i]+"($table[$i]);\n";
                code+="\treturn $ret;\n}\n";
@@ -640,15 +661,17 @@ QString WocPHPServerOut::propertyToXml(const WocClass&cls,QString sl)
                        return code;
                }
        }
+       //non lists:
+       QString code="\t$p=$this->get_"+prop+"();\n\tif($p!==null)";
        //is it an attribute?
        if(cls.propertyIsAttribute(prop))
-               return "\t$root->setAttribute(\""+prop+"\",$this->getstr_"+prop+"());\n";
+               return code+"\t$root->setAttribute(\""+prop+"\",$this->getstr_"+prop+"());\n";
        //is it an element?
        if(cls.propertyIsElement(prop))
-               return "\t$root->appendChild($xml->createElement(\""+prop+"\",xq($this->getstr_"+prop+"())));\n";
+               return code+"\t$root->appendChild($xml->createElement(\""+prop+"\",xq($this->getstr_"+prop+"())));\n";
        //is it a class?
        if(cls.propertyIsObject(prop))
-               return "\t$root->appendChild($this->get_"+prop+"()->toXml($xml,\""+prop+"\"));\n";
+               return code+"$root->appendChild($p->toXml($xml,\""+prop+"\"));\n";
        //anything else?
        qDebug("Warning: end of WocPHPServerOut::propertyToXml - this code should not be reachable.");
        return "//internal generator error!\n";
@@ -684,12 +707,12 @@ void WocPHPServerOut::newTransaction(const WocTransaction&trn)
                case WocTransaction::Checked:
                        code+="\t/*security check: authenticated and authorized*/\n";
                        code+="\t"+m_authinit+";\n";
-                       code+="\tif(!"+m_isauth+"||!"+QString(m_hasrole).replace("%","\""+trn.name()+"\"")+")notAuthenticated();\n";
+                       code+="\tif(!"+m_isauth+"||!"+QString(m_hasrole).replace("%","\""+trn.name()+"\"")+")$this->notAuthenticated();\n";
                        break;
                case WocTransaction::Auth:
                        code+="\t/*security check: authenticated*/\n";
                        code+="\t"+m_authinit+";\n";
-                       code+="\tif(!"+m_isauth+")notAuthenticated();\n";
+                       code+="\tif(!"+m_isauth+")$this->notAuthenticated();\n";
                        break;
                default:
                        code+="\t/*no security check, open function*/\n";
@@ -699,7 +722,7 @@ void WocPHPServerOut::newTransaction(const WocTransaction&trn)
        //parse low level XML
        code+="\t/*low level XML parsing*/\n";
        code+="\tglobal $HTTP_RAW_POST_DATA;\n\tif(isset($HTTP_RAW_POST_DATA))$txt=$HTTP_RAW_POST_DATA;else $txt=\"\";\n";
-       code+="\t$xml=new DOMDocument;\n\tif(!$xml->loadXML($txt))xmlParserError();\n";
+       code+="\t$xml=new DOMDocument;\n\tif(!$xml->loadXML($txt))$this->xmlParserError();\n";
        code+="\t$root=$xml->documentElement;\n";
        
        //parse inputs
@@ -708,7 +731,7 @@ void WocPHPServerOut::newTransaction(const WocTransaction&trn)
        //call
        if(trn.hasCall("php")){
                code+="\t/*call actual functionality:*/\n";
-               code+="\ttry{"+trn.callFunction("php")+"}catch(Exception $e){handleException($e);}\n";
+               code+="\ttry{"+trn.callFunction("php")+"}catch(Exception $e){$this->handleException($e);}\n";
        }else{
                code+="\t/*normally here would be the PHP call, but it is missing from the config*/\n";
                qDebug("Warning: transaction %s does not have a PHP call!",trn.name().toAscii().data());
@@ -815,7 +838,7 @@ QString WocPHPServerOut::trnInput(const WocTransaction&trn)
                        }
                }
        }
-       code+="\t}catch(Exception $e){handleException($e);}\n";
+       code+="\t}catch(Exception $e){$this->handleException($e);}\n";
        code+="\t/*end of input parsing*/\n";
        return code;
 }
@@ -855,7 +878,7 @@ QString WocPHPServerOut::trnOutput(const WocTransaction&trn)
        code+="\t\t$xml->appendChild($root);\n";
        code+="\t\theader(\"X-WobResponse-Status: Ok\");\n";
        code+="\t\tprint($xml->saveXml());\n";
-       code+="\t}catch(Exception $e){handleException($e);}\n";
+       code+="\t}catch(Exception $e){$this->handleException($e);}\n";
        code+="\t/*end of output*/\n";
        return code;
 }
index 8fea498..b3dba00 100644 (file)
@@ -38,6 +38,8 @@ class WocPHPServerOut:public WocOutput
                
                /**helper: generates PHP code to transform a class property to XML*/
                QString propertyToXml(const WocClass&,QString);
+               /**helper: generate class constructor*/
+               QString classConstruct(const WocClass&);
                /**helper: generate class internal enums*/
                QString classEnums(const WocClass&);
                /**helper: generate class internal props*/
index 946fb82..4e27b1e 100644 (file)
@@ -10,9 +10,7 @@
 //
 
 class WObject {
-       protected $data;
-       
-       protected function __construct($d){$this->data=$d;}
+       protected function __construct(){}
        
 };