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.
memberdb/application/classes/ORM.php
2014-09-29 15:17:37 +10:00

59 lines
1.8 KiB
PHP

<?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
*/
abstract class ORM extends lnAuth_ORM {
/**
* @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) {
$x=($active ? $this->where_active() : $this);
return $x->find_all();
}
public function list_count($active=TRUE) {
$x=($active ? $this->where_active() : $this);
return $x->find_all()->count();
}
public function where_active() {
return $this->where($this->_table_name.'.active','=',TRUE);
}
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');
}
}
?>