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.

2124 lines
91 KiB

  1. <?php
  2. /**
  3. * The abstract ContentBlockGen 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 ContentBlock subclass which
  8. * extends this ContentBlockGen 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 ContentBlock class.
  15. *
  16. * @package Quinta CMS
  17. * @subpackage GeneratedDataObjects
  18. * @property-read integer $Id the value for intId (Read-Only PK)
  19. * @property string $Name the value for strName (Unique)
  20. * @property string $Cssclass the value for strCssclass
  21. * @property string $Title the value for strTitle
  22. * @property string $Description the value for strDescription
  23. * @property boolean $ShowTitle the value for blnShowTitle (Not Null)
  24. * @property boolean $ShowDescription the value for blnShowDescription (Not Null)
  25. * @property boolean $Collapsable the value for blnCollapsable (Not Null)
  26. * @property integer $SortOrder the value for intSortOrder (Not Null)
  27. * @property integer $ParentContentBlockId the value for intParentContentBlockId
  28. * @property integer $LocationId the value for intLocationId (Not Null)
  29. * @property-read Page $_Page the value for the private _objPage (Read-Only) if set due to an expansion on the content_block_page_assn association table
  30. * @property-read Page[] $_PageArray the value for the private _objPageArray (Read-Only) if set due to an ExpandAsArray on the content_block_page_assn association table
  31. * @property-read ContentItem $_ContentItem the value for the private _objContentItem (Read-Only) if set due to an expansion on the content_item_content_block_assn association table
  32. * @property-read ContentItem[] $_ContentItemArray the value for the private _objContentItemArray (Read-Only) if set due to an ExpandAsArray on the content_item_content_block_assn association table
  33. * @property-read Menu $_Menu the value for the private _objMenu (Read-Only) if set due to an expansion on the menu_content_block_assn association table
  34. * @property-read Menu[] $_MenuArray the value for the private _objMenuArray (Read-Only) if set due to an ExpandAsArray on the menu_content_block_assn association table
  35. * @property-read Module $_Module the value for the private _objModule (Read-Only) if set due to an expansion on the module.content_block_id reverse relationship
  36. * @property-read Module[] $_ModuleArray the value for the private _objModuleArray (Read-Only) if set due to an ExpandAsArray on the module.content_block_id reverse relationship
  37. * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
  38. */
  39. class ContentBlockGen extends QBaseClass
  40. {
  41. ///////////////////////////////////////////////////////////////////////
  42. // PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
  43. ///////////////////////////////////////////////////////////////////////
  44. /////////// Object properties ////////////
  45. /**
  46. * Protected member variable that maps to the database PK Identity column content_block.id
  47. * @var integer intId
  48. *
  49. */
  50. protected $intId = null;
  51. /**
  52. * Protected member variable that maps to the database column content_block.name
  53. * @var string strName
  54. *
  55. */
  56. protected $strName = null;
  57. const NameMaxLength = 128;
  58. /**
  59. * Protected member variable that maps to the database column content_block.cssclass
  60. * @var string strCssclass
  61. *
  62. */
  63. protected $strCssclass = null;
  64. const CssclassMaxLength = 128;
  65. /**
  66. * Protected member variable that maps to the database column content_block.title
  67. * @var string strTitle
  68. *
  69. */
  70. protected $strTitle = null;
  71. const TitleMaxLength = 128;
  72. /**
  73. * Protected member variable that maps to the database column content_block.description
  74. * @var string strDescription
  75. *
  76. */
  77. protected $strDescription = null;
  78. const DescriptionMaxLength = 256;
  79. /**
  80. * Protected member variable that maps to the database column content_block.show_title
  81. * @var boolean blnShowTitle
  82. *
  83. */
  84. protected $blnShowTitle = null;
  85. /**
  86. * Protected member variable that maps to the database column content_block.show_description
  87. * @var boolean blnShowDescription
  88. *
  89. */
  90. protected $blnShowDescription = null;
  91. /**
  92. * Protected member variable that maps to the database column content_block.collapsable
  93. * @var boolean blnCollapsable
  94. *
  95. */
  96. protected $blnCollapsable = null;
  97. /**
  98. * Protected member variable that maps to the database column content_block.sort_order
  99. * @var integer intSortOrder
  100. *
  101. */
  102. protected $intSortOrder = null;
  103. /**
  104. * Protected member variable that maps to the database column content_block.parent_content_block_id
  105. * @var integer intParentContentBlockId
  106. *
  107. */
  108. protected $intParentContentBlockId = null;
  109. /**
  110. * Protected member variable that maps to the database column content_block.location_id
  111. * @var integer intLocationId
  112. *
  113. */
  114. protected $intLocationId = null;
  115. /**
  116. * Private member variable that stores a reference to a single Page object
  117. * (of type Page), if this ContentBlock object was restored with
  118. * an expansion on the content_block_page_assn association table.
  119. * @var Page _objPage;
  120. */
  121. private $_objPage;
  122. /**
  123. * Private member variable that stores a reference to an array of Page objects
  124. * (of type Page[]), if this ContentBlock object was restored with
  125. * an ExpandAsArray on the content_block_page_assn association table.
  126. * @var Page[] _objPageArray;
  127. */
  128. private $_objPageArray = array();
  129. /**
  130. * Private member variable that stores a reference to a single ContentItem object
  131. * (of type ContentItem), if this ContentBlock object was restored with
  132. * an expansion on the content_item_content_block_assn association table.
  133. * @var ContentItem _objContentItem;
  134. */
  135. private $_objContentItem;
  136. /**
  137. * Private member variable that stores a reference to an array of ContentItem objects
  138. * (of type ContentItem[]), if this ContentBlock object was restored with
  139. * an ExpandAsArray on the content_item_content_block_assn association table.
  140. * @var ContentItem[] _objContentItemArray;
  141. */
  142. private $_objContentItemArray = array();
  143. /**
  144. * Private member variable that stores a reference to a single Menu object
  145. * (of type Menu), if this ContentBlock object was restored with
  146. * an expansion on the menu_content_block_assn association table.
  147. * @var Menu _objMenu;
  148. */
  149. private $_objMenu;
  150. /**
  151. * Private member variable that stores a reference to an array of Menu objects
  152. * (of type Menu[]), if this ContentBlock object was restored with
  153. * an ExpandAsArray on the menu_content_block_assn association table.
  154. * @var Menu[] _objMenuArray;
  155. */
  156. private $_objMenuArray = array();
  157. /**
  158. * Private member variable that stores a reference to a single Module object
  159. * (of type Module), if this ContentBlock object was restored with
  160. * an expansion on the module association table.
  161. * @var Module _objModule;
  162. */
  163. private $_objModule;
  164. /**
  165. * Private member variable that stores a reference to an array of Module objects
  166. * (of type Module[]), if this ContentBlock object was restored with
  167. * an ExpandAsArray on the module association table.
  168. * @var Module[] _objModuleArray;
  169. */
  170. private $_objModuleArray = array();
  171. /**
  172. * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
  173. * columns from the run-time database query result for this object). Used by InstantiateDbRow and
  174. * GetVirtualAttribute.
  175. * @var string[] $__strVirtualAttributeArray
  176. */
  177. protected $__strVirtualAttributeArray = array();
  178. /**
  179. * Protected internal member variable that specifies whether or not this object is Restored from the database.
  180. * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
  181. * @var bool __blnRestored;
  182. */
  183. protected $__blnRestored;
  184. ///////////////////////////////
  185. // PROTECTED MEMBER OBJECTS
  186. ///////////////////////////////
  187. ///////////////////////////////
  188. // CLASS-WIDE LOAD AND COUNT METHODS
  189. ///////////////////////////////
  190. /**
  191. * Static method to retrieve the Database object that owns this class.
  192. * @return QDatabaseBase reference to the Database object that can query this class
  193. */
  194. public static function GetDatabase() {
  195. return QApplication::$Database[1];
  196. }
  197. /**
  198. * Load a ContentBlock from PK Info
  199. * @param integer $intId
  200. * @return ContentBlock
  201. */
  202. public static function Load($intId) {
  203. // Use QuerySingle to Perform the Query
  204. return ContentBlock::QuerySingle(
  205. QQ::Equal(QQN::ContentBlock()->Id, $intId)
  206. );
  207. }
  208. /**
  209. * Load all ContentBlocks
  210. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  211. * @return ContentBlock[]
  212. */
  213. public static function LoadAll($objOptionalClauses = null) {
  214. // Call ContentBlock::QueryArray to perform the LoadAll query
  215. try {
  216. return ContentBlock::QueryArray(QQ::All(), $objOptionalClauses);
  217. } catch (QCallerException $objExc) {
  218. $objExc->IncrementOffset();
  219. throw $objExc;
  220. }
  221. }
  222. /**
  223. * Count all ContentBlocks
  224. * @return int
  225. */
  226. public static function CountAll() {
  227. // Call ContentBlock::QueryCount to perform the CountAll query
  228. return ContentBlock::QueryCount(QQ::All());
  229. }
  230. ///////////////////////////////
  231. // QCODO QUERY-RELATED METHODS
  232. ///////////////////////////////
  233. /**
  234. * Internally called method to assist with calling Qcodo Query for this class
  235. * on load methods.
  236. * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
  237. * @param QQCondition $objConditions any conditions on the query, itself
  238. * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
  239. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
  240. * @param boolean $blnCountOnly only select a rowcount
  241. * @return string the query statement
  242. */
  243. protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
  244. // Get the Database Object for this Class
  245. $objDatabase = ContentBlock::GetDatabase();
  246. // Create/Build out the QueryBuilder object with ContentBlock-specific SELET and FROM fields
  247. $objQueryBuilder = new QQueryBuilder($objDatabase, 'content_block');
  248. ContentBlock::GetSelectFields($objQueryBuilder);
  249. $objQueryBuilder->AddFromItem('content_block');
  250. // Set "CountOnly" option (if applicable)
  251. if ($blnCountOnly)
  252. $objQueryBuilder->SetCountOnlyFlag();
  253. // Apply Any Conditions
  254. if ($objConditions)
  255. try {
  256. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  257. } catch (QCallerException $objExc) {
  258. $objExc->IncrementOffset();
  259. throw $objExc;
  260. }
  261. // Iterate through all the Optional Clauses (if any) and perform accordingly
  262. if ($objOptionalClauses) {
  263. if ($objOptionalClauses instanceof QQClause)
  264. $objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
  265. else if (is_array($objOptionalClauses))
  266. foreach ($objOptionalClauses as $objClause)
  267. $objClause->UpdateQueryBuilder($objQueryBuilder);
  268. else
  269. throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
  270. }
  271. // Get the SQL Statement
  272. $strQuery = $objQueryBuilder->GetStatement();
  273. // Prepare the Statement with the Query Parameters (if applicable)
  274. if ($mixParameterArray) {
  275. if (is_array($mixParameterArray)) {
  276. if (count($mixParameterArray))
  277. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  278. // Ensure that there are no other Unresolved Named Parameters
  279. if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
  280. throw new QCallerException('Unresolved named parameters in the query');
  281. } else
  282. throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
  283. }
  284. // Return the Objects
  285. return $strQuery;
  286. }
  287. /**
  288. * Static Qcodo Query method to query for a single ContentBlock object.
  289. * Uses BuildQueryStatment to perform most of the work.
  290. * @param QQCondition $objConditions any conditions on the query, itself
  291. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  292. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  293. * @return ContentBlock the queried object
  294. */
  295. public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  296. // Get the Query Statement
  297. try {
  298. $strQuery = ContentBlock::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  299. } catch (QCallerException $objExc) {
  300. $objExc->IncrementOffset();
  301. throw $objExc;
  302. }
  303. // Perform the Query, Get the First Row, and Instantiate a new ContentBlock object
  304. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  305. return ContentBlock::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray);
  306. }
  307. /**
  308. * Static Qcodo Query method to query for an array of ContentBlock objects.
  309. * Uses BuildQueryStatment to perform most of the work.
  310. * @param QQCondition $objConditions any conditions on the query, itself
  311. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  312. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  313. * @return ContentBlock[] the queried objects as an array
  314. */
  315. public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  316. // Get the Query Statement
  317. try {
  318. $strQuery = ContentBlock::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  319. } catch (QCallerException $objExc) {
  320. $objExc->IncrementOffset();
  321. throw $objExc;
  322. }
  323. // Perform the Query and Instantiate the Array Result
  324. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  325. return ContentBlock::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
  326. }
  327. /**
  328. * Static Qcodo Query method to query for a count of ContentBlock objects.
  329. * Uses BuildQueryStatment to perform most of the work.
  330. * @param QQCondition $objConditions any conditions on the query, itself
  331. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  332. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  333. * @return integer the count of queried objects as an integer
  334. */
  335. public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  336. // Get the Query Statement
  337. try {
  338. $strQuery = ContentBlock::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
  339. } catch (QCallerException $objExc) {
  340. $objExc->IncrementOffset();
  341. throw $objExc;
  342. }
  343. // Perform the Query and return the row_count
  344. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  345. // Figure out if the query is using GroupBy
  346. $blnGrouped = false;
  347. if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
  348. if ($objClause instanceof QQGroupBy) {
  349. $blnGrouped = true;
  350. break;
  351. }
  352. }
  353. if ($blnGrouped)
  354. // Groups in this query - return the count of Groups (which is the count of all rows)
  355. return $objDbResult->CountRows();
  356. else {
  357. // No Groups - return the sql-calculated count(*) value
  358. $strDbRow = $objDbResult->FetchRow();
  359. return QType::Cast($strDbRow[0], QType::Integer);
  360. }
  361. }
  362. /* public static function QueryArrayCached($strConditions, $mixParameterArray = null) {
  363. // Get the Database Object for this Class
  364. $objDatabase = ContentBlock::GetDatabase();
  365. // Lookup the QCache for This Query Statement
  366. $objCache = new QCache('query', 'content_block_' . serialize($strConditions));
  367. if (!($strQuery = $objCache->GetData())) {
  368. // Not Found -- Go ahead and Create/Build out a new QueryBuilder object with ContentBlock-specific fields
  369. $objQueryBuilder = new QQueryBuilder($objDatabase);
  370. ContentBlock::GetSelectFields($objQueryBuilder);
  371. ContentBlock::GetFromFields($objQueryBuilder);
  372. // Ensure the Passed-in Conditions is a string
  373. try {
  374. $strConditions = QType::Cast($strConditions, QType::String);
  375. } catch (QCallerException $objExc) {
  376. $objExc->IncrementOffset();
  377. throw $objExc;
  378. }
  379. // Create the Conditions object, and apply it
  380. $objConditions = eval('return ' . $strConditions . ';');
  381. // Apply Any Conditions
  382. if ($objConditions)
  383. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  384. // Get the SQL Statement
  385. $strQuery = $objQueryBuilder->GetStatement();
  386. // Save the SQL Statement in the Cache
  387. $objCache->SaveData($strQuery);
  388. }
  389. // Prepare the Statement with the Parameters
  390. if ($mixParameterArray)
  391. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  392. // Perform the Query and Instantiate the Array Result
  393. $objDbResult = $objDatabase->Query($strQuery);
  394. return ContentBlock::InstantiateDbResult($objDbResult);
  395. }*/
  396. /**
  397. * Updates a QQueryBuilder with the SELECT fields for this ContentBlock
  398. * @param QQueryBuilder $objBuilder the Query Builder object to update
  399. * @param string $strPrefix optional prefix to add to the SELECT fields
  400. */
  401. public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
  402. if ($strPrefix) {
  403. $strTableName = $strPrefix;
  404. $strAliasPrefix = $strPrefix . '__';
  405. } else {
  406. $strTableName = 'content_block';
  407. $strAliasPrefix = '';
  408. }
  409. $objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
  410. $objBuilder->AddSelectItem($strTableName, 'name', $strAliasPrefix . 'name');
  411. $objBuilder->AddSelectItem($strTableName, 'cssclass', $strAliasPrefix . 'cssclass');
  412. $objBuilder->AddSelectItem($strTableName, 'title', $strAliasPrefix . 'title');
  413. $objBuilder->AddSelectItem($strTableName, 'description', $strAliasPrefix . 'description');
  414. $objBuilder->AddSelectItem($strTableName, 'show_title', $strAliasPrefix . 'show_title');
  415. $objBuilder->AddSelectItem($strTableName, 'show_description', $strAliasPrefix . 'show_description');
  416. $objBuilder->AddSelectItem($strTableName, 'collapsable', $strAliasPrefix . 'collapsable');
  417. $objBuilder->AddSelectItem($strTableName, 'sort_order', $strAliasPrefix . 'sort_order');
  418. $objBuilder->AddSelectItem($strTableName, 'parent_content_block_id', $strAliasPrefix . 'parent_content_block_id');
  419. $objBuilder->AddSelectItem($strTableName, 'location_id', $strAliasPrefix . 'location_id');
  420. }
  421. ///////////////////////////////
  422. // INSTANTIATION-RELATED METHODS
  423. ///////////////////////////////
  424. /**
  425. * Instantiate a ContentBlock from a Database Row.
  426. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  427. * is calling this ContentBlock::InstantiateDbRow in order to perform
  428. * early binding on referenced objects.
  429. * @param DatabaseRowBase $objDbRow
  430. * @param string $strAliasPrefix
  431. * @param string $strExpandAsArrayNodes
  432. * @param QBaseClass $objPreviousItem
  433. * @param string[] $strColumnAliasArray
  434. * @return ContentBlock
  435. */
  436. public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $objPreviousItem = null, $strColumnAliasArray = array()) {
  437. // If blank row, return null
  438. if (!$objDbRow)
  439. return null;
  440. // See if we're doing an array expansion on the previous item
  441. $strAlias = $strAliasPrefix . 'id';
  442. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  443. if (($strExpandAsArrayNodes) && ($objPreviousItem) &&
  444. ($objPreviousItem->intId == $objDbRow->GetColumn($strAliasName, 'Integer'))) {
  445. // We are. Now, prepare to check for ExpandAsArray clauses
  446. $blnExpandedViaArray = false;
  447. if (!$strAliasPrefix)
  448. $strAliasPrefix = 'content_block__';
  449. $strAlias = $strAliasPrefix . 'page__page_id__id';
  450. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  451. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  452. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  453. if ($intPreviousChildItemCount = count($objPreviousItem->_objPageArray)) {
  454. $objPreviousChildItem = $objPreviousItem->_objPageArray[$intPreviousChildItemCount - 1];
  455. $objChildItem = Page::InstantiateDbRow($objDbRow, $strAliasPrefix . 'page__page_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  456. if ($objChildItem)
  457. $objPreviousItem->_objPageArray[] = $objChildItem;
  458. } else
  459. $objPreviousItem->_objPageArray[] = Page::InstantiateDbRow($objDbRow, $strAliasPrefix . 'page__page_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  460. $blnExpandedViaArray = true;
  461. }
  462. $strAlias = $strAliasPrefix . 'contentitem__content_item_id__id';
  463. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  464. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  465. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  466. if ($intPreviousChildItemCount = count($objPreviousItem->_objContentItemArray)) {
  467. $objPreviousChildItem = $objPreviousItem->_objContentItemArray[$intPreviousChildItemCount - 1];
  468. $objChildItem = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitem__content_item_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  469. if ($objChildItem)
  470. $objPreviousItem->_objContentItemArray[] = $objChildItem;
  471. } else
  472. $objPreviousItem->_objContentItemArray[] = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitem__content_item_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  473. $blnExpandedViaArray = true;
  474. }
  475. $strAlias = $strAliasPrefix . 'menu__menu_id__id';
  476. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  477. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  478. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  479. if ($intPreviousChildItemCount = count($objPreviousItem->_objMenuArray)) {
  480. $objPreviousChildItem = $objPreviousItem->_objMenuArray[$intPreviousChildItemCount - 1];
  481. $objChildItem = Menu::InstantiateDbRow($objDbRow, $strAliasPrefix . 'menu__menu_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  482. if ($objChildItem)
  483. $objPreviousItem->_objMenuArray[] = $objChildItem;
  484. } else
  485. $objPreviousItem->_objMenuArray[] = Menu::InstantiateDbRow($objDbRow, $strAliasPrefix . 'menu__menu_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  486. $blnExpandedViaArray = true;
  487. }
  488. $strAlias = $strAliasPrefix . 'module__id';
  489. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  490. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  491. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  492. if ($intPreviousChildItemCount = count($objPreviousItem->_objModuleArray)) {
  493. $objPreviousChildItem = $objPreviousItem->_objModuleArray[$intPreviousChildItemCount - 1];
  494. $objChildItem = Module::InstantiateDbRow($objDbRow, $strAliasPrefix . 'module__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  495. if ($objChildItem)
  496. $objPreviousItem->_objModuleArray[] = $objChildItem;
  497. } else
  498. $objPreviousItem->_objModuleArray[] = Module::InstantiateDbRow($objDbRow, $strAliasPrefix . 'module__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  499. $blnExpandedViaArray = true;
  500. }
  501. // Either return false to signal array expansion, or check-to-reset the Alias prefix and move on
  502. if ($blnExpandedViaArray)
  503. return false;
  504. else if ($strAliasPrefix == 'content_block__')
  505. $strAliasPrefix = null;
  506. }
  507. // Create a new instance of the ContentBlock object
  508. $objToReturn = new ContentBlock();
  509. $objToReturn->__blnRestored = true;
  510. $strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
  511. $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
  512. $strAliasName = array_key_exists($strAliasPrefix . 'name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'name'] : $strAliasPrefix . 'name';
  513. $objToReturn->strName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  514. $strAliasName = array_key_exists($strAliasPrefix . 'cssclass', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'cssclass'] : $strAliasPrefix . 'cssclass';
  515. $objToReturn->strCssclass = $objDbRow->GetColumn($strAliasName, 'VarChar');
  516. $strAliasName = array_key_exists($strAliasPrefix . 'title', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'title'] : $strAliasPrefix . 'title';
  517. $objToReturn->strTitle = $objDbRow->GetColumn($strAliasName, 'VarChar');
  518. $strAliasName = array_key_exists($strAliasPrefix . 'description', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'description'] : $strAliasPrefix . 'description';
  519. $objToReturn->strDescription = $objDbRow->GetColumn($strAliasName, 'VarChar');
  520. $strAliasName = array_key_exists($strAliasPrefix . 'show_title', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'show_title'] : $strAliasPrefix . 'show_title';
  521. $objToReturn->blnShowTitle = $objDbRow->GetColumn($strAliasName, 'Bit');
  522. $strAliasName = array_key_exists($strAliasPrefix . 'show_description', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'show_description'] : $strAliasPrefix . 'show_description';
  523. $objToReturn->blnShowDescription = $objDbRow->GetColumn($strAliasName, 'Bit');
  524. $strAliasName = array_key_exists($strAliasPrefix . 'collapsable', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'collapsable'] : $strAliasPrefix . 'collapsable';
  525. $objToReturn->blnCollapsable = $objDbRow->GetColumn($strAliasName, 'Bit');
  526. $strAliasName = array_key_exists($strAliasPrefix . 'sort_order', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'sort_order'] : $strAliasPrefix . 'sort_order';
  527. $objToReturn->intSortOrder = $objDbRow->GetColumn($strAliasName, 'Integer');
  528. $strAliasName = array_key_exists($strAliasPrefix . 'parent_content_block_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'parent_content_block_id'] : $strAliasPrefix . 'parent_content_block_id';
  529. $objToReturn->intParentContentBlockId = $objDbRow->GetColumn($strAliasName, 'Integer');
  530. $strAliasName = array_key_exists($strAliasPrefix . 'location_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'location_id'] : $strAliasPrefix . 'location_id';
  531. $objToReturn->intLocationId = $objDbRow->GetColumn($strAliasName, 'Integer');
  532. // Instantiate Virtual Attributes
  533. foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
  534. $strVirtualPrefix = $strAliasPrefix . '__';
  535. $strVirtualPrefixLength = strlen($strVirtualPrefix);
  536. if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
  537. $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
  538. }
  539. // Prepare to Check for Early/Virtual Binding
  540. if (!$strAliasPrefix)
  541. $strAliasPrefix = 'content_block__';
  542. // Check for Page Virtual Binding
  543. $strAlias = $strAliasPrefix . 'page__page_id__id';
  544. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  545. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  546. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  547. $objToReturn->_objPageArray[] = Page::InstantiateDbRow($objDbRow, $strAliasPrefix . 'page__page_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  548. else
  549. $objToReturn->_objPage = Page::InstantiateDbRow($objDbRow, $strAliasPrefix . 'page__page_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  550. }
  551. // Check for ContentItem Virtual Binding
  552. $strAlias = $strAliasPrefix . 'contentitem__content_item_id__id';
  553. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  554. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  555. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  556. $objToReturn->_objContentItemArray[] = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitem__content_item_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  557. else
  558. $objToReturn->_objContentItem = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitem__content_item_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  559. }
  560. // Check for Menu Virtual Binding
  561. $strAlias = $strAliasPrefix . 'menu__menu_id__id';
  562. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  563. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  564. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  565. $objToReturn->_objMenuArray[] = Menu::InstantiateDbRow($objDbRow, $strAliasPrefix . 'menu__menu_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  566. else
  567. $objToReturn->_objMenu = Menu::InstantiateDbRow($objDbRow, $strAliasPrefix . 'menu__menu_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  568. }
  569. // Check for Module Virtual Binding
  570. $strAlias = $strAliasPrefix . 'module__id';
  571. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  572. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  573. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  574. $objToReturn->_objModuleArray[] = Module::InstantiateDbRow($objDbRow, $strAliasPrefix . 'module__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  575. else
  576. $objToReturn->_objModule = Module::InstantiateDbRow($objDbRow, $strAliasPrefix . 'module__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  577. }
  578. return $objToReturn;
  579. }
  580. /**
  581. * Instantiate an array of ContentBlocks from a Database Result
  582. * @param DatabaseResultBase $objDbResult
  583. * @param string $strExpandAsArrayNodes
  584. * @param string[] $strColumnAliasArray
  585. * @return ContentBlock[]
  586. */
  587. public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
  588. $objToReturn = array();
  589. if (!$strColumnAliasArray)
  590. $strColumnAliasArray = array();
  591. // If blank resultset, then return empty array
  592. if (!$objDbResult)
  593. return $objToReturn;
  594. // Load up the return array with each row
  595. if ($strExpandAsArrayNodes) {
  596. $objLastRowItem = null;
  597. while ($objDbRow = $objDbResult->GetNextRow()) {
  598. $objItem = ContentBlock::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem, $strColumnAliasArray);
  599. if ($objItem) {
  600. $objToReturn[] = $objItem;
  601. $objLastRowItem = $objItem;
  602. }
  603. }
  604. } else {
  605. while ($objDbRow = $objDbResult->GetNextRow())
  606. $objToReturn[] = ContentBlock::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
  607. }
  608. return $objToReturn;
  609. }
  610. ///////////////////////////////////////////////////
  611. // INDEX-BASED LOAD METHODS (Single Load and Array)
  612. ///////////////////////////////////////////////////
  613. /**
  614. * Load a single ContentBlock object,
  615. * by Id Index(es)
  616. * @param integer $intId
  617. * @return ContentBlock
  618. */
  619. public static function LoadById($intId) {
  620. return ContentBlock::QuerySingle(
  621. QQ::Equal(QQN::ContentBlock()->Id, $intId)
  622. );
  623. }
  624. /**
  625. * Load a single ContentBlock object,
  626. * by Name Index(es)
  627. * @param string $strName
  628. * @return ContentBlock
  629. */
  630. public static function LoadByName($strName) {
  631. return ContentBlock::QuerySingle(
  632. QQ::Equal(QQN::ContentBlock()->Name, $strName)
  633. );
  634. }
  635. /**
  636. * Load an array of ContentBlock objects,
  637. * by ParentContentBlockId Index(es)
  638. * @param integer $intParentContentBlockId
  639. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  640. * @return ContentBlock[]
  641. */
  642. public static function LoadArrayByParentContentBlockId($intParentContentBlockId, $objOptionalClauses = null) {
  643. // Call ContentBlock::QueryArray to perform the LoadArrayByParentContentBlockId query
  644. try {
  645. return ContentBlock::QueryArray(
  646. QQ::Equal(QQN::ContentBlock()->ParentContentBlockId, $intParentContentBlockId),
  647. $objOptionalClauses);
  648. } catch (QCallerException $objExc) {
  649. $objExc->IncrementOffset();
  650. throw $objExc;
  651. }
  652. }
  653. /**
  654. * Count ContentBlocks
  655. * by ParentContentBlockId Index(es)
  656. * @param integer $intParentContentBlockId
  657. * @return int
  658. */
  659. public static function CountByParentContentBlockId($intParentContentBlockId) {
  660. // Call ContentBlock::QueryCount to perform the CountByParentContentBlockId query
  661. return ContentBlock::QueryCount(
  662. QQ::Equal(QQN::ContentBlock()->ParentContentBlockId, $intParentContentBlockId)
  663. );
  664. }
  665. /**
  666. * Load an array of ContentBlock objects,
  667. * by LocationId Index(es)
  668. * @param integer $intLocationId
  669. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  670. * @return ContentBlock[]
  671. */
  672. public static function LoadArrayByLocationId($intLocationId, $objOptionalClauses = null) {
  673. // Call ContentBlock::QueryArray to perform the LoadArrayByLocationId query
  674. try {
  675. return ContentBlock::QueryArray(
  676. QQ::Equal(QQN::ContentBlock()->LocationId, $intLocationId),
  677. $objOptionalClauses);
  678. } catch (QCallerException $objExc) {
  679. $objExc->IncrementOffset();
  680. throw $objExc;
  681. }
  682. }
  683. /**
  684. * Count ContentBlocks
  685. * by LocationId Index(es)
  686. * @param integer $intLocationId
  687. * @return int
  688. */
  689. public static function CountByLocationId($intLocationId) {
  690. // Call ContentBlock::QueryCount to perform the CountByLocationId query
  691. return ContentBlock::QueryCount(
  692. QQ::Equal(QQN::ContentBlock()->LocationId, $intLocationId)
  693. );
  694. }
  695. ////////////////////////////////////////////////////
  696. // INDEX-BASED LOAD METHODS (Array via Many to Many)
  697. ////////////////////////////////////////////////////
  698. /**
  699. * Load an array of Page objects for a given Page
  700. * via the content_block_page_assn table
  701. * @param integer $intPageId
  702. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  703. * @return ContentBlock[]
  704. */
  705. public static function LoadArrayByPage($intPageId, $objOptionalClauses = null) {
  706. // Call ContentBlock::QueryArray to perform the LoadArrayByPage query
  707. try {
  708. return ContentBlock::QueryArray(
  709. QQ::Equal(QQN::ContentBlock()->Page->PageId, $intPageId),
  710. $objOptionalClauses
  711. );
  712. } catch (QCallerException $objExc) {
  713. $objExc->IncrementOffset();
  714. throw $objExc;
  715. }
  716. }
  717. /**
  718. * Count ContentBlocks for a given Page
  719. * via the content_block_page_assn table
  720. * @param integer $intPageId
  721. * @return int
  722. */
  723. public static function CountByPage($intPageId) {
  724. return ContentBlock::QueryCount(
  725. QQ::Equal(QQN::ContentBlock()->Page->PageId, $intPageId)
  726. );
  727. }
  728. /**
  729. * Load an array of ContentItem objects for a given ContentItem
  730. * via the content_item_content_block_assn table
  731. * @param integer $intContentItemId
  732. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  733. * @return ContentBlock[]
  734. */
  735. public static function LoadArrayByContentItem($intContentItemId, $objOptionalClauses = null) {
  736. // Call ContentBlock::QueryArray to perform the LoadArrayByContentItem query
  737. try {
  738. return ContentBlock::QueryArray(
  739. QQ::Equal(QQN::ContentBlock()->ContentItem->ContentItemId, $intContentItemId),
  740. $objOptionalClauses
  741. );
  742. } catch (QCallerException $objExc) {
  743. $objExc->IncrementOffset();
  744. throw $objExc;
  745. }
  746. }
  747. /**
  748. * Count ContentBlocks for a given ContentItem
  749. * via the content_item_content_block_assn table
  750. * @param integer $intContentItemId
  751. * @return int
  752. */
  753. public static function CountByContentItem($intContentItemId) {
  754. return ContentBlock::QueryCount(
  755. QQ::Equal(QQN::ContentBlock()->ContentItem->ContentItemId, $intContentItemId)
  756. );
  757. }
  758. /**
  759. * Load an array of Menu objects for a given Menu
  760. * via the menu_content_block_assn table
  761. * @param integer $intMenuId
  762. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  763. * @return ContentBlock[]
  764. */
  765. public static function LoadArrayByMenu($intMenuId, $objOptionalClauses = null) {
  766. // Call ContentBlock::QueryArray to perform the LoadArrayByMenu query
  767. try {
  768. return ContentBlock::QueryArray(
  769. QQ::Equal(QQN::ContentBlock()->Menu->MenuId, $intMenuId),
  770. $objOptionalClauses
  771. );
  772. } catch (QCallerException $objExc) {
  773. $objExc->IncrementOffset();
  774. throw $objExc;
  775. }
  776. }
  777. /**
  778. * Count ContentBlocks for a given Menu
  779. * via the menu_content_block_assn table
  780. * @param integer $intMenuId
  781. * @return int
  782. */
  783. public static function CountByMenu($intMenuId) {
  784. return ContentBlock::QueryCount(
  785. QQ::Equal(QQN::ContentBlock()->Menu->MenuId, $intMenuId)
  786. );
  787. }
  788. //////////////////////////
  789. // SAVE, DELETE AND RELOAD
  790. //////////////////////////
  791. /**
  792. * Save this ContentBlock
  793. * @param bool $blnForceInsert
  794. * @param bool $blnForceUpdate
  795. * @return int
  796. */
  797. public function Save($blnForceInsert = false, $blnForceUpdate = false) {
  798. // Get the Database Object for this Class
  799. $objDatabase = ContentBlock::GetDatabase();
  800. $mixToReturn = null;
  801. try {
  802. if ((!$this->__blnRestored) || ($blnForceInsert)) {
  803. // Perform an INSERT query
  804. $objDatabase->NonQuery('
  805. INSERT INTO `content_block` (
  806. `name`,
  807. `cssclass`,
  808. `title`,
  809. `description`,
  810. `show_title`,
  811. `show_description`,
  812. `collapsable`,
  813. `sort_order`,
  814. `parent_content_block_id`,
  815. `location_id`
  816. ) VALUES (
  817. ' . $objDatabase->SqlVariable($this->strName) . ',
  818. ' . $objDatabase->SqlVariable($this->strCssclass) . ',
  819. ' . $objDatabase->SqlVariable($this->strTitle) . ',
  820. ' . $objDatabase->SqlVariable($this->strDescription) . ',
  821. ' . $objDatabase->SqlVariable($this->blnShowTitle) . ',
  822. ' . $objDatabase->SqlVariable($this->blnShowDescription) . ',
  823. ' . $objDatabase->SqlVariable($this->blnCollapsable) . ',
  824. ' . $objDatabase->SqlVariable($this->intSortOrder) . ',
  825. ' . $objDatabase->SqlVariable($this->intParentContentBlockId) . ',
  826. ' . $objDatabase->SqlVariable($this->intLocationId) . '
  827. )
  828. ');
  829. // Update Identity column and return its value
  830. $mixToReturn = $this->intId = $objDatabase->InsertId('content_block', 'id');
  831. } else {
  832. // Perform an UPDATE query
  833. // First checking for Optimistic Locking constraints (if applicable)
  834. // Perform the UPDATE query
  835. $objDatabase->NonQuery('
  836. UPDATE
  837. `content_block`
  838. SET
  839. `name` = ' . $objDatabase->SqlVariable($this->strName) . ',
  840. `cssclass` = ' . $objDatabase->SqlVariable($this->strCssclass) . ',
  841. `title` = ' . $objDatabase->SqlVariable($this->strTitle) . ',
  842. `description` = ' . $objDatabase->SqlVariable($this->strDescription) . ',
  843. `show_title` = ' . $objDatabase->SqlVariable($this->blnShowTitle) . ',
  844. `show_description` = ' . $objDatabase->SqlVariable($this->blnShowDescription) . ',
  845. `collapsable` = ' . $objDatabase->SqlVariable($this->blnCollapsable) . ',
  846. `sort_order` = ' . $objDatabase->SqlVariable($this->intSortOrder) . ',
  847. `parent_content_block_id` = ' . $objDatabase->SqlVariable($this->intParentContentBlockId) . ',
  848. `location_id` = ' . $objDatabase->SqlVariable($this->intLocationId) . '
  849. WHERE
  850. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  851. ');
  852. }
  853. } catch (QCallerException $objExc) {
  854. $objExc->IncrementOffset();
  855. throw $objExc;
  856. }
  857. // Update __blnRestored and any Non-Identity PK Columns (if applicable)
  858. $this->__blnRestored = true;
  859. // Return
  860. return $mixToReturn;
  861. }
  862. /**
  863. * Delete this ContentBlock
  864. * @return void
  865. */
  866. public function Delete() {
  867. if ((is_null($this->intId)))
  868. throw new QUndefinedPrimaryKeyException('Cannot delete this ContentBlock with an unset primary key.');
  869. // Get the Database Object for this Class
  870. $objDatabase = ContentBlock::GetDatabase();
  871. // Perform the SQL Query
  872. $objDatabase->NonQuery('
  873. DELETE FROM
  874. `content_block`
  875. WHERE
  876. `id` = ' . $objDatabase->SqlVariable($this->intId) . '');
  877. }
  878. /**
  879. * Delete all ContentBlocks
  880. * @return void
  881. */
  882. public static function DeleteAll() {
  883. // Get the Database Object for this Class
  884. $objDatabase = ContentBlock::GetDatabase();
  885. // Perform the Query
  886. $objDatabase->NonQuery('
  887. DELETE FROM
  888. `content_block`');
  889. }
  890. /**
  891. * Truncate content_block table
  892. * @return void
  893. */
  894. public static function Truncate() {
  895. // Get the Database Object for this Class
  896. $objDatabase = ContentBlock::GetDatabase();
  897. // Perform the Query
  898. $objDatabase->NonQuery('
  899. TRUNCATE `content_block`');
  900. }
  901. /**
  902. * Reload this ContentBlock from the database.
  903. * @return void
  904. */
  905. public function Reload() {
  906. // Make sure we are actually Restored from the database
  907. if (!$this->__blnRestored)
  908. throw new QCallerException('Cannot call Reload() on a new, unsaved ContentBlock object.');
  909. // Reload the Object
  910. $objReloaded = ContentBlock::Load($this->intId);
  911. // Update $this's local variables to match
  912. $this->strName = $objReloaded->strName;
  913. $this->strCssclass = $objReloaded->strCssclass;
  914. $this->strTitle = $objReloaded->strTitle;
  915. $this->strDescription = $objReloaded->strDescription;
  916. $this->blnShowTitle = $objReloaded->blnShowTitle;
  917. $this->blnShowDescription = $objReloaded->blnShowDescription;
  918. $this->blnCollapsable = $objReloaded->blnCollapsable;
  919. $this->intSortOrder = $objReloaded->intSortOrder;
  920. $this->intParentContentBlockId = $objReloaded->intParentContentBlockId;
  921. $this->intLocationId = $objReloaded->intLocationId;
  922. }
  923. ////////////////////
  924. // GETTORS AND SETTORS
  925. ////////////////////
  926. /**
  927. * Lookup a VirtualAttribute value (if applicable). Returns NULL if none found.
  928. * @param string $strName
  929. * @return string
  930. */
  931. public function GetVirtualAttribute($strName)
  932. {
  933. if (array_key_exists($strName, $this->__strVirtualAttributeArray))
  934. return $this->__strVirtualAttributeArray[$strName];
  935. return null;
  936. }
  937. /**
  938. * Override method to perform a property "Get"
  939. * This will get the value of $strName
  940. *
  941. * @param string $strName Name of the property to get
  942. * @return mixed
  943. */
  944. public function __get($strName)
  945. {
  946. switch ($strName)
  947. {
  948. ///////////////////
  949. // Member Variables
  950. ///////////////////
  951. case 'Id':
  952. /**
  953. * Gets the value for intId (Read-Only PK)
  954. * @return integer
  955. */
  956. return $this->intId;
  957. case 'Name':
  958. /**
  959. * Gets the value for strName (Unique)
  960. * @return string
  961. */
  962. return $this->strName;
  963. case 'Cssclass':
  964. /**
  965. * Gets the value for strCssclass
  966. * @return string
  967. */
  968. return $this->strCssclass;
  969. case 'Title':
  970. /**
  971. * Gets the value for strTitle
  972. * @return string
  973. */
  974. return $this->strTitle;
  975. case 'Description':
  976. /**
  977. * Gets the value for strDescription
  978. * @return string
  979. */
  980. return $this->strDescription;
  981. case 'ShowTitle':
  982. /**
  983. * Gets the value for blnShowTitle (Not Null)
  984. * @return boolean
  985. */
  986. return $this->blnShowTitle;
  987. case 'ShowDescription':
  988. /**
  989. * Gets the value for blnShowDescription (Not Null)
  990. * @return boolean
  991. */
  992. return $this->blnShowDescription;
  993. case 'Collapsable':
  994. /**
  995. * Gets the value for blnCollapsable (Not Null)
  996. * @return boolean
  997. */
  998. return $this->blnCollapsable;
  999. case 'SortOrder':
  1000. /**
  1001. * Gets the value for intSortOrder (Not Null)
  1002. * @return integer
  1003. */
  1004. return $this->intSortOrder;
  1005. case 'ParentContentBlockId':
  1006. /**
  1007. * Gets the value for intParentContentBlockId
  1008. * @return integer
  1009. */
  1010. return $this->intParentContentBlockId;
  1011. case 'LocationId':
  1012. /**
  1013. * Gets the value for intLocationId (Not Null)
  1014. * @return integer
  1015. */
  1016. return $this->intLocationId;
  1017. ///////////////////
  1018. // Member Objects
  1019. ///////////////////
  1020. ////////////////////////////
  1021. // Virtual Object References (Many to Many and Reverse References)
  1022. // (If restored via a "Many-to" expansion)
  1023. ////////////////////////////
  1024. case '_Page':
  1025. /**
  1026. * Gets the value for the private _objPage (Read-Only)
  1027. * if set due to an expansion on the content_block_page_assn association table
  1028. * @return Page
  1029. */
  1030. return $this->_objPage;
  1031. case '_PageArray':
  1032. /**
  1033. * Gets the value for the private _objPageArray (Read-Only)
  1034. * if set due to an ExpandAsArray on the content_block_page_assn association table
  1035. * @return Page[]
  1036. */
  1037. return (array) $this->_objPageArray;
  1038. case '_ContentItem':
  1039. /**
  1040. * Gets the value for the private _objContentItem (Read-Only)
  1041. * if set due to an expansion on the content_item_content_block_assn association table
  1042. * @return ContentItem
  1043. */
  1044. return $this->_objContentItem;
  1045. case '_ContentItemArray':
  1046. /**
  1047. * Gets the value for the private _objContentItemArray (Read-Only)
  1048. * if set due to an ExpandAsArray on the content_item_content_block_assn association table
  1049. * @return ContentItem[]
  1050. */
  1051. return (array) $this->_objContentItemArray;
  1052. case '_Menu':
  1053. /**
  1054. * Gets the value for the private _objMenu (Read-Only)
  1055. * if set due to an expansion on the menu_content_block_assn association table
  1056. * @return Menu
  1057. */
  1058. return $this->_objMenu;
  1059. case '_MenuArray':
  1060. /**
  1061. * Gets the value for the private _objMenuArray (Read-Only)
  1062. * if set due to an ExpandAsArray on the menu_content_block_assn association table
  1063. * @return Menu[]
  1064. */
  1065. return (array) $this->_objMenuArray;
  1066. case '_Module':
  1067. /**
  1068. * Gets the value for the private _objModule (Read-Only)
  1069. * if set due to an expansion on the module.content_block_id reverse relationship
  1070. * @return Module
  1071. */
  1072. return $this->_objModule;
  1073. case '_ModuleArray':
  1074. /**
  1075. * Gets the value for the private _objModuleArray (Read-Only)
  1076. * if set due to an ExpandAsArray on the module.content_block_id reverse relationship
  1077. * @return Module[]
  1078. */
  1079. return (array) $this->_objModuleArray;
  1080. case '__Restored':
  1081. return $this->__blnRestored;
  1082. default:
  1083. try {
  1084. return parent::__get($strName);
  1085. } catch (QCallerException $objExc) {
  1086. $objExc->IncrementOffset();
  1087. throw $objExc;
  1088. }
  1089. }
  1090. }
  1091. /**
  1092. * Override method to perform a property "Set"
  1093. * This will set the property $strName to be $mixValue
  1094. *
  1095. * @param string $strName Name of the property to set
  1096. * @param string $mixValue New value of the property
  1097. * @return mixed
  1098. */
  1099. public function __set($strName, $mixValue) {
  1100. switch ($strName) {
  1101. ///////////////////
  1102. // Member Variables
  1103. ///////////////////
  1104. case 'Name':
  1105. /**
  1106. * Sets the value for strName (Unique)
  1107. * @param string $mixValue
  1108. * @return string
  1109. */
  1110. try {
  1111. return ($this->strName = QType::Cast($mixValue, QType::String));
  1112. } catch (QCallerException $objExc) {
  1113. $objExc->IncrementOffset();
  1114. throw $objExc;
  1115. }
  1116. case 'Cssclass':
  1117. /**
  1118. * Sets the value for strCssclass
  1119. * @param string $mixValue
  1120. * @return string
  1121. */
  1122. try {
  1123. return ($this->strCssclass = QType::Cast($mixValue, QType::String));
  1124. } catch (QCallerException $objExc) {
  1125. $objExc->IncrementOffset();
  1126. throw $objExc;
  1127. }
  1128. case 'Title':
  1129. /**
  1130. * Sets the value for strTitle
  1131. * @param string $mixValue
  1132. * @return string
  1133. */
  1134. try {
  1135. return ($this->strTitle = QType::Cast($mixValue, QType::String));
  1136. } catch (QCallerException $objExc) {
  1137. $objExc->IncrementOffset();
  1138. throw $objExc;
  1139. }
  1140. case 'Description':
  1141. /**
  1142. * Sets the value for strDescription
  1143. * @param string $mixValue
  1144. * @return string
  1145. */
  1146. try {
  1147. return ($this->strDescription = QType::Cast($mixValue, QType::String));
  1148. } catch (QCallerException $objExc) {
  1149. $objExc->IncrementOffset();
  1150. throw $objExc;
  1151. }
  1152. case 'ShowTitle':
  1153. /**
  1154. * Sets the value for blnShowTitle (Not Null)
  1155. * @param boolean $mixValue
  1156. * @return boolean
  1157. */
  1158. try {
  1159. return ($this->blnShowTitle = QType::Cast($mixValue, QType::Boolean));
  1160. } catch (QCallerException $objExc) {
  1161. $objExc->IncrementOffset();
  1162. throw $objExc;
  1163. }
  1164. case 'ShowDescription':
  1165. /**
  1166. * Sets the value for blnShowDescription (Not Null)
  1167. * @param boolean $mixValue
  1168. * @return boolean
  1169. */
  1170. try {
  1171. return ($this->blnShowDescription = QType::Cast($mixValue, QType::Boolean));
  1172. } catch (QCallerException $objExc) {
  1173. $objExc->IncrementOffset();
  1174. throw $objExc;
  1175. }
  1176. case 'Collapsable':
  1177. /**
  1178. * Sets the value for blnCollapsable (Not Null)
  1179. * @param boolean $mixValue
  1180. * @return boolean
  1181. */
  1182. try {
  1183. return ($this->blnCollapsable = QType::Cast($mixValue, QType::Boolean));
  1184. } catch (QCallerException $objExc) {
  1185. $objExc->IncrementOffset();
  1186. throw $objExc;
  1187. }
  1188. case 'SortOrder':
  1189. /**
  1190. * Sets the value for intSortOrder (Not Null)
  1191. * @param integer $mixValue
  1192. * @return integer
  1193. */
  1194. try {
  1195. return ($this->intSortOrder = QType::Cast($mixValue, QType::Integer));
  1196. } catch (QCallerException $objExc) {
  1197. $objExc->IncrementOffset();
  1198. throw $objExc;
  1199. }
  1200. case 'ParentContentBlockId':
  1201. /**
  1202. * Sets the value for intParentContentBlockId
  1203. * @param integer $mixValue
  1204. * @return integer
  1205. */
  1206. try {
  1207. return ($this->intParentContentBlockId = QType::Cast($mixValue, QType::Integer));
  1208. } catch (QCallerException $objExc) {
  1209. $objExc->IncrementOffset();
  1210. throw $objExc;
  1211. }
  1212. case 'LocationId':
  1213. /**
  1214. * Sets the value for intLocationId (Not Null)
  1215. * @param integer $mixValue
  1216. * @return integer
  1217. */
  1218. try {
  1219. return ($this->intLocationId = QType::Cast($mixValue, QType::Integer));
  1220. } catch (QCallerException $objExc) {
  1221. $objExc->IncrementOffset();
  1222. throw $objExc;
  1223. }
  1224. ///////////////////
  1225. // Member Objects
  1226. ///////////////////
  1227. default:
  1228. try {
  1229. return parent::__set($strName, $mixValue);
  1230. } catch (QCallerException $objExc) {
  1231. $objExc->IncrementOffset();
  1232. throw $objExc;
  1233. }
  1234. }
  1235. }
  1236. ///////////////////////////////
  1237. // ASSOCIATED OBJECTS' METHODS
  1238. ///////////////////////////////
  1239. // Related Objects' Methods for Module
  1240. //-------------------------------------------------------------------
  1241. /**
  1242. * Gets all associated Modules as an array of Module objects
  1243. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1244. * @return Module[]
  1245. */
  1246. public function GetModuleArray($objOptionalClauses = null) {
  1247. if ((is_null($this->intId)))
  1248. return array();
  1249. try {
  1250. return Module::LoadArrayByContentBlockId($this->intId, $objOptionalClauses);
  1251. } catch (QCallerException $objExc) {
  1252. $objExc->IncrementOffset();
  1253. throw $objExc;
  1254. }
  1255. }
  1256. /**
  1257. * Counts all associated Modules
  1258. * @return int
  1259. */
  1260. public function CountModules() {
  1261. if ((is_null($this->intId)))
  1262. return 0;
  1263. return Module::CountByContentBlockId($this->intId);
  1264. }
  1265. /**
  1266. * Associates a Module
  1267. * @param Module $objModule
  1268. * @return void
  1269. */
  1270. public function AssociateModule(Module $objModule) {
  1271. if ((is_null($this->intId)))
  1272. throw new QUndefinedPrimaryKeyException('Unable to call AssociateModule on this unsaved ContentBlock.');
  1273. if ((is_null($objModule->Id)))
  1274. throw new QUndefinedPrimaryKeyException('Unable to call AssociateModule on this ContentBlock with an unsaved Module.');
  1275. // Get the Database Object for this Class
  1276. $objDatabase = ContentBlock::GetDatabase();
  1277. // Perform the SQL Query
  1278. $objDatabase->NonQuery('
  1279. UPDATE
  1280. `module`
  1281. SET
  1282. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1283. WHERE
  1284. `id` = ' . $objDatabase->SqlVariable($objModule->Id) . '
  1285. ');
  1286. }
  1287. /**
  1288. * Unassociates a Module
  1289. * @param Module $objModule
  1290. * @return void
  1291. */
  1292. public function UnassociateModule(Module $objModule) {
  1293. if ((is_null($this->intId)))
  1294. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateModule on this unsaved ContentBlock.');
  1295. if ((is_null($objModule->Id)))
  1296. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateModule on this ContentBlock with an unsaved Module.');
  1297. // Get the Database Object for this Class
  1298. $objDatabase = ContentBlock::GetDatabase();
  1299. // Perform the SQL Query
  1300. $objDatabase->NonQuery('
  1301. UPDATE
  1302. `module`
  1303. SET
  1304. `content_block_id` = null
  1305. WHERE
  1306. `id` = ' . $objDatabase->SqlVariable($objModule->Id) . ' AND
  1307. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1308. ');
  1309. }
  1310. /**
  1311. * Unassociates all Modules
  1312. * @return void
  1313. */
  1314. public function UnassociateAllModules() {
  1315. if ((is_null($this->intId)))
  1316. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateModule on this unsaved ContentBlock.');
  1317. // Get the Database Object for this Class
  1318. $objDatabase = ContentBlock::GetDatabase();
  1319. // Perform the SQL Query
  1320. $objDatabase->NonQuery('
  1321. UPDATE
  1322. `module`
  1323. SET
  1324. `content_block_id` = null
  1325. WHERE
  1326. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1327. ');
  1328. }
  1329. /**
  1330. * Deletes an associated Module
  1331. * @param Module $objModule
  1332. * @return void
  1333. */
  1334. public function DeleteAssociatedModule(Module $objModule) {
  1335. if ((is_null($this->intId)))
  1336. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateModule on this unsaved ContentBlock.');
  1337. if ((is_null($objModule->Id)))
  1338. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateModule on this ContentBlock with an unsaved Module.');
  1339. // Get the Database Object for this Class
  1340. $objDatabase = ContentBlock::GetDatabase();
  1341. // Perform the SQL Query
  1342. $objDatabase->NonQuery('
  1343. DELETE FROM
  1344. `module`
  1345. WHERE
  1346. `id` = ' . $objDatabase->SqlVariable($objModule->Id) . ' AND
  1347. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1348. ');
  1349. }
  1350. /**
  1351. * Deletes all associated Modules
  1352. * @return void
  1353. */
  1354. public function DeleteAllModules() {
  1355. if ((is_null($this->intId)))
  1356. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateModule on this unsaved ContentBlock.');
  1357. // Get the Database Object for this Class
  1358. $objDatabase = ContentBlock::GetDatabase();
  1359. // Perform the SQL Query
  1360. $objDatabase->NonQuery('
  1361. DELETE FROM
  1362. `module`
  1363. WHERE
  1364. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1365. ');
  1366. }
  1367. // Related Many-to-Many Objects' Methods for Page
  1368. //-------------------------------------------------------------------
  1369. /**
  1370. * Gets all many-to-many associated Pages as an array of Page objects
  1371. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1372. * @return Page[]
  1373. */
  1374. public function GetPageArray($objOptionalClauses = null) {
  1375. if ((is_null($this->intId)))
  1376. return array();
  1377. try {
  1378. return Page::LoadArrayByContentBlock($this->intId, $objOptionalClauses);
  1379. } catch (QCallerException $objExc) {
  1380. $objExc->IncrementOffset();
  1381. throw $objExc;
  1382. }
  1383. }
  1384. /**
  1385. * Counts all many-to-many associated Pages
  1386. * @return int
  1387. */
  1388. public function CountPages() {
  1389. if ((is_null($this->intId)))
  1390. return 0;
  1391. return Page::CountByContentBlock($this->intId);
  1392. }
  1393. /**
  1394. * Checks to see if an association exists with a specific Page
  1395. * @param Page $objPage
  1396. * @return bool
  1397. */
  1398. public function IsPageAssociated(Page $objPage) {
  1399. if ((is_null($this->intId)))
  1400. throw new QUndefinedPrimaryKeyException('Unable to call IsPageAssociated on this unsaved ContentBlock.');
  1401. if ((is_null($objPage->Id)))
  1402. throw new QUndefinedPrimaryKeyException('Unable to call IsPageAssociated on this ContentBlock with an unsaved Page.');
  1403. $intRowCount = ContentBlock::QueryCount(
  1404. QQ::AndCondition(
  1405. QQ::Equal(QQN::ContentBlock()->Id, $this->intId),
  1406. QQ::Equal(QQN::ContentBlock()->Page->PageId, $objPage->Id)
  1407. )
  1408. );
  1409. return ($intRowCount > 0);
  1410. }
  1411. /**
  1412. * Associates a Page
  1413. * @param Page $objPage
  1414. * @return void
  1415. */
  1416. public function AssociatePage(Page $objPage) {
  1417. if ((is_null($this->intId)))
  1418. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePage on this unsaved ContentBlock.');
  1419. if ((is_null($objPage->Id)))
  1420. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePage on this ContentBlock with an unsaved Page.');
  1421. // Get the Database Object for this Class
  1422. $objDatabase = ContentBlock::GetDatabase();
  1423. // Perform the SQL Query
  1424. $objDatabase->NonQuery('
  1425. INSERT INTO `content_block_page_assn` (
  1426. `content_block_id`,
  1427. `page_id`
  1428. ) VALUES (
  1429. ' . $objDatabase->SqlVariable($this->intId) . ',
  1430. ' . $objDatabase->SqlVariable($objPage->Id) . '
  1431. )
  1432. ');
  1433. }
  1434. /**
  1435. * Unassociates a Page
  1436. * @param Page $objPage
  1437. * @return void
  1438. */
  1439. public function UnassociatePage(Page $objPage) {
  1440. if ((is_null($this->intId)))
  1441. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePage on this unsaved ContentBlock.');
  1442. if ((is_null($objPage->Id)))
  1443. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePage on this ContentBlock with an unsaved Page.');
  1444. // Get the Database Object for this Class
  1445. $objDatabase = ContentBlock::GetDatabase();
  1446. // Perform the SQL Query
  1447. $objDatabase->NonQuery('
  1448. DELETE FROM
  1449. `content_block_page_assn`
  1450. WHERE
  1451. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  1452. `page_id` = ' . $objDatabase->SqlVariable($objPage->Id) . '
  1453. ');
  1454. }
  1455. /**
  1456. * Unassociates all Pages
  1457. * @return void
  1458. */
  1459. public function UnassociateAllPages() {
  1460. if ((is_null($this->intId)))
  1461. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllPageArray on this unsaved ContentBlock.');
  1462. // Get the Database Object for this Class
  1463. $objDatabase = ContentBlock::GetDatabase();
  1464. // Perform the SQL Query
  1465. $objDatabase->NonQuery('
  1466. DELETE FROM
  1467. `content_block_page_assn`
  1468. WHERE
  1469. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1470. ');
  1471. }
  1472. // Related Many-to-Many Objects' Methods for ContentItem
  1473. //-------------------------------------------------------------------
  1474. /**
  1475. * Gets all many-to-many associated ContentItems as an array of ContentItem objects
  1476. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1477. * @return ContentItem[]
  1478. */
  1479. public function GetContentItemArray($objOptionalClauses = null) {
  1480. if ((is_null($this->intId)))
  1481. return array();
  1482. try {
  1483. return ContentItem::LoadArrayByContentBlock($this->intId, $objOptionalClauses);
  1484. } catch (QCallerException $objExc) {
  1485. $objExc->IncrementOffset();
  1486. throw $objExc;
  1487. }
  1488. }
  1489. /**
  1490. * Counts all many-to-many associated ContentItems
  1491. * @return int
  1492. */
  1493. public function CountContentItems() {
  1494. if ((is_null($this->intId)))
  1495. return 0;
  1496. return ContentItem::CountByContentBlock($this->intId);
  1497. }
  1498. /**
  1499. * Checks to see if an association exists with a specific ContentItem
  1500. * @param ContentItem $objContentItem
  1501. * @return bool
  1502. */
  1503. public function IsContentItemAssociated(ContentItem $objContentItem) {
  1504. if ((is_null($this->intId)))
  1505. throw new QUndefinedPrimaryKeyException('Unable to call IsContentItemAssociated on this unsaved ContentBlock.');
  1506. if ((is_null($objContentItem->Id)))
  1507. throw new QUndefinedPrimaryKeyException('Unable to call IsContentItemAssociated on this ContentBlock with an unsaved ContentItem.');
  1508. $intRowCount = ContentBlock::QueryCount(
  1509. QQ::AndCondition(
  1510. QQ::Equal(QQN::ContentBlock()->Id, $this->intId),
  1511. QQ::Equal(QQN::ContentBlock()->ContentItem->ContentItemId, $objContentItem->Id)
  1512. )
  1513. );
  1514. return ($intRowCount > 0);
  1515. }
  1516. /**
  1517. * Associates a ContentItem
  1518. * @param ContentItem $objContentItem
  1519. * @return void
  1520. */
  1521. public function AssociateContentItem(ContentItem $objContentItem) {
  1522. if ((is_null($this->intId)))
  1523. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentItem on this unsaved ContentBlock.');
  1524. if ((is_null($objContentItem->Id)))
  1525. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentItem on this ContentBlock with an unsaved ContentItem.');
  1526. // Get the Database Object for this Class
  1527. $objDatabase = ContentBlock::GetDatabase();
  1528. // Perform the SQL Query
  1529. $objDatabase->NonQuery('
  1530. INSERT INTO `content_item_content_block_assn` (
  1531. `content_block_id`,
  1532. `content_item_id`
  1533. ) VALUES (
  1534. ' . $objDatabase->SqlVariable($this->intId) . ',
  1535. ' . $objDatabase->SqlVariable($objContentItem->Id) . '
  1536. )
  1537. ');
  1538. }
  1539. /**
  1540. * Unassociates a ContentItem
  1541. * @param ContentItem $objContentItem
  1542. * @return void
  1543. */
  1544. public function UnassociateContentItem(ContentItem $objContentItem) {
  1545. if ((is_null($this->intId)))
  1546. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItem on this unsaved ContentBlock.');
  1547. if ((is_null($objContentItem->Id)))
  1548. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItem on this ContentBlock with an unsaved ContentItem.');
  1549. // Get the Database Object for this Class
  1550. $objDatabase = ContentBlock::GetDatabase();
  1551. // Perform the SQL Query
  1552. $objDatabase->NonQuery('
  1553. DELETE FROM
  1554. `content_item_content_block_assn`
  1555. WHERE
  1556. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  1557. `content_item_id` = ' . $objDatabase->SqlVariable($objContentItem->Id) . '
  1558. ');
  1559. }
  1560. /**
  1561. * Unassociates all ContentItems
  1562. * @return void
  1563. */
  1564. public function UnassociateAllContentItems() {
  1565. if ((is_null($this->intId)))
  1566. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllContentItemArray on this unsaved ContentBlock.');
  1567. // Get the Database Object for this Class
  1568. $objDatabase = ContentBlock::GetDatabase();
  1569. // Perform the SQL Query
  1570. $objDatabase->NonQuery('
  1571. DELETE FROM
  1572. `content_item_content_block_assn`
  1573. WHERE
  1574. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1575. ');
  1576. }
  1577. // Related Many-to-Many Objects' Methods for Menu
  1578. //-------------------------------------------------------------------
  1579. /**
  1580. * Gets all many-to-many associated Menus as an array of Menu objects
  1581. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1582. * @return Menu[]
  1583. */
  1584. public function GetMenuArray($objOptionalClauses = null) {
  1585. if ((is_null($this->intId)))
  1586. return array();
  1587. try {
  1588. return Menu::LoadArrayByContentBlock($this->intId, $objOptionalClauses);
  1589. } catch (QCallerException $objExc) {
  1590. $objExc->IncrementOffset();
  1591. throw $objExc;
  1592. }
  1593. }
  1594. /**
  1595. * Counts all many-to-many associated Menus
  1596. * @return int
  1597. */
  1598. public function CountMenus() {
  1599. if ((is_null($this->intId)))
  1600. return 0;
  1601. return Menu::CountByContentBlock($this->intId);
  1602. }
  1603. /**
  1604. * Checks to see if an association exists with a specific Menu
  1605. * @param Menu $objMenu
  1606. * @return bool
  1607. */
  1608. public function IsMenuAssociated(Menu $objMenu) {
  1609. if ((is_null($this->intId)))
  1610. throw new QUndefinedPrimaryKeyException('Unable to call IsMenuAssociated on this unsaved ContentBlock.');
  1611. if ((is_null($objMenu->Id)))
  1612. throw new QUndefinedPrimaryKeyException('Unable to call IsMenuAssociated on this ContentBlock with an unsaved Menu.');
  1613. $intRowCount = ContentBlock::QueryCount(
  1614. QQ::AndCondition(
  1615. QQ::Equal(QQN::ContentBlock()->Id, $this->intId),
  1616. QQ::Equal(QQN::ContentBlock()->Menu->MenuId, $objMenu->Id)
  1617. )
  1618. );
  1619. return ($intRowCount > 0);
  1620. }
  1621. /**
  1622. * Associates a Menu
  1623. * @param Menu $objMenu
  1624. * @return void
  1625. */
  1626. public function AssociateMenu(Menu $objMenu) {
  1627. if ((is_null($this->intId)))
  1628. throw new QUndefinedPrimaryKeyException('Unable to call AssociateMenu on this unsaved ContentBlock.');
  1629. if ((is_null($objMenu->Id)))
  1630. throw new QUndefinedPrimaryKeyException('Unable to call AssociateMenu on this ContentBlock with an unsaved Menu.');
  1631. // Get the Database Object for this Class
  1632. $objDatabase = ContentBlock::GetDatabase();
  1633. // Perform the SQL Query
  1634. $objDatabase->NonQuery('
  1635. INSERT INTO `menu_content_block_assn` (
  1636. `content_block_id`,
  1637. `menu_id`
  1638. ) VALUES (
  1639. ' . $objDatabase->SqlVariable($this->intId) . ',
  1640. ' . $objDatabase->SqlVariable($objMenu->Id) . '
  1641. )
  1642. ');
  1643. }
  1644. /**
  1645. * Unassociates a Menu
  1646. * @param Menu $objMenu
  1647. * @return void
  1648. */
  1649. public function UnassociateMenu(Menu $objMenu) {
  1650. if ((is_null($this->intId)))
  1651. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateMenu on this unsaved ContentBlock.');
  1652. if ((is_null($objMenu->Id)))
  1653. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateMenu on this ContentBlock with an unsaved Menu.');
  1654. // Get the Database Object for this Class
  1655. $objDatabase = ContentBlock::GetDatabase();
  1656. // Perform the SQL Query
  1657. $objDatabase->NonQuery('
  1658. DELETE FROM
  1659. `menu_content_block_assn`
  1660. WHERE
  1661. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  1662. `menu_id` = ' . $objDatabase->SqlVariable($objMenu->Id) . '
  1663. ');
  1664. }
  1665. /**
  1666. * Unassociates all Menus
  1667. * @return void
  1668. */
  1669. public function UnassociateAllMenus() {
  1670. if ((is_null($this->intId)))
  1671. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllMenuArray on this unsaved ContentBlock.');
  1672. // Get the Database Object for this Class
  1673. $objDatabase = ContentBlock::GetDatabase();
  1674. // Perform the SQL Query
  1675. $objDatabase->NonQuery('
  1676. DELETE FROM
  1677. `menu_content_block_assn`
  1678. WHERE
  1679. `content_block_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1680. ');
  1681. }
  1682. }
  1683. /////////////////////////////////////
  1684. // ADDITIONAL CLASSES for QCODO QUERY
  1685. /////////////////////////////////////
  1686. class QQNodeContentBlockPage extends QQAssociationNode {
  1687. protected $strType = 'association';
  1688. protected $strName = 'page';
  1689. protected $strTableName = 'content_block_page_assn';
  1690. protected $strPrimaryKey = 'content_block_id';
  1691. protected $strClassName = 'Page';
  1692. public function __get($strName) {
  1693. switch ($strName) {
  1694. case 'PageId':
  1695. return new QQNode('page_id', 'PageId', 'integer', $this);
  1696. case 'Page':
  1697. return new QQNodePage('page_id', 'PageId', 'integer', $this);
  1698. case '_ChildTableNode':
  1699. return new QQNodePage('page_id', 'PageId', 'integer', $this);
  1700. default:
  1701. try {
  1702. return parent::__get($strName);
  1703. } catch (QCallerException $objExc) {
  1704. $objExc->IncrementOffset();
  1705. throw $objExc;
  1706. }
  1707. }
  1708. }
  1709. }
  1710. class QQNodeContentBlockContentItem extends QQAssociationNode {
  1711. protected $strType = 'association';
  1712. protected $strName = 'contentitem';
  1713. protected $strTableName = 'content_item_content_block_assn';
  1714. protected $strPrimaryKey = 'content_block_id';
  1715. protected $strClassName = 'ContentItem';
  1716. public function __get($strName) {
  1717. switch ($strName) {
  1718. case 'ContentItemId':
  1719. return new QQNode('content_item_id', 'ContentItemId', 'integer', $this);
  1720. case 'ContentItem':
  1721. return new QQNodeContentItem('content_item_id', 'ContentItemId', 'integer', $this);
  1722. case '_ChildTableNode':
  1723. return new QQNodeContentItem('content_item_id', 'ContentItemId', 'integer', $this);
  1724. default:
  1725. try {
  1726. return parent::__get($strName);
  1727. } catch (QCallerException $objExc) {
  1728. $objExc->IncrementOffset();
  1729. throw $objExc;
  1730. }
  1731. }
  1732. }
  1733. }
  1734. class QQNodeContentBlockMenu extends QQAssociationNode {
  1735. protected $strType = 'association';
  1736. protected $strName = 'menu';
  1737. protected $strTableName = 'menu_content_block_assn';
  1738. protected $strPrimaryKey = 'content_block_id';
  1739. protected $strClassName = 'Menu';
  1740. public function __get($strName) {
  1741. switch ($strName) {
  1742. case 'MenuId':
  1743. return new QQNode('menu_id', 'MenuId', 'integer', $this);
  1744. case 'Menu':
  1745. return new QQNodeMenu('menu_id', 'MenuId', 'integer', $this);
  1746. case '_ChildTableNode':
  1747. return new QQNodeMenu('menu_id', 'MenuId', 'integer', $this);
  1748. default:
  1749. try {
  1750. return parent::__get($strName);
  1751. } catch (QCallerException $objExc) {
  1752. $objExc->IncrementOffset();
  1753. throw $objExc;
  1754. }
  1755. }
  1756. }
  1757. }
  1758. class QQNodeContentBlock extends QQNode {
  1759. protected $strTableName = 'content_block';
  1760. protected $strPrimaryKey = 'id';
  1761. protected $strClassName = 'ContentBlock';
  1762. public function __get($strName) {
  1763. switch ($strName) {
  1764. case 'Id':
  1765. return new QQNode('id', 'Id', 'integer', $this);
  1766. case 'Name':
  1767. return new QQNode('name', 'Name', 'string', $this);
  1768. case 'Cssclass':
  1769. return new QQNode('cssclass', 'Cssclass', 'string', $this);
  1770. case 'Title':
  1771. return new QQNode('title', 'Title', 'string', $this);
  1772. case 'Description':
  1773. return new QQNode('description', 'Description', 'string', $this);
  1774. case 'ShowTitle':
  1775. return new QQNode('show_title', 'ShowTitle', 'boolean', $this);
  1776. case 'ShowDescription':
  1777. return new QQNode('show_description', 'ShowDescription', 'boolean', $this);
  1778. case 'Collapsable':
  1779. return new QQNode('collapsable', 'Collapsable', 'boolean', $this);
  1780. case 'SortOrder':
  1781. return new QQNode('sort_order', 'SortOrder', 'integer', $this);
  1782. case 'ParentContentBlockId':
  1783. return new QQNode('parent_content_block_id', 'ParentContentBlockId', 'integer', $this);
  1784. case 'LocationId':
  1785. return new QQNode('location_id', 'LocationId', 'integer', $this);
  1786. case 'Page':
  1787. return new QQNodeContentBlockPage($this);
  1788. case 'ContentItem':
  1789. return new QQNodeContentBlockContentItem($this);
  1790. case 'Menu':
  1791. return new QQNodeContentBlockMenu($this);
  1792. case 'Module':
  1793. return new QQReverseReferenceNodeModule($this, 'module', 'reverse_reference', 'content_block_id');
  1794. case '_PrimaryKeyNode':
  1795. return new QQNode('id', 'Id', 'integer', $this);
  1796. default:
  1797. try {
  1798. return parent::__get($strName);
  1799. } catch (QCallerException $objExc) {
  1800. $objExc->IncrementOffset();
  1801. throw $objExc;
  1802. }
  1803. }
  1804. }
  1805. }
  1806. class QQReverseReferenceNodeContentBlock extends QQReverseReferenceNode {
  1807. protected $strTableName = 'content_block';
  1808. protected $strPrimaryKey = 'id';
  1809. protected $strClassName = 'ContentBlock';
  1810. public function __get($strName) {
  1811. switch ($strName) {
  1812. case 'Id':
  1813. return new QQNode('id', 'Id', 'integer', $this);
  1814. case 'Name':
  1815. return new QQNode('name', 'Name', 'string', $this);
  1816. case 'Cssclass':
  1817. return new QQNode('cssclass', 'Cssclass', 'string', $this);
  1818. case 'Title':
  1819. return new QQNode('title', 'Title', 'string', $this);
  1820. case 'Description':
  1821. return new QQNode('description', 'Description', 'string', $this);
  1822. case 'ShowTitle':
  1823. return new QQNode('show_title', 'ShowTitle', 'boolean', $this);
  1824. case 'ShowDescription':
  1825. return new QQNode('show_description', 'ShowDescription', 'boolean', $this);
  1826. case 'Collapsable':
  1827. return new QQNode('collapsable', 'Collapsable', 'boolean', $this);
  1828. case 'SortOrder':
  1829. return new QQNode('sort_order', 'SortOrder', 'integer', $this);
  1830. case 'ParentContentBlockId':
  1831. return new QQNode('parent_content_block_id', 'ParentContentBlockId', 'integer', $this);
  1832. case 'LocationId':
  1833. return new QQNode('location_id', 'LocationId', 'integer', $this);
  1834. case 'Page':
  1835. return new QQNodeContentBlockPage($this);
  1836. case 'ContentItem':
  1837. return new QQNodeContentBlockContentItem($this);
  1838. case 'Menu':
  1839. return new QQNodeContentBlockMenu($this);
  1840. case 'Module':
  1841. return new QQReverseReferenceNodeModule($this, 'module', 'reverse_reference', 'content_block_id');
  1842. case '_PrimaryKeyNode':
  1843. return new QQNode('id', 'Id', 'integer', $this);
  1844. default:
  1845. try {
  1846. return parent::__get($strName);
  1847. } catch (QCallerException $objExc) {
  1848. $objExc->IncrementOffset();
  1849. throw $objExc;
  1850. }
  1851. }
  1852. }
  1853. }
  1854. ?>