1: <?php
2: /*
3:
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * or OpenGPL v3 license (GNU Public License V3.0)
9: * that is bundled with this package in the file LICENSE.txt.
10: * It is also available through the world-wide-web at this URL:
11: * http://opensource.org/licenses/osl-3.0.php
12: * or
13: * http://www.gnu.org/licenses/gpl-3.0.txt
14: * If you did not receive a copy of the license and are unable to
15: * obtain it through the world-wide-web, please send an email
16: * to info@e-abi.ee so we can send you a copy immediately.
17: *
18: * DISCLAIMER
19: *
20: * Do not edit or add to this file if you wish to upgrade this module to newer
21: * versions in the future.
22: *
23: * @category Eabi
24: * @package Eabi_Dpd
25: * @copyright Copyright (c) 2014 Aktsiamaailm LLC (http://en.e-abi.ee/)
26: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27: * @license http://www.gnu.org/licenses/gpl-3.0.txt GNU Public License V3.0
28: * @author Matis Halmann
29: *
30:
31: */
32:
33: /**
34: * <p>Represents collection of eabi_livehandler database table entries</p>
35: *
36: * @author matishalmann
37: */
38: class Eabi_Livehandler_Model_Mysql4_Entry_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
39:
40: public function _construct() {
41: parent::_construct();
42: $this->_init('eabi_livehandler/entry');
43: }
44:
45: /**
46: * <p>Finds eabi_livehandler entries by Magento Request name</p>
47: * <p>Request name is constructed as following:</p>
48: * <pre>
49: $routeName = $request->getRequestedRouteName();
50: $controllerName = $request->getRequestedControllerName();
51: $actionName = $request->getRequestedActionName();
52: $path = $routeName . '/' . $controllerName . '/' . $actionName;
53: *
54: * </pre>
55: * @param string $path Magento request name
56: * @param bool $isAdmin true, when eabi_livehandler is declared to be admin only.
57: * @param int $website id of a website, this action should only run on.
58: * @param int $store id of a store, this action should only run on.
59: * @return Eabi_Livehandler_Model_Mysql4_Entry_Collection
60: */
61: public function setFilter($path, $isAdmin = false, $website = 0, $store = 0) {
62: $this->addFieldToFilter('request_var', array('like' => $path.'%'));
63: $this->addFieldToFilter('is_admin', (int)$isAdmin);
64: $this->addFieldToFilter('is_enabled', 1);
65: $this->getSelect()->where('main_table.website_id = '.((int)$website).' or main_table.website_id = 0');
66: $this->getSelect()->where('main_table.store_id = '.((int)$store).' or main_table.store_id = 0');
67: $this->addOrder('request_var', 'asc');
68: $this->addOrder('website_id', 'desc');
69: $this->addOrder('store_id', 'desc');
70: return $this;
71: }
72:
73: /**
74: * <p>Finds eabi_livehandler entries by Magento model name</p>
75: * @param string $model Magento model name
76: * @param bool $isAdmin true, when eabi_livehandler is declared to be admin only.
77: * @param int $website id of a website, this action should only run on.
78: * @param int $store id of a store, this action should only run on.
79: * @return Eabi_Livehandler_Model_Mysql4_Entry_Collection
80: */
81: public function setModelFilter($model, $isAdmin = false, $website = 0, $store = 0) {
82: $this->addFieldToFilter('model_class', $model);
83: $this->addFieldToFilter('is_admin', (int)$isAdmin);
84: $this->addFieldToFilter('is_enabled', 1);
85: $this->getSelect()->where('main_table.website_id = '.((int)$website).' or main_table.website_id = 0');
86: $this->getSelect()->where('main_table.store_id = '.((int)$store).' or main_table.store_id = 0');
87: $this->addOrder('request_var', 'asc');
88: $this->addOrder('website_id', 'desc');
89: $this->addOrder('store_id', 'desc');
90: return $this;
91: }
92: }
93:
94: