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.

1438 lines
61 KiB

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