Mage_Catalog_Model_Design Class Reference

Inheritance diagram for Mage_Catalog_Model_Design:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 applyDesign ($object, $calledFrom=0)

Public Attributes

const APPLY_FOR_PRODUCT = 1
const APPLY_FOR_CATEGORY = 2
const CATEGORY_APPLY_CATEGORY_AND_PRODUCT_RECURSIVE = 1
const CATEGORY_APPLY_CATEGORY_ONLY = 2
const CATEGORY_APPLY_CATEGORY_AND_PRODUCT_ONLY = 3
const CATEGORY_APPLY_CATEGORY_RECURSIVE = 4

Protected Member Functions

 _apply ($package, $theme)
 _isApplyFor ($applyForObject, $applyTo, $pass=0)
 _isApplyDesign ($design, array $date)
 _applyDesignRecursively ($object, $calledFrom=0, $pass=0)
 _applyDesign ($designUpdateData, $calledFrom=0, $loaded=false, $pass=0)


Detailed Description

Definition at line 35 of file Design.php.


Member Function Documentation

_apply ( package,
theme 
) [protected]

Apply package and theme

Parameters:
string $package
string $theme

Definition at line 77 of file Design.php.

00078     {
00079         Mage::getSingleton('core/design_package')
00080             ->setPackageName($package)
00081             ->setTheme($theme);
00082     }

_applyDesign ( designUpdateData,
calledFrom = 0,
loaded = false,
pass = 0 
) [protected]

Apply design (if using Flat Category)

Parameters:
Varien_Object|array $designUpdateData
int $calledFrom
bool $loaded
Returns:
Mage_Catalog_Model_Design

Definition at line 215 of file Design.php.

00216     {
00217         $objects = array();
00218         if (is_object($designUpdateData)) {
00219             $objects = array($designUpdateData);
00220         } elseif (is_array($designUpdateData)) {
00221             $objects = &$designUpdateData;
00222         }
00223         foreach ($objects as $object) {
00224             $design     = $object->getCustomDesign();
00225             $date       = $object->getCustomDesignDate();
00226             $applyTo    = $object->getCustomDesignApply();
00227 
00228             $checkAndApply = $this->_isApplyFor($calledFrom, $applyTo, $pass)
00229                 && $this->_isApplyDesign($design, $date);
00230             if ($checkAndApply) {
00231                 return $this;
00232             }
00233         }
00234 
00235         $pass ++;
00236 
00237         if (false === $loaded && is_object($designUpdateData)) {
00238             $_designUpdateData = array();
00239             if ($designUpdateData instanceof Mage_Catalog_Model_Product) {
00240                 $_category = $designUpdateData->getCategory();
00241                 $_designUpdateData = array_merge(
00242                     $_designUpdateData, array($_category)
00243                 );
00244                 $pass --;
00245             } elseif ($designUpdateData instanceof Mage_Catalog_Model_Category) {
00246                 $_category = &$designUpdateData;
00247             }
00248             if ($_category && $_category->getId()) {
00249                 $_designUpdateData = array_merge(
00250                     $_designUpdateData,
00251                     $_category->getResource()->getDesignUpdateData($_category)
00252                 );
00253                 $this->_applyDesign($_designUpdateData, $calledFrom, true, $pass);
00254             }
00255         }
00256         return $this;
00257     }

_applyDesignRecursively ( object,
calledFrom = 0,
pass = 0 
) [protected]

Apply design recursively (if using EAV)

Parameters:
Varien_Object $object
int $calledFrom
Returns:
Mage_Catalog_Model_Design

Definition at line 177 of file Design.php.

00178     {
00179         $design     = $object->getCustomDesign();
00180         $date       = $object->getCustomDesignDate();
00181         $applyTo    = $object->getCustomDesignApply();
00182 
00183         $checkAndApply = $this->_isApplyFor($calledFrom, $applyTo, $pass)
00184             && $this->_isApplyDesign($design, $date);
00185         if ($checkAndApply) {
00186             return $this;
00187         }
00188 
00189         $pass ++;
00190 
00191         $category = null;
00192         if ($object instanceof Mage_Catalog_Model_Product) {
00193             $category = $object->getCategory();
00194             $pass --;
00195         }
00196         elseif ($object instanceof Mage_Catalog_Model_Category) {
00197             $category = $object->getParentCategory();
00198         }
00199 
00200         if ($category && $category->getId()){
00201             $this->_applyDesignRecursively($category, $calledFrom, $pass);
00202         }
00203 
00204         return $this;
00205     }

