PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/app/controllers/app_controller.php

https://github.com/ata/steak
PHP | 135 lines | 109 code | 21 blank | 5 comment | 11 complexity | d2706f71c132760decb5db6e918b185c MD5 | raw file
  1. <?php
  2. class AppController extends Controller {
  3. var $auth;
  4. var $components = array (
  5. //'Acl',
  6. 'Auth',
  7. 'RequestHandler'
  8. );
  9. var $helpers = array (
  10. 'Html',
  11. 'Session',
  12. 'Javascript',
  13. 'Form',
  14. 'Ajax'
  15. );
  16. var $paginate = array('limit' => 10, 'page' => 1);
  17. var $publicControllers = array (
  18. '',
  19. 'pages',
  20. 'configurations',
  21. 'acl',
  22. 'aclaros',
  23. 'aclacos',
  24. 'aclpermissions',
  25. 'tsilabus_akademik',
  26. 'tsilabus_mingguan_kelases'
  27. );
  28. function beforeFilter() {
  29. if($this->RequestHandler->isAjax()){
  30. //Configure::write('debug', 0);
  31. }
  32. if ($this->params['controller'] == 'pages') {
  33. $this->layout = 'page';
  34. }
  35. $this->Auth->autoRedirect = false;
  36. $logined = false;
  37. // auth configuration
  38. $this->Auth->userScope = array ('User.ENABLED_USER' => 1);
  39. $this->Auth->loginAction = '/users/login';
  40. $this->Auth->logoutRedirect = '/users/login';
  41. $this->Auth->fields = array (
  42. 'username' => 'USERNAME',
  43. 'password' => 'PASSWORD'
  44. );
  45. $this->Auth->authorize = 'controller';
  46. if (in_array(low($this->params['controller']), $this->publicControllers)) {
  47. $this->Auth->allow();
  48. }
  49. $this->auth = $this->Session->read('User');
  50. if ($this->auth && array_key_exists('User', $this->auth)) {
  51. $groupname = low($this->auth['User']['TYPE']);
  52. $currentPath = '/'.$this->params['controller'].'/'.$this->params['action'];
  53. if(!($mainMenu = Cache::read('MainMenu'))){
  54. $mainMenu = $this->_getMainMenu();
  55. Cache::write('MainMenu',$mainMenu);
  56. }
  57. // get parent path
  58. $this->loadModel('Link');
  59. $this->Link->unbindModel(array('hasAndBelongsToMany'=>array('Group'),'belongsTo'=>array('Parentlink'),'hasMany'=>array('Childlink')));
  60. $currentLink = $this->Link->find('first',array('fields'=>'Link.*','conditions'=>array('Link.path'=>$currentPath,'Link.parent_id IS NOT NULL')));
  61. $subMenu = array();
  62. $this->loadModel('Group');
  63. foreach($mainMenu as $mm){
  64. if($mm['id'] === $currentLink['Link']['parent_id']){
  65. if(!($subMenu = Cache::read('SubMenu'.$mm['id']))){
  66. $this->Group->Behaviors->attach('Containable');
  67. $this->Group->contain("Link.parent_id = {$mm['id']}");
  68. $conditions = array('Group.name'=>low($this->auth['User']['TYPE']));
  69. $group = $this->Group->find('first', array('conditions'=>$conditions));
  70. $subMenu = $group['Link'];
  71. Cache::write('SubMenu'.$mm['id'], $subMenu);
  72. }
  73. break;
  74. }
  75. }
  76. $this->set('mainMenu',$mainMenu);
  77. $this->set('subMenu',$subMenu);
  78. $this->set('currentPath', $currentPath);
  79. $this->set('currentLink', $currentLink);
  80. $logined = true;
  81. $this->set('username', $this->auth['User']['USERNAME']);
  82. $this->set('groupname', $groupname);
  83. $this->set('isDosenWali',$this->Session->read('isDosenWali'));
  84. }
  85. //Set param passed
  86. Configure::write( array(
  87. 'App.logined' => $logined,
  88. 'Paginator.params' => $this->params['named'],
  89. 'Paginator.limit' => $this->paginate['limit'],
  90. ) );
  91. $this->set('logined', $logined);
  92. $this->set("params",$this->params['named']);
  93. }
  94. function _getMainMenu(){
  95. $conditions = array('Group.name'=>low($this->auth['User']['TYPE']));
  96. $this->loadModel('Group');
  97. $this->Group->Behaviors->attach('Containable');
  98. $this->Group->contain('Link.parent_id IS NULL');
  99. $group = $this->Group->find('first', array('conditions'=>$conditions));
  100. return $group['Link'];
  101. }
  102. function isAuthorized() {
  103. return true;
  104. }
  105. function _extractGet() {
  106. $param = array();
  107. foreach($_GET as $key => $value) {
  108. if($key != 'url')
  109. $param[] = "$key=$value";
  110. }
  111. $param = implode("&", $param);
  112. return $param;
  113. }
  114. }