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_Adminhtml_Promo_WidgetController extends Mage_Adminhtml_Controller_Action
00029 {
00030     public function chooserAction()
00031     {
00032         $block = false;
00033         switch ($this->getRequest()->getParam('attribute')) {
00034             case 'sku':
00035                 $block = $this->getLayout()->createBlock(
00036                     'adminhtml/promo_widget_chooser_sku', 'promo_widget_chooser_sku',
00037                     array('js_form_object' => $this->getRequest()->getParam('form'),
00038                 ));
00039                 break;
00040 
00041             case 'category_ids':
00042                 $block = $this->getLayout()->createBlock(
00043                         'adminhtml/catalog_category_checkboxes_tree', 'promo_widget_chooser_category_ids',
00044                         array('js_form_object' => $this->getRequest()->getParam('form'))
00045                     )
00046                     ->setCategoryIds($this->getRequest()->getParam('selected', array()))
00047                 ;
00048                 break;
00049         }
00050         if ($block) {
00051             $this->getResponse()->setBody($block->toHtml());
00052         }
00053     }
00054 
00055     protected function _isAllowed()
00056     {
00057         return Mage::getSingleton('admin/session')->isAllowed('promo/catalog');
00058     }
00059 
00060 
00061 
00062 
00063     public function categoriesJsonAction()
00064     {
00065         if ($categoryId = (int) $this->getRequest()->getPost('id')) {
00066             $this->getRequest()->setParam('id', $categoryId);
00067 
00068             if (!$category = $this->_initCategory()) {
00069                 return;
00070             }
00071             $this->getResponse()->setBody(
00072                 $this->getLayout()->createBlock('adminhtml/catalog_category_tree')
00073                     ->getTreeJson($category)
00074             );
00075         }
00076     }
00077 
00078 
00079 
00080 
00081 
00082 
00083     protected function _initCategory()
00084     {
00085         $categoryId = (int) $this->getRequest()->getParam('id',false);
00086 
00087         $storeId    = (int) $this->getRequest()->getParam('store');
00088 
00089         $category = Mage::getModel('catalog/category');
00090         $category->setStoreId($storeId);
00091 
00092         if ($categoryId) {
00093             $category->load($categoryId);
00094             if ($storeId) {
00095                 $rootId = Mage::app()->getStore($storeId)->getRootCategoryId();
00096                 if (!in_array($rootId, $category->getPathIds())) {
00097                     $this->_redirect('*/*/', array('_current'=>true, 'id'=>null));
00098                     return false;
00099                 }
00100             }
00101         }
00102 
00103         Mage::register('category', $category);
00104         Mage::register('current_category', $category);
00105         return $category;
00106     }
00107 }