Mage_GoogleOptimizer_Model_Mysql4_Code Class Reference

Inheritance diagram for Mage_GoogleOptimizer_Model_Mysql4_Code:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 loadbyEntityType ($object, $storeId)
 deleteByEntityType ($object, $store_id)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 34 of file Code.php.


Member Function Documentation

_construct (  )  [protected]

Resource initialization

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 36 of file Code.php.

00037     {
00038         $this->_init('googleoptimizer/code', 'code_id');
00039     }

deleteByEntityType ( object,
store_id 
)

Delete scripts by entity and store

Parameters:
Mage_GoogleOptimizer_Model_Code $object
integer $store_id
Returns:
Mage_GoogleOptimizer_Model_Mysql4_Code

Definition at line 92 of file Code.php.

00093     {
00094         $write = $this->_getWriteAdapter();
00095         if ($write) {
00096             $entityIds = $object->getEntityIds();
00097             if (!empty($entityIds)) {
00098                 $where = $write->quoteInto($this->getMainTable().'.entity_id IN (?)', $entityIds);
00099             } else {
00100                 $where = $write->quoteInto($this->getMainTable().'.entity_id=?', $object->getEntity()->getId());
00101             }
00102             $where.= ' AND ' . $write->quoteInto($this->getMainTable().'.entity_type=?', $object->getEntityType()) .
00103                 ' AND ' . $write->quoteInto($this->getMainTable().'.store_id=?', $store_id);
00104             $write->delete($this->getMainTable(), $where);
00105         }
00106 
00107         $this->_afterDelete($object);
00108         return $this;
00109     }

loadbyEntityType ( object,
storeId 
)

Load scripts by entity and store

Parameters:
Mage_GoogleOptimizer_Model_Code $object
integer $storeId
Returns:
Mage_GoogleOptimizer_Model_Mysql4_Code

Definition at line 48 of file Code.php.

00049     {
00050         $read = $this->_getReadAdapter();
00051         if ($read) {
00052             //preapre colums to fetch, except scope columns
00053             $_columns = array_keys($read->describeTable($this->getMainTable()));
00054             $columnsToFetch = array();
00055             foreach ($_columns as $_column) {
00056                 if (in_array($_column, array('entity_id', 'entity_type'))) {
00057                     $columnsToFetch[] = $_column;
00058                 }
00059             }
00060             $select = $read->select()
00061                 ->from(array('_default_table' => $this->getMainTable()), $columnsToFetch)
00062                 ->joinLeft(array('_store_table' => $this->getMainTable()),
00063                     "_store_table.entity_id = _default_table.entity_id AND _store_table.entity_type = _default_table.entity_type AND _store_table.store_id = {$storeId}",
00064                     array('code_id' => new Zend_Db_Expr("IFNULL(_store_table.code_id, _default_table.code_id)"),
00065                         'store_id' => new Zend_Db_Expr("IFNULL(_store_table.store_id, _default_table.store_id)"),
00066                         'control_script' => new Zend_Db_Expr("IFNULL(_store_table.control_script, _default_table.control_script)"),
00067                         'tracking_script' => new Zend_Db_Expr("IFNULL(_store_table.tracking_script, _default_table.tracking_script)"),
00068                         'conversion_script' => new Zend_Db_Expr("IFNULL(_store_table.conversion_script, _default_table.conversion_script)"),
00069                         'conversion_page' => new Zend_Db_Expr("IFNULL(_store_table.conversion_page, _default_table.conversion_page)"),
00070                         'additional_data' => new Zend_Db_Expr("IFNULL(_store_table.additional_data, _default_table.additional_data)")))
00071                 ->where('_default_table.entity_id=?', $object->getEntity()->getId())
00072                 ->where('_default_table.entity_type=?', $object->getEntityType())
00073                 ->where('_default_table.store_id IN (0, ?)', $storeId)
00074                 ->order('_default_table.store_id DESC')
00075                 ->limit(1);
00076             $data = $read->fetchRow($select);
00077             if ($data) {
00078                 $object->setData($data);
00079             }
00080         }
00081         $this->_afterLoad($object);
00082         return $this;
00083     }


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

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