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.
lnauth/classes/lnAuth/Controller/Admin/Module/Method.php

96 lines
3.0 KiB
PHP
Raw Permalink Normal View History

2014-09-29 05:15:49 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides MODULE management
*
* @package lnAuth
* @category Controllers/Admin
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnAuth_Controller_Admin_Module_Method extends Controller_Admin_Module {
/**
* Add a method to the database
*/
public function action_add() {
$id = $this->request->param('id');
$method = $this->request->param('sid');
$mo = ORM::factory('Module',$id);
$mm = $this->_methods($mo->name);
if (! $mo->loaded() OR ! in_array($method,$mm['methods']))
HTTP::redirect(URL::link('admin','module/list'));
2016-08-25 13:23:25 +00:00
$mmo = $mo->module_method;
$mmo->name = $method;
$mmo->module_id = $mo->id;
2014-09-29 05:15:49 +00:00
2016-08-25 13:23:25 +00:00
if (! $this->save($mmo))
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($this->request->post())));
2014-09-29 05:15:49 +00:00
2016-08-25 13:23:25 +00:00
HTTP::redirect(URL::link('admin','module_method/edit/'.$mmo->id));
2014-09-29 05:15:49 +00:00
}
/**
* Edit a Module Configuration
*/
public function action_edit() {
$id = $this->request->param('id');
$mmo = ORM::factory('Module_Method',$id);
if (! $mmo->loaded()) {
SystemMessage::factory()
->title(_('Invalid Method ID'))
->type('error')
->body(sprintf(_('Method with ID %s doesnt appear to exist?'),$id));
HTTP::redirect(URL::link('admin','module/list'));
}
2016-08-25 13:23:25 +00:00
if ($this->request->post()) {
$mmo->values($this->request->post());
2014-09-29 05:15:49 +00:00
if (! $this->save($mmo))
2016-08-25 13:23:25 +00:00
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($this->request->post())));
2014-09-29 05:15:49 +00:00
foreach (ORM::factory('Group')->find_all() as $go) {
// If the group was defined and no longer
2016-08-25 13:23:25 +00:00
if ($mmo->has('group',$go) AND (! $this->request->post('groups') OR ! in_array($go->id,$this->request->post('groups')))) {
2014-09-29 05:15:49 +00:00
$gmo = ORM::factory('Group_Method',array('method_id'=>$mmo->id,'group_id'=>$go->id));
if (! $gmo->delete())
SystemMessage::factory()
->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
2016-08-25 13:23:25 +00:00
} elseif (! $mmo->has('group',$go) AND $this->request->post('groups') AND in_array($go->id,$this->request->post('groups'))) {
2014-09-29 05:15:49 +00:00
$gmo = ORM::factory('Group_Method')
->values(array(
'method_id'=>$mmo->id,
'group_id'=>$go->id,
));
if (! $this->save($gmo))
SystemMessage::factory()
->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));
}
}
HTTP::redirect(URL::link('admin','module/edit/'.$mmo->module_id));
}
Block::factory()
->title(sprintf(_('Configure access to method (%s::%s)'),$mmo->controller(),$mmo->method()))
2016-08-25 13:23:25 +00:00
->title_icon('fa fa-lock')
2014-09-29 07:30:54 +00:00
->type('form-horizontal')
->body(View::factory('module/method/admin/edit')->set('o',$mmo));
2014-09-29 05:15:49 +00:00
}
}
?>