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
2016-08-25 23:23:25 +10:00

96 lines
3.0 KiB
PHP

<?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'));
$mmo = $mo->module_method;
$mmo->name = $method;
$mmo->module_id = $mo->id;
if (! $this->save($mmo))
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($this->request->post())));
HTTP::redirect(URL::link('admin','module_method/edit/'.$mmo->id));
}
/**
* 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'));
}
if ($this->request->post()) {
$mmo->values($this->request->post());
if (! $this->save($mmo))
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($this->request->post())));
foreach (ORM::factory('Group')->find_all() as $go) {
// If the group was defined and no longer
if ($mmo->has('group',$go) AND (! $this->request->post('groups') OR ! in_array($go->id,$this->request->post('groups')))) {
$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
} elseif (! $mmo->has('group',$go) AND $this->request->post('groups') AND in_array($go->id,$this->request->post('groups'))) {
$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()))
->title_icon('fa fa-lock')
->type('form-horizontal')
->body(View::factory('module/method/admin/edit')->set('o',$mmo));
}
}
?>