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.

1144 lines
47 KiB

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