void XaMedia::List(){ string XaDomainMediaCategory_ID=HTTP.GetHttpParam("XaDomainMediaCategory_ID"); string XaField_ID=HTTP.GetHttpParam("XaField_ID"); string XaTable=HTTP.GetHttpParam("XaTable"); string XPathExpr="/XaMedia/fieldset/field"; vector<string> XmlFiles = {"XaMedia"}; //LOAD XML FOR MODEL xmlDocPtr XmlDomDoc=XaLibDom::DomFromFile(AddXmlFile(XmlFiles),0); //GET NUMBER OF FILEDS int FieldsNum=XaLibDom::GetNumRowByXPathInt(XmlDomDoc,XPathExpr); string QryFields="SELECT R.id"; string QryJoin=""; for (auto i=0;i<FieldsNum;i++) { string j=to_string(i+1); if (XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/list")=="yes") { if (XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/type")=="select-single-domain") { string FieldName=XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/name"); QryFields+=",X"+j+".name AS "+FieldName; QryJoin+=" LEFT JOIN XaDomain X"+j+" ON X"+j+".id=R."+FieldName; } else if (XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/type")=="input-text"){ QryFields+=",R."+XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/name"); } else if (XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/type")=="input-number"){ QryFields+=",R."+XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/name"); } else if (XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/type")=="select-boolean"){ QryFields+=",R."+XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/name"); } else if (XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/type")=="external-key"){ QryFields+=",R."+XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+j+"]/name"); } LOG.Write("INF", __FILE__, __FUNCTION__,__LINE__,"Field to retrieve for the list ->"+XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/name")); }; }; QryFields+=" FROM XaMedia R"; LOG.Write("INF", __FILE__, __FUNCTION__,__LINE__,"Query Fields ->"+QryFields); LOG.Write("INF", __FILE__, __FUNCTION__,__LINE__,"Query Join ->"+QryJoin); string Qry=QryFields+QryJoin; Qry+=" WHERE R.status=1 AND R.XaField_ID="+XaField_ID+" AND R.XaTable='"+XaTable+"' AND R.XaDomainMediaCategory_ID="+XaDomainMediaCategory_ID; LOG.Write("INF", __FILE__, __FUNCTION__,__LINE__,"Query ->"+Qry); DbResMap DbRes=XaLibSql::FreeQuerySelect(DB_READ,Qry); vector<string> ListFields=ListPrepare({"XaMedia"},"/XaMedia/fieldset/field",0); RESPONSE.Content=ListResponse(DbRes,ListFields); };
tuple<vector<string>,vector<string>> XaLibAction::CreatePrepare(const vector<string>& XmlFiles,const string& XPathExpr,const string& ModelName) { //TODO:GESTIONE ERRORI //LOAD XML FOR MODEL xmlDocPtr XmlDomDoc=XaLibDom::DomFromFile(AddXmlFile(XmlFiles),0); //GET NUMBER OF FILEDS int FieldsNum=XaLibDom::GetNumRowByXPathInt(XmlDomDoc,XPathExpr); tuple<vector<string>,vector<string>> Fields; for (auto i=0;i<FieldsNum;i++) { //LOADING PROPERTIES string FieldName=XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/name"); string FieldValue=HTTP.GetHttpParam(ModelName+"-"+FieldName); get<0>(Fields).push_back(FieldName); get<1>(Fields).push_back(FieldValue); //FieldsName.push_back(FieldName); //FieldsValue.push_back(FieldValue); LOG.Write("INF", __FILE__, __FUNCTION__,__LINE__,"Loaded value for property ->" +FieldName +" :: " + FieldValue); }; return Fields; };
void XaLibModel::CreatePrepare(const vector<string>& XmlFiles,const string& XPathExpr,vector <string>& FieldName,vector <string>& FieldValue) { vector <string> Properties = {"name","db_type","size","create","required"}; //LOAD XML FOR MODEL xmlDocPtr XmlDomDoc=XaLibDom::DomFromFile(AddXmlFile(XmlFiles),0); //GET NUMBER OF FILEDS int FieldsNum=XaLibDom::GetNumRowByXPathInt(XmlDomDoc,XPathExpr); /*For Each Field Check Properties and Load Value*/ for (auto i=0; i<FieldsNum; i++) { string FName=XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/name"); string FDbType=XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/db_type"); string FSize=XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/size"); string FCreate=XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/create"); string FRequired=XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/required"); string FValue=HTTP.GetHttpParam(FName); FieldName.push_back(FName); FieldValue.push_back(FValue); }; };
vector<string> XaLibModel::ListPrepare(const vector<string>& XmlFiles,const string& XPathExpr,const int& WithSystemFields) { //LOAD XML FOR MODEL xmlDocPtr XmlDomDoc=XaLibDom::DomFromFile(AddXmlFile(XmlFiles),0); //GET NUMBER OF FILEDS int FieldsNum=XaLibDom::GetNumRowByXPathInt(XmlDomDoc,XPathExpr); vector<string> FieldsToRead; for (auto i=0; i<FieldsNum; i++) { if (XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/list")=="yes") { FieldsToRead.push_back(XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/name")); }; LOG.Write("INF", __FILE__, __FUNCTION__,__LINE__,"Field to retrieve for the list ->"+FieldsToRead[i]); }; auto it = FieldsToRead.begin(); it = FieldsToRead.insert ( it , "id" ); if (WithSystemFields==1) { FieldsToRead.push_back("updated_by"); FieldsToRead.push_back("updated"); FieldsToRead.push_back("status"); FieldsToRead.push_back("orig_id"); } return FieldsToRead; };
vector<string> XaLibModel::ReadPrepare(const vector<string>& XmlFiles,const string& XPathExpr,const int& WithSystemFields) { //TODO:GESTIONE ERRORI vector<string> FieldsToRead; //LOAD XML FOR MODEL xmlDocPtr XmlDomDoc=XaLibDom::DomFromFile(AddXmlFile(XmlFiles),0); //GET NUMBER OF FILEDS int FieldsNum=XaLibDom::GetNumRowByXPathInt(XmlDomDoc,XPathExpr); for (auto i=0; i<FieldsNum; i++) { if (XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/read")=="yes") { FieldsToRead.push_back(XaLibDom::GetElementValueByXPath(XmlDomDoc,XPathExpr+"["+ to_string(i+1) + "]/name")); }; }; auto it = FieldsToRead.begin(); it = FieldsToRead.insert ( it , "id" ); if (WithSystemFields==1) { FieldsToRead.push_back("updated_by"); FieldsToRead.push_back("updated"); FieldsToRead.push_back("status"); FieldsToRead.push_back("orig_id"); } //SE E" VUOTO return FieldsToRead; };
void XaLibAction::SetLayout(const string &LayoutType){ if (LayoutType=="Standalone" ) { AddXslFile("XaGuiHead"); AddXslFile("XaGuiHeader"); AddXslFile("XaGuiFooter"); AddXslFile("XaGuiNav"); AddXslFile("templates"); //AddXslFile("manifest"); AddXmlFile("XaLabel-"+REQUEST.Language); AddXmlFile("XaGuiNav"); } else if (LayoutType=="Included") { AddXslFile("templates"); } else if (LayoutType=="Standard" || LayoutType=="NoHttpParam") { AddXslFile("XaGuiHead"); AddXslFile("XaGuiHeader"); AddXslFile("XaGuiFooter"); AddXslFile("XaGuiNav"); AddXslFile("templates"); AddXmlFile("XaLabel-"+REQUEST.Language); AddXmlFile("XaGuiNav"); } else if (LayoutType=="InfoPage") { AddXslFile("XaGuiHead"); AddXslFile("XaInfoPage"); AddXmlFile("XaInfoPage"); } else if (LayoutType=="Chart") { AddXslFile("templates"); AddXmlFile("XaLabel-"+REQUEST.Language); } else if (LayoutType=="ModalWindow") { AddXslFile("XaGuiHead"); AddXslFile("templates"); AddXmlFile("XaLabel-"+REQUEST.Language); } else if (LayoutType=="LoginFrm") { AddXslFile("XaGuiHead"); AddXslFile("XaGuiHeaderInternet"); AddXslFile("XaGuiFooter"); AddXmlFile("XaLabel-"+REQUEST.Language); } else if (LayoutType=="Search") { AddXslFile("XaGuiHead"); AddXslFile("XaGuiHeader"); AddXslFile("XaGuiFooter"); AddXslFile("XaGuiNav"); AddXslFile("templates-search"); AddXmlFile("XaLabel-"+REQUEST.Language); } else { LOG.Write("ERR", __FILE__, __FUNCTION__,__LINE__,"Requested Layout does not exists -> "+LayoutType); } LOG.Write("INF", __FILE__, __FUNCTION__,__LINE__,"Added Layout -> "+LayoutType); };