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);
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;}
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);
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)));
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());
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);
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();
av=MOdtRenderer::IntVar;
}else
if(varname=="EVENTPRICE"){
- value=event.defaultprice().value();
+ value=/*event.defaultprice().value()*/(int)1;
av=MOdtRenderer::MoneyVar;
}
}
}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;
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;
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 "";
}
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;}
<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-->
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());
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;
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
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";
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";
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";
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";
//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
//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());
}
}
}
- 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;
}
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;
}
/**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*/
//
class WObject {
- protected $data;
-
- protected function __construct($d){$this->data=$d;}
+ protected function __construct(){}
};