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.

90 lines
6.3 KiB

  1. /**
  2. * Main constructor. Constructor OR static create methods are designed to be called in either
  3. * a parent QPanel or the main QForm when wanting to create a
  4. * <%= $objTable->ClassName %>MetaControl to edit a single <%= $objTable->ClassName %> object within the
  5. * QPanel or QForm.
  6. *
  7. * This constructor takes in a single <%= $objTable->ClassName %> object, while any of the static
  8. * create methods below can be used to construct based off of individual PK ID(s).
  9. *
  10. * @param mixed $objParentObject QForm or QPanel which will be using this <%= $objTable->ClassName %>MetaControl
  11. * @param <%= $objTable->ClassName %> $<%= $objCodeGen->VariableNameFromTable($objTable->Name); %> new or existing <%= $objTable->ClassName %> object
  12. */
  13. public function __construct($objParentObject, <%= $objTable->ClassName %> $<%= $objCodeGen->VariableNameFromTable($objTable->Name); %>) {
  14. // Setup Parent Object (e.g. QForm or QPanel which will be using this <%= $objTable->ClassName %>MetaControl)
  15. $this->objParentObject = $objParentObject;
  16. // Setup linked <%= $objTable->ClassName %> object
  17. $this-><%= $objCodeGen->VariableNameFromTable($objTable->Name); %> = $<%= $objCodeGen->VariableNameFromTable($objTable->Name); %>;
  18. // Figure out if we're Editing or Creating New
  19. if ($this-><%= $objCodeGen->VariableNameFromTable($objTable->Name); %>->__Restored) {
  20. $this->strTitleVerb = QApplication::Translate('Edit');
  21. $this->blnEditMode = true;
  22. } else {
  23. $this->strTitleVerb = QApplication::Translate('Create');
  24. $this->blnEditMode = false;
  25. }
  26. }
  27. /**
  28. * Static Helper Method to Create using PK arguments
  29. * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  30. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  31. * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to
  32. * edit, or if we are also allowed to create a new one, etc.
  33. *
  34. * @param mixed $objParentObject QForm or QPanel which will be using this <%= $objTable->ClassName %>MetaControl
  35. <% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>
  36. * @param <%= $objColumn->VariableType %> $<%= $objColumn->VariableName %> primary key value
  37. <% } %>
  38. * @param QMetaControlCreateType $intCreateType rules governing <%= $objTable->ClassName %> object creation - defaults to CreateOrEdit
  39. * @return <%= $objTable->ClassName %>MetaControl
  40. */
  41. public static function Create($objParentObject, <% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>$<%= $objColumn->VariableName %> = null, <% } %>$intCreateType = QMetaControlCreateType::CreateOrEdit) {
  42. // Attempt to Load from PK Arguments
  43. if (<% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>strlen($<%= $objColumn->VariableName %>) && <% } %><%----%>) {
  44. $<%= $objCodeGen->VariableNameFromTable($objTable->Name); %> = <%= $objTable->ClassName %>::Load(<% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>$<%= $objColumn->VariableName %>, <% } %><%--%>);
  45. // <%= $objTable->ClassName %> was found -- return it!
  46. if ($<%= $objCodeGen->VariableNameFromTable($objTable->Name); %>)
  47. return new <%= $objTable->ClassName %>MetaControl($objParentObject, $<%= $objCodeGen->VariableNameFromTable($objTable->Name); %>);
  48. // If CreateOnRecordNotFound not specified, throw an exception
  49. else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
  50. throw new QCallerException('Could not find a <%= $objTable->ClassName %> object with PK arguments: ' . <% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>$<%= $objColumn->VariableName %> . ', ' . <% } %><%----------%>);
  51. // If EditOnly is specified, throw an exception
  52. } else if ($intCreateType == QMetaControlCreateType::EditOnly)
  53. throw new QCallerException('No PK arguments specified');
  54. // If we are here, then we need to create a new record
  55. return new <%= $objTable->ClassName %>MetaControl($objParentObject, new <%= $objTable->ClassName %>());
  56. }
  57. /**
  58. * Static Helper Method to Create using PathInfo arguments
  59. *
  60. * @param mixed $objParentObject QForm or QPanel which will be using this <%= $objTable->ClassName %>MetaControl
  61. * @param QMetaControlCreateType $intCreateType rules governing <%= $objTable->ClassName %> object creation - defaults to CreateOrEdit
  62. * @return <%= $objTable->ClassName %>MetaControl
  63. */
  64. public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  65. <% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>
  66. $<%= $objColumn->VariableName %> = QApplication::PathInfo(<%= $_INDEX %>);
  67. <% } %>
  68. return <%= $objTable->ClassName %>MetaControl::Create($objParentObject, <% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>$<%= $objColumn->VariableName %>, <% } %>$intCreateType);
  69. }
  70. /**
  71. * Static Helper Method to Create using QueryString arguments
  72. *
  73. * @param mixed $objParentObject QForm or QPanel which will be using this <%= $objTable->ClassName %>MetaControl
  74. * @param QMetaControlCreateType $intCreateType rules governing <%= $objTable->ClassName %> object creation - defaults to CreateOrEdit
  75. * @return <%= $objTable->ClassName %>MetaControl
  76. */
  77. public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  78. <% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>
  79. $<%= $objColumn->VariableName %> = QApplication::QueryString('<%= $objColumn->VariableName %>');
  80. <% } %>
  81. return <%= $objTable->ClassName %>MetaControl::Create($objParentObject, <% foreach ($objTable->PrimaryKeyColumnArray as $objColumn) { %>$<%= $objColumn->VariableName %>, <% } %>$intCreateType);
  82. }