/app/generators/php/plugins/simpleDbGenerator/commonSimpleDbGenerator.class.php

https://github.com/juddy/GIP · PHP · 439 lines · 230 code · 97 blank · 112 comment · 9 complexity · a2ad232235c95ce442f29b2303a1f189 MD5 · raw file

  1. <?
  2. class commonSimpleDb
  3. {
  4. // Variables
  5. // configurationFile field from table
  6. var $configurationFile ;
  7. // codeStarter field from table
  8. var $codeStarter ;
  9. // codeEnder field from table
  10. var $codeEnder ;
  11. // codeTab field from table
  12. var $codeTab ;
  13. // lineEnder field from table
  14. var $lineEnder ;
  15. // Variables
  16. // tableObject field from table
  17. var $tableObject ;
  18. // code field from table
  19. var $sourceCode;
  20. var $headerText ;
  21. var $footerText;
  22. /**
  23. * @return returns value of variable $configurationFile
  24. * @desc getConfigurationFile : Getting value for variable $configurationFile
  25. */
  26. function getConfigurationFile ()
  27. {
  28. return $this->configurationFile ;
  29. }
  30. /**
  31. * @param param : value to be saved in variable $configurationFile
  32. * @desc setConfigurationFile : Setting value for $configurationFile
  33. */
  34. function setConfigurationFile ($value)
  35. {
  36. $this->configurationFile = $value;
  37. }
  38. /**
  39. * @return returns value of variable $codeStarter
  40. * @desc getCodeStarter : Getting value for variable $codeStarter
  41. */
  42. function getCodeStarter ()
  43. {
  44. return $this->codeStarter ;
  45. }
  46. /**
  47. * @param param : value to be saved in variable $codeStarter
  48. * @desc setCodeStarter : Setting value for $codeStarter
  49. */
  50. function setCodeStarter ($value)
  51. {
  52. $this->codeStarter = $value;
  53. }
  54. /**
  55. * @return returns value of variable $codeEnder
  56. * @desc getCodeEnder : Getting value for variable $codeEnder
  57. */
  58. function getCodeEnder ()
  59. {
  60. return $this->codeEnder ;
  61. }
  62. /**
  63. * @param param : value to be saved in variable $codeEnder
  64. * @desc setCodeEnder : Setting value for $codeEnder
  65. */
  66. function setCodeEnder ($value)
  67. {
  68. $this->codeEnder = $value;
  69. }
  70. /**
  71. * @return returns value of variable $codeTab
  72. * @desc getCodeTab : Getting value for variable $codeTab
  73. */
  74. function getCodeTab ()
  75. {
  76. return $this->codeTab ;
  77. }
  78. /**
  79. * @param param : value to be saved in variable $codeTab
  80. * @desc setCodeTab : Setting value for $codeTab
  81. */
  82. function setCodeTab ($value)
  83. {
  84. $this->codeTab = $value;
  85. }
  86. /**
  87. * @return returns value of variable $lineEnder
  88. * @desc getLineEnder : Getting value for variable $lineEnder
  89. */
  90. function getLineEnder ()
  91. {
  92. return $this->lineEnder ;
  93. }
  94. /**
  95. * @param param : value to be saved in variable $lineEnder
  96. * @desc setLineEnder : Setting value for $lineEnder
  97. */
  98. function setLineEnder ($value)
  99. {
  100. $this->lineEnder = $value;
  101. }
  102. /**
  103. * @return returns value of variable $tableObject
  104. * @desc getTableObject : Getting value for variable $tableObject
  105. */
  106. function getTableObject ()
  107. {
  108. return $this->tableObject ;
  109. }
  110. /**
  111. * @param param : value to be saved in variable $tableObject
  112. * @desc setTableObject : Setting value for $tableObject
  113. */
  114. function setTableObject ($value)
  115. {
  116. $this->tableObject = $value;
  117. }
  118. /**
  119. * @return returns value of variable $code
  120. * @desc getCode : Getting value for variable $code
  121. */
  122. function getSourceCode()
  123. {
  124. return $this->sourceCode;
  125. }
  126. /**
  127. * @param param : value to be saved in variable $code
  128. * @desc setCode : Setting value for $code
  129. */
  130. function setSourceCode($value)
  131. {
  132. $this->sourceCode = $value;
  133. }
  134. /**
  135. * @return returns value of variable $headerText
  136. * @desc getHeaderText : Getting value for variable $headerText
  137. */
  138. function getHeaderText ()
  139. {
  140. return $this->headerText ;
  141. }
  142. /**
  143. * @param param : value to be saved in variable $headerText
  144. * @desc setHeaderText : Setting value for $headerText
  145. */
  146. function setHeaderText ($value)
  147. {
  148. $this->headerText = $value;
  149. }
  150. /**
  151. * @return returns value of variable $footerText
  152. * @desc getFooterText : Getting value for variable $footerText
  153. */
  154. function getFooterText()
  155. {
  156. return $this->footerText;
  157. }
  158. /**
  159. * @param param : value to be saved in variable $footerText
  160. * @desc setFooterText : Setting value for $footerText
  161. */
  162. function setFooterText($value)
  163. {
  164. $this->footerText = $value;
  165. }
  166. function initializeSimpleDbFramework($configurationFile="")
  167. {
  168. if ($configurationFile=="")
  169. {
  170. $thisT = $this->getTableObject();
  171. $configurationFile = strtolower($thisT->getDatabase()).".conf.inc.php";
  172. }
  173. $this->setConfigurationFile($configurationFile);
  174. $this->setCodeStarter("<?php\n");
  175. $this->setCodeEnder("?>");
  176. $this->setCodeTab("\t");
  177. $this->setLineEnder("\n");
  178. $this->setSourceCode("");
  179. }
  180. /**
  181. * @return put return description here..
  182. * @param param : parameter passed to function
  183. * @desc buildWebHeader : put function description here ...
  184. */
  185. function appendWebHeader ()
  186. {
  187. $code = "";
  188. $code .= $this->getCodeStarter();
  189. if ($this->getHeaderText()=="")
  190. {
  191. $code .= $this->getCodeTab()."include_once(\"dbConnection.php\");".$this->getLineEnder();
  192. $code .= $this->getCodeTab()."include_once(\"header.php\");".$this->getLineEnder();
  193. }
  194. else
  195. {
  196. $code .= stripslashes($this->getHeaderText()).$this->getLineEnder();
  197. }
  198. $code .= $this->getCodeEnder();
  199. $this->appendToCode($code);
  200. }
  201. /**
  202. * @return put return description here..
  203. * @param param : parameter passed to function
  204. * @desc buildWebFooter : put function description here ...
  205. */
  206. function appendWebFooter ()
  207. {
  208. $code = "";
  209. $code .= $this->getCodeStarter();
  210. if ($this->getFooterText()=="")
  211. {
  212. $code .= $this->getCodeTab()."include_once(\"footer.php\");".$this->getLineEnder();
  213. }
  214. else {
  215. $code .= stripslashes($this->getFooterText()).$this->getLineEnder();
  216. }
  217. $code .= $this->getCodeEnder();
  218. $this->appendToCode($code);
  219. }
  220. /**
  221. * @return put return description here..
  222. * @param param : parameter passed to function
  223. * @desc buildSuperHeader : put function description here ...
  224. */
  225. function appendSuperHeader ()
  226. {
  227. }
  228. /**
  229. * @return put return description here..
  230. * @param param : parameter passed to function
  231. * @desc buildSuperFoooter : put function description here ...
  232. */
  233. function appendSuperFoooter ()
  234. {
  235. // Write Function Code Here
  236. }
  237. /**
  238. * @return put return description here..
  239. * @param param : parameter passed to function
  240. * @desc appendToCode : put function description here ...
  241. */
  242. function appendToCode ($code)
  243. {
  244. $newCode = $this->getSourceCode().$code.$this->getLineEnder();;
  245. $this->setSourceCode($newCode);
  246. }
  247. /**
  248. * @return put return description here..
  249. * @param param : parameter passed to function
  250. * @desc prependToCode : put function description here ...
  251. */
  252. function prependToCode ($code)
  253. {
  254. $newCode = $code.$this->getLineEnder().$this->getSourceCode();
  255. $this->setSourceCode($newCode);
  256. }
  257. function generateGetDataFromDbForOneRowOOnPage()
  258. {
  259. $thisTable = $this->getTableObject();
  260. $code = "";
  261. $code .= "<?php\n";
  262. $code .= "\$this".ucfirst($thisTable->getPrimaryKey())." = \$_REQUEST['".$thisTable->getPrimaryKey().NAME_FORM_FIELD_SUFFIX."']\n";
  263. $code .= "?>\n";
  264. $thisSqlEngine = new selectSQLGenerator($thisTable->getTableName(),$thisTable->getDatabase()," * ","","","","","","y");
  265. $sql = $thisSqlEngine->constructSQL($thisTable);
  266. $code .= "<?php\n";
  267. $code .= "\$sql = \"".$sql."\";".$this->getLineEnder();
  268. $code .= "\$result = MYSQL_QUERY(\$sql);".$this->getLineEnder();
  269. $code .= "\$numberOfRows = MYSQL_NUMROWS(\$result);\n";
  270. $code .= "if (\$numberOfRows==0) { \n?>\n\n";
  271. $code .= LANG_SIMPLE_INSIDE_SORRY_NO_RECORDS_FOUND."\n\n";
  272. $code .= "<?php\n}\n";
  273. $code .= "else if (\$numberOfRows>0) {\n\n";
  274. $code .= $this->getCodeTab()."\$i=0;\n";
  275. $code .= $this->generateGetDataFromDbForOneRow();
  276. $code .= "\n}\n";
  277. $code .= "?>\n";
  278. return $code;
  279. }
  280. function generateRetreiveFromForm($requestMethod="")
  281. {
  282. $code = "";
  283. $code .= $this->getCodeStarter();
  284. $code .= $this->getRetreiveFromFormCode($requestMethod);
  285. $code .= $this->getCodeEnder();
  286. $this->appendToCode($code);
  287. }
  288. function getRetreiveFromFormCode($requestMethod="")
  289. {
  290. $code = "";
  291. if ($requestMethod=="")
  292. {
  293. $requestMethod = DEFAULT_RETREIVE_METHOD;
  294. }
  295. $thisTable = $this->getTableObject();
  296. $fieldNameArray = $thisTable->getFieldNameArray();
  297. $code .= "\t// Retreiving Form Elements from Form\n";
  298. for ($a=0;$a<count($fieldNameArray);$a++)
  299. {
  300. $fieldName = $fieldNameArray[$a];
  301. $code .= $this->getCodeTab();
  302. $code .= "\$".NAME_FORM_FIELD_PREFIX.ucfirst($fieldName)." = addslashes(\$_".$requestMethod."['".NAME_FORM_FIELD_PREFIX.ucfirst($fieldName).NAME_FORM_FIELD_SUFFIX."']);".$this->getLineEnder();
  303. }
  304. $code .= "\n";
  305. return $code;
  306. }
  307. function generateGetDataFromDbForOneRow()
  308. {
  309. $retrieveFromDbMethhodCall = "MYSQL_RESULT";
  310. $thisTable = $this->getTableObject();
  311. $fieldNameArray = $thisTable->getFieldNameArray();
  312. $code = "";
  313. for ($a=0;$a<count($fieldNameArray);$a++)
  314. {
  315. $fieldName = $fieldNameArray[$a];
  316. $code .= $this->getCodeTab();
  317. $code .= "\$".NAME_FORM_FIELD_PREFIX.ucfirst($fieldName)." = ".$retrieveFromDbMethhodCall."(\$result,\$i,\"".$fieldName."\");".$this->getLineEnder();
  318. }
  319. return $code;
  320. }
  321. function generateViewRecordTable()
  322. {
  323. $thisTable = $this->getTableObject();
  324. $code = "";
  325. $fields = $thisTable->getFieldNameArray();
  326. $code .= "<table>\n";
  327. for ($a=0;$a<count($fields);$a++)
  328. {
  329. $code .= "<tr height=\"30\">\n";
  330. $code .= "\t<td align=\"right\"><b>";
  331. $code .= ucfirst($fields[$a])." : ";
  332. $code .= "</b></td>\n";
  333. $code .= "\t<td>";
  334. $code .= "<? echo \$".NAME_FORM_FIELD_PREFIX.ucfirst($fields[$a])."; ?>";
  335. $code .= "</td>\n";
  336. $code .= "</tr>\n";
  337. }
  338. $code .="</table>\n";
  339. return $code;
  340. }
  341. }
  342. ?>