2012-06-28 17:24:12 +02:00
< ? php
2013-01-04 15:49:52 +01:00
2012-06-28 17:24:12 +02:00
App :: uses ( 'AppController' , 'Controller' );
2013-01-04 15:49:52 +01:00
2012-06-28 17:24:12 +02:00
/**
2012-12-12 16:15:01 +01:00
* Roles Controller
2012-06-28 17:24:12 +02:00
*
2012-12-12 16:15:01 +01:00
* @ property Role $Role
2012-06-28 17:24:12 +02:00
*/
2012-12-12 16:15:01 +01:00
class RolesController extends AppController {
2012-06-28 17:24:12 +02:00
2013-04-24 15:24:39 +02:00
public $options = array ( '0' => 'Read Only' , '1' => 'Manage My Own Events' , '2' => 'Manage Organization Events' , '3' => 'Manage & Publish Organization Events' ); // FIXME move this to Role Model
2012-11-08 10:31:50 +01:00
2012-06-28 17:24:12 +02:00
public $components = array (
2012-12-19 02:48:53 +01:00
'Security' ,
2013-01-22 15:46:39 +01:00
'Session' , 'AdminCrud' // => array('fields' => array('name'))
2012-12-19 02:48:53 +01:00
);
2012-09-18 17:32:34 +02:00
2013-01-22 16:15:32 +01:00
public $helpers = array ( 'Js' => array ( 'Jquery' ));
2012-12-19 02:48:53 +01:00
public $paginate = array (
'limit' => 60 ,
'order' => array (
'Role.name' => 'ASC'
)
);
2012-06-28 17:24:12 +02:00
2012-12-19 02:48:53 +01:00
public function beforeFilter () {
parent :: beforeFilter ();
}
2012-09-18 17:32:34 +02:00
2013-01-22 16:12:36 +01:00
/**
* view method
*
* @ param string $id
* @ return void
2013-01-28 12:05:23 +01:00
*
* @ throws NotFoundException
2013-01-22 16:12:36 +01:00
*/
public function view ( $id = null ) {
$this -> Role -> id = $id ;
2013-02-05 17:22:37 +01:00
//$this->Acl->allow($this->Role, 'controllers/Events/add');
2013-01-22 16:12:36 +01:00
if ( ! $this -> Role -> exists ()) {
throw new NotFoundException ( __ ( 'Invalid role' ));
}
$this -> set ( 'role' , $this -> Role -> read ( null , $id ));
}
2012-06-28 17:24:12 +02:00
/**
2013-01-04 15:49:52 +01:00
* admin_add method
2012-12-19 02:48:53 +01:00
*
2012-06-28 17:24:12 +02:00
* @ return void
*/
2013-01-04 15:49:52 +01:00
public function admin_add () {
2013-01-30 11:49:55 +01:00
if ( $this -> Auth -> User ( 'org' ) != 'ADMIN' ) $this -> redirect ( array ( 'controller' => 'roles' , 'action' => 'index' , 'admin' => false ));
2013-02-05 17:22:37 +01:00
if ( $this -> request -> is ( 'post' )) {
$this -> Role -> create ();
if ( $this -> Role -> save ( $this -> request -> data )) {
$this -> Session -> setFlash ( __ ( sprintf ( 'The Role has been saved.' )));
$this -> set ( 'options' , $this -> options );
$passAlong = $this -> Role -> read ( null , $this -> Role -> getInsertID ());
$this -> redirect ( array ( 'action' => 'index' ));
} else {
if ( ! ( $this -> Session -> check ( 'Message.flash' ))) {
$this -> Role -> Session -> setFlash ( __ ( sprintf ( 'The Role could not be saved. Please, try again.' )));
}
}
}
2013-01-04 15:49:52 +01:00
$this -> set ( 'options' , $this -> options );
2013-02-05 17:22:37 +01:00
//$this->AdminCrud->adminAdd();
2012-06-28 17:24:12 +02:00
}
2012-09-18 17:32:34 +02:00
2012-06-28 17:24:12 +02:00
/**
* admin_index method
*
* @ return void
*/
public function admin_index () {
2013-01-30 11:49:55 +01:00
if ( $this -> Auth -> User ( 'org' ) != 'ADMIN' ) $this -> redirect ( array ( 'controller' => 'roles' , 'action' => 'index' , 'admin' => false ));
2013-01-04 15:49:52 +01:00
$this -> AdminCrud -> adminIndex ();
2012-11-08 10:31:50 +01:00
$this -> set ( 'options' , $this -> options );
2012-06-28 17:24:12 +02:00
}
/**
* admin_edit method
*
* @ param string $id
* @ return void
2013-01-04 15:49:52 +01:00
* @ throws NotFoundException
2012-06-28 17:24:12 +02:00
*/
public function admin_edit ( $id = null ) {
2013-01-30 11:49:55 +01:00
if ( $this -> Auth -> User ( 'org' ) != 'ADMIN' ) $this -> redirect ( array ( 'controller' => 'roles' , 'action' => 'index' , 'admin' => false ));
2013-01-04 15:49:52 +01:00
$this -> AdminCrud -> adminEdit ( $id );
2013-02-21 17:24:41 +01:00
$passAlong = $this -> Role -> read ( null , $id );
2012-11-08 10:31:50 +01:00
$this -> set ( 'options' , $this -> options );
2012-06-28 17:24:12 +02:00
}
/**
* admin_delete method
*
2013-01-28 11:44:09 +01:00
* @ param string $id
2012-12-19 02:48:53 +01:00
*
2013-01-04 15:49:52 +01:00
* @ throws MethodNotAllowedException
2012-12-19 02:48:53 +01:00
* @ throws NotFoundException
*
2012-06-28 17:24:12 +02:00
* @ return void
*/
public function admin_delete ( $id = null ) {
2013-01-04 15:49:52 +01:00
$this -> AdminCrud -> adminDelete ( $id );
2012-06-28 17:24:12 +02:00
}
2013-01-28 11:44:09 +01:00
/**
* index method
*
* @ return void
*/
public function index () {
$this -> recursive = 0 ;
2013-04-24 15:24:39 +02:00
$this -> set ( 'list' , $this -> paginate ());
2013-01-28 11:44:09 +01:00
$this -> set ( 'options' , $this -> options );
}
2013-01-22 16:15:32 +01:00
}