1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Rule
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: class Mage_Rule_Model_Action_Collection extends Mage_Rule_Model_Action_Abstract
29: {
30: public function __construct()
31: {
32: parent::__construct();
33: $this->setActions(array());
34: $this->setType('rule/action_collection');
35: }
36:
37: /**
38: * Returns array containing actions in the collection
39: *
40: * Output example:
41: * array(
42: * {action::asArray},
43: * {action::asArray}
44: * )
45: *
46: * @return array
47: */
48: public function asArray(array $arrAttributes = array())
49: {
50: $out = parent::asArray();
51:
52: foreach ($this->getActions() as $item) {
53: $out['actions'][] = $item->asArray();
54: }
55: return $out;
56: }
57:
58: public function loadArray(array $arr)
59: {
60: if (!empty($arr['actions']) && is_array($arr['actions'])) {
61: foreach ($arr['actions'] as $actArr) {
62: if (empty($actArr['type'])) {
63: continue;
64: }
65: $action = Mage::getModel($actArr['type']);
66: $action->loadArray($actArr);
67: $this->addAction($action);
68: }
69: }
70: return $this;
71: }
72:
73: public function addAction(Mage_Rule_Model_Action_Interface $action)
74: {
75: $actions = $this->getActions();
76:
77: $action->setRule($this->getRule());
78:
79: $actions[] = $action;
80: if (!$action->getId()) {
81: $action->setId($this->getId().'.'.sizeof($actions));
82: }
83:
84: $this->setActions($actions);
85: return $this;
86: }
87:
88: public function asHtml()
89: {
90: $html = $this->getTypeElement()->toHtml().'Perform following actions: ';
91: if ($this->getId()!='1') {
92: $html.= $this->getRemoveLinkHtml();
93: }
94: return $html;
95: }
96: public function getNewChildElement()
97: {
98: return $this->getForm()->addField('action:'.$this->getId().':new_child', 'select', array(
99: 'name'=>'rule[actions]['.$this->getId().'][new_child]',
100: 'values'=>$this->getNewChildSelectOptions(),
101: 'value_name'=>$this->getNewChildName(),
102: ))->setRenderer(Mage::getBlockSingleton('rule/newchild'));
103: }
104:
105: public function asHtmlRecursive()
106: {
107: $html = $this->asHtml().'<ul id="action:'.$this->getId().':children">';
108: foreach ($this->getActions() as $cond) {
109: $html .= '<li>'.$cond->asHtmlRecursive().'</li>';
110: }
111: $html .= '<li>'.$this->getNewChildElement()->getHtml().'</li></ul>';
112: return $html;
113: }
114:
115: public function asString($format='')
116: {
117: $str = Mage::helper('rule')->__("Perform following actions");
118: return $str;
119: }
120:
121: public function asStringRecursive($level=0)
122: {
123: $str = $this->asString();
124: foreach ($this->getActions() as $action) {
125: $str .= "\n".$action->asStringRecursive($level+1);
126: }
127: return $str;
128: }
129:
130: public function process()
131: {
132: foreach ($this->getActions() as $action) {
133: $action->process();
134: }
135: return $this;
136: }
137: }
138: