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_Core_Model_Mysql4_Store_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00035 {
00036 protected $_loadDefault = false;
00037
00038 protected function _construct()
00039 {
00040 $this->_init('core/store');
00041 }
00042
00043 public function setLoadDefault($loadDefault)
00044 {
00045 $this->_loadDefault = $loadDefault;
00046 return $this;
00047 }
00048
00049 public function getLoadDefault()
00050 {
00051 return $this->_loadDefault;
00052 }
00053
00054 public function setWithoutDefaultFilter()
00055 {
00056 $this->getSelect()->where($this->getConnection()->quoteInto('main_table.store_id>?', 0));
00057 return $this;
00058 }
00059
00060 public function addGroupFilter($groupId)
00061 {
00062 $condition = $this->getConnection()->quoteInto("main_table.group_id=?", $groupId);
00063 $this->addFilter('group_id', $condition, 'string');
00064 return $this;
00065 }
00066
00067 public function addIdFilter($store)
00068 {
00069 if (is_array($store)) {
00070 $condition = $this->getConnection()->quoteInto("main_table.store_id IN (?)", $store);
00071 }
00072 else {
00073 $condition = $this->getConnection()->quoteInto("main_table.store_id=?",$store);
00074 }
00075
00076 $this->addFilter('store_id', $condition, 'string');
00077 return $this;
00078 }
00079
00080 public function addWebsiteFilter($website)
00081 {
00082 if (is_array($website)) {
00083 $condition = $this->getConnection()->quoteInto("main_table.website_id IN (?)", $website);
00084 }
00085 else {
00086 $condition = $this->getConnection()->quoteInto("main_table.website_id=?",$website);
00087 }
00088
00089 $this->addFilter('website_id', $condition, 'string');
00090 return $this;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099 public function addCategoryFilter($category)
00100 {
00101 if (!is_array($category)) {
00102 $category = array($category);
00103 }
00104 return $this->loadByCategoryIds($category);
00105 }
00106
00107 public function toOptionArray()
00108 {
00109 return $this->_toOptionArray('store_id', 'name');
00110 }
00111
00112 public function toOptionHash()
00113 {
00114 return $this->_toOptionHash('store_id', 'name');
00115 }
00116
00117 public function load($printQuery = false, $logQuery = false)
00118 {
00119 if (!$this->getLoadDefault()) {
00120 $this->getSelect()->where($this->getConnection()->quoteInto('main_table.store_id>?', 0));
00121 }
00122 $this->addOrder('CASE WHEN main_table.store_id = 0 THEN 0 ELSE 1 END', 'ASC')
00123 ->addOrder('main_table.sort_order', 'ASC')
00124 ->addOrder('main_table.name', 'ASC');
00125 parent::load($printQuery, $logQuery);
00126 return $this;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 public function loadByCategoryIds(array $categories)
00136 {
00137 $this->setLoadDefault(true);
00138 $condition = $this->getConnection()->quoteInto('group_table.root_category_id IN(?)', $categories);
00139 $this->_select->joinLeft(
00140 array('group_table' => $this->getTable('core/store_group')),
00141 'main_table.group_id=group_table.group_id',
00142 array('root_category_id')
00143 )->where($condition);
00144
00145 return $this;
00146 }
00147
00148 public function addRootCategoryIdAttribute()
00149 {
00150 $this->_select->joinLeft(
00151 array('group_table' => $this->getTable('core/store_group')),
00152 'main_table.group_id=group_table.group_id',
00153 array('root_category_id')
00154 );
00155 return $this;
00156 }
00157 }