A Qcodo based CMS/ecommerce framework
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.

257 lines
9.6 KiB

12 years ago
  1. <?php
  2. /**
  3. * This file is a part of Quasi CMS
  4. *@package Quasi
  5. */
  6. if(!defined('QUASICMS') ) die('No Quasi.');
  7. if (!defined("PRODUCTIMAGELABEL.CLASS.PHP")){
  8. define("PRODUCTIMAGELABEL.CLASS.PHP",1);
  9. /**
  10. * Class ProductImageLabel - class to display Product images
  11. * This class queries the ProductImage table for an image associated with the given
  12. * Product - it returns a QControl that displays the image. If no image is found it
  13. * defaults to showing "default_product.png". The default size is Small and height
  14. * and width are either set from the ProductImage if possible or left unspecified.
  15. *
  16. * All attributes except Product Id can be manually set - ProductId must be passed
  17. * to the constructor
  18. *
  19. *@author Erik Winn <erikwinnmail@yahoo.com>
  20. *
  21. * $Id: ProductImageLabel.class.php 272 2008-10-08 15:40:08Z erikwinn $
  22. *@version 0.1
  23. *
  24. *@copyright (C) 2008 by Erik Winn
  25. *@license GPL v.2
  26. This program is free software; you can redistribute it and/or modify
  27. it under the terms of the GNU General Public License as published by
  28. the Free Software Foundation; either version 2 of the License, or
  29. (at your option) any later version.
  30. This program is distributed in the hope that it will be useful,
  31. but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. GNU General Public License for more details.
  34. You should have received a copy of the GNU General Public License
  35. along with this program; if not, write to the Free Software
  36. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  37. *
  38. *@package Quasi
  39. * @subpackage CMS
  40. */
  41. class ProductImageLabel extends QControl
  42. {
  43. /**
  44. *@var Product member object
  45. */
  46. protected $objProduct;
  47. /**
  48. *@var string strImageUri - URI for the image to display
  49. */
  50. protected $strImageUri;
  51. /**
  52. *@var string strAlternateText - ALT text for the image to display
  53. */
  54. protected $strAlternateText;
  55. /**
  56. *@var integer intHeight - image height in pixels
  57. */
  58. protected $intHeight;
  59. /**
  60. *@var integer intWidth - image width in pixels
  61. */
  62. protected $intWidth;
  63. /**
  64. *@var integer intSizeType - the ImageSizeType of image to look for: Icon, Thumb, Small, Large ..etc.
  65. */
  66. protected $intSizeType = ImageSizeType::Small;
  67. /**
  68. * ProductImageLabel Constructor
  69. *
  70. * @param QControl objParentObject - the parent of this control
  71. * @param integer intProductId - id of the product for which the image is displayed
  72. * @param integer intSizeType - optional ImageSizeType flag (Small, Large, etc..)
  73. * @param integer intHeight - optional height specification
  74. * @param integer intWidth - optional width specification
  75. * @param string strControlId - optional string to use as CSS Id
  76. */
  77. public function __construct($objParentObject,
  78. $intProductId,
  79. $intSizeType = null,
  80. $intHeight = null,
  81. $intWidth = null,
  82. $strControlId = null)
  83. {
  84. try {
  85. parent::__construct($objParentObject, $strControlId);
  86. } catch (QCallerException $objExc) {
  87. $objExc->IncrementOffset();
  88. throw $objExc;
  89. }
  90. if($intSizeType)
  91. $this->intSizeType = $intSizeType;
  92. else
  93. $this->intSizeType = ImageSizeType::Small;
  94. $aryImages = ProductImage::QueryArray( QQ::AndCondition(
  95. QQ::Equal( QQN::ProductImage()->ProductId, $intProductId ),
  96. QQ::Equal( QQN::ProductImage()->SizeType, $this->intSizeType )
  97. ));
  98. $this->strImageUri = __QUASI_SUBDIRECTORY__;
  99. ///@todo we take the first image of size type - allow specification of which image if more than one
  100. if( is_array($aryImages) && ! empty($aryImages))
  101. {
  102. $objProductImage = $aryImages[0];
  103. if($intHeight)
  104. $this->intHeight = $intHeight;
  105. elseif( $objProductImage->XSize )
  106. $this->intHeight = $objProductImage->XSize;
  107. if($intWidth)
  108. $this->intWidth = $intWidth;
  109. elseif( $objProductImage->YSize )
  110. $this->intWidth = $objProductImage->YSize;
  111. $strFileUri = $objProductImage->Uri;
  112. if( file_exists( __QUASI_ROOT__ . $strFileUri ) )
  113. $this->strImageUri .= $strFileUri;
  114. else
  115. $this->strImageUri .= "/core/assets/images/default_product.png";
  116. }
  117. else
  118. {
  119. if($intHeight)
  120. $this->intHeight = $intHeight;
  121. if($intWidth)
  122. $this->intWidth = $intWidth;
  123. $this->strImageUri .= "/core/assets/images/default_product.png";
  124. }
  125. }
  126. public function GetJavaScriptAction() {return "onclick";}
  127. public function Validate() {return true;}
  128. public function ParsePostData(){}
  129. public function GetAttributes($blnIncludeCustom = true, $blnIncludeAction = true)
  130. {
  131. $strToReturn = parent::GetAttributes($blnIncludeCustom, $blnIncludeAction);
  132. if ($this->strAlternateText)
  133. $strToReturn .= sprintf('alt="%s" ', $this->strAlternateText);
  134. if ($this->strImageUri)
  135. $strToReturn .= sprintf('src="%s" ', $this->strImageUri);
  136. if ($this->intHeight)
  137. $strToReturn .= sprintf('height="%s" ', $this->intHeight);
  138. if ($this->strWidth)
  139. $strToReturn .= sprintf('width="%s" ', $this->intWidth);
  140. return $strToReturn;
  141. }
  142. protected function GetControlHtml()
  143. {
  144. $strStyle = $this->GetStyleAttributes();
  145. if ($strStyle)
  146. $strStyle = sprintf('style="%s"', $strStyle);
  147. $strToReturn = sprintf('<img name="%s" id="%s" %s%s />',
  148. $this->strControlId,
  149. $this->strControlId,
  150. $this->GetAttributes(),
  151. $strStyle);
  152. return $strToReturn;
  153. }
  154. public function __get($strName)
  155. {
  156. switch ($strName)
  157. {
  158. case 'Product':
  159. return $this->objProduct ;
  160. case 'ImageUri':
  161. return $this->strImageUri ;
  162. case 'AlternateText':
  163. return $this->strAlternateText ;
  164. case 'Height':
  165. return $this->intHeight ;
  166. case 'Width':
  167. return $this->intWidth ;
  168. default:
  169. try {
  170. return parent::__get($strName);
  171. } catch (QCallerException $objExc) {
  172. $objExc->IncrementOffset();
  173. throw $objExc;
  174. }
  175. }
  176. }
  177. public function __set($strName, $mixValue)
  178. {
  179. switch ($strName)
  180. {
  181. case 'Product':
  182. try {
  183. return ($this->objProduct = QType::Cast($mixValue, 'Product' ));
  184. } catch (QInvalidCastException $objExc) {
  185. $objExc->IncrementOffset();
  186. throw $objExc;
  187. }
  188. case 'ImageUri':
  189. try {
  190. return ($this->strImageUri = QType::Cast($mixValue, QType::String ));
  191. } catch (QInvalidCastException $objExc) {
  192. $objExc->IncrementOffset();
  193. throw $objExc;
  194. }
  195. case 'AlternateText':
  196. try {
  197. return ($this->strAlternateText = QType::Cast($mixValue, QType::String ));
  198. } catch (QInvalidCastException $objExc) {
  199. $objExc->IncrementOffset();
  200. throw $objExc;
  201. }
  202. case 'Height':
  203. try {
  204. return ($this->intHeight = QType::Cast($mixValue, QType::Integer ));
  205. } catch (QInvalidCastException $objExc) {
  206. $objExc->IncrementOffset();
  207. throw $objExc;
  208. }
  209. case 'Width':
  210. try {
  211. return ($this->intWidth = QType::Cast($mixValue, QType::Integer ));
  212. } catch (QInvalidCastException $objExc) {
  213. $objExc->IncrementOffset();
  214. throw $objExc;
  215. }
  216. default:
  217. try {
  218. return (parent::__set($strName, $mixValue));
  219. } catch (QCallerException $objExc) {
  220. $objExc->IncrementOffset();
  221. throw $objExc;
  222. }
  223. }
  224. }
  225. }//end class
  226. }//end define
  227. ?>