1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: abstract class Mage_Rule_Model_Action_Abstract extends Varien_Object implements Mage_Rule_Model_Action_Interface
36: {
37: public function __construct()
38: {
39: parent::__construct();
40: $this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions();
41:
42: foreach ($this->getAttributeOption() as $attr=>$dummy) { $this->setAttribute($attr); break; }
43: foreach ($this->getOperatorOption() as $operator=>$dummy) { $this->setOperator($operator); break; }
44: }
45:
46: public function getForm()
47: {
48: return $this->getRule()->getForm();
49: }
50:
51: public function asArray(array $arrAttributes = array())
52: {
53: $out = array(
54: 'type'=>$this->getType(),
55: 'attribute'=>$this->getAttribute(),
56: 'operator'=>$this->getOperator(),
57: 'value'=>$this->getValue(),
58: );
59: return $out;
60: }
61:
62: public function asXml()
63: {
64: $xml = "<type>".$this->getType()."</type>"
65: ."<attribute>".$this->getAttribute()."</attribute>"
66: ."<operator>".$this->getOperator()."</operator>"
67: ."<value>".$this->getValue()."</value>";
68: return $xml;
69: }
70:
71: public function loadArray(array $arr)
72: {
73: $this->addData(array(
74: 'type'=>$arr['type'],
75: 'attribute'=>$arr['attribute'],
76: 'operator'=>$arr['operator'],
77: 'value'=>$arr['value'],
78: ));
79: $this->loadAttributeOptions();
80: $this->loadOperatorOptions();
81: $this->loadValueOptions();
82: return $this;
83: }
84:
85: public function loadAttributeOptions()
86: {
87: $this->setAttributeOption(array());
88: return $this;
89: }
90:
91: public function getAttributeSelectOptions()
92: {
93: $opt = array();
94: foreach ($this->getAttributeOption() as $k=>$v) {
95: $opt[] = array('value'=>$k, 'label'=>$v);
96: }
97: return $opt;
98: }
99:
100: public function getAttributeName()
101: {
102: return $this->getAttributeOption($this->getAttribute());
103: }
104:
105: public function loadOperatorOptions()
106: {
107: $this->setOperatorOption(array(
108: '=' => Mage::helper('rule')->__('to'),
109: '+=' => Mage::helper('rule')->__('by'),
110: ));
111: return $this;
112: }
113:
114: public function getOperatorSelectOptions()
115: {
116: $opt = array();
117: foreach ($this->getOperatorOption() as $k=>$v) {
118: $opt[] = array('value'=>$k, 'label'=>$v);
119: }
120: return $opt;
121: }
122:
123: public function getOperatorName()
124: {
125: return $this->getOperatorOption($this->getOperator());
126: }
127:
128: public function loadValueOptions()
129: {
130: $this->setValueOption(array());
131: return $this;
132: }
133:
134: public function getValueSelectOptions()
135: {
136: $opt = array();
137: foreach ($this->getValueOption() as $k=>$v) {
138: $opt[] = array('value'=>$k, 'label'=>$v);
139: }
140: return $opt;
141: }
142:
143: public function getValueName()
144: {
145: $value = $this->getValue();
146: return !empty($value) || 0===$value ? $value : '...';;
147: }
148:
149: public function getNewChildSelectOptions()
150: {
151: return array(
152: array('value'=>'', 'label'=>Mage::helper('rule')->__('Please choose an action to add...')),
153: );
154: }
155:
156: public function getNewChildName()
157: {
158: return $this->getAddLinkHtml();
159: }
160:
161: public function asHtml()
162: {
163: return '';
164: }
165:
166: public function asHtmlRecursive()
167: {
168: $str = $this->asHtml();
169: return $str;
170: }
171:
172: public function getTypeElement()
173: {
174: return $this->getForm()->addField('action:'.$this->getId().':type', 'hidden', array(
175: 'name'=>'rule[actions]['.$this->getId().'][type]',
176: 'value'=>$this->getType(),
177: 'no_span'=>true,
178: ));
179: }
180:
181: public function getAttributeElement()
182: {
183: return $this->getForm()->addField('action:'.$this->getId().':attribute', 'select', array(
184: 'name'=>'rule[actions]['.$this->getId().'][attribute]',
185: 'values'=>$this->getAttributeSelectOptions(),
186: 'value'=>$this->getAttribute(),
187: 'value_name'=>$this->getAttributeName(),
188: ))->setRenderer(Mage::getBlockSingleton('rule/editable'));
189: }
190:
191: public function getOperatorElement()
192: {
193: return $this->getForm()->addField('action:'.$this->getId().':operator', 'select', array(
194: 'name'=>'rule[actions]['.$this->getId().'][operator]',
195: 'values'=>$this->getOperatorSelectOptions(),
196: 'value'=>$this->getOperator(),
197: 'value_name'=>$this->getOperatorName(),
198: ))->setRenderer(Mage::getBlockSingleton('rule/editable'));
199: }
200:
201: public function getValueElement()
202: {
203: return $this->getForm()->addField('action:'.$this->getId().':value', 'text', array(
204: 'name'=>'rule[actions]['.$this->getId().'][value]',
205: 'value'=>$this->getValue(),
206: 'value_name'=>$this->getValueName(),
207: ))->setRenderer(Mage::getBlockSingleton('rule/editable'));
208: }
209:
210: public function getAddLinkHtml()
211: {
212: $src = Mage::getDesign()->getSkinUrl('images/rule_component_add.gif');
213: $html = '<img src="'.$src.'" alt="" class="rule-param-add v-middle" />';
214: return $html;
215: }
216:
217:
218: public function getRemoveLinkHtml()
219: {
220: $src = Mage::getDesign()->getSkinUrl('images/rule_component_remove.gif');
221: $html = '<span class="rule-param"><a href="javascript:void(0)" class="rule-param-remove"><img src="'
222: . $src . '" alt="" class="v-middle" /></a></span>';
223: return $html;
224: }
225:
226: public function asString($format='')
227: {
228: return "";
229: }
230:
231: public function asStringRecursive($level=0)
232: {
233: $str = str_pad('', $level*3, ' ', STR_PAD_LEFT).$this->asString();
234: return $str;
235: }
236:
237: public function process()
238: {
239: return $this;
240: }
241: }
242: