00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_GoogleOptimizer_Model_Mysql4_Code extends Mage_Core_Model_Mysql4_Abstract
00035 {
00036 protected function _construct()
00037 {
00038 $this->_init('googleoptimizer/code', 'code_id');
00039 }
00040
00041
00042
00043
00044
00045
00046
00047
00048 public function loadbyEntityType($object, $storeId)
00049 {
00050 $read = $this->_getReadAdapter();
00051 if ($read) {
00052
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 }
00084
00085
00086
00087
00088
00089
00090
00091
00092 public function deleteByEntityType($object, $store_id)
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 }
00110 }