Misc many fixes

This commit is contained in:
Deon George
2011-09-17 20:45:08 +10:00
parent 52074d239b
commit 7180e01dcf
18 changed files with 162 additions and 55 deletions

View File

@@ -4,20 +4,10 @@ class Config extends lnApp_Config {
/**
* Find a list of all database enabled modules
*
* @uses cache
* Our available modules are defined in the DB (along with method
* security).
*/
public static function appmodules() {
$cacheable = TRUE;
if (array_key_exists('cache',Kohana::modules())) {
$cache = Cache::instance(static::cachetype());
if ($cacheable AND $cache->get('modules'))
return $cache->get('modules');
} else
$cache = '';
$modules = array();
$module_table = 'module';
@@ -28,9 +18,6 @@ class Config extends lnApp_Config {
$modules[$o->name] = MODPATH.$o->name;
}
if ($cache)
$cache->set('modules',$modules);
return $modules;
}
}

View File

@@ -15,7 +15,7 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
'add'=>TRUE,
'edit'=>TRUE,
'list'=>TRUE,
);
);
/**
* Get the list of methods for a class
@@ -51,7 +51,7 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin {
$mo = ORM::factory('module');
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Email For'),$this->ao->accnum(),$this->ao->name(TRUE)),
'title'=>_('Defined Modules'),
'body'=>Table::display(
$mo->find_all(),
25,

View File

@@ -0,0 +1,28 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_Debug extends Controller_TemplateDefault {
public function before() {
if (! in_array(Config::sitemode(),array(Kohana::DEVELOPMENT,Kohana::TESTING)))
$this->request->redirect();
parent::before();
}
public function action_site() {
$output = '';
$output .= debug::vars(array(
'm'=>__METHOD__,
'site'=>Config::site(),
'siteID'=>Config::siteid(),
'siteMode'=>Config::sitemodeverbose(),
'modules'=>Config::appmodules(),
));
Block::add(array(
'title'=>_('Site debug'),
'body'=>$output,
));
}
}
?>

View File

@@ -155,6 +155,8 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
$mt->save();
// Send our email with the token
// @todo Need to provide an option if Email_Template is not installed/activited.
// @todo Need to provide an option if account_reset_password template doesnt exist.
$et = Email_Template::instance('account_reset_password');
$et->to = array('account'=>array($mt->account_id));
$et->variables = array(

View File

@@ -89,7 +89,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
SystemMessage::add(array(
'title'=>_('Insufficient Access'),
'type'=>'debug',
'body'=>Kohana::debug(array('required'=>$this->auth_required,'action'=>$this->request->action(),'user'=>Auth::instance()->get_user()->username)),
'body'=>Debug::vars(array('required'=>$this->auth_required,'action'=>$this->request->action(),'user'=>Auth::instance()->get_user()->username)),
));
// @todo Login No Access redirects are not handled in JS?
@@ -206,7 +206,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
* Default Method to call from the tree menu
*/
public function action_menu() {
$this->template->content = _('Please choose from the menu.');
$this->template->content = _('Please choose from the menu on the left - you may need to expand the items by pressing on the triangle.');
}
protected function _headimages() {

View File

@@ -27,7 +27,7 @@ class Controller_TemplateDefault extends Controller_lnApp_TemplateDefault {
}
private function _cart() {
if (! Cart::instance()->contents()->reset(FALSE)->count_all())
if (! class_exists('cart') OR ! Cart::instance()->contents()->reset(FALSE)->count_all())
return '';
return Cart::instance()->cart_block();

View File

@@ -53,6 +53,17 @@ abstract class lnApp_Config extends Kohana_Config {
return $sites[static::site()];
}
public static function sitemodeverbose() {
$modes = array(
Kohana::PRODUCTION=>'Production',
Kohana::STAGING=>'Staging',
Kohana::TESTING=>'Testing',
Kohana::DEVELOPMENT=>'Development',
);
return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()];
}
public static function sitename() {
return Kohana::config('config.site_name');
}

View File

@@ -73,5 +73,56 @@ class ORM extends Kohana_ORM {
else
return HTML::nbsp($value);
}
/**
* Override KH's ORM has() function, to include our site_id in the query.
*
* This is a copy of KH's ORM has() function, with the addition of a where
* clause to include the site id.
*/
public function has($alias, $far_keys) {
$far_keys = ($far_keys instanceof ORM) ? $far_keys->pk() : $far_keys;
// We need an array to simplify the logic
$far_keys = (array) $far_keys;
// Nothing to check if the model isn't loaded or we don't have any far_keys
if ( ! $far_keys OR ! $this->_loaded)
return FALSE;
$count = (int) DB::select(array('COUNT("*")', 'records_found'))
->from($this->_has_many[$alias]['through'])
->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())
->where($this->_has_many[$alias]['far_key'], 'IN', $far_keys)
->where('site_id', '=', Config::siteid())
->execute($this->_db)->get('records_found');
// Rows found need to match the rows searched
return $count === count($far_keys);
}
/**
* Tests if this object has a relationship to a different model,
* or an array of different models.
*
* // Check for any of the following roles
* $model->has('roles', array(1, 2, 3, 4));
*
* @param string $alias Alias of the has_many "through" relationship
* @param mixed $far_keys An array of primary keys
* @return Database_Result
*/
public function has_any($alias, array $far_keys) {
// Nothing to check if the model isn't loaded or we don't have any far_keys
if ( ! $far_keys)
return FALSE;
// Rows found need to match the rows searched
return (int) DB::select(array('COUNT("*")', 'records_found'))
->from($this->_has_many[$alias]['through'])
->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk())
->where($this->_has_many[$alias]['far_key'], 'IN', $far_keys)
->execute($this->_db)->get('records_found');
}
}
?>