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.

170 lines
6.0 KiB

12 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("PRODUCTDISPLAYMODULE.CLASS.PHP")){
  4. define("PRODUCTDISPLAYMODULE.CLASS.PHP",1);
  5. /**
  6. * Class ProductDisplayModule - A managing module for views of products by list and by item
  7. *
  8. *
  9. * This module provides the center or main panel for display of products in the database. It
  10. * utilizes two main panels to do this, one a list of products and one an individual product view.
  11. * See ListModuleBase for more on the internals.
  12. *
  13. *
  14. *@author Erik Winn <erikwinnmail@yahoo.com>
  15. *
  16. *
  17. * $Id: ProductDisplayModule.class.php 410 2008-12-09 20:43:20Z erikwinn $
  18. *@version 0.1
  19. *
  20. *@copyright (C) 2008 by Erik Winn
  21. *@license GPL v.2
  22. This program is free software; you can redistribute it and/or modify
  23. it under the terms of the GNU General Public License as published by
  24. the Free Software Foundation; either version 2 of the License, or
  25. (at your option) any later version.
  26. This program is distributed in the hope that it will be useful,
  27. but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. GNU General Public License for more details.
  30. You should have received a copy of the GNU General Public License
  31. along with this program; if not, write to the Free Software
  32. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  33. *
  34. *@package Quasi
  35. * @subpackage Modules
  36. */
  37. class ProductDisplayModule extends ListModuleBase
  38. {
  39. private $strViewMode = 'None';
  40. private $intProductId = null;
  41. private $intProductCount = 0;
  42. private $objProductListView = null;
  43. private $objProductItemView = null;
  44. /**
  45. * Module constructor
  46. * NOTE: This module ignores the required extra parameters ..
  47. *@param ContentBlock - parent controller object.
  48. *@param mixed - extra parameters, ignored
  49. */
  50. public function __construct( ContentBlockView $objParentObject, $mixParameters=null)
  51. {
  52. //Parent should always be a ContentBlockView
  53. $this->objParentObject =& $objParentObject;
  54. try {
  55. parent::__construct($this->objParentObject);
  56. } catch (QCallerException $objExc) {
  57. $objExc->IncrementOffset();
  58. throw $objExc;
  59. }
  60. $this->AutoRenderChildren = true;
  61. // $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/ProductDisplayModule.tpl.php';
  62. $this->countProducts();
  63. $this->createDisplay();
  64. }
  65. private function countProducts()
  66. {
  67. ///@todo implement display by Model for pretty urls ..
  68. ///@todo check permissions here - stop on failure. redirect or limit the count to permissable ...
  69. $this->intProductCount = 0;
  70. $strParams = urldecode(IndexPage::$strPageParameters);
  71. $aryParameters = explode('/', $strParams);
  72. //really we are only concerned with the last parameter as this is the
  73. // category of items to be listed ..
  74. $strParam = array_pop($aryParameters);
  75. if(! $strParam)
  76. {
  77. $this->intProductCount = Product::CountAll();
  78. $this->strViewMode = 'List';
  79. }
  80. //last part may also be a product id
  81. elseif( is_numeric($strParam) )
  82. {
  83. $objProduct = Product::Load($strParam);
  84. if( $objProduct instanceof Product)
  85. {
  86. $this->intProductId = $strParam;
  87. $this->intProductCount = 1;
  88. $this->strViewMode = 'Item';
  89. }
  90. else
  91. {
  92. $this->intProductCount = 0;
  93. $this->intProductId = null;
  94. }
  95. }
  96. //otherwise, it must be a category ..
  97. else
  98. {
  99. $objCategory = ProductCategory::LoadByName($strParam);
  100. if($objCategory)
  101. $this->intProductCount = Product::CountByProductCategoryAsCategory( $objCategory->Id );
  102. }
  103. }
  104. private function createDisplay()
  105. {
  106. if( $this->intProductCount > 1 )
  107. {
  108. $this->strViewMode = 'List';
  109. if(!$this->objProductListView)
  110. $this->objProductListView = new ProductListView( $this->pnlListView, $this, 'ShowItemPanel', 'CloseItemPanel' );
  111. $this->pnlListView->Visible = true;
  112. }
  113. else
  114. {
  115. $this->strViewMode = 'Item';
  116. new ProductItemView( $this->pnlItemView, $this, 'CloseItemPanel', $this->intProductId );
  117. $this->pnlItemView->Visible = true;
  118. }
  119. }
  120. //Overrides the parent to ensure that the list view is populated
  121. public function CloseItemPanel($blnUpdatesMade)
  122. {
  123. if(!$this->objProductListView)
  124. $this->objProductListView = new ProductListView( $this->pnlListView, $this, 'ShowItemPanel', 'CloseItemPanel' );
  125. parent::CloseItemPanel($blnUpdatesMade);
  126. }
  127. public function __get($strName)
  128. {
  129. switch ($strName)
  130. {
  131. default:
  132. try {
  133. return parent::__get($strName);
  134. } catch (QCallerException $objExc) {
  135. $objExc->IncrementOffset();
  136. throw $objExc;
  137. }
  138. }
  139. }
  140. public function __set($strName, $mixValue)
  141. {
  142. switch ($strName)
  143. {
  144. default:
  145. try {
  146. return (parent::__set($strName, $mixValue));
  147. } catch (QCallerException $objExc) {
  148. $objExc->IncrementOffset();
  149. throw $objExc;
  150. }
  151. }
  152. }
  153. }//end class
  154. }//end define
  155. ?>