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.

1527 lines
64 KiB

  1. <?php
  2. /**
  3. * The abstract ModuleGen class defined here is
  4. * code-generated and contains all the basic CRUD-type functionality as well as
  5. * basic methods to handle relationships and index-based loading.
  6. *
  7. * To use, you should use the Module subclass which
  8. * extends this ModuleGen class.
  9. *
  10. * Because subsequent re-code generations will overwrite any changes to this
  11. * file, you should leave this file unaltered to prevent yourself from losing
  12. * any information or code changes. All customizations should be done by
  13. * overriding existing or implementing new methods, properties and variables
  14. * in the Module class.
  15. *
  16. * @package Quinta CMS
  17. * @subpackage GeneratedDataObjects
  18. * @property-read integer $Id the value for intId (Read-Only PK)
  19. * @property string $Name the value for strName (Unique)
  20. * @property string $Cssclass the value for strCssclass
  21. * @property string $Title the value for strTitle
  22. * @property string $Description the value for strDescription
  23. * @property string $ClassName the value for strClassName
  24. * @property boolean $ShowTitle the value for blnShowTitle (Not Null)
  25. * @property boolean $ShowDescription the value for blnShowDescription (Not Null)
  26. * @property integer $ContentBlockId the value for intContentBlockId
  27. * @property integer $ParentModuleId the value for intParentModuleId
  28. * @property ContentBlock $ContentBlock the value for the ContentBlock object referenced by intContentBlockId
  29. * @property Module $ParentModule the value for the Module object referenced by intParentModuleId
  30. * @property-read Module $_ChildModule the value for the private _objChildModule (Read-Only) if set due to an expansion on the module.parent_module_id reverse relationship
  31. * @property-read Module[] $_ChildModuleArray the value for the private _objChildModuleArray (Read-Only) if set due to an ExpandAsArray on the module.parent_module_id reverse relationship
  32. * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
  33. */
  34. class ModuleGen extends QBaseClass
  35. {
  36. ///////////////////////////////////////////////////////////////////////
  37. // PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
  38. ///////////////////////////////////////////////////////////////////////
  39. /////////// Object properties ////////////
  40. /**
  41. * Protected member variable that maps to the database PK Identity column module.id
  42. * @var integer intId
  43. *
  44. */
  45. protected $intId = null;
  46. /**
  47. * Protected member variable that maps to the database column module.name
  48. * @var string strName
  49. *
  50. */
  51. protected $strName = null;
  52. const NameMaxLength = 128;
  53. /**
  54. * Protected member variable that maps to the database column module.cssclass
  55. * @var string strCssclass
  56. *
  57. */
  58. protected $strCssclass = null;
  59. const CssclassMaxLength = 128;
  60. /**
  61. * Protected member variable that maps to the database column module.title
  62. * @var string strTitle
  63. *
  64. */
  65. protected $strTitle = null;
  66. const TitleMaxLength = 128;
  67. /**
  68. * Protected member variable that maps to the database column module.description
  69. * @var string strDescription
  70. *
  71. */
  72. protected $strDescription = null;
  73. const DescriptionMaxLength = 256;
  74. /**
  75. * Protected member variable that maps to the database column module.class_name
  76. * @var string strClassName
  77. *
  78. */
  79. protected $strClassName = null;
  80. const ClassNameMaxLength = 256;
  81. /**
  82. * Protected member variable that maps to the database column module.show_title
  83. * @var boolean blnShowTitle
  84. *
  85. */
  86. protected $blnShowTitle = null;
  87. /**
  88. * Protected member variable that maps to the database column module.show_description
  89. * @var boolean blnShowDescription
  90. *
  91. */
  92. protected $blnShowDescription = null;
  93. /**
  94. * Protected member variable that maps to the database column module.content_block_id
  95. * @var integer intContentBlockId
  96. *
  97. */
  98. protected $intContentBlockId = null;
  99. /**
  100. * Protected member variable that maps to the database column module.parent_module_id
  101. * @var integer intParentModuleId
  102. *
  103. */
  104. protected $intParentModuleId = null;
  105. /**
  106. * Private member variable that stores a reference to a single ChildModule object
  107. * (of type Module), if this Module object was restored with
  108. * an expansion on the module association table.
  109. * @var Module _objChildModule;
  110. */
  111. private $_objChildModule;
  112. /**
  113. * Private member variable that stores a reference to an array of ChildModule objects
  114. * (of type Module[]), if this Module object was restored with
  115. * an ExpandAsArray on the module association table.
  116. * @var Module[] _objChildModuleArray;
  117. */
  118. private $_objChildModuleArray = array();
  119. /**
  120. * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
  121. * columns from the run-time database query result for this object). Used by InstantiateDbRow and
  122. * GetVirtualAttribute.
  123. * @var string[] $__strVirtualAttributeArray
  124. */
  125. protected $__strVirtualAttributeArray = array();
  126. /**
  127. * Protected internal member variable that specifies whether or not this object is Restored from the database.
  128. * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
  129. * @var bool __blnRestored;
  130. */
  131. protected $__blnRestored;
  132. ///////////////////////////////
  133. // PROTECTED MEMBER OBJECTS
  134. ///////////////////////////////
  135. /**
  136. * Protected member variable that contains the object pointed by the reference
  137. * in the database column module.content_block_id.
  138. *
  139. * NOTE: Always use the ContentBlock property getter to correctly retrieve this ContentBlock object.
  140. * (Because this class implements late binding, this variable reference MAY be null.)
  141. * @var ContentBlock objContentBlock
  142. */
  143. protected $objContentBlock;
  144. /**
  145. * Protected member variable that contains the object pointed by the reference
  146. * in the database column module.parent_module_id.
  147. *
  148. * NOTE: Always use the ParentModule property getter to correctly retrieve this Module object.
  149. * (Because this class implements late binding, this variable reference MAY be null.)
  150. * @var Module objParentModule
  151. */
  152. protected $objParentModule;
  153. ///////////////////////////////
  154. // CLASS-WIDE LOAD AND COUNT METHODS
  155. ///////////////////////////////
  156. /**
  157. * Static method to retrieve the Database object that owns this class.
  158. * @return QDatabaseBase reference to the Database object that can query this class
  159. */
  160. public static function GetDatabase() {
  161. return QApplication::$Database[1];
  162. }
  163. /**
  164. * Load a Module from PK Info
  165. * @param integer $intId
  166. * @return Module
  167. */
  168. public static function Load($intId) {
  169. // Use QuerySingle to Perform the Query
  170. return Module::QuerySingle(
  171. QQ::Equal(QQN::Module()->Id, $intId)
  172. );
  173. }
  174. /**
  175. * Load all Modules
  176. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  177. * @return Module[]
  178. */
  179. public static function LoadAll($objOptionalClauses = null) {
  180. // Call Module::QueryArray to perform the LoadAll query
  181. try {
  182. return Module::QueryArray(QQ::All(), $objOptionalClauses);
  183. } catch (QCallerException $objExc) {
  184. $objExc->IncrementOffset();
  185. throw $objExc;
  186. }
  187. }
  188. /**
  189. * Count all Modules
  190. * @return int
  191. */
  192. public static function CountAll() {
  193. // Call Module::QueryCount to perform the CountAll query
  194. return Module::QueryCount(QQ::All());
  195. }
  196. ///////////////////////////////
  197. // QCODO QUERY-RELATED METHODS
  198. ///////////////////////////////
  199. /**
  200. * Internally called method to assist with calling Qcodo Query for this class
  201. * on load methods.
  202. * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
  203. * @param QQCondition $objConditions any conditions on the query, itself
  204. * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
  205. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
  206. * @param boolean $blnCountOnly only select a rowcount
  207. * @return string the query statement
  208. */
  209. protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
  210. // Get the Database Object for this Class
  211. $objDatabase = Module::GetDatabase();
  212. // Create/Build out the QueryBuilder object with Module-specific SELET and FROM fields
  213. $objQueryBuilder = new QQueryBuilder($objDatabase, 'module');
  214. Module::GetSelectFields($objQueryBuilder);
  215. $objQueryBuilder->AddFromItem('module');
  216. // Set "CountOnly" option (if applicable)
  217. if ($blnCountOnly)
  218. $objQueryBuilder->SetCountOnlyFlag();
  219. // Apply Any Conditions
  220. if ($objConditions)
  221. try {
  222. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  223. } catch (QCallerException $objExc) {
  224. $objExc->IncrementOffset();
  225. throw $objExc;
  226. }
  227. // Iterate through all the Optional Clauses (if any) and perform accordingly
  228. if ($objOptionalClauses) {
  229. if ($objOptionalClauses instanceof QQClause)
  230. $objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
  231. else if (is_array($objOptionalClauses))
  232. foreach ($objOptionalClauses as $objClause)
  233. $objClause->UpdateQueryBuilder($objQueryBuilder);
  234. else
  235. throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
  236. }
  237. // Get the SQL Statement
  238. $strQuery = $objQueryBuilder->GetStatement();
  239. // Prepare the Statement with the Query Parameters (if applicable)
  240. if ($mixParameterArray) {
  241. if (is_array($mixParameterArray)) {
  242. if (count($mixParameterArray))
  243. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  244. // Ensure that there are no other Unresolved Named Parameters
  245. if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
  246. throw new QCallerException('Unresolved named parameters in the query');
  247. } else
  248. throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
  249. }
  250. // Return the Objects
  251. return $strQuery;
  252. }
  253. /**
  254. * Static Qcodo Query method to query for a single Module object.
  255. * Uses BuildQueryStatment to perform most of the work.
  256. * @param QQCondition $objConditions any conditions on the query, itself
  257. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  258. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  259. * @return Module the queried object
  260. */
  261. public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  262. // Get the Query Statement
  263. try {
  264. $strQuery = Module::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  265. } catch (QCallerException $objExc) {
  266. $objExc->IncrementOffset();
  267. throw $objExc;
  268. }
  269. // Perform the Query, Get the First Row, and Instantiate a new Module object
  270. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  271. return Module::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray);
  272. }
  273. /**
  274. * Static Qcodo Query method to query for an array of Module objects.
  275. * Uses BuildQueryStatment to perform most of the work.
  276. * @param QQCondition $objConditions any conditions on the query, itself
  277. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  278. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  279. * @return Module[] the queried objects as an array
  280. */
  281. public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  282. // Get the Query Statement
  283. try {
  284. $strQuery = Module::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  285. } catch (QCallerException $objExc) {
  286. $objExc->IncrementOffset();
  287. throw $objExc;
  288. }
  289. // Perform the Query and Instantiate the Array Result
  290. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  291. return Module::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
  292. }
  293. /**
  294. * Static Qcodo Query method to query for a count of Module objects.
  295. * Uses BuildQueryStatment to perform most of the work.
  296. * @param QQCondition $objConditions any conditions on the query, itself
  297. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  298. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  299. * @return integer the count of queried objects as an integer
  300. */
  301. public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  302. // Get the Query Statement
  303. try {
  304. $strQuery = Module::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
  305. } catch (QCallerException $objExc) {
  306. $objExc->IncrementOffset();
  307. throw $objExc;
  308. }
  309. // Perform the Query and return the row_count
  310. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  311. // Figure out if the query is using GroupBy
  312. $blnGrouped = false;
  313. if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
  314. if ($objClause instanceof QQGroupBy) {
  315. $blnGrouped = true;
  316. break;
  317. }
  318. }
  319. if ($blnGrouped)
  320. // Groups in this query - return the count of Groups (which is the count of all rows)
  321. return $objDbResult->CountRows();
  322. else {
  323. // No Groups - return the sql-calculated count(*) value
  324. $strDbRow = $objDbResult->FetchRow();
  325. return QType::Cast($strDbRow[0], QType::Integer);
  326. }
  327. }
  328. /* public static function QueryArrayCached($strConditions, $mixParameterArray = null) {
  329. // Get the Database Object for this Class
  330. $objDatabase = Module::GetDatabase();
  331. // Lookup the QCache for This Query Statement
  332. $objCache = new QCache('query', 'module_' . serialize($strConditions));
  333. if (!($strQuery = $objCache->GetData())) {
  334. // Not Found -- Go ahead and Create/Build out a new QueryBuilder object with Module-specific fields
  335. $objQueryBuilder = new QQueryBuilder($objDatabase);
  336. Module::GetSelectFields($objQueryBuilder);
  337. Module::GetFromFields($objQueryBuilder);
  338. // Ensure the Passed-in Conditions is a string
  339. try {
  340. $strConditions = QType::Cast($strConditions, QType::String);
  341. } catch (QCallerException $objExc) {
  342. $objExc->IncrementOffset();
  343. throw $objExc;
  344. }
  345. // Create the Conditions object, and apply it
  346. $objConditions = eval('return ' . $strConditions . ';');
  347. // Apply Any Conditions
  348. if ($objConditions)
  349. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  350. // Get the SQL Statement
  351. $strQuery = $objQueryBuilder->GetStatement();
  352. // Save the SQL Statement in the Cache
  353. $objCache->SaveData($strQuery);
  354. }
  355. // Prepare the Statement with the Parameters
  356. if ($mixParameterArray)
  357. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  358. // Perform the Query and Instantiate the Array Result
  359. $objDbResult = $objDatabase->Query($strQuery);
  360. return Module::InstantiateDbResult($objDbResult);
  361. }*/
  362. /**
  363. * Updates a QQueryBuilder with the SELECT fields for this Module
  364. * @param QQueryBuilder $objBuilder the Query Builder object to update
  365. * @param string $strPrefix optional prefix to add to the SELECT fields
  366. */
  367. public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
  368. if ($strPrefix) {
  369. $strTableName = $strPrefix;
  370. $strAliasPrefix = $strPrefix . '__';
  371. } else {
  372. $strTableName = 'module';
  373. $strAliasPrefix = '';
  374. }
  375. $objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
  376. $objBuilder->AddSelectItem($strTableName, 'name', $strAliasPrefix . 'name');
  377. $objBuilder->AddSelectItem($strTableName, 'cssclass', $strAliasPrefix . 'cssclass');
  378. $objBuilder->AddSelectItem($strTableName, 'title', $strAliasPrefix . 'title');
  379. $objBuilder->AddSelectItem($strTableName, 'description', $strAliasPrefix . 'description');
  380. $objBuilder->AddSelectItem($strTableName, 'class_name', $strAliasPrefix . 'class_name');
  381. $objBuilder->AddSelectItem($strTableName, 'show_title', $strAliasPrefix . 'show_title');
  382. $objBuilder->AddSelectItem($strTableName, 'show_description', $strAliasPrefix . 'show_description');
  383. $objBuilder->AddSelectItem($strTableName, 'content_block_id', $strAliasPrefix . 'content_block_id');
  384. $objBuilder->AddSelectItem($strTableName, 'parent_module_id', $strAliasPrefix . 'parent_module_id');
  385. }
  386. ///////////////////////////////
  387. // INSTANTIATION-RELATED METHODS
  388. ///////////////////////////////
  389. /**
  390. * Instantiate a Module from a Database Row.
  391. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  392. * is calling this Module::InstantiateDbRow in order to perform
  393. * early binding on referenced objects.
  394. * @param DatabaseRowBase $objDbRow
  395. * @param string $strAliasPrefix
  396. * @param string $strExpandAsArrayNodes
  397. * @param QBaseClass $objPreviousItem
  398. * @param string[] $strColumnAliasArray
  399. * @return Module
  400. */
  401. public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $objPreviousItem = null, $strColumnAliasArray = array()) {
  402. // If blank row, return null
  403. if (!$objDbRow)
  404. return null;
  405. // See if we're doing an array expansion on the previous item
  406. $strAlias = $strAliasPrefix . 'id';
  407. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  408. if (($strExpandAsArrayNodes) && ($objPreviousItem) &&
  409. ($objPreviousItem->intId == $objDbRow->GetColumn($strAliasName, 'Integer'))) {
  410. // We are. Now, prepare to check for ExpandAsArray clauses
  411. $blnExpandedViaArray = false;
  412. if (!$strAliasPrefix)
  413. $strAliasPrefix = 'module__';
  414. $strAlias = $strAliasPrefix . 'childmodule__id';
  415. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  416. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  417. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  418. if ($intPreviousChildItemCount = count($objPreviousItem->_objChildModuleArray)) {
  419. $objPreviousChildItem = $objPreviousItem->_objChildModuleArray[$intPreviousChildItemCount - 1];
  420. $objChildItem = Module::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childmodule__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  421. if ($objChildItem)
  422. $objPreviousItem->_objChildModuleArray[] = $objChildItem;
  423. } else
  424. $objPreviousItem->_objChildModuleArray[] = Module::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childmodule__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  425. $blnExpandedViaArray = true;
  426. }
  427. // Either return false to signal array expansion, or check-to-reset the Alias prefix and move on
  428. if ($blnExpandedViaArray)
  429. return false;
  430. else if ($strAliasPrefix == 'module__')
  431. $strAliasPrefix = null;
  432. }
  433. // Create a new instance of the Module object
  434. $objToReturn = new Module();
  435. $objToReturn->__blnRestored = true;
  436. $strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
  437. $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
  438. $strAliasName = array_key_exists($strAliasPrefix . 'name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'name'] : $strAliasPrefix . 'name';
  439. $objToReturn->strName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  440. $strAliasName = array_key_exists($strAliasPrefix . 'cssclass', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'cssclass'] : $strAliasPrefix . 'cssclass';
  441. $objToReturn->strCssclass = $objDbRow->GetColumn($strAliasName, 'VarChar');
  442. $strAliasName = array_key_exists($strAliasPrefix . 'title', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'title'] : $strAliasPrefix . 'title';
  443. $objToReturn->strTitle = $objDbRow->GetColumn($strAliasName, 'VarChar');
  444. $strAliasName = array_key_exists($strAliasPrefix . 'description', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'description'] : $strAliasPrefix . 'description';
  445. $objToReturn->strDescription = $objDbRow->GetColumn($strAliasName, 'VarChar');
  446. $strAliasName = array_key_exists($strAliasPrefix . 'class_name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'class_name'] : $strAliasPrefix . 'class_name';
  447. $objToReturn->strClassName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  448. $strAliasName = array_key_exists($strAliasPrefix . 'show_title', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'show_title'] : $strAliasPrefix . 'show_title';
  449. $objToReturn->blnShowTitle = $objDbRow->GetColumn($strAliasName, 'Bit');
  450. $strAliasName = array_key_exists($strAliasPrefix . 'show_description', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'show_description'] : $strAliasPrefix . 'show_description';
  451. $objToReturn->blnShowDescription = $objDbRow->GetColumn($strAliasName, 'Bit');
  452. $strAliasName = array_key_exists($strAliasPrefix . 'content_block_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'content_block_id'] : $strAliasPrefix . 'content_block_id';
  453. $objToReturn->intContentBlockId = $objDbRow->GetColumn($strAliasName, 'Integer');
  454. $strAliasName = array_key_exists($strAliasPrefix . 'parent_module_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'parent_module_id'] : $strAliasPrefix . 'parent_module_id';
  455. $objToReturn->intParentModuleId = $objDbRow->GetColumn($strAliasName, 'Integer');
  456. // Instantiate Virtual Attributes
  457. foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
  458. $strVirtualPrefix = $strAliasPrefix . '__';
  459. $strVirtualPrefixLength = strlen($strVirtualPrefix);
  460. if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
  461. $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
  462. }
  463. // Prepare to Check for Early/Virtual Binding
  464. if (!$strAliasPrefix)
  465. $strAliasPrefix = 'module__';
  466. // Check for ContentBlock Early Binding
  467. $strAlias = $strAliasPrefix . 'content_block_id__id';
  468. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  469. if (!is_null($objDbRow->GetColumn($strAliasName)))
  470. $objToReturn->objContentBlock = ContentBlock::InstantiateDbRow($objDbRow, $strAliasPrefix . 'content_block_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  471. // Check for ParentModule Early Binding
  472. $strAlias = $strAliasPrefix . 'parent_module_id__id';
  473. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  474. if (!is_null($objDbRow->GetColumn($strAliasName)))
  475. $objToReturn->objParentModule = Module::InstantiateDbRow($objDbRow, $strAliasPrefix . 'parent_module_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  476. // Check for ChildModule Virtual Binding
  477. $strAlias = $strAliasPrefix . 'childmodule__id';
  478. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  479. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  480. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  481. $objToReturn->_objChildModuleArray[] = Module::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childmodule__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  482. else
  483. $objToReturn->_objChildModule = Module::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childmodule__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  484. }
  485. return $objToReturn;
  486. }
  487. /**
  488. * Instantiate an array of Modules from a Database Result
  489. * @param DatabaseResultBase $objDbResult
  490. * @param string $strExpandAsArrayNodes
  491. * @param string[] $strColumnAliasArray
  492. * @return Module[]
  493. */
  494. public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
  495. $objToReturn = array();
  496. if (!$strColumnAliasArray)
  497. $strColumnAliasArray = array();
  498. // If blank resultset, then return empty array
  499. if (!$objDbResult)
  500. return $objToReturn;
  501. // Load up the return array with each row
  502. if ($strExpandAsArrayNodes) {
  503. $objLastRowItem = null;
  504. while ($objDbRow = $objDbResult->GetNextRow()) {
  505. $objItem = Module::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem, $strColumnAliasArray);
  506. if ($objItem) {
  507. $objToReturn[] = $objItem;
  508. $objLastRowItem = $objItem;
  509. }
  510. }
  511. } else {
  512. while ($objDbRow = $objDbResult->GetNextRow())
  513. $objToReturn[] = Module::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
  514. }
  515. return $objToReturn;
  516. }
  517. ///////////////////////////////////////////////////
  518. // INDEX-BASED LOAD METHODS (Single Load and Array)
  519. ///////////////////////////////////////////////////
  520. /**
  521. * Load a single Module object,
  522. * by Id Index(es)
  523. * @param integer $intId
  524. * @return Module
  525. */
  526. public static function LoadById($intId) {
  527. return Module::QuerySingle(
  528. QQ::Equal(QQN::Module()->Id, $intId)
  529. );
  530. }
  531. /**
  532. * Load a single Module object,
  533. * by Name Index(es)
  534. * @param string $strName
  535. * @return Module
  536. */
  537. public static function LoadByName($strName) {
  538. return Module::QuerySingle(
  539. QQ::Equal(QQN::Module()->Name, $strName)
  540. );
  541. }
  542. /**
  543. * Load an array of Module objects,
  544. * by ContentBlockId Index(es)
  545. * @param integer $intContentBlockId
  546. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  547. * @return Module[]
  548. */
  549. public static function LoadArrayByContentBlockId($intContentBlockId, $objOptionalClauses = null) {
  550. // Call Module::QueryArray to perform the LoadArrayByContentBlockId query
  551. try {
  552. return Module::QueryArray(
  553. QQ::Equal(QQN::Module()->ContentBlockId, $intContentBlockId),
  554. $objOptionalClauses);
  555. } catch (QCallerException $objExc) {
  556. $objExc->IncrementOffset();
  557. throw $objExc;
  558. }
  559. }
  560. /**
  561. * Count Modules
  562. * by ContentBlockId Index(es)
  563. * @param integer $intContentBlockId
  564. * @return int
  565. */
  566. public static function CountByContentBlockId($intContentBlockId) {
  567. // Call Module::QueryCount to perform the CountByContentBlockId query
  568. return Module::QueryCount(
  569. QQ::Equal(QQN::Module()->ContentBlockId, $intContentBlockId)
  570. );
  571. }
  572. /**
  573. * Load an array of Module objects,
  574. * by Title Index(es)
  575. * @param string $strTitle
  576. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  577. * @return Module[]
  578. */
  579. public static function LoadArrayByTitle($strTitle, $objOptionalClauses = null) {
  580. // Call Module::QueryArray to perform the LoadArrayByTitle query
  581. try {
  582. return Module::QueryArray(
  583. QQ::Equal(QQN::Module()->Title, $strTitle),
  584. $objOptionalClauses);
  585. } catch (QCallerException $objExc) {
  586. $objExc->IncrementOffset();
  587. throw $objExc;
  588. }
  589. }
  590. /**
  591. * Count Modules
  592. * by Title Index(es)
  593. * @param string $strTitle
  594. * @return int
  595. */
  596. public static function CountByTitle($strTitle) {
  597. // Call Module::QueryCount to perform the CountByTitle query
  598. return Module::QueryCount(
  599. QQ::Equal(QQN::Module()->Title, $strTitle)
  600. );
  601. }
  602. /**
  603. * Load an array of Module objects,
  604. * by ParentModuleId Index(es)
  605. * @param integer $intParentModuleId
  606. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  607. * @return Module[]
  608. */
  609. public static function LoadArrayByParentModuleId($intParentModuleId, $objOptionalClauses = null) {
  610. // Call Module::QueryArray to perform the LoadArrayByParentModuleId query
  611. try {
  612. return Module::QueryArray(
  613. QQ::Equal(QQN::Module()->ParentModuleId, $intParentModuleId),
  614. $objOptionalClauses);
  615. } catch (QCallerException $objExc) {
  616. $objExc->IncrementOffset();
  617. throw $objExc;
  618. }
  619. }
  620. /**
  621. * Count Modules
  622. * by ParentModuleId Index(es)
  623. * @param integer $intParentModuleId
  624. * @return int
  625. */
  626. public static function CountByParentModuleId($intParentModuleId) {
  627. // Call Module::QueryCount to perform the CountByParentModuleId query
  628. return Module::QueryCount(
  629. QQ::Equal(QQN::Module()->ParentModuleId, $intParentModuleId)
  630. );
  631. }
  632. ////////////////////////////////////////////////////
  633. // INDEX-BASED LOAD METHODS (Array via Many to Many)
  634. ////////////////////////////////////////////////////
  635. //////////////////////////
  636. // SAVE, DELETE AND RELOAD
  637. //////////////////////////
  638. /**
  639. * Save this Module
  640. * @param bool $blnForceInsert
  641. * @param bool $blnForceUpdate
  642. * @return int
  643. */
  644. public function Save($blnForceInsert = false, $blnForceUpdate = false) {
  645. // Get the Database Object for this Class
  646. $objDatabase = Module::GetDatabase();
  647. $mixToReturn = null;
  648. try {
  649. if ((!$this->__blnRestored) || ($blnForceInsert)) {
  650. // Perform an INSERT query
  651. $objDatabase->NonQuery('
  652. INSERT INTO `module` (
  653. `name`,
  654. `cssclass`,
  655. `title`,
  656. `description`,
  657. `class_name`,
  658. `show_title`,
  659. `show_description`,
  660. `content_block_id`,
  661. `parent_module_id`
  662. ) VALUES (
  663. ' . $objDatabase->SqlVariable($this->strName) . ',
  664. ' . $objDatabase->SqlVariable($this->strCssclass) . ',
  665. ' . $objDatabase->SqlVariable($this->strTitle) . ',
  666. ' . $objDatabase->SqlVariable($this->strDescription) . ',
  667. ' . $objDatabase->SqlVariable($this->strClassName) . ',
  668. ' . $objDatabase->SqlVariable($this->blnShowTitle) . ',
  669. ' . $objDatabase->SqlVariable($this->blnShowDescription) . ',
  670. ' . $objDatabase->SqlVariable($this->intContentBlockId) . ',
  671. ' . $objDatabase->SqlVariable($this->intParentModuleId) . '
  672. )
  673. ');
  674. // Update Identity column and return its value
  675. $mixToReturn = $this->intId = $objDatabase->InsertId('module', 'id');
  676. } else {
  677. // Perform an UPDATE query
  678. // First checking for Optimistic Locking constraints (if applicable)
  679. // Perform the UPDATE query
  680. $objDatabase->NonQuery('
  681. UPDATE
  682. `module`
  683. SET
  684. `name` = ' . $objDatabase->SqlVariable($this->strName) . ',
  685. `cssclass` = ' . $objDatabase->SqlVariable($this->strCssclass) . ',
  686. `title` = ' . $objDatabase->SqlVariable($this->strTitle) . ',
  687. `description` = ' . $objDatabase->SqlVariable($this->strDescription) . ',
  688. `class_name` = ' . $objDatabase->SqlVariable($this->strClassName) . ',
  689. `show_title` = ' . $objDatabase->SqlVariable($this->blnShowTitle) . ',
  690. `show_description` = ' . $objDatabase->SqlVariable($this->blnShowDescription) . ',
  691. `content_block_id` = ' . $objDatabase->SqlVariable($this->intContentBlockId) . ',
  692. `parent_module_id` = ' . $objDatabase->SqlVariable($this->intParentModuleId) . '
  693. WHERE
  694. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  695. ');
  696. }
  697. } catch (QCallerException $objExc) {
  698. $objExc->IncrementOffset();
  699. throw $objExc;
  700. }
  701. // Update __blnRestored and any Non-Identity PK Columns (if applicable)
  702. $this->__blnRestored = true;
  703. // Return
  704. return $mixToReturn;
  705. }
  706. /**
  707. * Delete this Module
  708. * @return void
  709. */
  710. public function Delete() {
  711. if ((is_null($this->intId)))
  712. throw new QUndefinedPrimaryKeyException('Cannot delete this Module with an unset primary key.');
  713. // Get the Database Object for this Class
  714. $objDatabase = Module::GetDatabase();
  715. // Perform the SQL Query
  716. $objDatabase->NonQuery('
  717. DELETE FROM
  718. `module`
  719. WHERE
  720. `id` = ' . $objDatabase->SqlVariable($this->intId) . '');
  721. }
  722. /**
  723. * Delete all Modules
  724. * @return void
  725. */
  726. public static function DeleteAll() {
  727. // Get the Database Object for this Class
  728. $objDatabase = Module::GetDatabase();
  729. // Perform the Query
  730. $objDatabase->NonQuery('
  731. DELETE FROM
  732. `module`');
  733. }
  734. /**
  735. * Truncate module table
  736. * @return void
  737. */
  738. public static function Truncate() {
  739. // Get the Database Object for this Class
  740. $objDatabase = Module::GetDatabase();
  741. // Perform the Query
  742. $objDatabase->NonQuery('
  743. TRUNCATE `module`');
  744. }
  745. /**
  746. * Reload this Module from the database.
  747. * @return void
  748. */
  749. public function Reload() {
  750. // Make sure we are actually Restored from the database
  751. if (!$this->__blnRestored)
  752. throw new QCallerException('Cannot call Reload() on a new, unsaved Module object.');
  753. // Reload the Object
  754. $objReloaded = Module::Load($this->intId);
  755. // Update $this's local variables to match
  756. $this->strName = $objReloaded->strName;
  757. $this->strCssclass = $objReloaded->strCssclass;
  758. $this->strTitle = $objReloaded->strTitle;
  759. $this->strDescription = $objReloaded->strDescription;
  760. $this->strClassName = $objReloaded->strClassName;
  761. $this->blnShowTitle = $objReloaded->blnShowTitle;
  762. $this->blnShowDescription = $objReloaded->blnShowDescription;
  763. $this->ContentBlockId = $objReloaded->ContentBlockId;
  764. $this->ParentModuleId = $objReloaded->ParentModuleId;
  765. }
  766. ////////////////////
  767. // GETTORS AND SETTORS
  768. ////////////////////
  769. /**
  770. * Lookup a VirtualAttribute value (if applicable). Returns NULL if none found.
  771. * @param string $strName
  772. * @return string
  773. */
  774. public function GetVirtualAttribute($strName)
  775. {
  776. if (array_key_exists($strName, $this->__strVirtualAttributeArray))
  777. return $this->__strVirtualAttributeArray[$strName];
  778. return null;
  779. }
  780. /**
  781. * Override method to perform a property "Get"
  782. * This will get the value of $strName
  783. *
  784. * @param string $strName Name of the property to get
  785. * @return mixed
  786. */
  787. public function __get($strName)
  788. {
  789. switch ($strName)
  790. {
  791. ///////////////////
  792. // Member Variables
  793. ///////////////////
  794. case 'Id':
  795. /**
  796. * Gets the value for intId (Read-Only PK)
  797. * @return integer
  798. */
  799. return $this->intId;
  800. case 'Name':
  801. /**
  802. * Gets the value for strName (Unique)
  803. * @return string
  804. */
  805. return $this->strName;
  806. case 'Cssclass':
  807. /**
  808. * Gets the value for strCssclass
  809. * @return string
  810. */
  811. return $this->strCssclass;
  812. case 'Title':
  813. /**
  814. * Gets the value for strTitle
  815. * @return string
  816. */
  817. return $this->strTitle;
  818. case 'Description':
  819. /**
  820. * Gets the value for strDescription
  821. * @return string
  822. */
  823. return $this->strDescription;
  824. case 'ClassName':
  825. /**
  826. * Gets the value for strClassName
  827. * @return string
  828. */
  829. return $this->strClassName;
  830. case 'ShowTitle':
  831. /**
  832. * Gets the value for blnShowTitle (Not Null)
  833. * @return boolean
  834. */
  835. return $this->blnShowTitle;
  836. case 'ShowDescription':
  837. /**
  838. * Gets the value for blnShowDescription (Not Null)
  839. * @return boolean
  840. */
  841. return $this->blnShowDescription;
  842. case 'ContentBlockId':
  843. /**
  844. * Gets the value for intContentBlockId
  845. * @return integer
  846. */
  847. return $this->intContentBlockId;
  848. case 'ParentModuleId':
  849. /**
  850. * Gets the value for intParentModuleId
  851. * @return integer
  852. */
  853. return $this->intParentModuleId;
  854. ///////////////////
  855. // Member Objects
  856. ///////////////////
  857. case 'ContentBlock':
  858. /**
  859. * Gets the value for the ContentBlock object referenced by intContentBlockId
  860. * @return ContentBlock
  861. */
  862. try {
  863. if ((!$this->objContentBlock) && (!is_null($this->intContentBlockId)))
  864. $this->objContentBlock = ContentBlock::Load($this->intContentBlockId);
  865. return $this->objContentBlock;
  866. } catch (QCallerException $objExc) {
  867. $objExc->IncrementOffset();
  868. throw $objExc;
  869. }
  870. case 'ParentModule':
  871. /**
  872. * Gets the value for the Module object referenced by intParentModuleId
  873. * @return Module
  874. */
  875. try {
  876. if ((!$this->objParentModule) && (!is_null($this->intParentModuleId)))
  877. $this->objParentModule = Module::Load($this->intParentModuleId);
  878. return $this->objParentModule;
  879. } catch (QCallerException $objExc) {
  880. $objExc->IncrementOffset();
  881. throw $objExc;
  882. }
  883. ////////////////////////////
  884. // Virtual Object References (Many to Many and Reverse References)
  885. // (If restored via a "Many-to" expansion)
  886. ////////////////////////////
  887. case '_ChildModule':
  888. /**
  889. * Gets the value for the private _objChildModule (Read-Only)
  890. * if set due to an expansion on the module.parent_module_id reverse relationship
  891. * @return Module
  892. */
  893. return $this->_objChildModule;
  894. case '_ChildModuleArray':
  895. /**
  896. * Gets the value for the private _objChildModuleArray (Read-Only)
  897. * if set due to an ExpandAsArray on the module.parent_module_id reverse relationship
  898. * @return Module[]
  899. */
  900. return (array) $this->_objChildModuleArray;
  901. case '__Restored':
  902. return $this->__blnRestored;
  903. default:
  904. try {
  905. return parent::__get($strName);
  906. } catch (QCallerException $objExc) {
  907. $objExc->IncrementOffset();
  908. throw $objExc;
  909. }
  910. }
  911. }
  912. /**
  913. * Override method to perform a property "Set"
  914. * This will set the property $strName to be $mixValue
  915. *
  916. * @param string $strName Name of the property to set
  917. * @param string $mixValue New value of the property
  918. * @return mixed
  919. */
  920. public function __set($strName, $mixValue) {
  921. switch ($strName) {
  922. ///////////////////
  923. // Member Variables
  924. ///////////////////
  925. case 'Name':
  926. /**
  927. * Sets the value for strName (Unique)
  928. * @param string $mixValue
  929. * @return string
  930. */
  931. try {
  932. return ($this->strName = QType::Cast($mixValue, QType::String));
  933. } catch (QCallerException $objExc) {
  934. $objExc->IncrementOffset();
  935. throw $objExc;
  936. }
  937. case 'Cssclass':
  938. /**
  939. * Sets the value for strCssclass
  940. * @param string $mixValue
  941. * @return string
  942. */
  943. try {
  944. return ($this->strCssclass = QType::Cast($mixValue, QType::String));
  945. } catch (QCallerException $objExc) {
  946. $objExc->IncrementOffset();
  947. throw $objExc;
  948. }
  949. case 'Title':
  950. /**
  951. * Sets the value for strTitle
  952. * @param string $mixValue
  953. * @return string
  954. */
  955. try {
  956. return ($this->strTitle = QType::Cast($mixValue, QType::String));
  957. } catch (QCallerException $objExc) {
  958. $objExc->IncrementOffset();
  959. throw $objExc;
  960. }
  961. case 'Description':
  962. /**
  963. * Sets the value for strDescription
  964. * @param string $mixValue
  965. * @return string
  966. */
  967. try {
  968. return ($this->strDescription = QType::Cast($mixValue, QType::String));
  969. } catch (QCallerException $objExc) {
  970. $objExc->IncrementOffset();
  971. throw $objExc;
  972. }
  973. case 'ClassName':
  974. /**
  975. * Sets the value for strClassName
  976. * @param string $mixValue
  977. * @return string
  978. */
  979. try {
  980. return ($this->strClassName = QType::Cast($mixValue, QType::String));
  981. } catch (QCallerException $objExc) {
  982. $objExc->IncrementOffset();
  983. throw $objExc;
  984. }
  985. case 'ShowTitle':
  986. /**
  987. * Sets the value for blnShowTitle (Not Null)
  988. * @param boolean $mixValue
  989. * @return boolean
  990. */
  991. try {
  992. return ($this->blnShowTitle = QType::Cast($mixValue, QType::Boolean));
  993. } catch (QCallerException $objExc) {
  994. $objExc->IncrementOffset();
  995. throw $objExc;
  996. }
  997. case 'ShowDescription':
  998. /**
  999. * Sets the value for blnShowDescription (Not Null)
  1000. * @param boolean $mixValue
  1001. * @return boolean
  1002. */
  1003. try {
  1004. return ($this->blnShowDescription = QType::Cast($mixValue, QType::Boolean));
  1005. } catch (QCallerException $objExc) {
  1006. $objExc->IncrementOffset();
  1007. throw $objExc;
  1008. }
  1009. case 'ContentBlockId':
  1010. /**
  1011. * Sets the value for intContentBlockId
  1012. * @param integer $mixValue
  1013. * @return integer
  1014. */
  1015. try {
  1016. $this->objContentBlock = null;
  1017. return ($this->intContentBlockId = QType::Cast($mixValue, QType::Integer));
  1018. } catch (QCallerException $objExc) {
  1019. $objExc->IncrementOffset();
  1020. throw $objExc;
  1021. }
  1022. case 'ParentModuleId':
  1023. /**
  1024. * Sets the value for intParentModuleId
  1025. * @param integer $mixValue
  1026. * @return integer
  1027. */
  1028. try {
  1029. $this->objParentModule = null;
  1030. return ($this->intParentModuleId = QType::Cast($mixValue, QType::Integer));
  1031. } catch (QCallerException $objExc) {
  1032. $objExc->IncrementOffset();
  1033. throw $objExc;
  1034. }
  1035. ///////////////////
  1036. // Member Objects
  1037. ///////////////////
  1038. case 'ContentBlock':
  1039. /**
  1040. * Sets the value for the ContentBlock object referenced by intContentBlockId
  1041. * @param ContentBlock $mixValue
  1042. * @return ContentBlock
  1043. */
  1044. if (is_null($mixValue)) {
  1045. $this->intContentBlockId = null;
  1046. $this->objContentBlock = null;
  1047. return null;
  1048. } else {
  1049. // Make sure $mixValue actually is a ContentBlock object
  1050. try {
  1051. $mixValue = QType::Cast($mixValue, 'ContentBlock');
  1052. } catch (QInvalidCastException $objExc) {
  1053. $objExc->IncrementOffset();
  1054. throw $objExc;
  1055. }
  1056. // Make sure $mixValue is a SAVED ContentBlock object
  1057. if (is_null($mixValue->Id))
  1058. throw new QCallerException('Unable to set an unsaved ContentBlock for this Module');
  1059. // Update Local Member Variables
  1060. $this->objContentBlock = $mixValue;
  1061. $this->intContentBlockId = $mixValue->Id;
  1062. // Return $mixValue
  1063. return $mixValue;
  1064. }
  1065. break;
  1066. case 'ParentModule':
  1067. /**
  1068. * Sets the value for the Module object referenced by intParentModuleId
  1069. * @param Module $mixValue
  1070. * @return Module
  1071. */
  1072. if (is_null($mixValue)) {
  1073. $this->intParentModuleId = null;
  1074. $this->objParentModule = null;
  1075. return null;
  1076. } else {
  1077. // Make sure $mixValue actually is a Module object
  1078. try {
  1079. $mixValue = QType::Cast($mixValue, 'Module');
  1080. } catch (QInvalidCastException $objExc) {
  1081. $objExc->IncrementOffset();
  1082. throw $objExc;
  1083. }
  1084. // Make sure $mixValue is a SAVED Module object
  1085. if (is_null($mixValue->Id))
  1086. throw new QCallerException('Unable to set an unsaved ParentModule for this Module');
  1087. // Update Local Member Variables
  1088. $this->objParentModule = $mixValue;
  1089. $this->intParentModuleId = $mixValue->Id;
  1090. // Return $mixValue
  1091. return $mixValue;
  1092. }
  1093. break;
  1094. default:
  1095. try {
  1096. return parent::__set($strName, $mixValue);
  1097. } catch (QCallerException $objExc) {
  1098. $objExc->IncrementOffset();
  1099. throw $objExc;
  1100. }
  1101. }
  1102. }
  1103. ///////////////////////////////
  1104. // ASSOCIATED OBJECTS' METHODS
  1105. ///////////////////////////////
  1106. // Related Objects' Methods for ChildModule
  1107. //-------------------------------------------------------------------
  1108. /**
  1109. * Gets all associated ChildModules as an array of Module objects
  1110. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1111. * @return Module[]
  1112. */
  1113. public function GetChildModuleArray($objOptionalClauses = null) {
  1114. if ((is_null($this->intId)))
  1115. return array();
  1116. try {
  1117. return Module::LoadArrayByParentModuleId($this->intId, $objOptionalClauses);
  1118. } catch (QCallerException $objExc) {
  1119. $objExc->IncrementOffset();
  1120. throw $objExc;
  1121. }
  1122. }
  1123. /**
  1124. * Counts all associated ChildModules
  1125. * @return int
  1126. */
  1127. public function CountChildModules() {
  1128. if ((is_null($this->intId)))
  1129. return 0;
  1130. return Module::CountByParentModuleId($this->intId);
  1131. }
  1132. /**
  1133. * Associates a ChildModule
  1134. * @param Module $objModule
  1135. * @return void
  1136. */
  1137. public function AssociateChildModule(Module $objModule) {
  1138. if ((is_null($this->intId)))
  1139. throw new QUndefinedPrimaryKeyException('Unable to call AssociateChildModule on this unsaved Module.');
  1140. if ((is_null($objModule->Id)))
  1141. throw new QUndefinedPrimaryKeyException('Unable to call AssociateChildModule on this Module with an unsaved Module.');
  1142. // Get the Database Object for this Class
  1143. $objDatabase = Module::GetDatabase();
  1144. // Perform the SQL Query
  1145. $objDatabase->NonQuery('
  1146. UPDATE
  1147. `module`
  1148. SET
  1149. `parent_module_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1150. WHERE
  1151. `id` = ' . $objDatabase->SqlVariable($objModule->Id) . '
  1152. ');
  1153. }
  1154. /**
  1155. * Unassociates a ChildModule
  1156. * @param Module $objModule
  1157. * @return void
  1158. */
  1159. public function UnassociateChildModule(Module $objModule) {
  1160. if ((is_null($this->intId)))
  1161. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateChildModule on this unsaved Module.');
  1162. if ((is_null($objModule->Id)))
  1163. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateChildModule on this Module with an unsaved Module.');
  1164. // Get the Database Object for this Class
  1165. $objDatabase = Module::GetDatabase();
  1166. // Perform the SQL Query
  1167. $objDatabase->NonQuery('
  1168. UPDATE
  1169. `module`
  1170. SET
  1171. `parent_module_id` = null
  1172. WHERE
  1173. `id` = ' . $objDatabase->SqlVariable($objModule->Id) . ' AND
  1174. `parent_module_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1175. ');
  1176. }
  1177. /**
  1178. * Unassociates all ChildModules
  1179. * @return void
  1180. */
  1181. public function UnassociateAllChildModules() {
  1182. if ((is_null($this->intId)))
  1183. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateChildModule on this unsaved Module.');
  1184. // Get the Database Object for this Class
  1185. $objDatabase = Module::GetDatabase();
  1186. // Perform the SQL Query
  1187. $objDatabase->NonQuery('
  1188. UPDATE
  1189. `module`
  1190. SET
  1191. `parent_module_id` = null
  1192. WHERE
  1193. `parent_module_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1194. ');
  1195. }
  1196. /**
  1197. * Deletes an associated ChildModule
  1198. * @param Module $objModule
  1199. * @return void
  1200. */
  1201. public function DeleteAssociatedChildModule(Module $objModule) {
  1202. if ((is_null($this->intId)))
  1203. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateChildModule on this unsaved Module.');
  1204. if ((is_null($objModule->Id)))
  1205. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateChildModule on this Module with an unsaved Module.');
  1206. // Get the Database Object for this Class
  1207. $objDatabase = Module::GetDatabase();
  1208. // Perform the SQL Query
  1209. $objDatabase->NonQuery('
  1210. DELETE FROM
  1211. `module`
  1212. WHERE
  1213. `id` = ' . $objDatabase->SqlVariable($objModule->Id) . ' AND
  1214. `parent_module_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1215. ');
  1216. }
  1217. /**
  1218. * Deletes all associated ChildModules
  1219. * @return void
  1220. */
  1221. public function DeleteAllChildModules() {
  1222. if ((is_null($this->intId)))
  1223. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateChildModule on this unsaved Module.');
  1224. // Get the Database Object for this Class
  1225. $objDatabase = Module::GetDatabase();
  1226. // Perform the SQL Query
  1227. $objDatabase->NonQuery('
  1228. DELETE FROM
  1229. `module`
  1230. WHERE
  1231. `parent_module_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1232. ');
  1233. }
  1234. }
  1235. /////////////////////////////////////
  1236. // ADDITIONAL CLASSES for QCODO QUERY
  1237. /////////////////////////////////////
  1238. class QQNodeModule extends QQNode {
  1239. protected $strTableName = 'module';
  1240. protected $strPrimaryKey = 'id';
  1241. protected $strClassName = 'Module';
  1242. public function __get($strName) {
  1243. switch ($strName) {
  1244. case 'Id':
  1245. return new QQNode('id', 'Id', 'integer', $this);
  1246. case 'Name':
  1247. return new QQNode('name', 'Name', 'string', $this);
  1248. case 'Cssclass':
  1249. return new QQNode('cssclass', 'Cssclass', 'string', $this);
  1250. case 'Title':
  1251. return new QQNode('title', 'Title', 'string', $this);
  1252. case 'Description':
  1253. return new QQNode('description', 'Description', 'string', $this);
  1254. case 'ClassName':
  1255. return new QQNode('class_name', 'ClassName', 'string', $this);
  1256. case 'ShowTitle':
  1257. return new QQNode('show_title', 'ShowTitle', 'boolean', $this);
  1258. case 'ShowDescription':
  1259. return new QQNode('show_description', 'ShowDescription', 'boolean', $this);
  1260. case 'ContentBlockId':
  1261. return new QQNode('content_block_id', 'ContentBlockId', 'integer', $this);
  1262. case 'ContentBlock':
  1263. return new QQNodeContentBlock('content_block_id', 'ContentBlock', 'integer', $this);
  1264. case 'ParentModuleId':
  1265. return new QQNode('parent_module_id', 'ParentModuleId', 'integer', $this);
  1266. case 'ParentModule':
  1267. return new QQNodeModule('parent_module_id', 'ParentModule', 'integer', $this);
  1268. case 'ChildModule':
  1269. return new QQReverseReferenceNodeModule($this, 'childmodule', 'reverse_reference', 'parent_module_id');
  1270. case '_PrimaryKeyNode':
  1271. return new QQNode('id', 'Id', 'integer', $this);
  1272. default:
  1273. try {
  1274. return parent::__get($strName);
  1275. } catch (QCallerException $objExc) {
  1276. $objExc->IncrementOffset();
  1277. throw $objExc;
  1278. }
  1279. }
  1280. }
  1281. }
  1282. class QQReverseReferenceNodeModule extends QQReverseReferenceNode {
  1283. protected $strTableName = 'module';
  1284. protected $strPrimaryKey = 'id';
  1285. protected $strClassName = 'Module';
  1286. public function __get($strName) {
  1287. switch ($strName) {
  1288. case 'Id':
  1289. return new QQNode('id', 'Id', 'integer', $this);
  1290. case 'Name':
  1291. return new QQNode('name', 'Name', 'string', $this);
  1292. case 'Cssclass':
  1293. return new QQNode('cssclass', 'Cssclass', 'string', $this);
  1294. case 'Title':
  1295. return new QQNode('title', 'Title', 'string', $this);
  1296. case 'Description':
  1297. return new QQNode('description', 'Description', 'string', $this);
  1298. case 'ClassName':
  1299. return new QQNode('class_name', 'ClassName', 'string', $this);
  1300. case 'ShowTitle':
  1301. return new QQNode('show_title', 'ShowTitle', 'boolean', $this);
  1302. case 'ShowDescription':
  1303. return new QQNode('show_description', 'ShowDescription', 'boolean', $this);
  1304. case 'ContentBlockId':
  1305. return new QQNode('content_block_id', 'ContentBlockId', 'integer', $this);
  1306. case 'ContentBlock':
  1307. return new QQNodeContentBlock('content_block_id', 'ContentBlock', 'integer', $this);
  1308. case 'ParentModuleId':
  1309. return new QQNode('parent_module_id', 'ParentModuleId', 'integer', $this);
  1310. case 'ParentModule':
  1311. return new QQNodeModule('parent_module_id', 'ParentModule', 'integer', $this);
  1312. case 'ChildModule':
  1313. return new QQReverseReferenceNodeModule($this, 'childmodule', 'reverse_reference', 'parent_module_id');
  1314. case '_PrimaryKeyNode':
  1315. return new QQNode('id', 'Id', 'integer', $this);
  1316. default:
  1317. try {
  1318. return parent::__get($strName);
  1319. } catch (QCallerException $objExc) {
  1320. $objExc->IncrementOffset();
  1321. throw $objExc;
  1322. }
  1323. }
  1324. }
  1325. }
  1326. ?>