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/application/classes/Controller/Admin/Module.php

131 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
*
2013-03-19 22:35:19 +00:00
* @package OSB
* @category Controllers/Admin
2010-11-29 22:41:08 +00:00
* @author Deon George
2013-03-19 22:35:19 +00:00
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
2010-11-29 22:41:08 +00:00
*/
2011-08-26 01:16:48 +00:00
class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'add'=>TRUE,
2011-08-26 01:16:48 +00:00
'edit'=>TRUE,
'list'=>TRUE,
2011-09-17 10:45:08 +00:00
);
2011-08-26 01:16:48 +00:00
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 = URL::$method_directory;
2011-08-26 01:16:48 +00:00
array_unshift($classes,'');
foreach ($classes as $c) {
2012-11-09 23:13:57 +00:00
$cn = sprintf($ch,$c ? ucfirst($c).'_'.ucfirst($class) : $class);
2011-08-26 01:16:48 +00:00
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() {
2012-11-09 23:13:57 +00:00
$mo = ORM::factory('Module');
2010-11-29 22:41:08 +00:00
Block::add(array(
2011-09-17 10:45:08 +00:00
'title'=>_('Defined Modules'),
'body'=>Table::display(
$mo->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>URL::link('admin','module/edit/')),
'name'=>array('label'=>'Name'),
'status'=>array('label'=>'Active'),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
2010-11-29 22:41:08 +00:00
}
/**
* Edit a Module Configuration
*
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 = $this->request->param('id');
2012-11-09 23:13:57 +00:00
$mo = ORM::factory('Module',$mid);
2010-11-29 22:41:08 +00:00
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.
Block::add(array(
'title'=>sprintf('%s: %s ',_('Defined Module Methods For'),$mo->display('name')),
'body'=>Table::display(
$mo->module_method->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>URL::link('admin','module_method/edit/')),
'name'=>array('label'=>'Name'),
'notes'=>array('label'=>'Notes'),
'menu_display'=>array('label'=>'Menu'),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
2010-11-29 22:41:08 +00:00
// Show new methods NOT defined in the DB already.
foreach ($mo->module_method->find_all() as $meo)
if (($method = array_search($meo->name,$methods)) !== false)
unset($methods[$method]);
2010-11-29 22:41:08 +00:00
if (count($methods))
Block::add(array(
'title'=>sprintf('%s: %s ',_('Undefined Module Methods For'),$mo->display('name')),
'body'=>Table::display(
$methods,
25,
array(
'__VALUE__'=>array('label'=>'Name','url'=>URL::link('admin','module_method/add/'.$mo->id)),
),
array(
'page'=>TRUE,
'type'=>'list',
)),
));
2010-11-29 22:41:08 +00:00
}
}
?>