1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34:
35: class Mage_Tag_CustomerController extends Mage_Core_Controller_Front_Action
36: {
37: protected function _getTagId()
38: {
39: $tagId = (int) $this->getRequest()->getParam('tagId');
40: if ($tagId) {
41: $customerId = Mage::getSingleton('customer/session')->getCustomerId();
42: $model = Mage::getModel('tag/tag_relation');
43: $model->loadByTagCustomer(null, $tagId, $customerId);
44: Mage::register('tagModel', $model);
45: return $model->getTagId();
46: }
47: return false;
48: }
49:
50: public function indexAction()
51: {
52: if( !Mage::getSingleton('customer/session')->isLoggedIn() ) {
53: Mage::getSingleton('customer/session')->authenticate($this);
54: return;
55: }
56:
57: $this->loadLayout();
58: $this->_initLayoutMessages('tag/session');
59: $this->_initLayoutMessages('catalog/session');
60:
61: $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation');
62: if ($navigationBlock) {
63: $navigationBlock->setActive('tag/customer');
64: }
65:
66: $block = $this->getLayout()->getBlock('customer_tags');
67: if ($block) {
68: $block->setRefererUrl($this->_getRefererUrl());
69: }
70:
71: $this->getLayout()->getBlock('head')->setTitle(Mage::helper('tag')->__('My Tags'));
72: $this->renderLayout();
73: }
74:
75: public function viewAction()
76: {
77: if( !Mage::getSingleton('customer/session')->isLoggedIn() ) {
78: Mage::getSingleton('customer/session')->authenticate($this);
79: return;
80: }
81:
82: $tagId = $this->_getTagId();
83: if ($tagId) {
84: Mage::register('tagId', $tagId);
85: $this->loadLayout();
86: $this->_initLayoutMessages('tag/session');
87:
88: $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation');
89: if ($navigationBlock) {
90: $navigationBlock->setActive('tag/customer');
91: }
92:
93: $this->_initLayoutMessages('checkout/session');
94: $this->getLayout()->getBlock('head')->setTitle(Mage::helper('tag')->__('My Tags'));
95: $this->renderLayout();
96: }
97: else {
98: $this->_forward('noRoute');
99: }
100: }
101:
102: 103: 104: 105: 106:
107: public function editAction()
108: {
109: $this->_forward('noRoute');
110: }
111:
112: public function removeAction()
113: {
114: if( !Mage::getSingleton('customer/session')->isLoggedIn() ) {
115: Mage::getSingleton('customer/session')->authenticate($this);
116: return;
117: }
118:
119: $tagId = $this->_getTagId();
120: if ($tagId) {
121: try {
122: $model = Mage::registry('tagModel');
123: $model->deactivate();
124: $tag = Mage::getModel('tag/tag')->load($tagId)->aggregate();
125: Mage::getSingleton('tag/session')->addSuccess(Mage::helper('tag')->__('The tag has been deleted.'));
126: $this->getResponse()->setRedirect(Mage::getUrl('*/*/', array(
127: self::PARAM_NAME_URL_ENCODED => Mage::helper('core')->urlEncode(Mage::getUrl('customer/account/'))
128: )));
129: return;
130: } catch (Exception $e) {
131: Mage::getSingleton('tag/session')->addError(Mage::helper('tag')->__('Unable to remove tag. Please, try again later.'));
132: }
133: }
134: else {
135: $this->_forward('noRoute');
136: }
137: }
138:
139: 140: 141: 142: 143:
144: public function saveAction()
145: {
146: $this->_forward('noRoute');
147: }
148: }
149: