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.

1143 lines
46 KiB

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