_isApplyDesign ( design,
array date 
) [protected]

Check and apply design

Parameters:
string $design
array $date

Definition at line 146 of file Design.php.

00147     {
00148         if (!array_key_exists('from', $date) || !array_key_exists('to', $date)) {
00149             return false;
00150         }
00151 
00152         $designInfo = explode("/", $design);
00153         if (count($designInfo) != 2) {
00154             return false;
00155         }
00156 
00157         // define package and theme
00158         $package    = $designInfo[0];
00159         $theme      = $designInfo[1];
00160 
00161         // compare dates
00162         if (Mage::app()->getLocale()->IsStoreDateInInterval(null, $date['from'], $date['to'])) {
00163             $this->_apply($package, $theme);
00164             return true;
00165         }
00166 
00167         return false;
00168     }

_isApplyFor ( applyForObject,
applyTo,
pass = 0 
) [protected]

Check is allow apply for

Parameters:
int $applyForObject
int $applyTo
int $pass
Returns:
bool

Definition at line 92 of file Design.php.

00093     {
00094         $hasError = false;
00095         if ($pass == 0) {
00096             switch ($applyForObject) {
00097                 case self::APPLY_FOR_CATEGORY:
00098                     break;
00099                 case self::APPLY_FOR_PRODUCT:
00100                     $validApplyTo = array(
00101                         self::CATEGORY_APPLY_CATEGORY_AND_PRODUCT_RECURSIVE,
00102                         self::CATEGORY_APPLY_CATEGORY_AND_PRODUCT_ONLY
00103                     );
00104                     if ($applyTo && !in_array($applyTo, $validApplyTo)) {
00105                         $hasError = true;
00106                     }
00107                     break;
00108                 default:
00109                     $hasError = true;
00110                     break;
00111             }
00112         }
00113         else {
00114             switch ($applyForObject) {
00115                 case self::APPLY_FOR_CATEGORY:
00116                     $validApplyTo = array(
00117                         self::CATEGORY_APPLY_CATEGORY_AND_PRODUCT_RECURSIVE,
00118                         self::CATEGORY_APPLY_CATEGORY_RECURSIVE
00119                     );
00120                     if ($applyTo && !in_array($applyTo, $validApplyTo)) {
00121                         $hasError = true;
00122                     }
00123                     break;
00124                 case self::APPLY_FOR_PRODUCT:
00125                     $validApplyTo = array(
00126                         self::CATEGORY_APPLY_CATEGORY_AND_PRODUCT_RECURSIVE
00127                     );
00128                     if ($applyTo && !in_array($applyTo, $validApplyTo)) {
00129                         $hasError = true;
00130                     }
00131                     break;
00132                 default:
00133                     $hasError = true;
00134                     break;
00135             }
00136         }
00137         return !$hasError;
00138     }

applyDesign ( object,
calledFrom = 0 
)

Apply design from catalog object

Parameters:
array|Mage_Catalog_Model_Category|Mage_Catalog_Model_Product $object
int $calledFrom
Returns:
Mage_Catalog_Model_Design

Definition at line 56 of file Design.php.

00057     {
00058         if ($calledFrom != self::APPLY_FOR_CATEGORY && $calledFrom != self::APPLY_FOR_PRODUCT) {
00059             return $this;
00060         }
00061 
00062         if (Mage::helper('catalog/category_flat')->isEnabled()) {
00063             $this->_applyDesign($object, $calledFrom);
00064         } else {
00065             $this->_applyDesignRecursively($object, $calledFrom);
00066         }
00067 
00068         return $this;
00069     }


Member Data Documentation

const APPLY_FOR_CATEGORY = 2

Definition at line 38 of file Design.php.

const APPLY_FOR_PRODUCT = 1

Definition at line 37 of file Design.php.

Definition at line 46 of file Design.php.

Category / Custom Design / Apply To constants

Definition at line 44 of file Design.php.

Definition at line 45 of file Design.php.

Definition at line 47 of file Design.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:38 2009 for Magento by  doxygen 1.5.8