Moved some more common code into lnapp
This commit is contained in:
4
classes/Controller/TemplateDefault.php
Normal file
4
classes/Controller/TemplateDefault.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
abstract class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {}
|
||||
?>
|
4
classes/Request.php
Normal file
4
classes/Request.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
class Request extends lnApp_Request {}
|
||||
?>
|
@@ -35,6 +35,9 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa
|
||||
*/
|
||||
protected $secure_actions = array();
|
||||
|
||||
// Our acccount object
|
||||
protected $ao;
|
||||
|
||||
public function __construct(Request $request, Response $response) {
|
||||
if (Config::theme())
|
||||
$this->template = Config::theme().'/page';
|
||||
@@ -69,6 +72,16 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa
|
||||
* @uses meta
|
||||
*/
|
||||
public function before() {
|
||||
if ($this->auth_required) {
|
||||
if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()])))
|
||||
throw HTTP_Exception::factory(403,'Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action()));
|
||||
|
||||
$this->ao = Auth::instance()->get_user();
|
||||
|
||||
if (! is_null($this->ao) AND (is_string($this->ao) OR ! $this->ao->loaded()))
|
||||
throw HTTP_Exception::factory(501,'Account doesnt exist :account ?',array(':account'=>(is_string($this->ao) OR is_null($this->ao)) ? $this->ao : Auth::instance()->get_user()->id));
|
||||
}
|
||||
|
||||
// Actions that start with ajax, should only be ajax
|
||||
if (! Kohana::$config->load('debug')->ajax AND preg_match('/^ajax/',Request::current()->action()) AND ! Request::current()->is_ajax())
|
||||
throw HTTP_Exception::factory(412,_('Unable to fulfil request.'));
|
||||
|
@@ -76,6 +76,56 @@ abstract class lnApp_ORM extends Kohana_ORM {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is our AJAX helper, used by module list_autocomplete()
|
||||
*/
|
||||
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
|
||||
$result = array();
|
||||
|
||||
$query = empty($options['object']) ? $this : $options['object'];
|
||||
|
||||
foreach ($limit as $w) {
|
||||
list($k,$s,$v) = $w;
|
||||
|
||||
$query->and_where($k,$s,$v);
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
foreach ((empty($options['object']) ? $query->find_all() : $query->execute()) as $o) {
|
||||
// If we got here via a DB query, we need to reload our ORM object from the result.
|
||||
if (! is_object($o)) {
|
||||
if (empty($options['key']))
|
||||
throw new Kohana_Exception('Missing key for non object');
|
||||
|
||||
$o = $this->clear()->where($options['key'],'=',$o[$options['key']])->find();
|
||||
}
|
||||
|
||||
switch ($index) {
|
||||
case 'url':
|
||||
if (empty($options['urlprefix']))
|
||||
throw new Kohana_Exception('Missing URL Prefix');
|
||||
|
||||
$v = $options['urlprefix'].$o->resolve($value);
|
||||
|
||||
break;
|
||||
|
||||
default: $v = $o->resolve($value);
|
||||
}
|
||||
|
||||
$k = '';
|
||||
foreach ($label as $k => $details)
|
||||
foreach ($details as $lvalue)
|
||||
$k = preg_replace('/%s/',$o->resolve($lvalue),$k,1);
|
||||
|
||||
$result[$c++] = array(
|
||||
'value'=>$v,
|
||||
'label'=>$k,
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of data that can be used in a SELECT statement.
|
||||
* The ID and VALUE is defined in the model for the select.
|
||||
@@ -84,7 +134,7 @@ abstract class lnApp_ORM extends Kohana_ORM {
|
||||
$result = array();
|
||||
|
||||
if ($blank)
|
||||
$result[] = '';
|
||||
$result[NULL] = '';
|
||||
|
||||
if ($this->_form AND array_intersect(array('id','value'),$this->_form))
|
||||
foreach ($this->find_all() as $o)
|
||||
|
31
classes/lnApp/Request.php
Normal file
31
classes/lnApp/Request.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* Request. Uses the [Route] class to determine what
|
||||
* [Controller] to send the request to.
|
||||
*
|
||||
* @package lnApp
|
||||
* @category Modifications
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Request extends Kohana_Request {
|
||||
/**
|
||||
* Sets and gets the directory for the controller.
|
||||
*
|
||||
* We override the Kohana version, so that we can have short directory URLs.
|
||||
* eg: admin=>a,reseller=>r.
|
||||
*
|
||||
* @param string $directory Directory to execute the controller from
|
||||
* @return mixed
|
||||
*/
|
||||
public function directory($directory = NULL) {
|
||||
// If $directory is NULL, we are a getter and see if we need to expand the directory
|
||||
if ($directory === NULL AND $this->_directory)
|
||||
$this->_directory = URL::dir($this->_directory);
|
||||
|
||||
return parent::directory($directory);
|
||||
}
|
||||
}
|
||||
?>
|
@@ -63,7 +63,11 @@ abstract class lnApp_Table {
|
||||
$x = $d;
|
||||
|
||||
else
|
||||
$x = $d->display($key);
|
||||
$x = isset($d->{$key}) ? $d->display($key) : '';
|
||||
|
||||
// We cant display array values
|
||||
if (is_array($x))
|
||||
$x = array_shift($x);
|
||||
|
||||
if (isset($this->prepend[$key]) AND $x) {
|
||||
foreach ($this->prepend[$key] as $act => $data) {
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class lnApp_URL extends Kohana_URL {
|
||||
abstract class lnApp_URL extends Kohana_URL {
|
||||
// Our method paths for different functions
|
||||
public static $method_directory = array(
|
||||
'admin'=>'a',
|
||||
|
Reference in New Issue
Block a user