1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Checkout
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Resource Model for Agreement Collection
30: *
31: * @category Mage
32: * @package Mage_Checkout
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Checkout_Model_Resource_Agreement_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: protected $_map = array('fields' => array(
38: 'agreement_id' => 'main_table.agreement_id',
39: ));
40:
41: /**
42: * Is store filter with admin store
43: *
44: * @var bool
45: */
46: protected $_isStoreFilterWithAdmin = true;
47:
48: /**
49: * Initialize resource
50: *
51: */
52: protected function _construct()
53: {
54: $this->_init('checkout/agreement');
55: }
56:
57: /**
58: * Filter collection by specified store ids
59: *
60: * @param int|Mage_Core_Model_Store $store
61: * @return Mage_Checkout_Model_Resource_Agreement_Collection
62: */
63: public function addStoreFilter($store)
64: {
65: // check and prepare data
66: if ($store instanceof Mage_Core_Model_Store) {
67: $store = array($store->getId());
68: } elseif (is_numeric($store)) {
69: $store = array($store);
70: }
71:
72: $alias = 'store_table_' . implode('_', $store);
73: if ($this->getFlag($alias)) {
74: return $this;
75: }
76:
77: $storeFilter = array($store);
78: if ($this->_isStoreFilterWithAdmin) {
79: $storeFilter[] = 0;
80: }
81:
82: // add filter
83: $this->getSelect()->join(
84: array($alias => $this->getTable('checkout/agreement_store')),
85: 'main_table.agreement_id = ' . $alias . '.agreement_id',
86: array()
87: )
88: ->where($alias . '.store_id IN (?)', $storeFilter)
89: ->group('main_table.agreement_id');
90:
91: $this->setFlag($alias, true);
92:
93: /*
94: * Allow Analytic functions usage
95: */
96: $this->_useAnalyticFunction = true;
97:
98:
99: return $this;
100: }
101:
102: /**
103: * Make store filter using admin website or not
104: *
105: * @param bool $value
106: * @return Mage_Checkout_Model_Resource_Agreement_Collection
107: */
108: public function setIsStoreFilterWithAdmin($value)
109: {
110: $this->_isStoreFilterWithAdmin = (bool)$value;
111: return $this;
112: }
113: }
114: