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.
khosb/application/classes/Model/Setup.php

84 lines
2.2 KiB
PHP
Raw Normal View History

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Setup Model
*
* This module must remain in applications/ as it is used very early in the
* OSB initialisation.
*
* @package OSB
* @category Models
* @author Deon George
2013-03-19 22:35:19 +00:00
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Setup extends ORM_OSB {
2011-12-30 07:10:02 +00:00
// Setup doesnt use the update column
protected $_updated_column = FALSE;
protected $_has_one = array(
'account'=>array('foreign_key'=>'id','far_key'=>'admin_id'),
'country'=>array('foreign_key'=>'id','far_key'=>'country_id'),
2012-07-30 05:10:58 +00:00
'language'=>array('foreign_key'=>'id','far_key'=>'language_id'),
);
2011-12-30 07:10:02 +00:00
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();
2012-11-09 23:13:57 +00:00
$mo = ORM::factory('Module')->where('name','=',$key)->find();
2011-12-30 07:10:02 +00:00
if (! $mo->loaded())
throw new Kohana_Exception('Unknown module :name',array(':name'=>$key));
$mc = $this->module_config ? $this->module_config : array();
2011-12-30 07:10:02 +00:00
// If $value is NULL, we are a getter
if ($value === NULL)
return empty($mc[$mo->id]) ? array() : $mc[$mo->id];
2011-12-30 07:10:02 +00:00
// Store new value
$mc[$mo->id] = $value;
$this->module_config = $mc;
2011-12-30 07:10:02 +00:00
return $this;
2011-12-30 07:10:02 +00:00
}
/**
* 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) {
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)
2012-01-01 09:41:42 +00:00
return empty($this->site_details[$key]) ? '' : $this->site_details[$key];
2011-12-30 07:10:02 +00:00
// Store new value
$sc[$key] = $value;
return $this;
2011-12-30 07:10:02 +00:00
}
}
?>