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.

1102 lines
44 KiB

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