Skip to content
Browse files

Fixed loading of parent resources for MOP_Controller descendents

  • Loading branch information...
1 parent f06cdf3 commit ebed4079a05b5d179d265a49603d6f7a7c1a3fe0 @deepwinter deepwinter committed May 22, 2011
Showing with 42 additions and 13 deletions.
  1. +42 −13 modules/mopcore/classes/controller/mop.php
View
55 modules/mopcore/classes/controller/mop.php
@@ -16,18 +16,19 @@ class Controller_MOP extends Controller {
//constructor
public function __construct($request, $response){
- parent::__construct($request, $response);
+ parent::__construct($request, $response);
- $this->controllerName = strtolower(substr(get_class($this), 11));
+ $this->controllerName = strtolower(substr(get_class($this), 11));
$this->checkAccess();
if($request->is_initial()){
self::$topController = $this;
}
//look up all matching js and css based off controller name
-
- $this->loadResources($this->controllerName);
+
+ $this->loadResources();
+
}
/*
@@ -38,9 +39,11 @@ public function __construct($request, $response){
* Returns: nothing
*/
public function checkAccess(){
+ Kohana::$log->add(Log::ERROR, 'Skipping login for control panel');
+ /* SKIPPING LOGIN
//Authentication check
$role = Kohana::config(strtolower($this->controllerName).'.authrole', FALSE, FALSE);
-
+
//checked if logged in
if($role && !Auth::instance()->logged_in()){
Request::current()->redirect('auth/login/'.Request::initial()->uri());
@@ -77,19 +80,31 @@ public function checkAccess(){
url::redirect($redirect);
exit;
}
+ */
}
+ protected function loadResources(){
+ $this->loadResourcesForKey($this->controllerName);
- protected function loadResources($key){
- if(is_subclass_of(self::$topController, 'Controller_MOP')){
- //should add to self, then merge into topController
- if($css = Kohana::find_file('views', 'css/'.$key, 'css')){
- $this->resources['css'][$css] = helper_mop::convertFullPathToWebPath($css);
- }
- if($js = Kohana::find_file('views', 'js/'.$key, 'js')){
- $this->resources['js'][$js] = helper_mop::convertFullPathToWebPath($js);
+ $parents = $this->getParents();
+ foreach($parents as $parent){
+ if($parent == 'MOP_Controller'){
+ break;
}
+ $parentKey = strtolower(substr($parent, 11));
+ $this->loadResourcesForKey($parentKey);
+ }
+ }
+
+ protected function loadResourcesForKey($key){
+
+ //should add to self, then merge into topController
+ if($css = Kohana::find_file('views', 'css/'.$key, 'css')){
+ $this->resources['css'][$css] = helper_mop::convertFullPathToWebPath($css);
+ }
+ if($js = Kohana::find_file('views', 'js/'.$key, 'js')){
+ $this->resources['js'][$js] = helper_mop::convertFullPathToWebPath($js);
}
$config = Kohana::config($key);
@@ -108,6 +123,20 @@ protected function loadResources($key){
self::$topController->resources[$key] = array_merge(self::$topController->resources[$key], $this->resources[$key]);
}
}
+
+ }
+
+ public function getParents($class=null, $plist=array()) {
+ $class = $class ? $class : $this;
+ $parent = get_parent_class($class);
+ if($parent) {
+ $plist[] = $parent;
+ /*Do not use $this. Use 'self' here instead, or you
+ * * will get an infinite loop. */
+ $plist = self::getParents($parent, $plist);
+ }
+ return $plist;
}
+
}

0 comments on commit ebed407

Please sign in to comment.
Something went wrong with that request. Please try again.