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.

1103 lines
44 KiB

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