//static get instance
QStringList cols=tbl.columns();
QStringList pcols=tbl.primaryColumns();
+ //header
code+="public static function getFromDB(";
for(int i=0;i<pcols.size();i++){
if(i)code+=",";
code+="$"+pcols[i];
}
QString dbi="$"+woc->dbInst();
+ //DB query
code+="){\n\tglobal "+dbi+";\n\t$res="+dbi+"->select(\""+tbl.name()+"\",\"*\",\"";
for(int i=0;i<pcols.size();i++){
if(i)code+=" AND ";
code+=pcols[i]+"=\"."+dbi+"->escapeColumn(\""+tbl.name()+"\",\""+pcols[i]+"\",$"+pcols[i]+").\"";
}
- code+="\");\n\tif($res!==false && count($res)<1)return false;\n\telse return new WT"+tbl.name()+"($res[0],true);\n}\n\n";
+ code+="\");\n";
+ //check result
+ code+="\tif($res===false)return false;\n\tif(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=\"\",$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";
WocTable tab=WocProcessor::instance()->table(k[i]);
//single object mapping
code+="\nstatic public function fromTable"+k[i]+"($table){\n";
+ code+="\tif($table === false)return false;\n";
code+="\t$data=new WO"+cls.name()+"();\n";
QMap<QString,QString>map=cls.mapping(k[i]);
QStringList mapk=cls.mappingProperties(k[i]);
cl.isprime=str2bool(el.attribute("primarykey","0"));
cl.isunique=str2bool(el.attribute("unique","0"));
cl.isindex=str2bool(el.attribute("index","0"));
+ if(cl.isprime)cl.isnull=false;
+ else cl.isnull=true;
if(el.hasAttribute("null"))
cl.isnull=str2bool(el.attribute("null"));
- else
+ else if(el.hasAttribute("notnull"))
cl.isnull=!str2bool(el.attribute("notnull","0"));
cl.type=el.attribute("type");
//TODO: validate type
code+=",\n P"+pp[i].replace(':',"_");
code+="\n };\n";
code+=" static QString rightToString(Right);\n";
+ code+=" static QString rightToLocalString(Right);\n";
code+=" static Right stringToRight(QString);\n";
code+=" static QStringList allKnownRightsString();\n";
code+=" static QList<Right> allKnownRights();\n";
for(int i=0;i<p.size();i++)
code+="\t\tcase P"+pp[i]+":return \""+p[i]+"\";\n";
code+="\t\tdefault:return \"\";\n\t}\n}\n";
+ code+="QString "+m_prefix+"Interface::rightToLocalString(Right r)\n{\n\tswitch(r){\n";
+ for(int i=0;i<r.size();i++)
+ code+="\t\tcase R"+r[i]+":return tr(\""+r[i]+"\");\n";
+ for(int i=0;i<p.size();i++)
+ code+="\t\tcase P"+pp[i]+":return tr(\""+p[i]+"\");\n";
+ code+="\t\tdefault:return \"\";\n\t}\n}\n";
code+=m_prefix+"Interface::Right "+m_prefix+"Interface::stringToRight(QString s)\n{\n";
for(int i=0;i<r.size();i++)
code+="\tif(s==\""+r[i]+"\")return R"+r[i]+";else\n";