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-27 06:33:46 +00:00
|
|
|
class Controller_Admin_Module_Method extends Controller_Admin_Module {
|
2010-11-29 22:41:08 +00:00
|
|
|
/**
|
|
|
|
* 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),
|
|
|
|
));
|
|
|
|
|
2011-05-14 07:35:33 +00:00
|
|
|
Request::current()->redirect(sprintf('admin/module/edit/%s',$mo->id));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
} 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,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit a Module Configuration
|
|
|
|
*
|
|
|
|
* @param int $mid Module ID
|
|
|
|
*/
|
2011-08-27 06:33:46 +00:00
|
|
|
public function action_edit() {
|
|
|
|
$mid = $this->request->param('id');
|
2010-11-29 22:41:08 +00:00
|
|
|
$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();
|
|
|
|
|
2011-08-27 06:33:46 +00:00
|
|
|
$output .= View::factory('module/admin/method_detail_head');
|
2010-11-29 22:41:08 +00:00
|
|
|
foreach ($groups->find_all() as $go) {
|
|
|
|
$output .= View::factory('module/admin/method_detail_body')
|
|
|
|
->set('group',$go)
|
|
|
|
->set('defined',$mmo->has('group',$go));
|
|
|
|
}
|
2011-08-27 06:33:46 +00:00
|
|
|
$output .= View::factory('module/admin/method_detail_foot');
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-08-31 06:54:44 +00:00
|
|
|
$output .= '<div>'.Form::submit('submit',_('Update'),array('class'=>'form_button')).'</div>';
|
2010-11-29 22:41:08 +00:00
|
|
|
$output .= Form::close();
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf(_('%s->%s Method'),strtoupper($mmo->module->name),strtoupper($mmo->name)),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|