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.

1689 lines
71 KiB

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