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 one entry of eabi_livehandler database table.</p>
35: * <p>Performs following:</p>
36: * <ul>
37: <li>Render javascript before_body_end part of the page, when Magento request variables match</li>
38: <li>Generates unique URL, where sending data to causes to fire service() function on the model_class instance.</li>
39: <li>Works only when javascript at the bottom of the page is rendered. Which means if you see this page you can fire the action.</li>
40: </ul>
41: * <p>Structure:</p>
42: * <ul>
43: <li><b>id</b> - unique auto incement id</li>
44: <li><b>name</b> - Human readable description</li>
45: <li><b>is_enabled</b> - 1 means action is enabled, 0 means action is disabled</li>
46: <li><b>is_admin</b> - 1 means action is admin only, 0 means action is public only</li>
47: <li><b>request_var</b> - Magento request var name, which current action must match. Example: adminhtml/sales_order/index - Magentos Sales Order Grid</li>
48: <li><b>store_id</b> - id of the store this action should run in</li>
49: <li><b>website_id</b> - if of the website this action should run in</li>
50: <li><b>model_class</b> - full Magento model name for the implementing class. Must be instance of Eabi_Livehandler_Model_Abstract</li>
51: <li><b>created_time</b> - when was this database entry created</li>
52: <li><b>update_time</b> - when was this database entry updated</li>
53: <li><b>cached_attributes</b> - not in use, could be used to store data in serialized form</li>
54: <li><b>parameters</b> - not in use, could be used to store data in serialized form</li>
55: <li><b>css</b> - used to declare extra css rules, those can also be declared by implementing class. Will be injected to before_body_end as style tag.</li>
56: <li><b>js</b> - used to display extra javascript, those can be also be declared by implementing class. Will be injetected before_body_end in script[type=javascript] tag</li>
57: <li><b>html</b> - used to display extra HTML, those can be also be declared by implementing class. Will be injetected before_body_end</li>
58: </ul>
59: *
60: * @author matishalmann
61: */
62: class Eabi_Livehandler_Model_Entry extends Mage_Core_Model_Abstract {
63:
64: /**
65: * <p>instance of implementing class</p>
66: * @var Eabi_Livehandler_Model_Adminhtml_Gridmanager
67: */
68: private $_caller;
69:
70: public function _construct() {
71: parent::_construct();
72: $this->_init('eabi_livehandler/entry');
73:
74: }
75:
76: /**
77: * <p>Sets up the instance of implementing class</p>
78: * @return Eabi_Livehandler_Model_Entry
79: */
80: protected function _afterLoad() {
81: $load = parent::_afterLoad();
82: if ($this->getData('model_class') != '') {
83: $this->_caller = Mage::getModel($this->getData('model_class'));
84: }
85: return $load;
86: }
87:
88: /**
89: * <p>Loads up extra javascript from js property or from implementing class (preferred).</p>
90: * @return string
91: */
92: public function getJs() {
93: $js = trim($this->getData('js'));
94: if ($js == '' && $this->_caller != null) {
95: $js = $this->_caller->getJs();
96: }
97:
98: return $js;
99:
100: }
101:
102:
103: /**
104: * <p>Loads up extra CSS from css property or from implementing class (preferred).</p>
105: * @return string
106: */
107: public function getCss() {
108: $css = trim($this->getData('css'));
109: if ($css == '' && $this->_caller != null) {
110: $css = $this->_caller->getCss();
111: }
112:
113: return $css;
114:
115: }
116:
117: /**
118: * <p>Loads up extra HTML from html property or from implementing class (preferred).</p>
119: * @return string
120: */
121: public function getHtml() {
122: $html = trim($this->getData('html'));
123: if ($html == '' && $this->_caller != null) {
124: $html = $this->_caller->getHtml();
125: }
126:
127: return $html;
128:
129: }
130:
131:
132: /**
133: * <p>Attempts to call implementing classes <code>service</code> function with posted parameters in frontend environment.</p>
134: * @param array $postedData posted parameters
135: * @return array returned result
136: */
137: public function runPublic($postedData) {
138: $result = array();
139: if ($this->_caller != null) {
140: $result = $this->_caller->service($postedData);
141: }
142: return $result;
143: }
144:
145:
146: /**
147: * <p>Attempts to call implementing classes <code>service</code> function with posted parameters in adminhtml environment.</p>
148: * @param array $postedData posted parameters
149: * @return array returned result
150: */
151: public function runAdmin($postedData) {
152: $result = array();
153: if ($this->_caller != null) {
154: $result = $this->_caller->service($postedData);
155: }
156: return $result;
157: }
158: }
159: