Mage_GoogleOptimizer_Model_Code Class Reference

Inheritance diagram for Mage_GoogleOptimizer_Model_Code:

Mage_Core_Model_Abstract Varien_Object Mage_GoogleOptimizer_Model_Code_Category Mage_GoogleOptimizer_Model_Code_Page Mage_GoogleOptimizer_Model_Code_Product

List of all members.

Public Member Functions

 setEntity (Varien_Object $entity)
 getEntity ()
 getEntityType ()
 loadScripts ($storeId)
 saveScripts ($storeId)
 deleteScripts ($storeId)

Protected Member Functions

 _construct ()
 _validate ()

Protected Attributes

 $_entity = null
 $_entityType = null
 $_validateEntryFlag = false
 $_scriptTypes = array('control', 'tracking', 'conversion')


Detailed Description

Definition at line 34 of file Code.php.


Member Function Documentation

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 41 of file Code.php.

00042     {
00043         parent::_construct();
00044         $this->_init('googleoptimizer/code');
00045     }

_validate (  )  [protected]

Validate sctipts that assigned on entity

Returns:
bool

Reimplemented in Mage_GoogleOptimizer_Model_Code_Page, and Mage_GoogleOptimizer_Model_Code_Product.

Definition at line 105 of file Code.php.

00106     {
00107         $entryFlag = false;
00108         $validationResult = false;
00109         if ($control = $this->getControlScript()) {
00110             $entryFlag = true;
00111         }
00112         if ($tracking = $this->getTrackingScript()) {
00113             $entryFlag = true;
00114         }
00115         if ($conversion = $this->getConversionScript()) {
00116             $entryFlag = true;
00117         }
00118         if ($conversionPage = $this->getConversionPage()) {
00119             $entryFlag = true;
00120         }
00121         $this->_validateEntryFlag = $entryFlag;
00122         if ($entryFlag && (!$control || !$tracking || !$conversion || !$conversionPage)) {
00123             return false;
00124         }
00125         return true;
00126     }

deleteScripts ( storeId  ) 

Removing scripts assigned to entity

Parameters:
integer $storeId
Returns:
Mage_Googleoptimizer_Model_Code

Reimplemented in Mage_GoogleOptimizer_Model_Code_Category.

Definition at line 175 of file Code.php.

00176     {
00177         if (is_null($this->getEntity()) || is_null($this->getEntityType())) {
00178             return $this;
00179         }
00180         $this->getResource()->deleteByEntityType($this, $storeId);
00181         return $this;
00182     }

getEntity (  ) 

Return entity

Returns:
unknown

Definition at line 64 of file Code.php.

00065     {
00066         return $this->_entity;
00067     }

getEntityType (  ) 

Return entity type (product|category|...etc)

Returns:
string

Definition at line 74 of file Code.php.

00075     {
00076         return $this->_entityType;
00077     }

loadScripts ( storeId  ) 

Loading scripts and assigning scripts on entity

Parameters:
Varien_Object $entity
Returns:
Mage_Googleoptimizer_Model_Code

Definition at line 85 of file Code.php.

00086     {
00087         if (is_null($this->getEntity()) || is_null($this->getEntityType())) {
00088             return $this;
00089         }
00090 
00091         if (!$storeId) {
00092             $storeId = Mage::app()->getStore()->getId();
00093         }
00094 
00095         $this->getResource()->loadByEntityType($this, $storeId);
00096         $this->_afterLoad();
00097         return $this;
00098     }

saveScripts ( storeId  ) 

Save scripts assigned on entity

Parameters:
Varien_Object $entity
Returns:
Mage_Googleoptimizer_Model_Code

We can't modify store id if existing stcript

Definition at line 134 of file Code.php.

00135     {
00136         if (is_null($this->getEntity()) || is_null($this->getEntityType())) {
00137             return $this;
00138         }
00139         if (!$this->getEntity()->getGoogleOptimizerScripts()) {
00140             return $this;
00141         }
00142         $script = $this->getEntity()->getGoogleOptimizerScripts();
00143 
00144         $this->setData($script->getData())
00145             ->setEntityId($this->getEntity()->getId())
00146             ->setEntityType($this->getEntityType());
00147 
00148         /**
00149          * We can't modify store id if existing stcript
00150          */
00151         if (!$script->getId()) {
00152             $this->setStoreId($storeId);
00153         }
00154 
00155         if (false === $this->_validate()) {
00156             throw new Exception(Mage::helper('googleoptimizer')->__('All fields of script types have to be filled.'));
00157         }
00158 
00159         // use default scripts, need to delete scripts for current store
00160         if ($this->getStoreFlag()) {
00161             $this->deleteScripts($storeId);
00162             return $this;
00163         }
00164 
00165         $this->save();
00166         return $this;
00167     }

setEntity ( Varien_Object entity  ) 

Set entity

Parameters:
Varien_Object $entity
Returns:
Mage_GoogleOptimizer_Model_Code

Definition at line 53 of file Code.php.

00054     {
00055         $this->_entity = $entity;
00056         return $this;
00057     }


Member Data Documentation

$_entity = null [protected]

Definition at line 36 of file Code.php.

$_entityType = null [protected]

$_scriptTypes = array('control', 'tracking', 'conversion') [protected]

Definition at line 39 of file Code.php.

$_validateEntryFlag = false [protected]

Definition at line 38 of file Code.php.


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

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