Minor fixes to statement, services and internal things

Many misc updates
This commit is contained in:
Deon George
2011-10-14 16:44:12 +11:00
parent 7876a16413
commit 56c11507f4
71 changed files with 2192 additions and 677 deletions

View File

@@ -198,7 +198,7 @@ class Auth_OSB extends Auth_ORM {
Session::instance()->set('token',$token);
$user = ORM::factory('account',$mmto->account_id);
$user->log(sprintf('Token %s used for method %s',$mmto->token,$mmto->method_id));
$user->log(sprintf('Token %s used for method %s',$mmto->token,$mmto->module_method->name()));
}
}
}

View File

@@ -15,24 +15,24 @@ class Company {
return new Company;
}
public static function name() {
return Config::sitename();
}
public static function street() {
// @todo Details should be obtained from DB
return 'PO Box 149';
return Config::instance()->so->display('site_address');
}
public static function city() {
// @todo Details should be obtained from DB
return 'Bendigo';
return Config::instance()->so->display('site_city');
}
public static function state() {
// @todo Details should be obtained from DB
return 'VIC';
return Config::instance()->so->display('site_state');
}
public static function pcode() {
// @todo Details should be obtained from DB
return '3550';
return Config::instance()->so->display('site_zip');
}
public static function address($ln='<br/>') {
@@ -40,13 +40,11 @@ class Company {
}
public static function phone() {
// @todo Company phone should be obtained from db
return '03 5410 1135';
return Config::instance()->so->display('site_phone');
}
public static function fax() {
// @todo Details should be obtained from DB
return '03 5410 1145';
return Config::instance()->so->display('site_fax');
}
public static function contacts() {

View File

@@ -29,6 +29,8 @@ class Config extends lnApp_Config {
if (! $this->so->loaded())
throw new Kohana_Exception(_('Site [:site] not defined in DB?'),array(':site'=>URL::base('http')));
Kohana::$environment = (int)static::sitemode();
return $this;
}

View File

@@ -12,6 +12,7 @@
*/
class Controller_Admin_Account extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'autocomplete'=>FALSE, // @todo To Change
'listlog'=>TRUE,
);
@@ -36,5 +37,40 @@ class Controller_Admin_Account extends Controller_TemplateDefault_Admin {
)),
));
}
public function action_autocomplete() {
$return = array();
$a = ORM::factory('account')->where('status','=',1);
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
$t = $_REQUEST['term'];
// @todo - Implement different search criteria, eg: @ by email, space for first/last, etc
if (FALSE) {
// All search
} else {
$a = $a
->where_open()
->where('first_name','like','%'.$t.'%')
->or_where('last_name','like','%'.$t.'%')
->or_where('company','like','%'.$t.'%')
->or_where('email','like','%'.$t.'%')
->where_close();
}
}
// @todo The results should be limited so that users dont see what they shouldnt.
foreach ($a->find_all() as $ao)
array_push($return,array(
'id'=>$ao->id,
'label'=>sprintf('%s (%s)',$ao->name(),$ao->email),
'value'=>$ao->id,
));
$this->auto_render = FALSE;
$this->response->headers('Content-Type','application/json');
$this->response->body(json_encode($return));
}
}
?>

View File

