Site setup fixes
This commit is contained in:
@@ -16,35 +16,38 @@ class Company {
|
||||
}
|
||||
|
||||
public static function name() {
|
||||
return Config::sitename();
|
||||
return Config::instance()->so->site_details('name');
|
||||
}
|
||||
|
||||
public static function street() {
|
||||
return Config::instance()->so->display('site_address');
|
||||
public static function street($ln='<br/>') {
|
||||
if ($b = Config::instance()->so->site_details('address2'))
|
||||
return implode($ln,array(Config::instance()->so->site_details('address1'),Config::instance()->so->site_details('address2')));
|
||||
else
|
||||
return Config::instance()->so->site_details('address1');
|
||||
}
|
||||
|
||||
public static function city() {
|
||||
return Config::instance()->so->display('site_city');
|
||||
return Config::instance()->so->site_details('city');
|
||||
}
|
||||
|
||||
public static function state() {
|
||||
return Config::instance()->so->display('site_state');
|
||||
return Config::instance()->so->site_details('state');
|
||||
}
|
||||
|
||||
public static function pcode() {
|
||||
return Config::instance()->so->display('site_zip');
|
||||
return Config::instance()->so->site_details('pcode');
|
||||
}
|
||||
|
||||
public static function address($ln='<br/>') {
|
||||
return implode($ln,array(static::street(),sprintf('%s, %s %s',static::city(),static::state(),static::pcode())));
|
||||
return implode($ln,array(static::street($ln),sprintf('%s, %s %s',static::city(),static::state(),static::pcode())));
|
||||
}
|
||||
|
||||
public static function phone() {
|
||||
return Config::instance()->so->display('site_phone');
|
||||
return Config::instance()->so->site_details('phone');
|
||||
}
|
||||
|
||||
public static function fax() {
|
||||
return Config::instance()->so->display('site_fax');
|
||||
return Config::instance()->so->site_details('fax');
|
||||
}
|
||||
|
||||
public static function contacts() {
|
||||
|
@@ -13,6 +13,7 @@
|
||||
class Config extends lnApp_Config {
|
||||
// Our setup object
|
||||
public $so;
|
||||
public static $no_site_id_tables = array('setup','country','currency','tax');
|
||||
|
||||
/**
|
||||
* Load our site configuration from the DB
|
||||
@@ -53,5 +54,17 @@ class Config extends lnApp_Config {
|
||||
public static function moduleexist($module) {
|
||||
return array_key_exists($module,static::modules()) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
public static function sitename() {
|
||||
return Company::name();
|
||||
}
|
||||
|
||||
public static function siteid() {
|
||||
return Config::instance()->loadsite()->so->id;
|
||||
}
|
||||
|
||||
public static function sitemode() {
|
||||
return Config::instance()->loadsite()->so->status;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
47
application/classes/controller/admin/setup.php
Normal file
47
application/classes/controller/admin/setup.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides Siet Configuration Setup
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page/Setup
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_Admin_Setup extends Controller_TemplateDefault_Admin {
|
||||
protected $secure_actions = array(
|
||||
'edit'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* View/Update the site configuration
|
||||
*/
|
||||
public function action_edit() {
|
||||
$o = Config::instance()->so;
|
||||
$output = '';
|
||||
|
||||
if ($_POST) {
|
||||
// Entry updated
|
||||
if ($o->values($_POST)->check() AND $o->save())
|
||||
SystemMessage::add(array(
|
||||
'title'=>'Site Configuration Recorded',
|
||||
'type'=>'info',
|
||||
'body'=>'Site Config successfully recorded.',
|
||||
));
|
||||
}
|
||||
|
||||
$output .= Form::open();
|
||||
$output .= View::factory($this->viewpath())
|
||||
->set('o',$o);;
|
||||
$output .= Form::submit('submit','submit',array('class'=>'form_button'));
|
||||
$output .= Form::close();
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Update Site Configuration'),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
@@ -163,7 +163,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
$this->meta->language = Config::instance()->so->language_id;
|
||||
|
||||
// Copyright
|
||||
$this->meta->copywrite = Config::instance()->so->site_name;
|
||||
$this->meta->copywrite = Config::sitename();
|
||||
|
||||
// Copyright
|
||||
$this->meta->description = sprintf('%s::%s',$this->request->controller(),$this->request->action());
|
||||
|
@@ -16,7 +16,10 @@ class DB extends Kohana_DB {
|
||||
{
|
||||
$db = new Database_Query_Builder_Delete($table);
|
||||
|
||||
return $db->where($table.'.site_id','=',Config::siteid());
|
||||
if (! in_array($table,Config::$no_site_id_tables))
|
||||
return $db->where($table.'.site_id','=',Config::siteid());
|
||||
else
|
||||
return $db;
|
||||
}
|
||||
|
||||
// Add the site_id to the update query
|
||||
@@ -24,7 +27,10 @@ class DB extends Kohana_DB {
|
||||
{
|
||||
$db = new Database_Query_Builder_Update($table);
|
||||
|
||||
return $db->where($table.'.site_id','=',Config::siteid());
|
||||
if (! in_array($table,Config::$no_site_id_tables))
|
||||
return $db->where($table.'.site_id','=',Config::siteid());
|
||||
else
|
||||
return $db;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -41,14 +41,14 @@ abstract class lnApp_Config extends Kohana_Config {
|
||||
* Work out our site ID for multiehosting
|
||||
*/
|
||||
public static function siteid() {
|
||||
return Config::instance()->loadsite()->so->id;
|
||||
return Kohana::Config('config.site.id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out our site mode (dev,test,prod)
|
||||
*/
|
||||
public static function sitemode() {
|
||||
return Config::instance()->loadsite()->so->status;
|
||||
return Kohana::Config('config.site.mode');
|
||||
}
|
||||
|
||||
public static function sitemodeverbose() {
|
||||
@@ -69,7 +69,7 @@ abstract class lnApp_Config extends Kohana_Config {
|
||||
}
|
||||
|
||||
public static function sitename() {
|
||||
return Config::instance()->loadsite()->so->site_name;
|
||||
return Kohana::Config('config.site.name');
|
||||
}
|
||||
|
||||
// Called in Invoice/Emailing to embed the file.
|
||||
|
@@ -14,8 +14,78 @@
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Model_Setup extends ORMOSB {
|
||||
// Setup doesnt use the update column
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
protected $_has_one = array(
|
||||
'country'=>array('foreign_key'=>'id','far_key'=>'country_id'),
|
||||
);
|
||||
|
||||
public function rules() {
|
||||
$r = parent::rules();
|
||||
|
||||
// This module doesnt use site_id.
|
||||
unset($r['site_id']);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get/Set Module Configuration
|
||||
*
|
||||
* @param $key Module name.
|
||||
* @param $value Values to store. If NULL, retrieves the value stored, otherwise stores value.
|
||||
*/
|
||||
public function module_config($key,array $value=NULL) {
|
||||
// If we are not loaded, we dont have any config.
|
||||
if (! $this->loaded() OR (is_null($value) AND ! $this->module_config))
|
||||
return array();
|
||||
|
||||
$mo = ORM::factory('module')->where('name','=',$key)->find();
|
||||
|
||||
if (! $mo->loaded())
|
||||
throw new Kohana_Exception('Unknown module :name',array(':name'=>$key));
|
||||
|
||||
static $mc = array();
|
||||
|
||||
if (! $mc)
|
||||
$mc = $this->blob($this->module_config);
|
||||
|
||||
// If $value is NULL, we are a getter
|
||||
if ($value === NULL)
|
||||
return empty($mc[$mo->id]) ? array() : $mc[$mo->id];
|
||||
|
||||
// Store new value
|
||||
$mc[$mo->id] = $value;
|
||||
$this->module_config = $this->blob($mc,TRUE);
|
||||
$this->save();
|
||||
|
||||
return $this->saved();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get/Set our Site Configuration from the DB
|
||||
*
|
||||
* @param $key Key
|
||||
* @param $value Values to store. If NULL, retrieves the value stored, otherwise stores value.
|
||||
*/
|
||||
public function site_details($key,array $value=NULL) {
|
||||
static $sc = array();
|
||||
|
||||
if (! $sc AND $this->site_details)
|
||||
$sc = $this->blob($this->site_details);
|
||||
|
||||
if (! in_array($key,array('name','address1','address2','city','state','pcode','phone','fax','email')))
|
||||
throw new Kohana_Exception('Unknown Site Configuration Key :key',array(':key'=>$key));
|
||||
|
||||
// If $value is NULL, we are a getter
|
||||
if ($value === NULL)
|
||||
return empty($sc[$key]) ? '' : $sc[$key];
|
||||
|
||||
// Store new value
|
||||
$sc[$key] = $value;
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -40,7 +40,7 @@ class ORM extends Kohana_ORM {
|
||||
// Add our OSB site_id to each SELECT query
|
||||
final protected function _build($type) {
|
||||
// Exclude tables without site ID's
|
||||
if (! in_array($this->_table_name,array('setup','country','currency','tax')))
|
||||
if (! in_array($this->_table_name,Config::$no_site_id_tables))
|
||||
$this->where($this->_table_name.'.site_id','=',Config::siteid());
|
||||
|
||||
return parent::_build($type);
|
||||
|
@@ -104,8 +104,25 @@ abstract class ORMOSB extends ORM {
|
||||
$model->$field = serialize($value);
|
||||
}
|
||||
|
||||
public function save(Validation $validation = NULL) {
|
||||
// Find any fields that have changed, and that are blobs, and encode them.
|
||||
if ($this->_changed)
|
||||
foreach ($this->_changed as $c)
|
||||
if ($this->_table_columns[$c]['data_type'] == 'blob')
|
||||
$this->$c = $this->blob($this->$c,TRUE);
|
||||
|
||||
return parent::save($validation);
|
||||
}
|
||||
|
||||
public function changed() {
|
||||
return $this->_changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve and Store DB BLOB data.
|
||||
*/
|
||||
protected function blob($data,$set=FALSE) {
|
||||
return $set ? gzcompress(serialize($data)) : unserialize(gzuncompress($data));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user