PageRenderTime 55ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/app/plugins/javan/controllers/components/util.php

https://github.com/ata/steak
PHP | 91 lines | 63 code | 18 blank | 10 comment | 4 complexity | ced58afa8e53449c13ec74d7c8936d17 MD5 | raw file
  1. <?php
  2. class UtilComponent extends Object{
  3. public $info = array();
  4. var $__controller = null ;
  5. function initialize(&$controller) {
  6. $this->info['controller'] = $controller->params['controller'];
  7. $this->info['action'] = $controller->params['action'];
  8. $this->__controller = $controller;
  9. }
  10. function startup(&$controller) {
  11. }
  12. function beforeFilter () {
  13. }
  14. function beforeRender(&$controller) {
  15. $this->__controller->set('breadcrumbs', $this->requestAction('/javan/breadcrumb'));
  16. }
  17. function setPublic($publics) {
  18. foreach($publics as $public)
  19. {
  20. extract($public);
  21. if($controller === $this->info['controller'])
  22. {
  23. $this->Auth->allowedActions = $action;
  24. return true;
  25. }
  26. }
  27. return false;
  28. }
  29. /**
  30. * gets all available actions in controller.
  31. *
  32. * @param array $reserved reserved action (for example, that already inserted to databse)
  33. * @return array An array of action in key=>value format (suitable for listbox, checkbox, etc)
  34. * @access public
  35. * @static
  36. */
  37. function listActions($reserved=array()){
  38. $menu = array();
  39. $reservedPath = array();
  40. foreach($reserved as $res){
  41. $reservedPath[] = $res['Link']['controller'].'/'.$res['Link']['action'];
  42. }
  43. $controllers = Configure::listObjects('controller');
  44. $controllers = array_diff($controllers,array('App','Pages'));
  45. $baseMethods = get_class_methods('Controller');
  46. // look at each controller in app/controllers
  47. foreach ($controllers as $ctrlName) {
  48. App::import('Controller', $ctrlName);
  49. $ctrlclass = $ctrlName . 'Controller';
  50. $methods = get_class_methods($ctrlclass);
  51. //clean the methods. to remove those in Controller and private actions.
  52. foreach ($methods as $k => $method) {
  53. $path = Inflector::underscore($ctrlName).'/'.$method;
  54. if (strpos($method, '_', 0) === 0) {
  55. unset($methods[$k]);
  56. continue;
  57. }
  58. if (in_array($method, $baseMethods)) {
  59. unset($methods[$k]);
  60. continue;
  61. }
  62. if(in_array($path, $reservedPath)) {
  63. unset($methods[$k]);
  64. continue;
  65. }
  66. $menu[$path] = $path;
  67. }
  68. }
  69. ksort($menu);
  70. return $menu;
  71. }
  72. }
  73. ?>