Assembla home | Assembla project page
 

Changeset 102

Show
Ignore:
Timestamp:
07/17/07 22:51:55 (1 year ago)
Author:
AD7six
Message:

adding administrative functions for menus

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branch/controllers/menus_controller.php

    r71 r102  
    11<?php 
    2 class menusController extends AppController { 
    3  
    4         var $name = 'menus'; 
    5         var $helpers = array('Html', 'Form' ); 
    6          
     2class MenusController extends AppController { 
     3        var $name = 'Menus'; 
     4        var $helpers = array('Form', 'Tree'); 
    75        var $uses = array('Menu','Group'); 
    8  
    96        var $recursion = 2; 
    107 
    11         function index($section = "*") 
    12         { 
    13         $data = $this->Menu->findAllThreaded(array('section_id'=>$section, 'published'=>1), null, 'Menu.position'); 
    14      
    15         if(isset($this->params['requested'])) { 
    16                         return $data; 
     8        function admin_recover_tree ($sectionId = null) { 
     9                $this->Menu->recoverTree(); 
     10        } 
     11         
     12        function admin_delete($id = null) { 
     13                if ($id && $this->Menu->delete($Id)) { 
     14                        $this->Session->setFlash('Menu #'.$id.' deleted'); 
     15                } else { 
     16                        $this->Session->setFlash('Invalid id for Menu'); 
    1717                } 
    18          
    19         $this->set('menus', $data); 
    20   } 
     18                $this->redirect($this->referer(array('action' => 'index'), null, true)); 
     19        } 
    2120 
    22         function admin_index() { 
    23                 $this->Menu->recursive = 0; 
    24                 $this->set('menus', $this->paginate()); 
     21        function admin_index($sectionId = null) { 
     22                $this->paginate['limit'] = 10; 
     23                $this->paginate['order'] = 'Menu.lft'; 
     24                $this->Menu->recursive = -1; 
     25                $constraint = array(); 
     26                if ($sectionId) { 
     27                        $constraint['Menu.section_id'] = $sectionId; 
     28                } 
     29                $this->set('menus', $this->paginate($constraint)); 
     30        } 
     31 
     32        function admin_tree($sectionId = null) { 
     33                if (!($sectionId && $this->Menu->hasAny(array('Menu.section_id'=> $sectionId)))) { 
     34                        $this->Session->setFlash('invalid section id'); 
     35                        $this->redirect(array('action' => 'index')); 
     36                } 
     37                $this->helpers[] = 'Tree'; 
     38                $this->Menu->recursive = -1; 
     39                $this->data = $this->Menu->findAll(array('Menu.section_id' => $sectionId),null,'Menu.lft ASC'); 
     40                $this->set('data', $this->data); 
    2541        } 
    2642 
     
    3147                } 
    3248                $this->set('menu', $this->Menu->read(null, $id)); 
     49        } 
     50 
     51        function admin_move_up($id) { 
     52                if (!$this->Menu->moveUp($id)) { 
     53                        $this->Session->setFlash('Could not move previous.'); 
     54                } 
     55                $this->redirect($this->referer(array ('action' => 'index'), true), null, true); 
     56        } 
     57 
     58        function admin_move_down($id) { 
     59                if (!$this->Menu->moveDown($id)) { 
     60                        $this->Session->setFlash('Could not move after.'); 
     61                } 
     62                $this->redirect($this->referer(array ('action' => 'index'), true), null, true); 
     63        } 
     64 
     65        function admin_set_parent($id, $parentId = null) { 
     66                $this->Menu->setparent($parentId); 
     67                $this->redirect($this->referer(array('action' => 'index')), null, true); 
     68        } 
     69         
     70        function admin_promote($id) { 
     71                $this->Menu->id = $id; 
     72                $menu = $this->Menu->read(null, $id); 
     73                $parent = $this->Menu->getParentMenu(); 
     74                if ($parent) { 
     75                        $this->Menu->saveField('parent_id', $parent['Menu']['parent_id']); 
     76                } else { 
     77                        $this->Session->setFlash($menu[$this->modelClass]['title'] . ' has no parent, cannot promote.'); 
     78                } 
     79                $this->redirect($this->referer(array ('action' => 'index')), null, true); 
     80        } 
     81 
     82        function admin_remove($id, $delete = false) { 
     83                $parent = $this->Menu->field('parent_id'); 
     84                $this->Menu->enableHistoric(false); 
     85                $this->Menu->removeFromTree($id, $delete); 
     86                return $this->redirect($this->referer(array ('action' => 'index'), true), null, true); 
    3387        } 
    3488 
     
    84138        } 
    85139 
    86         function admin_delete($id = null) { 
    87                 if(!$id) { 
    88                         $this->Session->setFlash('Invalid id for Menu'); 
    89                         $this->redirect(array('action'=>'index'), null, true); 
     140        function index($sectionId = null) { 
     141                $data = $this->Menu->findAll(array( 
     142                        'Menu.section_id' => $sectionId, 
     143                        'Menu.published' => 1, 
     144                        'Menu.access_level' => '<= '.$this->othAuth->group('level')), null, 'Menu.lft',null,null,-1); 
     145                $data = $this->Menu->__doThread($data, null); 
     146                if ($this->othAuth->check()) { 
     147                        $data[]['Menu'] = array('name' => 'logout', 'parent_id' => null, 'url' => array('controller' => 'users', 'action' => 'logout')); 
     148                } else { 
     149                        $data[]['Menu'] = array('name' => 'login', 'parent_id' => null, 'url' => array('controller' => 'users', 'action' => 'login')); 
    90150                } 
    91                 if($this->Menu->del($id)) { 
    92                         $this->Session->setFlash('Menu #'.$id.' deleted'); 
    93                         $this->redirect(array('action'=>'index'), null, true); 
     151                if (isset($this->params['requested'])) { 
     152                        return $data; 
    94153                } 
     154                $this->set('menus', $data); 
    95155        } 
    96156