Site/Module setup work and auto_format fixes
This commit is contained in:
@@ -65,8 +65,13 @@ class Company {
|
||||
}
|
||||
|
||||
public static function taxid() {
|
||||
// @todo Details should be obtained from DB
|
||||
return Kohana::config('config.taxid');
|
||||
// Tax ID details are stored in invoice config
|
||||
$mc = Config::instance()->so->module_config('invoice');
|
||||
|
||||
if (empty($mc['TAX_ID_NAME']))
|
||||
return empty($mc['TAX_ID']) ? '' : $mc['TAX_ID'];
|
||||
else
|
||||
return sprintf('%s: %s',$mc['TAX_ID_NAME'],empty($mc['TAX_ID']) ? '' : $mc['TAX_ID']);
|
||||
}
|
||||
|
||||
public static function render() {
|
||||
|
@@ -33,15 +33,42 @@ class Controller_Admin_Setup extends Controller_TemplateDefault_Admin {
|
||||
}
|
||||
|
||||
$output .= Form::open();
|
||||
|
||||
// site_details
|
||||
$output .= View::factory($this->viewpath())
|
||||
->set('o',$o);;
|
||||
$output .= Form::submit('submit','submit',array('class'=>'form_button'));
|
||||
|
||||
$output .= '<div>'.Form::submit('submit','submit',array('class'=>'form_button')).'</div>';
|
||||
$output .= Form::close();
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Update Site Configuration'),
|
||||
'body'=>$output,
|
||||
));
|
||||
|
||||
// module_config
|
||||
$output = '';
|
||||
$output .= View::factory($this->viewpath().'/module/head');
|
||||
|
||||
foreach ($o->module_config as $mid => $detail) {
|
||||
$mo = ORM::factory('module',$mid);
|
||||
|
||||
$output .= View::factory($this->viewpath().'/module/body')
|
||||
->set('mo',$mo);
|
||||
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("div[id='.$mo->name.']").load("'.URL::site('admin/'.$mo->name.'/setup').'");
|
||||
});'
|
||||
));
|
||||
}
|
||||
|
||||
$output .= View::factory($this->viewpath().'/module/foot');
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Update Module Specific Configuration'),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -11,5 +11,37 @@
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_TemplateDefault_Admin extends Controller_TemplateDefault_User {
|
||||
protected function setup(array $config_items=array()) {
|
||||
$module = Request::current()->controller();
|
||||
|
||||
if ($_POST AND isset($_POST['module_config'][$module]))
|
||||
Config::instance()->so->module_config($module,$_POST['module_config'][$module])->save();
|
||||
|
||||
if ($config_items) {
|
||||
$output = '';
|
||||
$mc = Config::instance()->so->module_config($module);
|
||||
|
||||
$output .= Form::open();
|
||||
$output .= View::factory('setup/admin/module/head');
|
||||
|
||||
foreach ($config_items as $k=>$v)
|
||||
$output .= View::factory('setup/admin/module/body')
|
||||
->set('module',$module)
|
||||
->set('mc',$mc)
|
||||
->set('key',$k)
|
||||
->set('info',$v)
|
||||
->set('val',empty($mc[$k]) ? '' : $mc[$k]);
|
||||
|
||||
$output .= View::factory('setup/admin/module/foot');
|
||||
|
||||
$output .= Form::submit('submit',_('Submit'),array('class'=>'form_button'));
|
||||
$output .= Form::close();
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s',strtoupper($module),_('Configuration')),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -17,6 +17,10 @@ class Controller_TemplateDefault_User extends Controller_TemplateDefault {
|
||||
protected $ao;
|
||||
|
||||
public function before() {
|
||||
// If our action doesnt exist, no point processing any further.
|
||||
if (! method_exists($this,'action_'.Request::current()->action()))
|
||||
return;
|
||||
|
||||
if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()])))
|
||||
throw new Kohana_Exception('Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action()));
|
||||
|
||||
|
@@ -46,14 +46,17 @@ class Model_Setup extends ORMOSB {
|
||||
if (! $mo->loaded())
|
||||
throw new Kohana_Exception('Unknown module :name',array(':name'=>$key));
|
||||
|
||||
$mc = $this->module_config ? $this->module_config : array();
|
||||
|
||||
// If $value is NULL, we are a getter
|
||||
if ($value === NULL)
|
||||
return empty($this->module_config[$mo->id]) ? array() : $this->module_config[$mo->id];
|
||||
return empty($mc[$mo->id]) ? array() : $mc[$mo->id];
|
||||
|
||||
// Store new value
|
||||
$this->module_config[$mo->id] = $value;
|
||||
$mc[$mo->id] = $value;
|
||||
$this->module_config = $mc;
|
||||
|
||||
return $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +76,7 @@ class Model_Setup extends ORMOSB {
|
||||
// Store new value
|
||||
$sc[$key] = $value;
|
||||
|
||||
return $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -106,9 +106,18 @@ abstract class ORMOSB extends ORM {
|
||||
|
||||
public function __get($column) {
|
||||
// If the column is a blob, we'll decode it automatically
|
||||
if (array_key_exists($column,$this->_object) AND $this->_table_columns[$column]['data_type'] == 'blob' AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])) {
|
||||
if (array_key_exists($column,$this->_table_columns) AND $this->_table_columns[$column]['data_type'] == 'blob' AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])) {
|
||||
|
||||
// In case our blob hasnt been saved as one.
|
||||
try {
|
||||
$this->_object[$column] = $this->blob($this->_object[$column]);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
// @todo Log this exception
|
||||
echo Kohana_Exception::text($e), "\n";
|
||||
echo debug_print_backtrace();
|
||||
}
|
||||
|
||||
$this->_object[$column] = $this->blob($this->_object[$column]);
|
||||
$this->_table_columns[$column]['auto_convert'] = TRUE;
|
||||
}
|
||||
|
||||
@@ -119,9 +128,14 @@ abstract class ORMOSB extends ORM {
|
||||
// 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')
|
||||
if ($this->_table_columns[$c]['data_type'] == 'blob') {
|
||||
$this->$c = $this->blob($this->$c,TRUE);
|
||||
|
||||
// We need to reset our auto_convert flag
|
||||
if (isset($this->_table_columns[$c]['auto_convert']))
|
||||
$this->_table_columns[$c]['auto_convert'] = FALSE;
|
||||
}
|
||||
|
||||
return parent::save($validation);
|
||||
}
|
||||
|
||||
@@ -135,5 +149,11 @@ abstract class ORMOSB extends ORM {
|
||||
private function blob($data,$set=FALSE) {
|
||||
return $set ? gzcompress(serialize($data)) : unserialize(gzuncompress($data));
|
||||
}
|
||||
|
||||
public function config($key) {
|
||||
$mc = Config::instance()->so->module_config($this->_object_name);
|
||||
|
||||
return empty($mc[$key]) ? '' : $mc[$key];
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user