OSB enhancements to date

This commit is contained in:
Deon George
2010-11-30 09:41:08 +11:00
parent 8715a2059b
commit ec6a542bc3
478 changed files with 23423 additions and 9309 deletions

View File

@@ -0,0 +1,101 @@
<?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
*/
class Controller_Admin_Module extends Controller_Module {
/**
* Our menu method
*
* We need this method, otherwise we have redirect from our parent
*/
public function action_menu() {
$this->template->content = _('See menu on tree');
}
/**
* 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,
));
$this->template->content = Block::factory();
}
/**
* Edit a Module Configuration
*
* @param int $mid Module ID
*/
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,
));
$this->template->content = Block::factory();
}
}
?>

View File

@@ -0,0 +1,138 @@
<?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
*/
class Controller_Admin_Module_Method extends Controller_Module {
/**
* Add a method to the database
*/
public function action_add($mid,$method) {
$mo = ORM::factory('module',$mid);
$mmo = ORM::factory('module_method');
if (! $mo->loaded() OR ! in_array($method,$this->_methods($mo->name)))
throw new Kohana_Exception('Method (:method) does not exist in :class',array(':method'=>$method,':class'=>$mo->name));
$mmo->name = $method;
$mmo->module_id = $mo->id;
$mmo->values($_POST);
$output = '';
if ($_POST AND $mmo->values($_POST)->check()) {
$mmo->save();
if ($mmo->saved()) {
SystemMessage::add(array(
'title'=>_('Method Added'),
'type'=>'info',
'body'=>sprintf(_('Method %s defined to database'),$mmo->name),
));
Request::instance()->redirect(sprintf('admin/module/edit/%s',$mo->id));
} else {
SystemMessage::add(array(
'title'=>_('Method Not Saved'),
'type'=>'error',
'body'=>sprintf(_('Unable to define Method %s to database?'),$mmo->name),
));
}
}
$output .= View::factory('module/admin/method_add')
->set('module',$mo)
->set('method',$mmo);
Block::add(array(
'title'=>sprintf(_('Add Method (%s) to Database for (%s)'),strtoupper($mmo->name),strtoupper($mo->name)),
'body'=>$output,
));
$this->template->content = Block::factory();
}
/**
* Edit a Module Configuration
*
* @param int $mid Module ID
*/
public function action_edit($mid) {
$mmo = ORM::factory('module_method',$mid);
if (! $mmo->loaded()) {
SystemMessage::add(array(
'title'=>_('Invalid Method ID'),
'type'=>'error',
'body'=>sprintf(_('Method with ID %s doesnt appear to exist?'),$mid),
));
return;
}
$output = '';
// The groups that can run this method.
$groups = ORM::factory('group');
if ($_POST) {
foreach ($groups->find_all() as $go) {
// If the group was defined and no longer
if ($mmo->has('group',$go) AND (! isset($_POST['groups']) OR ! in_array($go->id,$_POST['groups']))) {
$gm = ORM::factory('group_method',array('method_id'=>$mmo->id,'group_id'=>$go->id));
if (! $gm->delete())
SystemMessage::add(array(
'title'=>_('Unable to DELETE Group Method'),
'type'=>'error',
'body'=>sprintf(_('Unable to delete Group Method for method %s and group %s'),$mmo->name,$go->name),
));
// If the group was not defined and now is
} elseif (! $mmo->has('group',$go) AND isset($_POST['groups']) AND in_array($go->id,$_POST['groups'])) {
$gm = ORM::factory('group_method')
->values(array(
'method_id'=>$mmo->id,
'group_id'=>$go->id,
));
if (! $gm->check() OR ! $gm->save())
SystemMessage::add(array(
'title'=>_('Unable to SAVE Group Method'),
'type'=>'error',
'body'=>sprintf(_('Unable to save Group Method for method %s and group %s'),$mmo->name,$go->name),
));
}
}
}
$output .= Form::open();
$output .= View::factory('module/admin/method_detail_header');
foreach ($groups->find_all() as $go) {
$output .= View::factory('module/admin/method_detail_body')
->set('group',$go)
->set('defined',$mmo->has('group',$go));
}
$output .= View::factory('module/admin/method_detail_footer');
$output .= '<div>'.Form::submit('submit',_('Update')).'</div>';
$output .= Form::close();
Block::add(array(
'title'=>sprintf(_('%s->%s Method'),strtoupper($mmo->module->name),strtoupper($mmo->name)),
'body'=>$output,
));
$this->template->content = Block::factory();
}
}
?>

View File

@@ -0,0 +1,52 @@
<?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
*/
class Controller_Module extends Controller_TemplateDefault {
public $secure_actions = array(
'edit'=>TRUE,
'list'=>TRUE,
'menu'=>TRUE,
);
public function action_menu() {
// Redirect us to the admin menu, no user facilities here!
Request::instance()->redirect('/admin/module/menu');
}
/**
* Get the list of methods for a class
*/
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;
}
}
?>