Quadra_ConditionalAction - Version 1.0.0

Version Notes

This extension allows backoffice developers to add, on Grid, actions (links) that display only according to a condition.
Example : on the orders list, you can add an "print" action that displays only on ligns with orders in "complete" status.

To do that, you have to add a lign "condition" in the array, when declaring the action.
Example :
array(
'caption' => Mage::helper('sales')->__('Print'),
'url' => array('base'=>'*/*/print'),
'field' => 'order_id',
'condition' => array('data' => 'status', 'operator' => 'eq', 'value' => 'processing'),
)

The "operator" lign can have several values :
eq (or ==) : equal
neq (or !=) : not equal
gt (or >) : greater than
lt (or =) : greater than or equal
lteq (or <=) : lesser than or equal

This extension also allows to display several actions (links) lign per lign instead of in a select tag.
The "type" attribute of the column must be "multipleaction" instead of "action".

Download this release

Release Info

Developer Magento Core Team
Extension Quadra_ConditionalAction
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Quadra/ConditionalAction/Block/Adminhtml/Widget/Grid/Column.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Quadra
22
+ * @package Quadra_ConditionalAction
23
+ * @copyright Copyright (c) 2009 Quadra Informatique (http://www.quadra-informatique.fr/)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Grid column block
29
+ *
30
+ * @category Quadra
31
+ * @package Quadra_ConditionalAction
32
+ * @author Nicolas Fischer <nicolas.fischer@quadra-informatique.fr>
33
+ */
34
+ class Quadra_ConditionalAction_Block_Adminhtml_Widget_Grid_Column extends Mage_Adminhtml_Block_Widget_Grid_Column
35
+ {
36
+
37
+ protected function _getRendererByType()
38
+ {
39
+ switch (strtolower($this->getType())) {
40
+ case 'multipleaction':
41
+ $rendererClass = 'conditionalaction/adminhtml_widget_grid_column_renderer_multipleAction';
42
+ break;
43
+ default:
44
+ $rendererClass = parent::_getRendererByType();
45
+ break;
46
+ }
47
+ return $rendererClass;
48
+ }
49
+
50
+ }
app/code/local/Quadra/ConditionalAction/Block/Adminhtml/Widget/Grid/Column/Renderer/Action.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Quadra
22
+ * @package Quadra_ConditionalAction
23
+ * @copyright Copyright (c) 2009 Quadra Informatique (http://www.quadra-informatique.fr/)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Grid column widget for rendering conditional action grid cells
29
+ *
30
+ * @category Quadra
31
+ * @package Quadra_ConditionalAction
32
+ * @author Nicolas Fischer <nicolas.fischer@quadra-informatique.fr>
33
+ */
34
+ class Quadra_ConditionalAction_Block_Adminhtml_Widget_Grid_Column_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
35
+ {
36
+
37
+ /**
38
+ * Renders column
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $actions = $this->getColumn()->getActions();
46
+ if ( empty($actions) || !is_array($actions) ) {
47
+ return '&nbsp';
48
+ }
49
+
50
+ if(sizeof($actions)==1 && !$this->getColumn()->getNoLink()) {
51
+ foreach ($actions as $action){
52
+ if ( is_array($action) ) {
53
+ return $this->_toLinkHtml($action, $row);
54
+ }
55
+ }
56
+ }
57
+
58
+ $out = '<select class="action-select" onchange="varienGridAction.execute(this);">'
59
+ . '<option value=""></option>';
60
+ $i = 0;
61
+ foreach ($actions as $action){
62
+ $i++;
63
+ if ( is_array($action) ) {
64
+ $display = true;
65
+ if (array_key_exists('condition', $action)) {
66
+ $conditions = $action['condition'];
67
+ foreach ($conditions as $condition) {
68
+ if (is_array($condition)) {
69
+ $display = $display && $this->_checkCondition($row, $condition);
70
+ } else {
71
+ $display = $this->_checkCondition($row, $conditions);
72
+ break;
73
+ }
74
+ }
75
+ }
76
+
77
+ if ($display) {
78
+ $out .= $this->_toOptionHtml($action, $row);
79
+ }
80
+ }
81
+ }
82
+ $out .= '</select>';
83
+ return $out;
84
+ }
85
+
86
+ /**
87
+ * Check condition
88
+ *
89
+ * @param Varien_Object $row
90
+ * @param Array $condition
91
+ * @return boolean
92
+ */
93
+ protected function _checkCondition($row, $condition) {
94
+ if (!array_key_exists('data', $condition) || !array_key_exists('operator', $condition) || !array_key_exists('value', $condition)) {
95
+ return true;
96
+ } else {
97
+ $op = $condition['operator'];
98
+ if ($op == 'eq' || $op == '==') {
99
+ return ($row->getData($condition['data']) == $condition['value']);
100
+ } elseif ($op == 'neq' || $op == '!=') {
101
+ return ($row->getData($condition['data']) != $condition['value']);
102
+ } elseif ($op == 'gt' || $op == '>') {
103
+ return ($row->getData($condition['data']) > $condition['value']);
104
+ } elseif ($op == 'lt' || $op == '<') {
105
+ return ($row->getData($condition['data']) < $condition['value']);
106
+ } elseif ($op == 'gteq' || $op == '>=') {
107
+ return ($row->getData($condition['data']) >= $condition['value']);
108
+ } elseif ($op == 'lteq' || $op == '<=') {
109
+ return ($row->getData($condition['data']) <= $condition['value']);
110
+ }
111
+ }
112
+
113
+ return true;
114
+ }
115
+
116
+ }
app/code/local/Quadra/ConditionalAction/Block/Adminhtml/Widget/Grid/Column/Renderer/MultipleAction.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Quadra
22
+ * @package Quadra_ConditionalAction
23
+ * @copyright Copyright (c) 2009 Quadra Informatique (http://www.quadra-informatique.fr/)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Grid column widget for rendering conditional action grid cells
29
+ *
30
+ * @category Quadra
31
+ * @package Quadra_ConditionalAction
32
+ * @author Nicolas Fischer <nicolas.fischer@quadra-informatique.fr>
33
+ */
34
+ class Quadra_ConditionalAction_Block_Adminhtml_Widget_Grid_Column_Renderer_MultipleAction extends Quadra_ConditionalAction_Block_Adminhtml_Widget_Grid_Column_Renderer_Action
35
+ {
36
+
37
+ /**
38
+ * Renders column
39
+ *
40
+ * @param Varien_Object $row
41
+ * @return string
42
+ */
43
+ public function render(Varien_Object $row)
44
+ {
45
+ $actions = $this->getColumn()->getActions();
46
+ if ( empty($actions) || !is_array($actions) ) {
47
+ return '&nbsp';
48
+ }
49
+
50
+ if(sizeof($actions)==1 && !$this->getColumn()->getNoLink()) {
51
+ foreach ($actions as $action){
52
+ if ( is_array($action) ) {
53
+ return $this->_toLinkHtml($action, $row);
54
+ }
55
+ }
56
+ }
57
+
58
+ $out = '';
59
+ $i = 0;
60
+ foreach ($actions as $action){
61
+ $i++;
62
+ if ( is_array($action) ) {
63
+ $display = true;
64
+ if (array_key_exists('condition', $action)) {
65
+ $conditions = $action['condition'];
66
+ foreach ($conditions as $condition) {
67
+ if (is_array($condition)) {
68
+ $display = $display && $this->_checkCondition($row, $condition);
69
+ } else {
70
+ $display = $this->_checkCondition($row, $conditions);
71
+ break;
72
+ }
73
+ }
74
+ }
75
+
76
+ if ($display) {
77
+ $out .= $this->_toLinkHtml($action, $row).'<br>';
78
+ }
79
+ }
80
+ }
81
+
82
+ return $out;
83
+ }
84
+
85
+ }
app/code/local/Quadra/ConditionalAction/etc/config.xml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.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
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * @category Quadra
17
+ * @package Quadra_ConditionalAction
18
+ * @copyright Copyright (c) 2009 Quadra Informatique (http://www.quadra-informatique.fr/)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+ -->
22
+ <config>
23
+ <modules>
24
+ <Quadra_ConditionalAction>
25
+ <version>1.0.0</version>
26
+ </Quadra_ConditionalAction>
27
+ </modules>
28
+ <global>
29
+ <blocks>
30
+ <conditionalaction>
31
+ <class>Quadra_ConditionalAction_Block</class>
32
+ </conditionalaction>
33
+ <adminhtml>
34
+ <rewrite>
35
+ <widget_grid_column>Quadra_ConditionalAction_Block_Adminhtml_Widget_Grid_Column</widget_grid_column>
36
+ <widget_grid_column_renderer_action>Quadra_ConditionalAction_Block_Adminhtml_Widget_Grid_Column_Renderer_Action</widget_grid_column_renderer_action>
37
+ </rewrite>
38
+ </adminhtml>
39
+ </blocks>
40
+ </global>
41
+ </config>
app/etc/modules/Quadra_ConditionalAction.xml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.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
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * @category Quadra
17
+ * @package Quadra_ConditionalAction
18
+ * @copyright Copyright (c) 2009 Quadra Informatique (http://www.quadra-informatique.fr/)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+ -->
22
+ <config>
23
+ <modules>
24
+ <Quadra_ConditionalAction>
25
+ <active>true</active>
26
+ <codePool>local</codePool>
27
+ <depends>
28
+ <Mage_Adminhtml/>
29
+ </depends>
30
+ </Quadra_ConditionalAction>
31
+ </modules>
32
+ </config>
package.xml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Quadra_ConditionalAction</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Enable conditional action (link) in backoffice Grid class</summary>
10
+ <description>Enable conditional action (link) in backoffice Grid class with adding a condition lign like :
11
+ array(
12
+ 'caption' =&gt; Mage::helper('sales')-&gt;__('Print'),
13
+ 'url' =&gt; array('base'=&gt;'*/*/print'),
14
+ 'field' =&gt; 'order_id',
15
+ 'condition' =&gt; array('data' =&gt; 'status', 'operator' =&gt; 'eq', 'value' =&gt; 'processing'),
16
+ )</description>
17
+ <notes>This extension allows backoffice developers to add, on Grid, actions (links) that display only according to a condition.
18
+ Example : on the orders list, you can add an "print" action that displays only on ligns with orders in "complete" status.
19
+
20
+ To do that, you have to add a lign "condition" in the array, when declaring the action.
21
+ Example :
22
+ array(
23
+ 'caption' =&gt; Mage::helper('sales')-&gt;__('Print'),
24
+ 'url' =&gt; array('base'=&gt;'*/*/print'),
25
+ 'field' =&gt; 'order_id',
26
+ 'condition' =&gt; array('data' =&gt; 'status', 'operator' =&gt; 'eq', 'value' =&gt; 'processing'),
27
+ )
28
+
29
+ The "operator" lign can have several values :
30
+ eq (or ==) : equal
31
+ neq (or !=) : not equal
32
+ gt (or &gt;) : greater than
33
+ lt (or &lt;) : lesser than
34
+ gteq (or &gt;=) : greater than or equal
35
+ lteq (or &lt;=) : lesser than or equal
36
+
37
+ This extension also allows to display several actions (links) lign per lign instead of in a select tag.
38
+ The "type" attribute of the column must be "multipleaction" instead of "action".</notes>
39
+ <authors><author><name>Quadra Team</name><user>auto-converted</user><email>magento@quadra-informatique.fr</email></author></authors>
40
+ <date>2009-11-12</date>
41
+ <time>19:24:10</time>
42
+ <contents><target name="mageetc"><dir name="modules"><file name="Quadra_ConditionalAction.xml" hash="0f19ae1215575f8b3cde23f0ee692ca2"/></dir></target><target name="magelocal"><dir name="Quadra"><dir name="ConditionalAction"><dir name="Block"><dir name="Adminhtml"><dir name="Widget"><dir name="Grid"><dir name="Column"><dir name="Renderer"><file name="Action.php" hash="f8aa7768d6a9c6ba7f279a6d5cea67ab"/><file name="MultipleAction.php" hash="0164403f128d7691c1630f1da06c4a05"/></dir></dir><file name="Column.php" hash="ff48ccefc8bf2ad9031d39ff17d823d3"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="37a2eb0fa87732ae7e07534c035950a6"/></dir></dir></dir></target></contents>
43
+ <compatible/>
44
+ <dependencies/>
45
+ </package>