Skip to content

Commit 7dfe48f

Browse files
committed
Added adminhtml form
1 parent ccbf836 commit 7dfe48f

5 files changed

Lines changed: 261 additions & 8 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* General Helper
4+
*
5+
* @category IntegerNet
6+
* @package IntegerNet_Anonymizer
7+
* @author Andreas von Studnitz <avs@integer-net.de>
8+
*/
9+
class IntegerNet_Anonymizer_Block_Anonymizer extends Mage_Adminhtml_Block_Widget
10+
{
11+
public function __construct()
12+
{
13+
parent::__construct();
14+
$this->setTitle($this->__('Anonymizer'));
15+
$this->setTemplate('anonymizer/form.phtml');
16+
}
17+
18+
/**
19+
* Retrieve the POST URL for the form
20+
*
21+
* @return string URL
22+
*/
23+
public function getPostActionUrl()
24+
{
25+
return $this->getUrl('*/*/save');
26+
}
27+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* General Helper
4+
*
5+
* @category IntegerNet
6+
* @package IntegerNet_Anonymizer
7+
* @author Andreas von Studnitz <avs@integer-net.de>
8+
*/
9+
class IntegerNet_Anonymizer_Helper_Data extends Mage_Core_Helper_Abstract
10+
{
11+
12+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
/**
3+
* Controller for AdminHtml Form
4+
*
5+
* @category IntegerNet
6+
* @package IntegerNet_Anonymizer
7+
* @author Andreas von Studnitz <avs@integer-net.de>
8+
*/
9+
class IntegerNet_Anonymizer_AnonymizerController extends Mage_Adminhtml_Controller_Action
10+
{
11+
public function indexAction()
12+
{
13+
$this->_title(Mage::helper('anonymizer')->__('System'))
14+
->_title(Mage::helper('adminhtml')->__('Tools'))
15+
->_title(Mage::helper('adminhtml')->__('Anonymizer'));
16+
17+
$this->loadLayout();
18+
$this->_setActiveMenu('system/tools/anonymizer');
19+
$this->_addBreadcrumb(Mage::helper('anonymizer')->__('Anonymizer'), Mage::helper('anonymizer')->__('Anonymizer'));
20+
21+
$block = $this->getLayout()->createBlock(
22+
'anonymizer/anonymizer',
23+
'anonymizer'
24+
);
25+
26+
$this->getLayout()->getBlock('content')->append($block);
27+
28+
$this->renderLayout();
29+
}
30+
31+
public function newAction()
32+
{
33+
$this->_forward('edit');
34+
}
35+
36+
/**
37+
* Action for /admin/action/edit/
38+
* Edit action details
39+
*
40+
* @return void
41+
*/
42+
public function editAction()
43+
{
44+
$this->loadLayout()
45+
->_addContent($this->getLayout()->createBlock('sfp_banking/action_edit'))
46+
->renderLayout();
47+
}
48+
49+
/**
50+
* Action for saving an action
51+
*
52+
* @return void
53+
*/
54+
public function saveAction()
55+
{
56+
$actionId = $this->getRequest()->getParam('id', false);
57+
58+
if ($data = $this->getRequest()->getPost()) {
59+
60+
/** @var $action Sfp_Banking_Model_Action */
61+
$action = Mage::getModel('sfp_banking/action');
62+
63+
if ($actionId) {
64+
65+
$action->load($actionId);
66+
}
67+
68+
if (is_array($data['custom_prices'])) {
69+
$data['custom_prices'] = serialize($data['custom_prices']);
70+
}
71+
72+
$action->addData($data);
73+
74+
try {
75+
$this->_checkForExistingCode($action);
76+
$action->save();
77+
78+
Mage::getSingleton('adminhtml/session')
79+
->addSuccess(Mage::helper('sfp_banking')->__('Action was saved successfully'));
80+
$this->getResponse()->setRedirect($this->getUrl('*/*/'));
81+
return;
82+
} catch (Exception $e) {
83+
Mage::getSingleton('adminhtml/session')
84+
->addError($e->getMessage());
85+
}
86+
}
87+
$this->_redirectReferer();
88+
}
89+
90+
/**
91+
* Check if the given code already exists in any institute or action (different from the current one)
92+
*
93+
* @param Sfp_Banking_Model_Action $action
94+
*/
95+
protected function _checkForExistingCode($action)
96+
{
97+
if (!$action->getCode()) return;
98+
99+
$instituteCollection = Mage::getModel('sfp_banking/institute')
100+
->getCollection()
101+
->addFieldToFilter('code', $action->getCode());
102+
103+
if ($instituteCollection->getSize() > 0) {
104+
105+
Mage::throwException(Mage::helper('sfp_banking')->__('Code already exists.'));
106+
}
107+
108+
$actionCollection = Mage::getModel('sfp_banking/action')
109+
->getCollection()
110+
->addFieldToFilter('code', $action->getCode());
111+
112+
if ($actionId = $action->getId()) {
113+
$actionCollection->addFieldToFilter('action_id', array('neq' => $actionId));
114+
}
115+
116+
if ($actionCollection->getSize() > 0) {
117+
118+
Mage::throwException(Mage::helper('sfp_banking')->__('Code already exists.'));
119+
}
120+
}
121+
122+
/**
123+
* Action for deleting an action
124+
*
125+
* @return void
126+
*/
127+
public function deleteAction()
128+
{
129+
$actionId = $this->getRequest()->getParam('id', false);
130+
131+
try {
132+
Mage::getModel('sfp_banking/action')->setId($actionId)->delete();
133+
Mage::getSingleton('adminhtml/session')
134+
->addSuccess(Mage::helper('sfp_banking')
135+
->__('Action successfully deleted'));
136+
$this->getResponse()->setRedirect($this->getUrl('*/*/'));
137+
138+
return;
139+
} catch (Exception $e) {
140+
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
141+
}
142+
143+
$this->_redirectReferer();
144+
}
145+
146+
}

app/code/community/IntegerNet/Anonymizer/etc/config.xml

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818
<class>IntegerNet_Anonymizer_Model</class>
1919
</anonymizer>
2020
</models>
21+
<blocks>
22+
<anonymizer>
23+
<class>IntegerNet_Anonymizer_Block</class>
24+
</anonymizer>
25+
</blocks>
2126
<helpers>
2227
<anonymizer>
2328
<class>IntegerNet_Anonymizer_Helper</class>
2429
</anonymizer>
2530
</helpers>
2631
</global>
2732
<admin>
28-
<routers>
33+
<routers>
2934
<adminhtml>
3035
<args>
3136
<modules>
@@ -45,12 +50,40 @@
4550
</IntegerNet_Anonymizer>
4651
</modules>
4752
</translate>
48-
<layout>
49-
<updates>
50-
<anonymizer>
51-
<file>anonymizer.xml</file>
52-
</anonymizer>
53-
</updates>
54-
</layout>
53+
<menu>
54+
<system>
55+
<children>
56+
<tools>
57+
<children>
58+
<setup translate="title">
59+
<title>Anonymizer</title>
60+
<action>adminhtml/anonymizer</action>
61+
<sort_order>0</sort_order>
62+
</setup>
63+
</children>
64+
</tools>
65+
</children>
66+
</system>
67+
</menu>
68+
<acl>
69+
<resources>
70+
<admin>
71+
<children>
72+
<system>
73+
<children>
74+
<tools>
75+
<children>
76+
<anonymizer translate="title">
77+
<title>Anonymizer</title>
78+
<sort_order>0</sort_order>
79+
</anonymizer>
80+
</children>
81+
</tools>
82+
</children>
83+
</system>
84+
</children>
85+
</admin>
86+
</resources>
87+
</acl>
5588
</adminhtml>
5689
</config>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/** @var $this IntegerNet_Anonymizer_Block_Anonymizer */
3+
?>
4+
5+
<div class="content-header">
6+
<h3><?php echo $this->__('Anonymizer') ?></h3>
7+
<p class="form-buttons">
8+
<?php echo $this->getButtonHtml($this->__('Anonymize Data'), 'anonymizerForm.submit();', 'save'); ?>
9+
</p>
10+
</div>
11+
12+
<div class="entry-edit">
13+
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="anonymizer_form">
14+
<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
15+
<div class="entry-edit-head">
16+
<h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('The following Data Types will be anonymized:') ?></h4>
17+
<div class="form-buttons"></div>
18+
</div>
19+
20+
<div class="fieldset fieldset-wide" id="group_fields7">
21+
<ul>
22+
<li><?php echo $this->__('Customers'); ?></li>
23+
<li><?php echo $this->__('Customers Addresses'); ?></li>
24+
<li><?php echo $this->__('Orders'); ?></li>
25+
<li><?php echo $this->__('Order Addresses'); ?></li>
26+
<li><?php echo $this->__('Quotes'); ?></li>
27+
<li><?php echo $this->__('Quote Addresses'); ?></li>
28+
<li><?php echo $this->__('Newsletter Subscribers'); ?></li>
29+
</ul>
30+
</div>
31+
</form>
32+
</div>
33+
<script type="text/javascript">
34+
anonymizerForm = new varienForm('anonymizer_form', '');
35+
</script>

0 commit comments

Comments
 (0)