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.

2347 lines
104 KiB

  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 Usergroup objects for a given Usergroup
  868. * via the content_item_usergroup_assn table
  869. * @param integer $intUsergroupId
  870. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  871. * @return ContentItem[]
  872. */
  873. public static function LoadArrayByUsergroup($intUsergroupId, $objOptionalClauses = null) {
  874. // Call ContentItem::QueryArray to perform the LoadArrayByUsergroup query
  875. try {
  876. return ContentItem::QueryArray(
  877. QQ::Equal(QQN::ContentItem()->Usergroup->UsergroupId, $intUsergroupId),
  878. $objOptionalClauses
  879. );
  880. } catch (QCallerException $objExc) {
  881. $objExc->IncrementOffset();
  882. throw $objExc;
  883. }
  884. }
  885. /**
  886. * Count ContentItems for a given Usergroup
  887. * via the content_item_usergroup_assn table
  888. * @param integer $intUsergroupId
  889. * @return int
  890. */
  891. public static function CountByUsergroup($intUsergroupId) {
  892. return ContentItem::QueryCount(
  893. QQ::Equal(QQN::ContentItem()->Usergroup->UsergroupId, $intUsergroupId)
  894. );
  895. }
  896. //////////////////////////
  897. // SAVE, DELETE AND RELOAD
  898. //////////////////////////
  899. /**
  900. * Save this ContentItem
  901. * @param bool $blnForceInsert
  902. * @param bool $blnForceUpdate
  903. * @return int
  904. */
  905. public function Save($blnForceInsert = false, $blnForceUpdate = false) {
  906. // Get the Database Object for this Class
  907. $objDatabase = ContentItem::GetDatabase();
  908. $mixToReturn = null;
  909. try {
  910. if ((!$this->__blnRestored) || ($blnForceInsert)) {
  911. // Perform an INSERT query
  912. $objDatabase->NonQuery('
  913. INSERT INTO `content_item` (
  914. `name`,
  915. `cssclass`,
  916. `title`,
  917. `description`,
  918. `text`,
  919. `sort_order`,
  920. `show_title`,
  921. `show_description`,
  922. `show_creator`,
  923. `show_creation_date`,
  924. `show_last_modification`,
  925. `creator_id`,
  926. `copyright_notice`,
  927. `type_id`,
  928. `status_id`
  929. ) VALUES (
  930. ' . $objDatabase->SqlVariable($this->strName) . ',
  931. ' . $objDatabase->SqlVariable($this->strCssclass) . ',
  932. ' . $objDatabase->SqlVariable($this->strTitle) . ',
  933. ' . $objDatabase->SqlVariable($this->strDescription) . ',
  934. ' . $objDatabase->SqlVariable($this->strText) . ',
  935. ' . $objDatabase->SqlVariable($this->intSortOrder) . ',
  936. ' . $objDatabase->SqlVariable($this->blnShowTitle) . ',
  937. ' . $objDatabase->SqlVariable($this->blnShowDescription) . ',
  938. ' . $objDatabase->SqlVariable($this->blnShowCreator) . ',
  939. ' . $objDatabase->SqlVariable($this->blnShowCreationDate) . ',
  940. ' . $objDatabase->SqlVariable($this->blnShowLastModification) . ',
  941. ' . $objDatabase->SqlVariable($this->intCreatorId) . ',
  942. ' . $objDatabase->SqlVariable($this->strCopyrightNotice) . ',
  943. ' . $objDatabase->SqlVariable($this->intTypeId) . ',
  944. ' . $objDatabase->SqlVariable($this->intStatusId) . '
  945. )
  946. ');
  947. // Update Identity column and return its value
  948. $mixToReturn = $this->intId = $objDatabase->InsertId('content_item', 'id');
  949. } else {
  950. // Perform an UPDATE query
  951. // First checking for Optimistic Locking constraints (if applicable)
  952. if (!$blnForceUpdate) {
  953. // Perform the Optimistic Locking check
  954. $objResult = $objDatabase->Query('
  955. SELECT
  956. `creation_date`
  957. FROM
  958. `content_item`
  959. WHERE
  960. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  961. ');
  962. $objRow = $objResult->FetchArray();
  963. if ($objRow[0] != $this->strCreationDate)
  964. throw new QOptimisticLockingException('ContentItem');
  965. }
  966. if (!$blnForceUpdate) {
  967. // Perform the Optimistic Locking check
  968. $objResult = $objDatabase->Query('
  969. SELECT
  970. `last_modification`
  971. FROM
  972. `content_item`
  973. WHERE
  974. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  975. ');
  976. $objRow = $objResult->FetchArray();
  977. if ($objRow[0] != $this->strLastModification)
  978. throw new QOptimisticLockingException('ContentItem');
  979. }
  980. // Perform the UPDATE query
  981. $objDatabase->NonQuery('
  982. UPDATE
  983. `content_item`
  984. SET
  985. `name` = ' . $objDatabase->SqlVariable($this->strName) . ',
  986. `cssclass` = ' . $objDatabase->SqlVariable($this->strCssclass) . ',
  987. `title` = ' . $objDatabase->SqlVariable($this->strTitle) . ',
  988. `description` = ' . $objDatabase->SqlVariable($this->strDescription) . ',
  989. `text` = ' . $objDatabase->SqlVariable($this->strText) . ',
  990. `sort_order` = ' . $objDatabase->SqlVariable($this->intSortOrder) . ',
  991. `show_title` = ' . $objDatabase->SqlVariable($this->blnShowTitle) . ',
  992. `show_description` = ' . $objDatabase->SqlVariable($this->blnShowDescription) . ',
  993. `show_creator` = ' . $objDatabase->SqlVariable($this->blnShowCreator) . ',
  994. `show_creation_date` = ' . $objDatabase->SqlVariable($this->blnShowCreationDate) . ',
  995. `show_last_modification` = ' . $objDatabase->SqlVariable($this->blnShowLastModification) . ',
  996. `creator_id` = ' . $objDatabase->SqlVariable($this->intCreatorId) . ',
  997. `copyright_notice` = ' . $objDatabase->SqlVariable($this->strCopyrightNotice) . ',
  998. `type_id` = ' . $objDatabase->SqlVariable($this->intTypeId) . ',
  999. `status_id` = ' . $objDatabase->SqlVariable($this->intStatusId) . '
  1000. WHERE
  1001. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1002. ');
  1003. }
  1004. } catch (QCallerException $objExc) {
  1005. $objExc->IncrementOffset();
  1006. throw $objExc;
  1007. }
  1008. // Update __blnRestored and any Non-Identity PK Columns (if applicable)
  1009. $this->__blnRestored = true;
  1010. // Update Local Timestamp
  1011. $objResult = $objDatabase->Query('
  1012. SELECT
  1013. `creation_date`
  1014. FROM
  1015. `content_item`
  1016. WHERE
  1017. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1018. ');
  1019. $objRow = $objResult->FetchArray();
  1020. $this->strCreationDate = $objRow[0];
  1021. // Update Local Timestamp
  1022. $objResult = $objDatabase->Query('
  1023. SELECT
  1024. `last_modification`
  1025. FROM
  1026. `content_item`
  1027. WHERE
  1028. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1029. ');
  1030. $objRow = $objResult->FetchArray();
  1031. $this->strLastModification = $objRow[0];
  1032. // Return
  1033. return $mixToReturn;
  1034. }
  1035. /**
  1036. * Delete this ContentItem
  1037. * @return void
  1038. */
  1039. public function Delete() {
  1040. if ((is_null($this->intId)))
  1041. throw new QUndefinedPrimaryKeyException('Cannot delete this ContentItem with an unset primary key.');
  1042. // Get the Database Object for this Class
  1043. $objDatabase = ContentItem::GetDatabase();
  1044. // Perform the SQL Query
  1045. $objDatabase->NonQuery('
  1046. DELETE FROM
  1047. `content_item`
  1048. WHERE
  1049. `id` = ' . $objDatabase->SqlVariable($this->intId) . '');
  1050. }
  1051. /**
  1052. * Delete all ContentItems
  1053. * @return void
  1054. */
  1055. public static function DeleteAll() {
  1056. // Get the Database Object for this Class
  1057. $objDatabase = ContentItem::GetDatabase();
  1058. // Perform the Query
  1059. $objDatabase->NonQuery('
  1060. DELETE FROM
  1061. `content_item`');
  1062. }
  1063. /**
  1064. * Truncate content_item table
  1065. * @return void
  1066. */
  1067. public static function Truncate() {
  1068. // Get the Database Object for this Class
  1069. $objDatabase = ContentItem::GetDatabase();
  1070. // Perform the Query
  1071. $objDatabase->NonQuery('
  1072. TRUNCATE `content_item`');
  1073. }
  1074. /**
  1075. * Reload this ContentItem from the database.
  1076. * @return void
  1077. */
  1078. public function Reload() {
  1079. // Make sure we are actually Restored from the database
  1080. if (!$this->__blnRestored)
  1081. throw new QCallerException('Cannot call Reload() on a new, unsaved ContentItem object.');
  1082. // Reload the Object
  1083. $objReloaded = ContentItem::Load($this->intId);
  1084. // Update $this's local variables to match
  1085. $this->strName = $objReloaded->strName;
  1086. $this->strCssclass = $objReloaded->strCssclass;
  1087. $this->strTitle = $objReloaded->strTitle;
  1088. $this->strDescription = $objReloaded->strDescription;
  1089. $this->strText = $objReloaded->strText;
  1090. $this->intSortOrder = $objReloaded->intSortOrder;
  1091. $this->blnShowTitle = $objReloaded->blnShowTitle;
  1092. $this->blnShowDescription = $objReloaded->blnShowDescription;
  1093. $this->blnShowCreator = $objReloaded->blnShowCreator;
  1094. $this->blnShowCreationDate = $objReloaded->blnShowCreationDate;
  1095. $this->blnShowLastModification = $objReloaded->blnShowLastModification;
  1096. $this->CreatorId = $objReloaded->CreatorId;
  1097. $this->strCopyrightNotice = $objReloaded->strCopyrightNotice;
  1098. $this->strCreationDate = $objReloaded->strCreationDate;
  1099. $this->strLastModification = $objReloaded->strLastModification;
  1100. $this->TypeId = $objReloaded->TypeId;
  1101. $this->StatusId = $objReloaded->StatusId;
  1102. }
  1103. ////////////////////
  1104. // GETTORS AND SETTORS
  1105. ////////////////////
  1106. /**
  1107. * Lookup a VirtualAttribute value (if applicable). Returns NULL if none found.
  1108. * @param string $strName
  1109. * @return string
  1110. */
  1111. public function GetVirtualAttribute($strName)
  1112. {
  1113. if (array_key_exists($strName, $this->__strVirtualAttributeArray))
  1114. return $this->__strVirtualAttributeArray[$strName];
  1115. return null;
  1116. }
  1117. /**
  1118. * Override method to perform a property "Get"
  1119. * This will get the value of $strName
  1120. *
  1121. * @param string $strName Name of the property to get
  1122. * @return mixed
  1123. */
  1124. public function __get($strName)
  1125. {
  1126. switch ($strName)
  1127. {
  1128. ///////////////////
  1129. // Member Variables
  1130. ///////////////////
  1131. case 'Id':
  1132. /**
  1133. * Gets the value for intId (Read-Only PK)
  1134. * @return integer
  1135. */
  1136. return $this->intId;
  1137. case 'Name':
  1138. /**
  1139. * Gets the value for strName (Unique)
  1140. * @return string
  1141. */
  1142. return $this->strName;
  1143. case 'Cssclass':
  1144. /**
  1145. * Gets the value for strCssclass
  1146. * @return string
  1147. */
  1148. return $this->strCssclass;
  1149. case 'Title':
  1150. /**
  1151. * Gets the value for strTitle
  1152. * @return string
  1153. */
  1154. return $this->strTitle;
  1155. case 'Description':
  1156. /**
  1157. * Gets the value for strDescription
  1158. * @return string
  1159. */
  1160. return $this->strDescription;
  1161. case 'Text':
  1162. /**
  1163. * Gets the value for strText
  1164. * @return string
  1165. */
  1166. return $this->strText;
  1167. case 'SortOrder':
  1168. /**
  1169. * Gets the value for intSortOrder
  1170. * @return integer
  1171. */
  1172. return $this->intSortOrder;
  1173. case 'ShowTitle':
  1174. /**
  1175. * Gets the value for blnShowTitle (Not Null)
  1176. * @return boolean
  1177. */
  1178. return $this->blnShowTitle;
  1179. case 'ShowDescription':
  1180. /**
  1181. * Gets the value for blnShowDescription (Not Null)
  1182. * @return boolean
  1183. */
  1184. return $this->blnShowDescription;
  1185. case 'ShowCreator':
  1186. /**
  1187. * Gets the value for blnShowCreator (Not Null)
  1188. * @return boolean
  1189. */
  1190. return $this->blnShowCreator;
  1191. case 'ShowCreationDate':
  1192. /**
  1193. * Gets the value for blnShowCreationDate (Not Null)
  1194. * @return boolean
  1195. */
  1196. return $this->blnShowCreationDate;
  1197. case 'ShowLastModification':
  1198. /**
  1199. * Gets the value for blnShowLastModification (Not Null)
  1200. * @return boolean
  1201. */
  1202. return $this->blnShowLastModification;
  1203. case 'CreatorId':
  1204. /**
  1205. * Gets the value for intCreatorId
  1206. * @return integer
  1207. */
  1208. return $this->intCreatorId;
  1209. case 'CopyrightNotice':
  1210. /**
  1211. * Gets the value for strCopyrightNotice
  1212. * @return string
  1213. */
  1214. return $this->strCopyrightNotice;
  1215. case 'CreationDate':
  1216. /**
  1217. * Gets the value for strCreationDate (Read-Only Timestamp)
  1218. * @return string
  1219. */
  1220. return $this->strCreationDate;
  1221. case 'LastModification':
  1222. /**
  1223. * Gets the value for strLastModification (Read-Only Timestamp)
  1224. * @return string
  1225. */
  1226. return $this->strLastModification;
  1227. case 'TypeId':
  1228. /**
  1229. * Gets the value for intTypeId (Not Null)
  1230. * @return integer
  1231. */
  1232. return $this->intTypeId;
  1233. case 'StatusId':
  1234. /**
  1235. * Gets the value for intStatusId (Not Null)
  1236. * @return integer
  1237. */
  1238. return $this->intStatusId;
  1239. ///////////////////
  1240. // Member Objects
  1241. ///////////////////
  1242. case 'Creator':
  1243. /**
  1244. * Gets the value for the Person object referenced by intCreatorId
  1245. * @return Person
  1246. */
  1247. try {
  1248. if ((!$this->objCreator) && (!is_null($this->intCreatorId)))
  1249. $this->objCreator = Person::Load($this->intCreatorId);
  1250. return $this->objCreator;
  1251. } catch (QCallerException $objExc) {
  1252. $objExc->IncrementOffset();
  1253. throw $objExc;
  1254. }
  1255. ////////////////////////////
  1256. // Virtual Object References (Many to Many and Reverse References)
  1257. // (If restored via a "Many-to" expansion)
  1258. ////////////////////////////
  1259. case '_ContentBlock':
  1260. /**
  1261. * Gets the value for the private _objContentBlock (Read-Only)
  1262. * if set due to an expansion on the content_item_content_block_assn association table
  1263. * @return ContentBlock
  1264. */
  1265. return $this->_objContentBlock;
  1266. case '_ContentBlockArray':
  1267. /**
  1268. * Gets the value for the private _objContentBlockArray (Read-Only)
  1269. * if set due to an ExpandAsArray on the content_item_content_block_assn association table
  1270. * @return ContentBlock[]
  1271. */
  1272. return (array) $this->_objContentBlockArray;
  1273. case '_ContentCategory':
  1274. /**
  1275. * Gets the value for the private _objContentCategory (Read-Only)
  1276. * if set due to an expansion on the content_item_content_category_assn association table
  1277. * @return ContentCategory
  1278. */
  1279. return $this->_objContentCategory;
  1280. case '_ContentCategoryArray':
  1281. /**
  1282. * Gets the value for the private _objContentCategoryArray (Read-Only)
  1283. * if set due to an ExpandAsArray on the content_item_content_category_assn association table
  1284. * @return ContentCategory[]
  1285. */
  1286. return (array) $this->_objContentCategoryArray;
  1287. case '_Usergroup':
  1288. /**
  1289. * Gets the value for the private _objUsergroup (Read-Only)
  1290. * if set due to an expansion on the content_item_usergroup_assn association table
  1291. * @return Usergroup
  1292. */
  1293. return $this->_objUsergroup;
  1294. case '_UsergroupArray':
  1295. /**
  1296. * Gets the value for the private _objUsergroupArray (Read-Only)
  1297. * if set due to an ExpandAsArray on the content_item_usergroup_assn association table
  1298. * @return Usergroup[]
  1299. */
  1300. return (array) $this->_objUsergroupArray;
  1301. case '__Restored':
  1302. return $this->__blnRestored;
  1303. default:
  1304. try {
  1305. return parent::__get($strName);
  1306. } catch (QCallerException $objExc) {
  1307. $objExc->IncrementOffset();
  1308. throw $objExc;
  1309. }
  1310. }
  1311. }
  1312. /**
  1313. * Override method to perform a property "Set"
  1314. * This will set the property $strName to be $mixValue
  1315. *
  1316. * @param string $strName Name of the property to set
  1317. * @param string $mixValue New value of the property
  1318. * @return mixed
  1319. */
  1320. public function __set($strName, $mixValue) {
  1321. switch ($strName) {
  1322. ///////////////////
  1323. // Member Variables
  1324. ///////////////////
  1325. case 'Name':
  1326. /**
  1327. * Sets the value for strName (Unique)
  1328. * @param string $mixValue
  1329. * @return string
  1330. */
  1331. try {
  1332. return ($this->strName = QType::Cast($mixValue, QType::String));
  1333. } catch (QCallerException $objExc) {
  1334. $objExc->IncrementOffset();
  1335. throw $objExc;
  1336. }
  1337. case 'Cssclass':
  1338. /**
  1339. * Sets the value for strCssclass
  1340. * @param string $mixValue
  1341. * @return string
  1342. */
  1343. try {
  1344. return ($this->strCssclass = QType::Cast($mixValue, QType::String));
  1345. } catch (QCallerException $objExc) {
  1346. $objExc->IncrementOffset();
  1347. throw $objExc;
  1348. }
  1349. case 'Title':
  1350. /**
  1351. * Sets the value for strTitle
  1352. * @param string $mixValue
  1353. * @return string
  1354. */
  1355. try {
  1356. return ($this->strTitle = QType::Cast($mixValue, QType::String));
  1357. } catch (QCallerException $objExc) {
  1358. $objExc->IncrementOffset();
  1359. throw $objExc;
  1360. }
  1361. case 'Description':
  1362. /**
  1363. * Sets the value for strDescription
  1364. * @param string $mixValue
  1365. * @return string
  1366. */
  1367. try {
  1368. return ($this->strDescription = QType::Cast($mixValue, QType::String));
  1369. } catch (QCallerException $objExc) {
  1370. $objExc->IncrementOffset();
  1371. throw $objExc;
  1372. }
  1373. case 'Text':
  1374. /**
  1375. * Sets the value for strText
  1376. * @param string $mixValue
  1377. * @return string
  1378. */
  1379. try {
  1380. return ($this->strText = QType::Cast($mixValue, QType::String));
  1381. } catch (QCallerException $objExc) {
  1382. $objExc->IncrementOffset();
  1383. throw $objExc;
  1384. }
  1385. case 'SortOrder':
  1386. /**
  1387. * Sets the value for intSortOrder
  1388. * @param integer $mixValue
  1389. * @return integer
  1390. */
  1391. try {
  1392. return ($this->intSortOrder = QType::Cast($mixValue, QType::Integer));
  1393. } catch (QCallerException $objExc) {
  1394. $objExc->IncrementOffset();
  1395. throw $objExc;
  1396. }
  1397. case 'ShowTitle':
  1398. /**
  1399. * Sets the value for blnShowTitle (Not Null)
  1400. * @param boolean $mixValue
  1401. * @return boolean
  1402. */
  1403. try {
  1404. return ($this->blnShowTitle = QType::Cast($mixValue, QType::Boolean));
  1405. } catch (QCallerException $objExc) {
  1406. $objExc->IncrementOffset();
  1407. throw $objExc;
  1408. }
  1409. case 'ShowDescription':
  1410. /**
  1411. * Sets the value for blnShowDescription (Not Null)
  1412. * @param boolean $mixValue
  1413. * @return boolean
  1414. */
  1415. try {
  1416. return ($this->blnShowDescription = QType::Cast($mixValue, QType::Boolean));
  1417. } catch (QCallerException $objExc) {
  1418. $objExc->IncrementOffset();
  1419. throw $objExc;
  1420. }
  1421. case 'ShowCreator':
  1422. /**
  1423. * Sets the value for blnShowCreator (Not Null)
  1424. * @param boolean $mixValue
  1425. * @return boolean
  1426. */
  1427. try {
  1428. return ($this->blnShowCreator = QType::Cast($mixValue, QType::Boolean));
  1429. } catch (QCallerException $objExc) {
  1430. $objExc->IncrementOffset();
  1431. throw $objExc;
  1432. }
  1433. case 'ShowCreationDate':
  1434. /**
  1435. * Sets the value for blnShowCreationDate (Not Null)
  1436. * @param boolean $mixValue
  1437. * @return boolean
  1438. */
  1439. try {
  1440. return ($this->blnShowCreationDate = QType::Cast($mixValue, QType::Boolean));
  1441. } catch (QCallerException $objExc) {
  1442. $objExc->IncrementOffset();
  1443. throw $objExc;
  1444. }
  1445. case 'ShowLastModification':
  1446. /**
  1447. * Sets the value for blnShowLastModification (Not Null)
  1448. * @param boolean $mixValue
  1449. * @return boolean
  1450. */
  1451. try {
  1452. return ($this->blnShowLastModification = QType::Cast($mixValue, QType::Boolean));
  1453. } catch (QCallerException $objExc) {
  1454. $objExc->IncrementOffset();
  1455. throw $objExc;
  1456. }
  1457. case 'CreatorId':
  1458. /**
  1459. * Sets the value for intCreatorId
  1460. * @param integer $mixValue
  1461. * @return integer
  1462. */
  1463. try {
  1464. $this->objCreator = null;
  1465. return ($this->intCreatorId = QType::Cast($mixValue, QType::Integer));
  1466. } catch (QCallerException $objExc) {
  1467. $objExc->IncrementOffset();
  1468. throw $objExc;
  1469. }
  1470. case 'CopyrightNotice':
  1471. /**
  1472. * Sets the value for strCopyrightNotice
  1473. * @param string $mixValue
  1474. * @return string
  1475. */
  1476. try {
  1477. return ($this->strCopyrightNotice = QType::Cast($mixValue, QType::String));
  1478. } catch (QCallerException $objExc) {
  1479. $objExc->IncrementOffset();
  1480. throw $objExc;
  1481. }
  1482. case 'TypeId':
  1483. /**
  1484. * Sets the value for intTypeId (Not Null)
  1485. * @param integer $mixValue
  1486. * @return integer
  1487. */
  1488. try {
  1489. return ($this->intTypeId = QType::Cast($mixValue, QType::Integer));
  1490. } catch (QCallerException $objExc) {
  1491. $objExc->IncrementOffset();
  1492. throw $objExc;
  1493. }
  1494. case 'StatusId':
  1495. /**
  1496. * Sets the value for intStatusId (Not Null)
  1497. * @param integer $mixValue
  1498. * @return integer
  1499. */
  1500. try {
  1501. return ($this->intStatusId = QType::Cast($mixValue, QType::Integer));
  1502. } catch (QCallerException $objExc) {
  1503. $objExc->IncrementOffset();
  1504. throw $objExc;
  1505. }
  1506. ///////////////////
  1507. // Member Objects
  1508. ///////////////////
  1509. case 'Creator':
  1510. /**
  1511. * Sets the value for the Person object referenced by intCreatorId
  1512. * @param Person $mixValue
  1513. * @return Person
  1514. */
  1515. if (is_null($mixValue)) {
  1516. $this->intCreatorId = null;
  1517. $this->objCreator = null;
  1518. return null;
  1519. } else {
  1520. // Make sure $mixValue actually is a Person object
  1521. try {
  1522. $mixValue = QType::Cast($mixValue, 'Person');
  1523. } catch (QInvalidCastException $objExc) {
  1524. $objExc->IncrementOffset();
  1525. throw $objExc;
  1526. }
  1527. // Make sure $mixValue is a SAVED Person object
  1528. if (is_null($mixValue->Id))
  1529. throw new QCallerException('Unable to set an unsaved Creator for this ContentItem');
  1530. // Update Local Member Variables
  1531. $this->objCreator = $mixValue;
  1532. $this->intCreatorId = $mixValue->Id;
  1533. // Return $mixValue
  1534. return $mixValue;
  1535. }
  1536. break;
  1537. default:
  1538. try {
  1539. return parent::__set($strName, $mixValue);
  1540. } catch (QCallerException $objExc) {
  1541. $objExc->IncrementOffset();
  1542. throw $objExc;
  1543. }
  1544. }
  1545. }
  1546. ///////////////////////////////
  1547. // ASSOCIATED OBJECTS' METHODS
  1548. ///////////////////////////////
  1549. // Related Many-to-Many Objects' Methods for ContentBlock
  1550. //-------------------------------------------------------------------
  1551. /**
  1552. * Gets all many-to-many associated ContentBlocks as an array of ContentBlock objects
  1553. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1554. * @return ContentBlock[]
  1555. */
  1556. public function GetContentBlockArray($objOptionalClauses = null) {
  1557. if ((is_null($this->intId)))
  1558. return array();
  1559. try {
  1560. return ContentBlock::LoadArrayByContentItem($this->intId, $objOptionalClauses);
  1561. } catch (QCallerException $objExc) {
  1562. $objExc->IncrementOffset();
  1563. throw $objExc;
  1564. }
  1565. }
  1566. /**
  1567. * Counts all many-to-many associated ContentBlocks
  1568. * @return int
  1569. */
  1570. public function CountContentBlocks() {
  1571. if ((is_null($this->intId)))
  1572. return 0;
  1573. return ContentBlock::CountByContentItem($this->intId);
  1574. }
  1575. /**
  1576. * Checks to see if an association exists with a specific ContentBlock
  1577. * @param ContentBlock $objContentBlock
  1578. * @return bool
  1579. */
  1580. public function IsContentBlockAssociated(ContentBlock $objContentBlock) {
  1581. if ((is_null($this->intId)))
  1582. throw new QUndefinedPrimaryKeyException('Unable to call IsContentBlockAssociated on this unsaved ContentItem.');
  1583. if ((is_null($objContentBlock->Id)))
  1584. throw new QUndefinedPrimaryKeyException('Unable to call IsContentBlockAssociated on this ContentItem with an unsaved ContentBlock.');
  1585. $intRowCount = ContentItem::QueryCount(
  1586. QQ::AndCondition(
  1587. QQ::Equal(QQN::ContentItem()->Id, $this->intId),
  1588. QQ::Equal(QQN::ContentItem()->ContentBlock->ContentBlockId, $objContentBlock->Id)
  1589. )
  1590. );
  1591. return ($intRowCount > 0);
  1592. }
  1593. /**
  1594. * Associates a ContentBlock
  1595. * @param ContentBlock $objContentBlock
  1596. * @return void
  1597. */
  1598. public function AssociateContentBlock(ContentBlock $objContentBlock) {
  1599. if ((is_null($this->intId)))
  1600. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentBlock on this unsaved ContentItem.');
  1601. if ((is_null($objContentBlock->Id)))
  1602. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentBlock on this ContentItem with an unsaved ContentBlock.');
  1603. // Get the Database Object for this Class
  1604. $objDatabase = ContentItem::GetDatabase();
  1605. // Perform the SQL Query
  1606. $objDatabase->NonQuery('
  1607. INSERT INTO `content_item_content_block_assn` (
  1608. `content_item_id`,
  1609. `content_block_id`
  1610. ) VALUES (
  1611. ' . $objDatabase->SqlVariable($this->intId) . ',
  1612. ' . $objDatabase->SqlVariable($objContentBlock->Id) . '
  1613. )
  1614. ');
  1615. }
  1616. /**
  1617. * Unassociates a ContentBlock
  1618. * @param ContentBlock $objContentBlock
  1619. * @return void
  1620. */
  1621. public function UnassociateContentBlock(ContentBlock $objContentBlock) {
  1622. if ((is_null($this->intId)))
  1623. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentBlock on this unsaved ContentItem.');
  1624. if ((is_null($objContentBlock->Id)))
  1625. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentBlock on this ContentItem with an unsaved ContentBlock.');
  1626. // Get the Database Object for this Class
  1627. $objDatabase = ContentItem::GetDatabase();
  1628. // Perform the SQL Query
  1629. $objDatabase->NonQuery('
  1630. DELETE FROM
  1631. `content_item_content_block_assn`
  1632. WHERE
  1633. `content_item_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  1634. `content_block_id` = ' . $objDatabase->SqlVariable($objContentBlock->Id) . '
  1635. ');
  1636. }
  1637. /**
  1638. * Unassociates all ContentBlocks
  1639. * @return void
  1640. */
  1641. public function UnassociateAllContentBlocks() {
  1642. if ((is_null($this->intId)))
  1643. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllContentBlockArray on this unsaved ContentItem.');
  1644. // Get the Database Object for this Class
  1645. $objDatabase = ContentItem::GetDatabase();
  1646. // Perform the SQL Query
  1647. $objDatabase->NonQuery('
  1648. DELETE FROM
  1649. `content_item_content_block_assn`
  1650. WHERE
  1651. `content_item_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1652. ');
  1653. }
  1654. // Related Many-to-Many Objects' Methods for ContentCategory
  1655. //-------------------------------------------------------------------
  1656. /**
  1657. * Gets all many-to-many associated ContentCategories as an array of ContentCategory objects
  1658. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1659. * @return ContentCategory[]
  1660. */
  1661. public function GetContentCategoryArray($objOptionalClauses = null) {
  1662. if ((is_null($this->intId)))
  1663. return array();
  1664. try {
  1665. return ContentCategory::LoadArrayByContentItem($this->intId, $objOptionalClauses);
  1666. } catch (QCallerException $objExc) {
  1667. $objExc->IncrementOffset();
  1668. throw $objExc;
  1669. }
  1670. }
  1671. /**
  1672. * Counts all many-to-many associated ContentCategories
  1673. * @return int
  1674. */
  1675. public function CountContentCategories() {
  1676. if ((is_null($this->intId)))
  1677. return 0;
  1678. return ContentCategory::CountByContentItem($this->intId);
  1679. }
  1680. /**
  1681. * Checks to see if an association exists with a specific ContentCategory
  1682. * @param ContentCategory $objContentCategory
  1683. * @return bool
  1684. */
  1685. public function IsContentCategoryAssociated(ContentCategory $objContentCategory) {
  1686. if ((is_null($this->intId)))
  1687. throw new QUndefinedPrimaryKeyException('Unable to call IsContentCategoryAssociated on this unsaved ContentItem.');
  1688. if ((is_null($objContentCategory->Id)))
  1689. throw new QUndefinedPrimaryKeyException('Unable to call IsContentCategoryAssociated on this ContentItem with an unsaved ContentCategory.');
  1690. $intRowCount = ContentItem::QueryCount(
  1691. QQ::AndCondition(
  1692. QQ::Equal(QQN::ContentItem()->Id, $this->intId),
  1693. QQ::Equal(QQN::ContentItem()->ContentCategory->ContentCategoryId, $objContentCategory->Id)
  1694. )
  1695. );
  1696. return ($intRowCount > 0);
  1697. }
  1698. /**
  1699. * Associates a ContentCategory
  1700. * @param ContentCategory $objContentCategory
  1701. * @return void
  1702. */
  1703. public function AssociateContentCategory(ContentCategory $objContentCategory) {
  1704. if ((is_null($this->intId)))
  1705. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentCategory on this unsaved ContentItem.');
  1706. if ((is_null($objContentCategory->Id)))
  1707. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentCategory on this ContentItem with an unsaved ContentCategory.');
  1708. // Get the Database Object for this Class
  1709. $objDatabase = ContentItem::GetDatabase();
  1710. // Perform the SQL Query
  1711. $objDatabase->NonQuery('
  1712. INSERT INTO `content_item_content_category_assn` (
  1713. `content_item_id`,
  1714. `content_category_id`
  1715. ) VALUES (
  1716. ' . $objDatabase->SqlVariable($this->intId) . ',
  1717. ' . $objDatabase->SqlVariable($objContentCategory->Id) . '
  1718. )
  1719. ');
  1720. }
  1721. /**
  1722. * Unassociates a ContentCategory
  1723. * @param ContentCategory $objContentCategory
  1724. * @return void
  1725. */
  1726. public function UnassociateContentCategory(ContentCategory $objContentCategory) {
  1727. if ((is_null($this->intId)))
  1728. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentCategory on this unsaved ContentItem.');
  1729. if ((is_null($objContentCategory->Id)))
  1730. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentCategory on this ContentItem with an unsaved ContentCategory.');
  1731. // Get the Database Object for this Class
  1732. $objDatabase = ContentItem::GetDatabase();
  1733. // Perform the SQL Query
  1734. $objDatabase->NonQuery('
  1735. DELETE FROM
  1736. `content_item_content_category_assn`
  1737. WHERE
  1738. `content_item_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  1739. `content_category_id` = ' . $objDatabase->SqlVariable($objContentCategory->Id) . '
  1740. ');
  1741. }
  1742. /**
  1743. * Unassociates all ContentCategories
  1744. * @return void
  1745. */
  1746. public function UnassociateAllContentCategories() {
  1747. if ((is_null($this->intId)))
  1748. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllContentCategoryArray on this unsaved ContentItem.');
  1749. // Get the Database Object for this Class
  1750. $objDatabase = ContentItem::GetDatabase();
  1751. // Perform the SQL Query
  1752. $objDatabase->NonQuery('
  1753. DELETE FROM
  1754. `content_item_content_category_assn`
  1755. WHERE
  1756. `content_item_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1757. ');
  1758. }
  1759. // Related Many-to-Many Objects' Methods for Usergroup
  1760. //-------------------------------------------------------------------
  1761. /**
  1762. * Gets all many-to-many associated Usergroups as an array of Usergroup objects
  1763. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1764. * @return Usergroup[]
  1765. */
  1766. public function GetUsergroupArray($objOptionalClauses = null) {
  1767. if ((is_null($this->intId)))
  1768. return array();
  1769. try {
  1770. return Usergroup::LoadArrayByContentItem($this->intId, $objOptionalClauses);
  1771. } catch (QCallerException $objExc) {
  1772. $objExc->IncrementOffset();
  1773. throw $objExc;
  1774. }
  1775. }
  1776. /**
  1777. * Counts all many-to-many associated Usergroups
  1778. * @return int
  1779. */
  1780. public function CountUsergroups() {
  1781. if ((is_null($this->intId)))
  1782. return 0;
  1783. return Usergroup::CountByContentItem($this->intId);
  1784. }
  1785. /**
  1786. * Checks to see if an association exists with a specific Usergroup
  1787. * @param Usergroup $objUsergroup
  1788. * @return bool
  1789. */
  1790. public function IsUsergroupAssociated(Usergroup $objUsergroup) {
  1791. if ((is_null($this->intId)))
  1792. throw new QUndefinedPrimaryKeyException('Unable to call IsUsergroupAssociated on this unsaved ContentItem.');
  1793. if ((is_null($objUsergroup->Id)))
  1794. throw new QUndefinedPrimaryKeyException('Unable to call IsUsergroupAssociated on this ContentItem with an unsaved Usergroup.');
  1795. $intRowCount = ContentItem::QueryCount(
  1796. QQ::AndCondition(
  1797. QQ::Equal(QQN::ContentItem()->Id, $this->intId),
  1798. QQ::Equal(QQN::ContentItem()->Usergroup->UsergroupId, $objUsergroup->Id)
  1799. )
  1800. );
  1801. return ($intRowCount > 0);
  1802. }
  1803. /**
  1804. * Associates a Usergroup
  1805. * @param Usergroup $objUsergroup
  1806. * @return void
  1807. */
  1808. public function AssociateUsergroup(Usergroup $objUsergroup) {
  1809. if ((is_null($this->intId)))
  1810. throw new QUndefinedPrimaryKeyException('Unable to call AssociateUsergroup on this unsaved ContentItem.');
  1811. if ((is_null($objUsergroup->Id)))
  1812. throw new QUndefinedPrimaryKeyException('Unable to call AssociateUsergroup on this ContentItem with an unsaved Usergroup.');
  1813. // Get the Database Object for this Class
  1814. $objDatabase = ContentItem::GetDatabase();
  1815. // Perform the SQL Query
  1816. $objDatabase->NonQuery('
  1817. INSERT INTO `content_item_usergroup_assn` (
  1818. `content_item_id`,
  1819. `usergroup_id`
  1820. ) VALUES (
  1821. ' . $objDatabase->SqlVariable($this->intId) . ',
  1822. ' . $objDatabase->SqlVariable($objUsergroup->Id) . '
  1823. )
  1824. ');
  1825. }
  1826. /**
  1827. * Unassociates a Usergroup
  1828. * @param Usergroup $objUsergroup
  1829. * @return void
  1830. */
  1831. public function UnassociateUsergroup(Usergroup $objUsergroup) {
  1832. if ((is_null($this->intId)))
  1833. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateUsergroup on this unsaved ContentItem.');
  1834. if ((is_null($objUsergroup->Id)))
  1835. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateUsergroup on this ContentItem with an unsaved Usergroup.');
  1836. // Get the Database Object for this Class
  1837. $objDatabase = ContentItem::GetDatabase();
  1838. // Perform the SQL Query
  1839. $objDatabase->NonQuery('
  1840. DELETE FROM
  1841. `content_item_usergroup_assn`
  1842. WHERE
  1843. `content_item_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  1844. `usergroup_id` = ' . $objDatabase->SqlVariable($objUsergroup->Id) . '
  1845. ');
  1846. }
  1847. /**
  1848. * Unassociates all Usergroups
  1849. * @return void
  1850. */
  1851. public function UnassociateAllUsergroups() {
  1852. if ((is_null($this->intId)))
  1853. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllUsergroupArray on this unsaved ContentItem.');
  1854. // Get the Database Object for this Class
  1855. $objDatabase = ContentItem::GetDatabase();
  1856. // Perform the SQL Query
  1857. $objDatabase->NonQuery('
  1858. DELETE FROM
  1859. `content_item_usergroup_assn`
  1860. WHERE
  1861. `content_item_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1862. ');
  1863. }
  1864. }
  1865. /////////////////////////////////////
  1866. // ADDITIONAL CLASSES for QCODO QUERY
  1867. /////////////////////////////////////
  1868. class QQNodeContentItemContentBlock extends QQAssociationNode {
  1869. protected $strType = 'association';
  1870. protected $strName = 'contentblock';
  1871. protected $strTableName = 'content_item_content_block_assn';
  1872. protected $strPrimaryKey = 'content_item_id';
  1873. protected $strClassName = 'ContentBlock';
  1874. public function __get($strName) {
  1875. switch ($strName) {
  1876. case 'ContentBlockId':
  1877. return new QQNode('content_block_id', 'ContentBlockId', 'integer', $this);
  1878. case 'ContentBlock':
  1879. return new QQNodeContentBlock('content_block_id', 'ContentBlockId', 'integer', $this);
  1880. case '_ChildTableNode':
  1881. return new QQNodeContentBlock('content_block_id', 'ContentBlockId', 'integer', $this);
  1882. default:
  1883. try {
  1884. return parent::__get($strName);
  1885. } catch (QCallerException $objExc) {
  1886. $objExc->IncrementOffset();
  1887. throw $objExc;
  1888. }
  1889. }
  1890. }
  1891. }
  1892. class QQNodeContentItemContentCategory extends QQAssociationNode {
  1893. protected $strType = 'association';
  1894. protected $strName = 'contentcategory';
  1895. protected $strTableName = 'content_item_content_category_assn';
  1896. protected $strPrimaryKey = 'content_item_id';
  1897. protected $strClassName = 'ContentCategory';
  1898. public function __get($strName) {
  1899. switch ($strName) {
  1900. case 'ContentCategoryId':
  1901. return new QQNode('content_category_id', 'ContentCategoryId', 'integer', $this);
  1902. case 'ContentCategory':
  1903. return new QQNodeContentCategory('content_category_id', 'ContentCategoryId', 'integer', $this);
  1904. case '_ChildTableNode':
  1905. return new QQNodeContentCategory('content_category_id', 'ContentCategoryId', 'integer', $this);
  1906. default:
  1907. try {
  1908. return parent::__get($strName);
  1909. } catch (QCallerException $objExc) {
  1910. $objExc->IncrementOffset();
  1911. throw $objExc;
  1912. }
  1913. }
  1914. }
  1915. }
  1916. class QQNodeContentItemUsergroup extends QQAssociationNode {
  1917. protected $strType = 'association';
  1918. protected $strName = 'usergroup';
  1919. protected $strTableName = 'content_item_usergroup_assn';
  1920. protected $strPrimaryKey = 'content_item_id';
  1921. protected $strClassName = 'Usergroup';
  1922. public function __get($strName) {
  1923. switch ($strName) {
  1924. case 'UsergroupId':
  1925. return new QQNode('usergroup_id', 'UsergroupId', 'integer', $this);
  1926. case 'Usergroup':
  1927. return new QQNodeUsergroup('usergroup_id', 'UsergroupId', 'integer', $this);
  1928. case '_ChildTableNode':
  1929. return new QQNodeUsergroup('usergroup_id', 'UsergroupId', 'integer', $this);
  1930. default:
  1931. try {
  1932. return parent::__get($strName);
  1933. } catch (QCallerException $objExc) {
  1934. $objExc->IncrementOffset();
  1935. throw $objExc;
  1936. }
  1937. }
  1938. }
  1939. }
  1940. class QQNodeContentItem extends QQNode {
  1941. protected $strTableName = 'content_item';
  1942. protected $strPrimaryKey = 'id';
  1943. protected $strClassName = 'ContentItem';
  1944. public function __get($strName) {
  1945. switch ($strName) {
  1946. case 'Id':
  1947. return new QQNode('id', 'Id', 'integer', $this);
  1948. case 'Name':
  1949. return new QQNode('name', 'Name', 'string', $this);
  1950. case 'Cssclass':
  1951. return new QQNode('cssclass', 'Cssclass', 'string', $this);
  1952. case 'Title':
  1953. return new QQNode('title', 'Title', 'string', $this);
  1954. case 'Description':
  1955. return new QQNode('description', 'Description', 'string', $this);
  1956. case 'Text':
  1957. return new QQNode('text', 'Text', 'string', $this);
  1958. case 'SortOrder':
  1959. return new QQNode('sort_order', 'SortOrder', 'integer', $this);
  1960. case 'ShowTitle':
  1961. return new QQNode('show_title', 'ShowTitle', 'boolean', $this);
  1962. case 'ShowDescription':
  1963. return new QQNode('show_description', 'ShowDescription', 'boolean', $this);
  1964. case 'ShowCreator':
  1965. return new QQNode('show_creator', 'ShowCreator', 'boolean', $this);
  1966. case 'ShowCreationDate':
  1967. return new QQNode('show_creation_date', 'ShowCreationDate', 'boolean', $this);
  1968. case 'ShowLastModification':
  1969. return new QQNode('show_last_modification', 'ShowLastModification', 'boolean', $this);
  1970. case 'CreatorId':
  1971. return new QQNode('creator_id', 'CreatorId', 'integer', $this);
  1972. case 'Creator':
  1973. return new QQNodePerson('creator_id', 'Creator', 'integer', $this);
  1974. case 'CopyrightNotice':
  1975. return new QQNode('copyright_notice', 'CopyrightNotice', 'string', $this);
  1976. case 'CreationDate':
  1977. return new QQNode('creation_date', 'CreationDate', 'string', $this);
  1978. case 'LastModification':
  1979. return new QQNode('last_modification', 'LastModification', 'string', $this);
  1980. case 'TypeId':
  1981. return new QQNode('type_id', 'TypeId', 'integer', $this);
  1982. case 'StatusId':
  1983. return new QQNode('status_id', 'StatusId', 'integer', $this);
  1984. case 'ContentBlock':
  1985. return new QQNodeContentItemContentBlock($this);
  1986. case 'ContentCategory':
  1987. return new QQNodeContentItemContentCategory($this);
  1988. case 'Usergroup':
  1989. return new QQNodeContentItemUsergroup($this);
  1990. case '_PrimaryKeyNode':
  1991. return new QQNode('id', 'Id', 'integer', $this);
  1992. default:
  1993. try {
  1994. return parent::__get($strName);
  1995. } catch (QCallerException $objExc) {
  1996. $objExc->IncrementOffset();
  1997. throw $objExc;
  1998. }
  1999. }
  2000. }
  2001. }
  2002. class QQReverseReferenceNodeContentItem extends QQReverseReferenceNode {
  2003. protected $strTableName = 'content_item';
  2004. protected $strPrimaryKey = 'id';
  2005. protected $strClassName = 'ContentItem';
  2006. public function __get($strName) {
  2007. switch ($strName) {
  2008. case 'Id':
  2009. return new QQNode('id', 'Id', 'integer', $this);
  2010. case 'Name':
  2011. return new QQNode('name', 'Name', 'string', $this);
  2012. case 'Cssclass':
  2013. return new QQNode('cssclass', 'Cssclass', 'string', $this);
  2014. case 'Title':
  2015. return new QQNode('title', 'Title', 'string', $this);
  2016. case 'Description':
  2017. return new QQNode('description', 'Description', 'string', $this);
  2018. case 'Text':
  2019. return new QQNode('text', 'Text', 'string', $this);
  2020. case 'SortOrder':
  2021. return new QQNode('sort_order', 'SortOrder', 'integer', $this);
  2022. case 'ShowTitle':
  2023. return new QQNode('show_title', 'ShowTitle', 'boolean', $this);
  2024. case 'ShowDescription':
  2025. return new QQNode('show_description', 'ShowDescription', 'boolean', $this);
  2026. case 'ShowCreator':
  2027. return new QQNode('show_creator', 'ShowCreator', 'boolean', $this);
  2028. case 'ShowCreationDate':
  2029. return new QQNode('show_creation_date', 'ShowCreationDate', 'boolean', $this);
  2030. case 'ShowLastModification':
  2031. return new QQNode('show_last_modification', 'ShowLastModification', 'boolean', $this);
  2032. case 'CreatorId':
  2033. return new QQNode('creator_id', 'CreatorId', 'integer', $this);
  2034. case 'Creator':
  2035. return new QQNodePerson('creator_id', 'Creator', 'integer', $this);
  2036. case 'CopyrightNotice':
  2037. return new QQNode('copyright_notice', 'CopyrightNotice', 'string', $this);
  2038. case 'CreationDate':
  2039. return new QQNode('creation_date', 'CreationDate', 'string', $this);
  2040. case 'LastModification':
  2041. return new QQNode('last_modification', 'LastModification', 'string', $this);
  2042. case 'TypeId':
  2043. return new QQNode('type_id', 'TypeId', 'integer', $this);
  2044. case 'StatusId':
  2045. return new QQNode('status_id', 'StatusId', 'integer', $this);
  2046. case 'ContentBlock':
  2047. return new QQNodeContentItemContentBlock($this);
  2048. case 'ContentCategory':
  2049. return new QQNodeContentItemContentCategory($this);
  2050. case 'Usergroup':
  2051. return new QQNodeContentItemUsergroup($this);
  2052. case '_PrimaryKeyNode':
  2053. return new QQNode('id', 'Id', 'integer', $this);
  2054. default:
  2055. try {
  2056. return parent::__get($strName);
  2057. } catch (QCallerException $objExc) {
  2058. $objExc->IncrementOffset();
  2059. throw $objExc;
  2060. }
  2061. }
  2062. }
  2063. }
  2064. ?>