This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/module/classes/controller/admin/module.php

122 lines
3.2 KiB
PHP
Raw Normal View History

2010-11-29 22:41:08 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides MODULE management
*
* @package lnApp
* @subpackage Page/Module
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
2011-08-26 01:16:48 +00:00
class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'edit'=>TRUE,
'list'=>TRUE,
);
2010-11-29 22:41:08 +00:00
/**
2011-08-26 01:16:48 +00:00
* Get the list of methods for a class
2010-11-29 22:41:08 +00:00
*/
2011-08-26 01:16:48 +00:00
protected function _methods($class) {
// Get a list of methods this module has
$ch = 'Controller_%s';
$methods = array();
// List of classes where all our methods are, including this one.
$classes = Kohana::config('config.method_directory');
array_unshift($classes,'');
foreach ($classes as $c) {
$cn = sprintf($ch,$c ? $c.'_'.$class : $class);
if (class_exists($cn)) {
$r = new ReflectionClass($cn);
foreach ($r->getMethods() as $method)
if (preg_match('/^Controller_(.*_)?'.$class.'$/i',$method->class) AND ! preg_match('/^_/',$method->name))
array_push($methods,str_replace('action_',($c ? $c.'_' : $c),$method->name));
}
}
return $methods;
2010-11-29 22:41:08 +00:00
}
/**
* List our installed modules
*/
public function action_list() {
$modules = ORM::factory('module');
$output = '';
$output .= View::factory('module/admin/list_header');
foreach ($modules->find_all() as $mo) {
$output .= View::factory('module/admin/list_body')
->set('module',$mo);
}
$output .= View::factory('module/admin/list_footer');
Block::add(array(
'title'=>_('Currently installed modules'),
'body'=>$output,
));
}
/**
* Edit a Module Configuration
*
* @param int $mid Module ID
2011-07-14 09:09:03 +00:00
* @todo Highlight those methods that have security, but the class does not have auth_required set to YES or the method isnt defined in secure_actions
2010-11-29 22:41:08 +00:00
*/
public function action_edit($mid) {
$mo = ORM::factory('module',$mid);
if (! $mo->loaded()) {
SystemMessage::add(array(
'title'=>_('Invalid Module ID'),
'type'=>'error',
'body'=>sprintf(_('Module with ID %s doesnt appear to exist?'),$mid),
));
return;
}
$output = '';
$methods = $this->_methods($mo->name);
// Show methods defined in the DB already.
$output .= View::factory('module/admin/method_list_header');
foreach ($mo->module_method->find_all() as $meo) {
if (($method = array_search($meo->name,$methods)) !== false)
unset($methods[$method]);
$output .= View::factory('module/admin/method_list_body')
->set('method',$meo)
->set('module',$mo)
->set('defined',$method !== false);
}
$output .= View::factory('module/admin/method_list_spacer');
// Show new methods NOT defined in the DB already.
foreach ($methods as $method) {
$meo = ORM::factory('module_method')
->values(array('name'=>$method,'notes'=>_('Not defined in DB')));
$output .= View::factory('module/admin/method_list_body')
->set('method',$meo)
->set('module',$mo)
->set('defined',$method === false);
}
$output .= View::factory('module/admin/method_list_footer');
Block::add(array(
'title'=>sprintf(_('%s Methods'),strtoupper($mo->name)),
'body'=>$output,
));
}
}
?>