2014-07-09 03:04:56 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class extends Kohana's [ORM] class to create defaults for Membership Database.
|
|
|
|
*
|
|
|
|
* @package Membership Database
|
|
|
|
* @category Helpers
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2014 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
2014-09-29 05:17:37 +00:00
|
|
|
abstract class ORM extends lnAuth_ORM {
|
2014-07-09 03:04:56 +00:00
|
|
|
/**
|
|
|
|
* @var string Database to connect to
|
|
|
|
*/
|
|
|
|
protected $_db = 'default';
|
|
|
|
|
|
|
|
public function config($key) {
|
|
|
|
$mc = Config::instance()->module_config($this->_object_name);
|
|
|
|
|
|
|
|
return empty($mc[$key]) ? '' : $mc[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function help to find records that are active
|
|
|
|
*/
|
|
|
|
public function list_active($active=TRUE) {
|
2014-09-01 13:01:01 +00:00
|
|
|
$x=($active ? $this->where_active() : $this);
|
2014-07-09 03:04:56 +00:00
|
|
|
|
|
|
|
return $x->find_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function list_count($active=TRUE) {
|
2014-09-01 13:01:01 +00:00
|
|
|
$x=($active ? $this->where_active() : $this);
|
2014-07-09 03:04:56 +00:00
|
|
|
|
|
|
|
return $x->find_all()->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function where_active() {
|
2014-09-01 13:01:01 +00:00
|
|
|
return $this->where($this->_table_name.'.active','=',TRUE);
|
2014-07-09 03:04:56 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 05:13:25 +00:00
|
|
|
public function where_startstop($date,$date_end,$start='date_start',$stop='date_stop') {
|
|
|
|
if (array_key_exists('priority',$this->table_columns()))
|
|
|
|
$this->order_by('priority','ASC');
|
|
|
|
|
|
|
|
return $this
|
|
|
|
->where_open()
|
|
|
|
->where_open()->where($start,'<=',$date)->and_where($stop,'>=',$date)->where_close()
|
|
|
|
->or_where_open()->where($start,'<=',$date_end)->and_where($stop,'>=',$date_end)->where_close()
|
|
|
|
->or_where_open()->where($start,'is',NULL)->where_open()->where($stop,'is',NULL)->or_where($stop,'>=',$date)->where_close()->where_close()
|
|
|
|
->or_where_open()->where($stop,'is',NULL)->where_open()->where($start,'is',NULL)->or_where($start,'<=',$date_end)->where_close()->where_close()
|
|
|
|
->where_close()
|
|
|
|
->order_by($start,'ASC')
|
|
|
|
->order_by($stop,'ASC');
|
|
|
|
}
|
2014-07-09 03:04:56 +00:00
|
|
|
}
|
|
|
|
?>
|