@@ -126,7 +126,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
foreach (array('file'=>array(
'js/jquery.cookie.js',
'js/jquery.jstree-1.0rc3.js',
'js/jquery-1.4.2.js',
'js/jquery-1.6.4.min.js',
)) as $type => $datas) {
foreach ($datas as $data) {

View File

@@ -18,7 +18,7 @@ class Controller_lnApp_Tree extends Controller_Default {
public function after() {
$this->response->headers('Content-Type','application/json');
$this->response->body(sprintf('[%s]',json_encode($this->output)));
$this->response->body(json_encode($this->output));
parent::after();
}
@@ -29,6 +29,7 @@ class Controller_lnApp_Tree extends Controller_Default {
return '
<div id="tree" class=""></div>
<script type="text/javascript">
<!--
$(function () {
$("#tree").jstree({
themes : {
@@ -40,6 +41,7 @@ $(function () {
},
cookies : {
"save_selected" : false,
"cookie_options" : { path : "'.URL::site().'" }
},
json_data : {
"correct_state" : "true",
@@ -60,7 +62,7 @@ $(function () {
id = data.rslt.obj.attr(\'id\').substr(a+1);
if (href = $("#N_"+id).attr("href")) {
$("#ajBODY").empty().html("<img src=\"'.URL::site('media/img/ajax-progress.gif').'\"/>");
$("#ajBODY").empty().html("<img src=\"'.URL::site('media/img/ajax-progress.gif').'\" alt=\"Loading...\" />");
$("#ajBODY").load(href, function(r,s,x) {
if (s == "error") {
var msg = "Sorry but there was an error: ";
@@ -72,6 +74,7 @@ $(function () {
}
});
});
// -->
</script>';
}

View File

@@ -43,8 +43,8 @@ class Controller_Tree extends Controller_lnApp_Tree {
} else {
$idx = NULL;
if (preg_match('/:/',$id))
list($id,$idx) = explode(':',$id,2);
if (preg_match('/_/',$id))
list($id,$idx) = explode('_',$id,2);
$mo = ORM::factory('module',$id);
@@ -106,7 +106,7 @@ class Controller_Tree extends Controller_lnApp_Tree {
else
foreach ($subdata as $t=>$x)
array_push($data,array('id'=>$mmo->module_id.':'.$t,'name'=>$t,'state'=>'closed'));
array_push($data,array('id'=>$mmo->module_id.'_'.$t,'name'=>$t,'state'=>'closed'));
}
}

View File

@@ -36,7 +36,6 @@ class lnApp_Script extends HTMLRender {
$i = $j = 0;
foreach (static::$_data as $value) {
switch ($value['type']) {
case 'file':
$foutput .= HTML::script($mediapath->uri(array('file'=>$value['data'])));

View File

@@ -22,9 +22,9 @@ class lnApp_Sort {
*/
public static function MAsort(&$data,$sortby,$rev=0) {
// if the array to sort is null or empty, or our sortby is bad
if (! preg_match('/^[a-zA-Z0-9_]+(\([a-zA-Z0-9_,]*\))?$/',$sortby) || ! $data)
if (! preg_match('/^([a-zA-Z0-9_]+(\([a-zA-Z0-9_,]*\)(->[a-zA-Z0-9])?)?,?)+$/',$sortby) || ! $data)
return;
$code = '$c=0;';
foreach (explode(',',$sortby) as $key) {
@@ -83,7 +83,7 @@ class lnApp_Sort {
$code .= 'return $c;';
$result = create_function('$a, $b',$code);
uasort($data,$result);
}
}

View File

@@ -30,25 +30,27 @@ class lnApp_Style extends HTMLRender {
* @see HTMLRender::render()
*/
protected function render() {
$output = '';
$foutput = $soutput = '';
$mediapath = Route::get(static::$_media_path);
$i = 0;
$i = $j = 0;
foreach (static::$_data as $value) {
if ($i++)
$output .= static::$_spacer;
switch ($value['type']) {
case 'file':
$output .= HTML::style($mediapath->uri(array('file'=>$value['data'])),
$foutput .= HTML::style($mediapath->uri(array('file'=>$value['data'])),
array('media'=>(! empty($value['media'])) ? $value['media'] : 'screen'),TRUE);
break;
case 'stdin':
$soutput .= sprintf("<style type=\"text/css\">%s</style>",$value['data']);
if ($j++)
$soutput .= static::$_spacer;
break;
default:
throw new Kohana_Exception('Unknown style type :type',array(':type'=>$value['type']));
}
}
return $output;
return $foutput.static::$_spacer.$soutput;
}
}
?>

View File

@@ -31,13 +31,18 @@ class lnApp_Table {
return '';
$pag = NULL;
$view = $output = '';
$view = $output = $button = '';
if (isset($option['type']) AND $option['type'])
switch ($option['type']) {
case 'select':
$view = 'table/select';
if (! empty($option['button']))
$button = implode('',$option['button']);
else
$button = '<input type="submit" name="Submit" value="View/Edit" class="form_button"/>';
Script::add(array(
'type'=>'stdin',
'data'=>'
@@ -156,6 +161,10 @@ $(document).ready(function() {
'));
$output .= Form::open((isset($option['form']) ? $option['form'] : ''));
if (! empty($option['hidden']))
$output .= '<div>'.implode('',$option['hidden']).'</div>';
break;
case 'list':
@@ -226,7 +235,8 @@ $(document).ready(function() {
->set('count',$i-$rows)
->set('other',$other);
$output .= View::factory($view.'_foot');
$output .= View::factory($view.'_foot')
->set('button',$button);
if (isset($option['type']) AND $option['type'])
switch ($option['type']) {

View File

@@ -35,5 +35,10 @@ class Model_Module_Method extends ORMOSB {
// This module doesnt keep track of column updates automatically
protected $_created_column = FALSE;
protected $_updated_column = FALSE;
// Return the method name.
public function name() {
return sprintf('%s::%s',$this->module->name,$this->name);
}
}
?>

View File

@@ -14,7 +14,7 @@ class Model_Module_Method_Token extends ORMOSB {
// Relationships
protected $_belongs_to = array(
'account'=>array(),
'module_method'=>array(),
'module_method'=>array('foreign_key'=>'method_id'),
);
protected $_has_one = array(
'record_id'=>array(),

View File

@@ -63,6 +63,7 @@ abstract class ORMOSB extends ORM {
* @param array Validate object
* @param string Primary Key
*/
// @todo Do we need the $array?
public static function get_next_id(Validation $array,$model,$field) {
if (! is_null($model->$field))
return TRUE;
@@ -81,6 +82,7 @@ abstract class ORMOSB extends ORM {
return TRUE;
}
// @todo Do we need the $array?
public static function set_site_id(Validation $array,$model,$field) {
if (! is_null($model->$field))
return TRUE;
@@ -91,6 +93,17 @@ abstract class ORMOSB extends ORM {
return TRUE;
}
public static function serialize_array(ORM $model,$field,$value) {
if (is_null($value))
return TRUE;
if (! is_array($value))
return FALSE;
$model->_changed[$field] = $field;
$model->$field = serialize($value);
}
/**
* Generate a view path to help View::factory() calls
*

View File

@@ -105,7 +105,7 @@ class Period {
$return = array(
'start'=>$period_start,
'start_time'=>$period_start,
'start_time'=>$start,
'date'=>$start,
'end'=>$period_end,
'end_time'=>$period_end,

View File

@@ -0,0 +1,34 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This is class renders Charge Sweep Types on responses and forms.
*
* @package OSB
* @subpackage Utilities
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class StaticList_SweepType extends StaticList {
protected function table() {
return array(
0=>_('Daily'),
1=>_('Weekly'),
2=>_('Monthly'),
3=>_('Quarterly'),
4=>_('Semi-Annually'),
5=>_('Annually'),
6=>_('Service Rebill'),
);
}
public static function factory() {
return new StaticList_SweepType;
}
public static function display($value) {
return static::_display($value);
}
}
?>