A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
3.2 KiB

  1. /**
  2. * This will save this object's <%= $objTable->ClassName; %> instance,
  3. * updating only the fields which have had a control created for it.
  4. */
  5. public function Save<%= $objTable->ClassName; %>() {
  6. try {
  7. // Update any fields for controls that have been created
  8. <% foreach ($objTable->ColumnArray as $objColumn) { %><%
  9. if ((!$objColumn->Identity) && (!$objColumn->Timestamp)) {
  10. // Use the "control_create_" subtemplates to generate the code
  11. // required to create/setup the control.
  12. $mixArguments = array(
  13. 'objColumn' => $objColumn,
  14. 'strObjectName' => $objCodeGen->VariableNameFromTable($objTable->Name),
  15. 'strClassName' => $objTable->ClassName,
  16. 'strControlId' => $objCodeGen->FormControlVariableNameForColumn($objColumn)
  17. );
  18. // Figure out WHICH "control_create_" to use
  19. if ($objColumn->Reference) {
  20. if ($objColumn->Reference->IsType)
  21. $strTemplateFilename = 'type';
  22. else
  23. $strTemplateFilename = 'reference';
  24. } else switch ($objColumn->VariableType) {
  25. case QType::Boolean:
  26. $strTemplateFilename = 'checkbox';
  27. break;
  28. case QType::DateTime:
  29. $strTemplateFilename = 'calendar';
  30. break;
  31. default:
  32. $strTemplateFilename = 'textbox';
  33. break;
  34. }
  35. // Get the subtemplate and evaluate
  36. return $objCodeGen->EvaluateSubTemplate(sprintf('control_update_%s.tpl', $strTemplateFilename), $strModuleName, $mixArguments) . "\n";
  37. } else
  38. return null;
  39. %><% } %>
  40. // Update any UniqueReverseReferences (if any) for controls that have been created for it
  41. <% foreach ($objTable->ReverseReferenceArray as $objReverseReference) { %><%
  42. if ($objReverseReference->Unique) {
  43. // Use the "control_update_unique_reversereference" subtemplate to generate the code
  44. // required to create/setup the control.
  45. $mixArguments = array(
  46. 'objReverseReference' => $objReverseReference,
  47. 'strObjectName' => $objCodeGen->VariableNameFromTable($objTable->Name),
  48. 'strClassName' => $objTable->ClassName,
  49. 'strControlId' => $objCodeGen->FormControlVariableNameForUniqueReverseReference($objReverseReference)
  50. );
  51. // Get the subtemplate and evaluate
  52. return $objCodeGen->EvaluateSubTemplate('control_update_unique_reversereference.tpl', $strModuleName, $mixArguments) . "\n";
  53. } else
  54. return null;
  55. %><% } %>
  56. // Save the <%= $objTable->ClassName; %> object
  57. $this-><%= $objCodeGen->VariableNameFromTable($objTable->Name); %>->Save();
  58. // Finally, update any ManyToManyReferences (if any)
  59. <% foreach ($objTable->ManyToManyReferenceArray as $objManyToManyReference) { %>
  60. $this-><%= $objCodeGen->FormControlVariableNameForManyToManyReference($objManyToManyReference); %>_Update();
  61. <% } %>
  62. } catch (QCallerException $objExc) {
  63. $objExc->IncrementOffset();
  64. throw $objExc;
  65. }
  66. }