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 class Mage_Rule_Model_Action_Collection extends Mage_Rule_Model_Action_Abstract
00029 {
00030 public function __construct()
00031 {
00032 parent::__construct();
00033 $this->setActions(array());
00034 $this->setType('rule/action_collection');
00035 }
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 public function asArray(array $arrAttributes = array())
00049 {
00050 $out = parent::asArray();
00051
00052 foreach ($this->getActions() as $item) {
00053 $out['actions'][] = $item->asArray();
00054 }
00055 return $out;
00056 }
00057
00058 public function loadArray(array $arr)
00059 {
00060 if (!empty($arr['actions']) && is_array($arr['actions'])) {
00061 foreach ($arr['actions'] as $actArr) {
00062 if (empty($actArr['type'])) {
00063 continue;
00064 }
00065 $action = Mage::getModel($actArr['type']);
00066 $action->loadArray($actArr);
00067 $this->addAction($action);
00068 }
00069 }
00070 return $this;
00071 }
00072
00073 public function addAction(Mage_Rule_Model_Action_Interface $action)
00074 {
00075 $actions = $this->getActions();
00076
00077 $action->setRule($this->getRule());
00078
00079 $actions[] = $action;
00080 if (!$action->getId()) {
00081 $action->setId($this->getId().'.'.sizeof($actions));
00082 }
00083
00084 $this->setActions($actions);
00085 return $this;
00086 }
00087
00088 public function asHtml()
00089 {
00090 $html = $this->getTypeElement()->toHtml().'Perform following actions: ';
00091 if ($this->getId()!='1') {
00092 $html.= $this->getRemoveLinkHtml();
00093 }
00094 return $html;
00095 }
00096 public function getNewChildElement()
00097 {
00098 return $this->getForm()->addField('action:'.$this->getId().':new_child', 'select', array(
00099 'name'=>'rule[actions]['.$this->getId().'][new_child]',
00100 'values'=>$this->getNewChildSelectOptions(),
00101 'value_name'=>$this->getNewChildName(),
00102 ))->setRenderer(Mage::getBlockSingleton('rule/newchild'));
00103 }
00104
00105 public function asHtmlRecursive()
00106 {
00107 $html = $this->asHtml().'<ul id="action:'.$this->getId().':children">';
00108 foreach ($this->getActions() as $cond) {
00109 $html .= '<li>'.$cond->asHtmlRecursive().'</li>';
00110 }
00111 $html .= '<li>'.$this->getNewChildElement()->getHtml().'</li></ul>';
00112 return $html;
00113 }
00114
00115 public function asString($format='')
00116 {
00117 $str = Mage::helper('rule')->__("Perform following actions");
00118 return $str;
00119 }
00120
00121 public function asStringRecursive($level=0)
00122 {
00123 $str = $this->asString();
00124 foreach ($this->getActions() as $action) {
00125 $str .= "\n".$action->asStringRecursive($level+1);
00126 }
00127 return $str;
00128 }
00129
00130 public function process()
00131 {
00132 foreach ($this->getActions() as $action) {
00133 $action->process();
00134 }
00135 return $this;
00136 }
00137 }