/includes/data_classes/generated/ContentItemGen.class.php

https://github.com/quinta/quintacms · PHP · 997 lines · 411 code · 122 blank · 464 comment · 54 complexity · 941d616a186035804b55cb75acfd4c53 MD5 · raw file

  1. <?php
  2. /**
  3. * The abstract ContentItemGen 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 ContentItem subclass which
  8. * extends this ContentItemGen 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 ContentItem class.
  15. *
  16. * @package Quinta CMS
  17. * @subpackage GeneratedDataObjects
  18. * @property-read integer $Id the value for intId (Read-Only PK)
  19. * @property string $Name the value for strName (Unique)
  20. * @property string $Cssclass the value for strCssclass
  21. * @property string $Title the value for strTitle
  22. * @property string $Description the value for strDescription
  23. * @property string $Text the value for strText
  24. * @property integer $SortOrder the value for intSortOrder
  25. * @property boolean $ShowTitle the value for blnShowTitle (Not Null)
  26. * @property boolean $ShowDescription the value for blnShowDescription (Not Null)
  27. * @property boolean $ShowCreator the value for blnShowCreator (Not Null)
  28. * @property boolean $ShowCreationDate the value for blnShowCreationDate (Not Null)
  29. * @property boolean $ShowLastModification the value for blnShowLastModification (Not Null)
  30. * @property integer $CreatorId the value for intCreatorId
  31. * @property string $CopyrightNotice the value for strCopyrightNotice
  32. * @property-read string $CreationDate the value for strCreationDate (Read-Only Timestamp)
  33. * @property-read string $LastModification the value for strLastModification (Read-Only Timestamp)
  34. * @property integer $TypeId the value for intTypeId (Not Null)
  35. * @property integer $StatusId the value for intStatusId (Not Null)
  36. * @property Person $Creator the value for the Person object referenced by intCreatorId
  37. * @property-read ContentBlock $_ContentBlock the value for the private _objContentBlock (Read-Only) if set due to an expansion on the content_item_content_block_assn association table
  38. * @property-read ContentBlock[] $_ContentBlockArray the value for the private _objContentBlockArray (Read-Only) if set due to an ExpandAsArray on the content_item_content_block_assn association table
  39. * @property-read ContentCategory $_ContentCategory the value for the private _objContentCategory (Read-Only) if set due to an expansion on the content_item_content_category_assn association table
  40. * @property-read ContentCategory[] $_ContentCategoryArray the value for the private _objContentCategoryArray (Read-Only) if set due to an ExpandAsArray on the content_item_content_category_assn association table
  41. * @property-read Usergroup $_Usergroup the value for the private _objUsergroup (Read-Only) if set due to an expansion on the content_item_usergroup_assn association table
  42. * @property-read Usergroup[] $_UsergroupArray the value for the private _objUsergroupArray (Read-Only) if set due to an ExpandAsArray on the content_item_usergroup_assn association table
  43. * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
  44. */
  45. class ContentItemGen extends QBaseClass
  46. {
  47. ///////////////////////////////////////////////////////////////////////
  48. // PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
  49. ///////////////////////////////////////////////////////////////////////
  50. /////////// Object properties ////////////
  51. /**
  52. * Protected member variable that maps to the database PK Identity column content_item.id
  53. * @var integer intId
  54. *
  55. */
  56. protected $intId = null;
  57. /**
  58. * Protected member variable that maps to the database column content_item.name
  59. * @var string strName
  60. *
  61. */
  62. protected $strName = null;
  63. const NameMaxLength = 128;
  64. /**
  65. * Protected member variable that maps to the database column content_item.cssclass
  66. * @var string strCssclass
  67. *
  68. */
  69. protected $strCssclass = null;
  70. const CssclassMaxLength = 128;
  71. /**
  72. * Protected member variable that maps to the database column content_item.title
  73. * @var string strTitle
  74. *
  75. */
  76. protected $strTitle = null;
  77. const TitleMaxLength = 128;
  78. /**
  79. * Protected member variable that maps to the database column content_item.description
  80. * @var string strDescription
  81. *
  82. */
  83. protected $strDescription = null;
  84. const DescriptionMaxLength = 256;
  85. /**
  86. * Protected member variable that maps to the database column content_item.text
  87. * @var string strText
  88. *
  89. */
  90. protected $strText = null;
  91. /**
  92. * Protected member variable that maps to the database column content_item.sort_order
  93. * @var integer intSortOrder
  94. *
  95. */
  96. protected $intSortOrder = null;
  97. /**
  98. * Protected member variable that maps to the database column content_item.show_title
  99. * @var boolean blnShowTitle
  100. *
  101. */
  102. protected $blnShowTitle = null;
  103. /**
  104. * Protected member variable that maps to the database column content_item.show_description
  105. * @var boolean blnShowDescription
  106. *
  107. */
  108. protected $blnShowDescription = null;
  109. /**
  110. * Protected member variable that maps to the database column content_item.show_creator
  111. * @var boolean blnShowCreator
  112. *
  113. */
  114. protected $blnShowCreator = null;
  115. /**
  116. * Protected member variable that maps to the database column content_item.show_creation_date
  117. * @var boolean blnShowCreationDate
  118. *
  119. */
  120. protected $blnShowCreationDate = null;
  121. /**
  122. * Protected member variable that maps to the database column content_item.show_last_modification
  123. * @var boolean blnShowLastModification
  124. *
  125. */
  126. protected $blnShowLastModification = null;
  127. /**
  128. * Protected member variable that maps to the database column content_item.creator_id
  129. * @var integer intCreatorId
  130. *
  131. */
  132. protected $intCreatorId = null;
  133. /**
  134. * Protected member variable that maps to the database column content_item.copyright_notice
  135. * @var string strCopyrightNotice
  136. *
  137. */
  138. protected $strCopyrightNotice = null;
  139. const CopyrightNoticeMaxLength = 256;
  140. /**
  141. * Protected member variable that maps to the database column content_item.creation_date
  142. * @var string strCreationDate
  143. *
  144. */
  145. protected $strCreationDate = null;
  146. /**
  147. * Protected member variable that maps to the database column content_item.last_modification
  148. * @var string strLastModification
  149. *
  150. */
  151. protected $strLastModification = null;
  152. /**
  153. * Protected member variable that maps to the database column content_item.type_id
  154. * @var integer intTypeId
  155. *
  156. */
  157. protected $intTypeId = null;
  158. /**
  159. * Protected member variable that maps to the database column content_item.status_id
  160. * @var integer intStatusId
  161. *
  162. */
  163. protected $intStatusId = null;
  164. /**
  165. * Private member variable that stores a reference to a single ContentBlock object
  166. * (of type ContentBlock), if this ContentItem object was restored with
  167. * an expansion on the content_item_content_block_assn association table.
  168. * @var ContentBlock _objContentBlock;
  169. */
  170. private $_objContentBlock;
  171. /**
  172. * Private member variable that stores a reference to an array of ContentBlock objects
  173. * (of type ContentBlock[]), if this ContentItem object was restored with
  174. * an ExpandAsArray on the content_item_content_block_assn association table.
  175. * @var ContentBlock[] _objContentBlockArray;
  176. */
  177. private $_objContentBlockArray = array();
  178. /**
  179. * Private member variable that stores a reference to a single ContentCategory object
  180. * (of type ContentCategory), if this ContentItem object was restored with
  181. * an expansion on the content_item_content_category_assn association table.
  182. * @var ContentCategory _objContentCategory;
  183. */
  184. private $_objContentCategory;
  185. /**
  186. * Private member variable that stores a reference to an array of ContentCategory objects
  187. * (of type ContentCategory[]), if this ContentItem object was restored with
  188. * an ExpandAsArray on the content_item_content_category_assn association table.
  189. * @var ContentCategory[] _objContentCategoryArray;
  190. */
  191. private $_objContentCategoryArray = array();
  192. /**
  193. * Private member variable that stores a reference to a single Usergroup object
  194. * (of type Usergroup), if this ContentItem object was restored with
  195. * an expansion on the content_item_usergroup_assn association table.
  196. * @var Usergroup _objUsergroup;
  197. */
  198. private $_objUsergroup;
  199. /**
  200. * Private member variable that stores a reference to an array of Usergroup objects
  201. * (of type Usergroup[]), if this ContentItem object was restored with
  202. * an ExpandAsArray on the content_item_usergroup_assn association table.
  203. * @var Usergroup[] _objUsergroupArray;
  204. */
  205. private $_objUsergroupArray = array();
  206. /**
  207. * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
  208. * columns from the run-time database query result for this object). Used by InstantiateDbRow and
  209. * GetVirtualAttribute.
  210. * @var string[] $__strVirtualAttributeArray
  211. */
  212. protected $__strVirtualAttributeArray = array();
  213. /**
  214. * Protected internal member variable that specifies whether or not this object is Restored from the database.
  215. * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
  216. * @var bool __blnRestored;
  217. */
  218. protected $__blnRestored;
  219. ///////////////////////////////
  220. // PROTECTED MEMBER OBJECTS
  221. ///////////////////////////////
  222. /**
  223. * Protected member variable that contains the object pointed by the reference
  224. * in the database column content_item.creator_id.
  225. *
  226. * NOTE: Always use the Creator property getter to correctly retrieve this Person object.
  227. * (Because this class implements late binding, this variable reference MAY be null.)
  228. * @var Person objCreator
  229. */
  230. protected $objCreator;
  231. ///////////////////////////////
  232. // CLASS-WIDE LOAD AND COUNT METHODS
  233. ///////////////////////////////
  234. /**
  235. * Static method to retrieve the Database object that owns this class.
  236. * @return QDatabaseBase reference to the Database object that can query this class
  237. */
  238. public static function GetDatabase() {
  239. return QApplication::$Database[1];
  240. }
  241. /**
  242. * Load a ContentItem from PK Info
  243. * @param integer $intId
  244. * @return ContentItem
  245. */
  246. public static function Load($intId) {
  247. // Use QuerySingle to Perform the Query
  248. return ContentItem::QuerySingle(
  249. QQ::Equal(QQN::ContentItem()->Id, $intId)
  250. );
  251. }
  252. /**
  253. * Load all ContentItems
  254. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  255. * @return ContentItem[]
  256. */
  257. public static function LoadAll($objOptionalClauses = null) {
  258. // Call ContentItem::QueryArray to perform the LoadAll query
  259. try {
  260. return ContentItem::QueryArray(QQ::All(), $objOptionalClauses);
  261. } catch (QCallerException $objExc) {
  262. $objExc->IncrementOffset();
  263. throw $objExc;
  264. }
  265. }
  266. /**
  267. * Count all ContentItems
  268. * @return int
  269. */
  270. public static function CountAll() {
  271. // Call ContentItem::QueryCount to perform the CountAll query
  272. return ContentItem::QueryCount(QQ::All());
  273. }
  274. ///////////////////////////////
  275. // QCODO QUERY-RELATED METHODS
  276. ///////////////////////////////
  277. /**
  278. * Internally called method to assist with calling Qcodo Query for this class
  279. * on load methods.
  280. * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
  281. * @param QQCondition $objConditions any conditions on the query, itself
  282. * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
  283. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
  284. * @param boolean $blnCountOnly only select a rowcount
  285. * @return string the query statement
  286. */
  287. protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
  288. // Get the Database Object for this Class
  289. $objDatabase = ContentItem::GetDatabase();
  290. // Create/Build out the QueryBuilder object with ContentItem-specific SELET and FROM fields
  291. $objQueryBuilder = new QQueryBuilder($objDatabase, 'content_item');
  292. ContentItem::GetSelectFields($objQueryBuilder);
  293. $objQueryBuilder->AddFromItem('content_item');
  294. // Set "CountOnly" option (if applicable)
  295. if ($blnCountOnly)
  296. $objQueryBuilder->SetCountOnlyFlag();
  297. // Apply Any Conditions
  298. if ($objConditions)
  299. try {
  300. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  301. } catch (QCallerException $objExc) {
  302. $objExc->IncrementOffset();
  303. throw $objExc;
  304. }
  305. // Iterate through all the Optional Clauses (if any) and perform accordingly
  306. if ($objOptionalClauses) {
  307. if ($objOptionalClauses instanceof QQClause)
  308. $objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
  309. else if (is_array($objOptionalClauses))
  310. foreach ($objOptionalClauses as $objClause)
  311. $objClause->UpdateQueryBuilder($objQueryBuilder);
  312. else
  313. throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
  314. }
  315. // Get the SQL Statement
  316. $strQuery = $objQueryBuilder->GetStatement();
  317. // Prepare the Statement with the Query Parameters (if applicable)
  318. if ($mixParameterArray) {
  319. if (is_array($mixParameterArray)) {
  320. if (count($mixParameterArray))
  321. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  322. // Ensure that there are no other Unresolved Named Parameters
  323. if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
  324. throw new QCallerException('Unresolved named parameters in the query');
  325. } else
  326. throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
  327. }
  328. // Return the Objects
  329. return $strQuery;
  330. }
  331. /**
  332. * Static Qcodo Query method to query for a single ContentItem object.
  333. * Uses BuildQueryStatment to perform most of the work.
  334. * @param QQCondition $objConditions any conditions on the query, itself
  335. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  336. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  337. * @return ContentItem the queried object
  338. */
  339. public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  340. // Get the Query Statement
  341. try {
  342. $strQuery = ContentItem::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  343. } catch (QCallerException $objExc) {
  344. $objExc->IncrementOffset();
  345. throw $objExc;
  346. }
  347. // Perform the Query, Get the First Row, and Instantiate a new ContentItem object
  348. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  349. return ContentItem::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray);
  350. }
  351. /**
  352. * Static Qcodo Query method to query for an array of ContentItem objects.
  353. * Uses BuildQueryStatment to perform most of the work.
  354. * @param QQCondition $objConditions any conditions on the query, itself
  355. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  356. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  357. * @return ContentItem[] the queried objects as an array
  358. */
  359. public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  360. // Get the Query Statement
  361. try {
  362. $strQuery = ContentItem::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  363. } catch (QCallerException $objExc) {
  364. $objExc->IncrementOffset();
  365. throw $objExc;
  366. }
  367. // Perform the Query and Instantiate the Array Result
  368. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  369. return ContentItem::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
  370. }
  371. /**
  372. * Static Qcodo Query method to query for a count of ContentItem objects.
  373. * Uses BuildQueryStatment to perform most of the work.
  374. * @param QQCondition $objConditions any conditions on the query, itself
  375. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  376. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  377. * @return integer the count of queried objects as an integer
  378. */
  379. public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  380. // Get the Query Statement
  381. try {
  382. $strQuery = ContentItem::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
  383. } catch (QCallerException $objExc) {
  384. $objExc->IncrementOffset();
  385. throw $objExc;
  386. }
  387. // Perform the Query and return the row_count
  388. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  389. // Figure out if the query is using GroupBy
  390. $blnGrouped = false;
  391. if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
  392. if ($objClause instanceof QQGroupBy) {
  393. $blnGrouped = true;
  394. break;
  395. }
  396. }
  397. if ($blnGrouped)
  398. // Groups in this query - return the count of Groups (which is the count of all rows)
  399. return $objDbResult->CountRows();
  400. else {
  401. // No Groups - return the sql-calculated count(*) value
  402. $strDbRow = $objDbResult->FetchRow();
  403. return QType::Cast($strDbRow[0], QType::Integer);
  404. }
  405. }
  406. /* public static function QueryArrayCached($strConditions, $mixParameterArray = null) {
  407. // Get the Database Object for this Class
  408. $objDatabase = ContentItem::GetDatabase();
  409. // Lookup the QCache for This Query Statement
  410. $objCache = new QCache('query', 'content_item_' . serialize($strConditions));
  411. if (!($strQuery = $objCache->GetData())) {
  412. // Not Found -- Go ahead and Create/Build out a new QueryBuilder object with ContentItem-specific fields
  413. $objQueryBuilder = new QQueryBuilder($objDatabase);
  414. ContentItem::GetSelectFields($objQueryBuilder);
  415. ContentItem::GetFromFields($objQueryBuilder);
  416. // Ensure the Passed-in Conditions is a string
  417. try {
  418. $strConditions = QType::Cast($strConditions, QType::String);
  419. } catch (QCallerException $objExc) {
  420. $objExc->IncrementOffset();
  421. throw $objExc;
  422. }
  423. // Create the Conditions object, and apply it
  424. $objConditions = eval('return ' . $strConditions . ';');
  425. // Apply Any Conditions
  426. if ($objConditions)
  427. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  428. // Get the SQL Statement
  429. $strQuery = $objQueryBuilder->GetStatement();
  430. // Save the SQL Statement in the Cache
  431. $objCache->SaveData($strQuery);
  432. }
  433. // Prepare the Statement with the Parameters
  434. if ($mixParameterArray)
  435. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  436. // Perform the Query and Instantiate the Array Result
  437. $objDbResult = $objDatabase->Query($strQuery);
  438. return ContentItem::InstantiateDbResult($objDbResult);
  439. }*/
  440. /**
  441. * Updates a QQueryBuilder with the SELECT fields for this ContentItem
  442. * @param QQueryBuilder $objBuilder the Query Builder object to update
  443. * @param string $strPrefix optional prefix to add to the SELECT fields
  444. */
  445. public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
  446. if ($strPrefix) {
  447. $strTableName = $strPrefix;
  448. $strAliasPrefix = $strPrefix . '__';
  449. } else {
  450. $strTableName = 'content_item';
  451. $strAliasPrefix = '';
  452. }
  453. $objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
  454. $objBuilder->AddSelectItem($strTableName, 'name', $strAliasPrefix . 'name');
  455. $objBuilder->AddSelectItem($strTableName, 'cssclass', $strAliasPrefix . 'cssclass');
  456. $objBuilder->AddSelectItem($strTableName, 'title', $strAliasPrefix . 'title');
  457. $objBuilder->AddSelectItem($strTableName, 'description', $strAliasPrefix . 'description');
  458. $objBuilder->AddSelectItem($strTableName, 'text', $strAliasPrefix . 'text');
  459. $objBuilder->AddSelectItem($strTableName, 'sort_order', $strAliasPrefix . 'sort_order');
  460. $objBuilder->AddSelectItem($strTableName, 'show_title', $strAliasPrefix . 'show_title');
  461. $objBuilder->AddSelectItem($strTableName, 'show_description', $strAliasPrefix . 'show_description');
  462. $objBuilder->AddSelectItem($strTableName, 'show_creator', $strAliasPrefix . 'show_creator');
  463. $objBuilder->AddSelectItem($strTableName, 'show_creation_date', $strAliasPrefix . 'show_creation_date');
  464. $objBuilder->AddSelectItem($strTableName, 'show_last_modification', $strAliasPrefix . 'show_last_modification');
  465. $objBuilder->AddSelectItem($strTableName, 'creator_id', $strAliasPrefix . 'creator_id');
  466. $objBuilder->AddSelectItem($strTableName, 'copyright_notice', $strAliasPrefix . 'copyright_notice');
  467. $objBuilder->AddSelectItem($strTableName, 'creation_date', $strAliasPrefix . 'creation_date');
  468. $objBuilder->AddSelectItem($strTableName, 'last_modification', $strAliasPrefix . 'last_modification');
  469. $objBuilder->AddSelectItem($strTableName, 'type_id', $strAliasPrefix . 'type_id');
  470. $objBuilder->AddSelectItem($strTableName, 'status_id', $strAliasPrefix . 'status_id');
  471. }
  472. ///////////////////////////////
  473. // INSTANTIATION-RELATED METHODS
  474. ///////////////////////////////
  475. /**
  476. * Instantiate a ContentItem from a Database Row.
  477. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  478. * is calling this ContentItem::InstantiateDbRow in order to perform
  479. * early binding on referenced objects.
  480. * @param DatabaseRowBase $objDbRow
  481. * @param string $strAliasPrefix
  482. * @param string $strExpandAsArrayNodes
  483. * @param QBaseClass $objPreviousItem
  484. * @param string[] $strColumnAliasArray
  485. * @return ContentItem
  486. */
  487. public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $objPreviousItem = null, $strColumnAliasArray = array()) {
  488. // If blank row, return null
  489. if (!$objDbRow)
  490. return null;
  491. // See if we're doing an array expansion on the previous item
  492. $strAlias = $strAliasPrefix . 'id';
  493. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  494. if (($strExpandAsArrayNodes) && ($objPreviousItem) &&
  495. ($objPreviousItem->intId == $objDbRow->GetColumn($strAliasName, 'Integer'))) {
  496. // We are. Now, prepare to check for ExpandAsArray clauses
  497. $blnExpandedViaArray = false;
  498. if (!$strAliasPrefix)
  499. $strAliasPrefix = 'content_item__';
  500. $strAlias = $strAliasPrefix . 'contentblock__content_block_id__id';
  501. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  502. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  503. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  504. if ($intPreviousChildItemCount = count($objPreviousItem->_objContentBlockArray)) {
  505. $objPreviousChildItem = $objPreviousItem->_objContentBlockArray[$intPreviousChildItemCount - 1];
  506. $objChildItem = ContentBlock::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentblock__content_block_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  507. if ($objChildItem)
  508. $objPreviousItem->_objContentBlockArray[] = $objChildItem;
  509. } else
  510. $objPreviousItem->_objContentBlockArray[] = ContentBlock::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentblock__content_block_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  511. $blnExpandedViaArray = true;
  512. }
  513. $strAlias = $strAliasPrefix . 'contentcategory__content_category_id__id';
  514. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  515. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  516. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  517. if ($intPreviousChildItemCount = count($objPreviousItem->_objContentCategoryArray)) {
  518. $objPreviousChildItem = $objPreviousItem->_objContentCategoryArray[$intPreviousChildItemCount - 1];
  519. $objChildItem = ContentCategory::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentcategory__content_category_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  520. if ($objChildItem)
  521. $objPreviousItem->_objContentCategoryArray[] = $objChildItem;
  522. } else
  523. $objPreviousItem->_objContentCategoryArray[] = ContentCategory::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentcategory__content_category_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  524. $blnExpandedViaArray = true;
  525. }
  526. $strAlias = $strAliasPrefix . 'usergroup__usergroup_id__id';
  527. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  528. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  529. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  530. if ($intPreviousChildItemCount = count($objPreviousItem->_objUsergroupArray)) {
  531. $objPreviousChildItem = $objPreviousItem->_objUsergroupArray[$intPreviousChildItemCount - 1];
  532. $objChildItem = Usergroup::InstantiateDbRow($objDbRow, $strAliasPrefix . 'usergroup__usergroup_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  533. if ($objChildItem)
  534. $objPreviousItem->_objUsergroupArray[] = $objChildItem;
  535. } else
  536. $objPreviousItem->_objUsergroupArray[] = Usergroup::InstantiateDbRow($objDbRow, $strAliasPrefix . 'usergroup__usergroup_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  537. $blnExpandedViaArray = true;
  538. }
  539. // Either return false to signal array expansion, or check-to-reset the Alias prefix and move on
  540. if ($blnExpandedViaArray)
  541. return false;
  542. else if ($strAliasPrefix == 'content_item__')
  543. $strAliasPrefix = null;
  544. }
  545. // Create a new instance of the ContentItem object
  546. $objToReturn = new ContentItem();
  547. $objToReturn->__blnRestored = true;
  548. $strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
  549. $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
  550. $strAliasName = array_key_exists($strAliasPrefix . 'name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'name'] : $strAliasPrefix . 'name';
  551. $objToReturn->strName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  552. $strAliasName = array_key_exists($strAliasPrefix . 'cssclass', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'cssclass'] : $strAliasPrefix . 'cssclass';
  553. $objToReturn->strCssclass = $objDbRow->GetColumn($strAliasName, 'VarChar');
  554. $strAliasName = array_key_exists($strAliasPrefix . 'title', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'title'] : $strAliasPrefix . 'title';
  555. $objToReturn->strTitle = $objDbRow->GetColumn($strAliasName, 'VarChar');
  556. $strAliasName = array_key_exists($strAliasPrefix . 'description', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'description'] : $strAliasPrefix . 'description';
  557. $objToReturn->strDescription = $objDbRow->GetColumn($strAliasName, 'VarChar');
  558. $strAliasName = array_key_exists($strAliasPrefix . 'text', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'text'] : $strAliasPrefix . 'text';
  559. $objToReturn->strText = $objDbRow->GetColumn($strAliasName, 'Blob');
  560. $strAliasName = array_key_exists($strAliasPrefix . 'sort_order', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'sort_order'] : $strAliasPrefix . 'sort_order';
  561. $objToReturn->intSortOrder = $objDbRow->GetColumn($strAliasName, 'Integer');
  562. $strAliasName = array_key_exists($strAliasPrefix . 'show_title', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'show_title'] : $strAliasPrefix . 'show_title';
  563. $objToReturn->blnShowTitle = $objDbRow->GetColumn($strAliasName, 'Bit');
  564. $strAliasName = array_key_exists($strAliasPrefix . 'show_description', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'show_description'] : $strAliasPrefix . 'show_description';
  565. $objToReturn->blnShowDescription = $objDbRow->GetColumn($strAliasName, 'Bit');
  566. $strAliasName = array_key_exists($strAliasPrefix . 'show_creator', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'show_creator'] : $strAliasPrefix . 'show_creator';
  567. $objToReturn->blnShowCreator = $objDbRow->GetColumn($strAliasName, 'Bit');
  568. $strAliasName = array_key_exists($strAliasPrefix . 'show_creation_date', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'show_creation_date'] : $strAliasPrefix . 'show_creation_date';
  569. $objToReturn->blnShowCreationDate = $objDbRow->GetColumn($strAliasName, 'Bit');
  570. $strAliasName = array_key_exists($strAliasPrefix . 'show_last_modification', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'show_last_modification'] : $strAliasPrefix . 'show_last_modification';
  571. $objToReturn->blnShowLastModification = $objDbRow->GetColumn($strAliasName, 'Bit');
  572. $strAliasName = array_key_exists($strAliasPrefix . 'creator_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'creator_id'] : $strAliasPrefix . 'creator_id';
  573. $objToReturn->intCreatorId = $objDbRow->GetColumn($strAliasName, 'Integer');
  574. $strAliasName = array_key_exists($strAliasPrefix . 'copyright_notice', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'copyright_notice'] : $strAliasPrefix . 'copyright_notice';
  575. $objToReturn->strCopyrightNotice = $objDbRow->GetColumn($strAliasName, 'VarChar');
  576. $strAliasName = array_key_exists($strAliasPrefix . 'creation_date', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'creation_date'] : $strAliasPrefix . 'creation_date';
  577. $objToReturn->strCreationDate = $objDbRow->GetColumn($strAliasName, 'VarChar');
  578. $strAliasName = array_key_exists($strAliasPrefix . 'last_modification', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'last_modification'] : $strAliasPrefix . 'last_modification';
  579. $objToReturn->strLastModification = $objDbRow->GetColumn($strAliasName, 'VarChar');
  580. $strAliasName = array_key_exists($strAliasPrefix . 'type_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'type_id'] : $strAliasPrefix . 'type_id';
  581. $objToReturn->intTypeId = $objDbRow->GetColumn($strAliasName, 'Integer');
  582. $strAliasName = array_key_exists($strAliasPrefix . 'status_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'status_id'] : $strAliasPrefix . 'status_id';
  583. $objToReturn->intStatusId = $objDbRow->GetColumn($strAliasName, 'Integer');
  584. // Instantiate Virtual Attributes
  585. foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
  586. $strVirtualPrefix = $strAliasPrefix . '__';
  587. $strVirtualPrefixLength = strlen($strVirtualPrefix);
  588. if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
  589. $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
  590. }
  591. // Prepare to Check for Early/Virtual Binding
  592. if (!$strAliasPrefix)
  593. $strAliasPrefix = 'content_item__';
  594. // Check for Creator Early Binding
  595. $strAlias = $strAliasPrefix . 'creator_id__id';
  596. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  597. if (!is_null($objDbRow->GetColumn($strAliasName)))
  598. $objToReturn->objCreator = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'creator_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  599. // Check for ContentBlock Virtual Binding
  600. $strAlias = $strAliasPrefix . 'contentblock__content_block_id__id';
  601. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  602. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  603. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  604. $objToReturn->_objContentBlockArray[] = ContentBlock::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentblock__content_block_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  605. else
  606. $objToReturn->_objContentBlock = ContentBlock::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentblock__content_block_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  607. }
  608. // Check for ContentCategory Virtual Binding
  609. $strAlias = $strAliasPrefix . 'contentcategory__content_category_id__id';
  610. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  611. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  612. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  613. $objToReturn->_objContentCategoryArray[] = ContentCategory::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentcategory__content_category_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  614. else
  615. $objToReturn->_objContentCategory = ContentCategory::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentcategory__content_category_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  616. }
  617. // Check for Usergroup Virtual Binding
  618. $strAlias = $strAliasPrefix . 'usergroup__usergroup_id__id';
  619. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  620. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  621. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  622. $objToReturn->_objUsergroupArray[] = Usergroup::InstantiateDbRow($objDbRow, $strAliasPrefix . 'usergroup__usergroup_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  623. else
  624. $objToReturn->_objUsergroup = Usergroup::InstantiateDbRow($objDbRow, $strAliasPrefix . 'usergroup__usergroup_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  625. }
  626. return $objToReturn;
  627. }
  628. /**
  629. * Instantiate an array of ContentItems from a Database Result
  630. * @param DatabaseResultBase $objDbResult
  631. * @param string $strExpandAsArrayNodes
  632. * @param string[] $strColumnAliasArray
  633. * @return ContentItem[]
  634. */
  635. public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
  636. $objToReturn = array();
  637. if (!$strColumnAliasArray)
  638. $strColumnAliasArray = array();
  639. // If blank resultset, then return empty array
  640. if (!$objDbResult)
  641. return $objToReturn;
  642. // Load up the return array with each row
  643. if ($strExpandAsArrayNodes) {
  644. $objLastRowItem = null;
  645. while ($objDbRow = $objDbResult->GetNextRow()) {
  646. $objItem = ContentItem::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem, $strColumnAliasArray);
  647. if ($objItem) {
  648. $objToReturn[] = $objItem;
  649. $objLastRowItem = $objItem;
  650. }
  651. }
  652. } else {
  653. while ($objDbRow = $objDbResult->GetNextRow())
  654. $objToReturn[] = ContentItem::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
  655. }
  656. return $objToReturn;
  657. }
  658. ///////////////////////////////////////////////////
  659. // INDEX-BASED LOAD METHODS (Single Load and Array)
  660. ///////////////////////////////////////////////////
  661. /**
  662. * Load a single ContentItem object,
  663. * by Id Index(es)
  664. * @param integer $intId
  665. * @return ContentItem
  666. */
  667. public static function LoadById($intId) {
  668. return ContentItem::QuerySingle(
  669. QQ::Equal(QQN::ContentItem()->Id, $intId)
  670. );
  671. }
  672. /**
  673. * Load a single ContentItem object,
  674. * by Name Index(es)
  675. * @param string $strName
  676. * @return ContentItem
  677. */
  678. public static function LoadByName($strName) {
  679. return ContentItem::QuerySingle(
  680. QQ::Equal(QQN::ContentItem()->Name, $strName)
  681. );
  682. }
  683. /**
  684. * Load an array of ContentItem objects,
  685. * by Title Index(es)
  686. * @param string $strTitle
  687. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  688. * @return ContentItem[]
  689. */
  690. public static function LoadArrayByTitle($strTitle, $objOptionalClauses = null) {
  691. // Call ContentItem::QueryArray to perform the LoadArrayByTitle query
  692. try {
  693. return ContentItem::QueryArray(
  694. QQ::Equal(QQN::ContentItem()->Title, $strTitle),
  695. $objOptionalClauses);
  696. } catch (QCallerException $objExc) {
  697. $objExc->IncrementOffset();
  698. throw $objExc;
  699. }
  700. }
  701. /**
  702. * Count ContentItems
  703. * by Title Index(es)
  704. * @param string $strTitle
  705. * @return int
  706. */
  707. public static function CountByTitle($strTitle) {
  708. // Call ContentItem::QueryCount to perform the CountByTitle query
  709. return ContentItem::QueryCount(
  710. QQ::Equal(QQN::ContentItem()->Title, $strTitle)
  711. );
  712. }
  713. /**
  714. * Load an array of ContentItem objects,
  715. * by CreatorId Index(es)
  716. * @param integer $intCreatorId
  717. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  718. * @return ContentItem[]
  719. */
  720. public static function LoadArrayByCreatorId($intCreatorId, $objOptionalClauses = null) {
  721. // Call ContentItem::QueryArray to perform the LoadArrayByCreatorId query
  722. try {
  723. return ContentItem::QueryArray(
  724. QQ::Equal(QQN::ContentItem()->CreatorId, $intCreatorId),
  725. $objOptionalClauses);
  726. } catch (QCallerException $objExc) {
  727. $objExc->IncrementOffset();
  728. throw $objExc;
  729. }
  730. }
  731. /**
  732. * Count ContentItems
  733. * by CreatorId Index(es)
  734. * @param integer $intCreatorId
  735. * @return int
  736. */
  737. public static function CountByCreatorId($intCreatorId) {
  738. // Call ContentItem::QueryCount to perform the CountByCreatorId query
  739. return ContentItem::QueryCount(
  740. QQ::Equal(QQN::ContentItem()->CreatorId, $intCreatorId)
  741. );
  742. }
  743. /**
  744. * Load an array of ContentItem objects,
  745. * by TypeId Index(es)
  746. * @param integer $intTypeId
  747. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  748. * @return ContentItem[]
  749. */
  750. public static function LoadArrayByTypeId($intTypeId, $objOptionalClauses = null) {
  751. // Call ContentItem::QueryArray to perform the LoadArrayByTypeId query
  752. try {
  753. return ContentItem::QueryArray(
  754. QQ::Equal(QQN::ContentItem()->TypeId, $intTypeId),
  755. $objOptionalClauses);
  756. } catch (QCallerException $objExc) {
  757. $objExc->IncrementOffset();
  758. throw $objExc;
  759. }
  760. }
  761. /**
  762. * Count ContentItems
  763. * by TypeId Index(es)
  764. * @param integer $intTypeId
  765. * @return int
  766. */
  767. public static function CountByTypeId($intTypeId) {
  768. // Call ContentItem::QueryCount to perform the CountByTypeId query
  769. return ContentItem::QueryCount(
  770. QQ::Equal(QQN::ContentItem()->TypeId, $intTypeId)
  771. );
  772. }
  773. /**
  774. * Load an array of ContentItem objects,
  775. * by StatusId Index(es)
  776. * @param integer $intStatusId
  777. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  778. * @return ContentItem[]
  779. */
  780. public static function LoadArrayByStatusId($intStatusId, $objOptionalClauses = null) {
  781. // Call ContentItem::QueryArray to perform the LoadArrayByStatusId query
  782. try {
  783. return ContentItem::QueryArray(
  784. QQ::Equal(QQN::ContentItem()->StatusId, $intStatusId),
  785. $objOptionalClauses);
  786. } catch (QCallerException $objExc) {
  787. $objExc->IncrementOffset();
  788. throw $objExc;
  789. }
  790. }
  791. /**
  792. * Count ContentItems
  793. * by StatusId Index(es)
  794. * @param integer $intStatusId
  795. * @return int
  796. */
  797. public static function CountByStatusId($intStatusId) {
  798. // Call ContentItem::QueryCount to perform the CountByStatusId query
  799. return ContentItem::QueryCount(
  800. QQ::Equal(QQN::ContentItem()->StatusId, $intStatusId)
  801. );
  802. }
  803. ////////////////////////////////////////////////////
  804. // INDEX-BASED LOAD METHODS (Array via Many to Many)
  805. ////////////////////////////////////////////////////
  806. /**
  807. * Load an array of ContentBlock objects for a given ContentBlock
  808. * via the content_item_content_block_assn table
  809. * @param integer $intContentBlockId
  810. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  811. * @return ContentItem[]
  812. */
  813. public static function LoadArrayByContentBlock($intContentBlockId, $objOptionalClauses = null) {
  814. // Call ContentItem::QueryArray to perform the LoadArrayByContentBlock query
  815. try {
  816. return ContentItem::QueryArray(
  817. QQ::Equal(QQN::ContentItem()->ContentBlock->ContentBlockId, $intContentBlockId),
  818. $objOptionalClauses
  819. );
  820. } catch (QCallerException $objExc) {
  821. $objExc->IncrementOffset();
  822. throw $objExc;
  823. }
  824. }
  825. /**
  826. * Count ContentItems for a given ContentBlock
  827. * via the content_item_content_block_assn table
  828. * @param integer $intContentBlockId
  829. * @return int
  830. */
  831. public static function CountByContentBlock($intContentBlockId) {
  832. return ContentItem::QueryCount(
  833. QQ::Equal(QQN::ContentItem()->ContentBlock->ContentBlockId, $intContentBlockId)
  834. );
  835. }
  836. /**
  837. * Load an array of ContentCategory objects for a given ContentCategory
  838. * via the content_item_content_category_assn table
  839. * @param integer $intContentCategoryId
  840. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  841. * @return ContentItem[]
  842. */
  843. public static function LoadArrayByContentCategory($intContentCategoryId, $objOptionalClauses = null) {
  844. // Call ContentItem::QueryArray to perform the LoadArrayByContentCategory query
  845. try {
  846. return ContentItem::QueryArray(
  847. QQ::Equal(QQN::ContentItem()->ContentCategory->ContentCategoryId, $intContentCategoryId),
  848. $objOptionalClauses
  849. );
  850. } catch (QCallerException $objExc) {
  851. $objExc->IncrementOffset();
  852. throw $objExc;
  853. }
  854. }
  855. /**
  856. * Count ContentItems for a given ContentCategory
  857. * via the content_item_content_category_assn table
  858. * @param integer $intContentCategoryId
  859. * @return int
  860. */
  861. public static function CountByContentCategory($intContentCategoryId) {
  862. return ContentItem::QueryCount(
  863. QQ::Equal(QQN::ContentItem()->ContentCategory->ContentCategoryId, $intContentCategoryId)
  864. );
  865. }
  866. /**
  867. * Load an array of Usergrou