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
00035 class Mage_Tag_Model_Mysql4_Tag_Relation extends Mage_Core_Model_Mysql4_Abstract
00036 {
00037 protected function _construct()
00038 {
00039 $this->_init('tag/relation', 'tag_relation_id');
00040 }
00041
00042 public function loadByTagCustomer($model)
00043 {
00044 if( $model->getTagId() && $model->getCustomerId() ) {
00045 $read = $this->_getReadAdapter();
00046 $select = $read->select();
00047
00048 $select->from($this->getMainTable())
00049 ->join($this->getTable('tag/tag'), "{$this->getTable('tag/tag')}.tag_id = {$this->getMainTable()}.tag_id")
00050 ->where("{$this->getMainTable()}.tag_id = ?", $model->getTagId())
00051 ->where('customer_id = ?', $model->getCustomerId());
00052
00053 if( $model->getProductId() ) {
00054 $select->where("{$this->getMainTable()}.product_id = ?", $model->getProductId());
00055 }
00056
00057 if( $model->hasStoreId() ) {
00058 $select->where("{$this->getMainTable()}.store_id = ?", $model->getStoreId());
00059 }
00060
00061 $data = $read->fetchRow($select);
00062 $model->setData( ( is_array($data) ) ? $data : array() );
00063 return $this;
00064 } else {
00065 return $this;
00066 }
00067 }
00068
00069 public function getProductIds($model)
00070 {
00071 $select = $this->_getReadAdapter()->select()
00072 ->from($this->getMainTable(), 'product_id')
00073 ->where("tag_id = ?", $model->getTagId())
00074 ->where('customer_id=?', $model->getCustomerId())
00075 ->where('active=1');
00076 if( $model->hasStoreId() ) {
00077 $select->where('store_id = ?', $model->getStoreId());
00078 }
00079 return $this->_getReadAdapter()->fetchCol($select);
00080 }
00081
00082 public function deactivate($tagId, $customerId)
00083 {
00084 $condition = $this->_getWriteAdapter()->quoteInto('tag_id = ?', $tagId) . ' AND ';
00085 $condition.= $this->_getWriteAdapter()->quoteInto('customer_id = ?', $customerId);
00086 $data = array('active'=>0);
00087 $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
00088 return $this;
00089 }
00090 }