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.

1740 lines
72 KiB

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