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
00035 abstract class Mage_Rule_Model_Action_Abstract extends Varien_Object implements Mage_Rule_Model_Action_Interface
00036 {
00037 public function __construct()
00038 {
00039 parent::__construct();
00040 $this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions();
00041
00042 foreach ($this->getAttributeOption() as $attr=>$dummy) { $this->setAttribute($attr); break; }
00043 foreach ($this->getOperatorOption() as $operator=>$dummy) { $this->setOperator($operator); break; }
00044 }
00045
00046 public function getForm()
00047 {
00048 return $this->getRule()->getForm();
00049 }
00050
00051 public function asArray(array $arrAttributes = array())
00052 {
00053 $out = array(
00054 'type'=>$this->getType(),
00055 'attribute'=>$this->getAttribute(),
00056 'operator'=>$this->getOperator(),
00057 'value'=>$this->getValue(),
00058 );
00059 return $out;
00060 }
00061
00062 public function asXml()
00063 {
00064 extract($this->toArray());
00065 $xml = "<type>".$this->getType()."</type>"
00066 ."<attribute>".$this->getAttribute()."</attribute>"
00067 ."<operator>".$this->getOperator()."</operator>"
00068 ."<value>".$this->getValue()."</value>";
00069 return $xml;
00070 }
00071
00072 public function loadArray(array $arr)
00073 {
00074 $this->addData(array(
00075 'type'=>$arr['type'],
00076 'attribute'=>$arr['attribute'],
00077 'operator'=>$arr['operator'],
00078 'value'=>$arr['value'],
00079 ));
00080 $this->loadAttributeOptions();
00081 $this->loadOperatorOptions();
00082 $this->loadValueOptions();
00083 return $this;
00084 }
00085
00086 public function loadAttributeOptions()
00087 {
00088 $this->setAttributeOption(array());
00089 return $this;
00090 }
00091
00092 public function getAttributeSelectOptions()
00093 {
00094 $opt = array();
00095 foreach ($this->getAttributeOption() as $k=>$v) {
00096 $opt[] = array('value'=>$k, 'label'=>$v);
00097 }
00098 return $opt;
00099 }
00100
00101 public function getAttributeName()
00102 {
00103 return $this->getAttributeOption($this->getAttribute());
00104 }
00105
00106 public function loadOperatorOptions()
00107 {
00108 $this->setOperatorOption(array(
00109 '=' => Mage::helper('rule')->__('to'),
00110 '+=' => Mage::helper('rule')->__('by'),
00111 ));
00112 return $this;
00113 }
00114
00115 public function getOperatorSelectOptions()
00116 {
00117 $opt = array();
00118 foreach ($this->getOperatorOption() as $k=>$v) {
00119 $opt[] = array('value'=>$k, 'label'=>$v);
00120 }
00121 return $opt;
00122 }
00123
00124 public function getOperatorName()
00125 {
00126 return $this->getOperatorOption($this->getOperator());
00127 }
00128
00129 public function loadValueOptions()
00130 {
00131 $this->setValueOption(array());
00132 return $this;
00133 }
00134
00135 public function getValueSelectOptions()
00136 {
00137 $opt = array();
00138 foreach ($this->getValueOption() as $k=>$v) {
00139 $opt[] = array('value'=>$k, 'label'=>$v);
00140 }
00141 return $opt;
00142 }
00143
00144 public function getValueName()
00145 {
00146 $value = $this->getValue();
00147 return !empty($value) || 0===$value ? $value : '...';;
00148 }
00149
00150 public function getNewChildSelectOptions()
00151 {
00152 return array(
00153 array('value'=>'', 'label'=>Mage::helper('rule')->__('Please choose an action to add...')),
00154 );
00155 }
00156
00157 public function getNewChildName()
00158 {
00159 return $this->getAddLinkHtml();
00160 }
00161
00162 public function asHtml()
00163 {
00164 return '';
00165 }
00166
00167 public function asHtmlRecursive()
00168 {
00169 $str = $this->asHtml();
00170 return $str;
00171 }
00172
00173 public function getTypeElement()
00174 {
00175 return $this->getForm()->addField('action:'.$this->getId().':type', 'hidden', array(
00176 'name'=>'rule[actions]['.$this->getId().'][type]',
00177 'value'=>$this->getType(),
00178 'no_span'=>true,
00179 ));
00180 }
00181
00182 public function getAttributeElement()
00183 {
00184 return $this->getForm()->addField('action:'.$this->getId().':attribute', 'select', array(
00185 'name'=>'rule[actions]['.$this->getId().'][attribute]',
00186 'values'=>$this->getAttributeSelectOptions(),
00187 'value'=>$this->getAttribute(),
00188 'value_name'=>$this->getAttributeName(),
00189 ))->setRenderer(Mage::getBlockSingleton('rule/editable'));
00190 }
00191
00192 public function getOperatorElement()
00193 {
00194 return $this->getForm()->addField('action:'.$this->getId().':operator', 'select', array(
00195 'name'=>'rule[actions]['.$this->getId().'][operator]',
00196 'values'=>$this->getOperatorSelectOptions(),
00197 'value'=>$this->getOperator(),
00198 'value_name'=>$this->getOperatorName(),
00199 ))->setRenderer(Mage::getBlockSingleton('rule/editable'));
00200 }
00201
00202 public function getValueElement()
00203 {
00204 return $this->getForm()->addField('action:'.$this->getId().':value', 'text', array(
00205 'name'=>'rule[actions]['.$this->getId().'][value]',
00206 'value'=>$this->getValue(),
00207 'value_name'=>$this->getValueName(),
00208 ))->setRenderer(Mage::getBlockSingleton('rule/editable'));
00209 }
00210
00211 public function getAddLinkHtml()
00212 {
00213 $src = Mage::getDesign()->getSkinUrl('images/rule_component_add.gif');
00214 $html = '<img src="'.$src.'" alt="" class="rule-param-add v-middle" />';
00215 return $html;
00216 }
00217
00218
00219 public function getRemoveLinkHtml()
00220 {
00221 $src = Mage::getDesign()->getSkinUrl('images/rule_component_remove.gif');
00222 $html = '<span class="rule-param"><a href="javascript:void(0)" class="rule-param-remove"><img src="'.$src.'" alt="" class="v-middle" /></a></span>';
00223 return $html;
00224 }
00225
00226 public function asString($format='')
00227 {
00228 return "";
00229 }
00230
00231 public function asStringRecursive($level=0)
00232 {
00233 $str = str_pad('', $level*3, ' ', STR_PAD_LEFT).$this->asString();
00234 return $str;
00235 }
00236
00237 public function process()
00238 {
00239 return $this;
00240 }
00241 }