root/trunk/application/models/ignitedrecord/base.php

49110
1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
/*
2
/*
3
 * Created on 2008 Jun 28
3
 * Created on 2008 Jul 9
4
 * by Martin Wernstahl <m4rw3r@gmail.com>
4
 * by Martin Wernstahl <m4rw3r@gmail.com>
5
 */
5
 */
6
6
...
...
29
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
 */
31
 */
32
32
/**
33
/**
33
 * @addtogroup IgnitedRecord
34
 * @addtogroup IgnitedRecord
34
 * @{
35
 * @{
35
 */
36
 */
36
/**
37
/**
37
 * A wrapper for the CodeIgniter ActiveRecord class.
38
 * Load IgnitedQuery.
38
 */
39
 */
39
class IR_base{
40
if( ! class_exists('IgnitedQuery'))
41
{
42
	require_once APPPATH.'libraries/ignitedquery.php';
43
}
44
45
/**
46
 * Define the global var to store the models.
47
 */
48
$GLOBALS['IR_MODELS'] = array();
49
50
/**
51
 * PHP 4 base for IgnitedRecord.
52
 */
53
class IR_base extends IgnitedQuery{
54
	
40
	/**
55
	/**
41
	 * Constructor.
56
	 * Returns the model which is mapped to the table $table.
57
	 * 
58
	 * Can be called statically.
59
	 * 
60
	 * @param $table A table name
61
	 * @return object or false
42
	 */
62
	 */
43
	function IR_base()
63
	function &get_model($table)
44
	{
64
	{
45
		$CI =& get_instance();
65
		if( ! isset($GLOBALS['IR_MODELS'][$table]))
46
		$this->db =& $CI->db;
66
		{
67
			$false = false;
68
			return $false;
69
		}
70
		
71
		return $GLOBALS['IR_MODELS'][$table];
47
	}
72
	}
48
	
73
	
49
	
50
	// --------------------------------------------------------------------
74
	// --------------------------------------------------------------------
51
		
75
		
52
	/**
76
	/**
53
	 * Resets the current query, enabling you to restart the building process
77
	 * Adds a model which is mapped to the $table to the internal array.
54
	 * @return void
78
	 * 
79
	 * Can be called statically.
80
	 * 
81
	 * @param $object The model object
82
	 * @param $table The tablename
55
	 */
83
	 */
56
	function reset()
84
	function add_model(&$object, $table)
57
	{
85
	{
58
		$this->db->_reset_select();
86
		$GLOBALS['IR_MODELS'][$table] =& $object;
59
	}
87
	}
60
	
61
	// --------------------------------------------------------------------
62
	
63
	function &dbprefix($table = ''){
64
		return $this->db->dbprefix($table);
65
	}
66
	function &select($select = '*', $protect_identifiers = TRUE){
67
		$this->db->select($select, $protect_identifiers);
68
		return $this;
69
	}
70
	function &select_max($select = '', $alias=''){
71
		$this->db->select_max($select, $alias);
72
		return $this;
73
	}
74
	function &select_min($select = '', $alias=''){
75
		$this->db->select_min($select, $alias);
76
		return $this;
77
	}
78
	function &select_avg($select = '', $alias=''){
79
		$this->db->select_avg($select, $alias);
80
		return $this;
81
	}
82
	function &select_sum($select = '', $alias=''){
83
		$this->db->select_sum($select, $alias);
84
		return $this;
85
	}
86
	function &distinct($val = TRUE){
87
		$this->db->distinct($val);
88
		return $this;
89
	}
90
	function &from($from){
91
		$this->db->from($from);
92
		return $this;
93
	}
94
	function &join($table, $cond, $type = ''){
95
		$this->db->join($table, $cond, $type);
96
		return $this;
97
	}
98
	function &where($key, $value = NULL, $escape = TRUE){
99
		$this->db->where($key, $value, $escape);
100
		return $this;
101
	}
102
	function &or_where($key, $value = NULL, $escape = TRUE){
103
		$this->db->or_where($key, $value, $escape);
104
		return $this;
105
	}
106
	function &orwhere($key, $value = NULL, $escape = TRUE){
107
		$this->db->orwhere($key, $value, $escape);
108
		return $this;
109
	}
110
	function &where_in($key = NULL, $values = NULL){
111
		$this->db->where_in($key, $values);
112
		return $this;
113
	}
114
	function &or_where_in($key = NULL, $values = NULL){
115
		$this->db->or_where_in($key, $values);
116
		return $this;
117
	}
118
	function &where_not_in($key = NULL, $values = NULL){
119
		$this->db->where_not_in($key, $values);
120
		return $this;
121
	}
122
	function &or_where_not_in($key = NULL, $values = NULL){
123
		$this->db->or_where_not_in($key, $values);
124
		return $this;
125
	}
126
	function &like($field, $match = '', $side = 'both'){
127
		$this->db->like($field, $match, $side);
128
		return $this;
129
	}
130
	function &not_like($field, $match = '', $side = 'both'){
131
		$this->db->not_like($field, $match, $side);
132
		return $this;
133
	}
134
	function &or_like($field, $match = '', $side = 'both'){
135
		$this->db->or_like($field, $match, $side);
136
		return $this;
137
	}
138
	function &or_not_like($field, $match = '', $side = 'both'){
139
		$this->db->or_not_like($field, $match, $side);
140
		return $this;
141
	}
142
	function &orlike($field, $match = '', $side = 'both'){
143
		$this->db->orlike($field, $match, $side);
144
		return $this;
145
	}
146
	function &group_by($by){
147
		$this->db->group_by($by);
148
		return $this;
149
	}
150
	function &groupby($by){
151
		$this->db->groupby($by);
152
		return $this;
153
	}
154
	function &having($key, $value = '', $escape = TRUE){
155
		$this->db->having($key, $value, $escape);
156
		return $this;
157
	}
158
	function &orhaving($key, $value = '', $escape = TRUE){
159
		$this->db->orhaving($key, $value, $escape);
160
		return $this;
161
	}
162
	function &or_having($key, $value = '', $escape = TRUE){
163
		$this->db->or_having($key, $value, $escape);
164
		return $this;
165
	}
166
	function &order_by($orderby, $direction = ''){
167
		$this->db->order_by($orderby, $direction);
168
		return $this;
169
	}
170
	function &orderby($orderby, $direction = ''){
171
		$this->db->orderby($orderby, $direction);
172
		return $this;
173
	}
174
	function &limit($value, $offset = ''){
175
		$this->db->limit($value, $offset);
176
		return $this;
177
	}
178
	function &offset($offset){
179
		$this->db->offset($offset);
180
		return $this;
181
	}
182
	function db_set($key, $value = '', $escape = TRUE){
183
		return $this->db->set($key, $value, $escape);
184
	}
185
	function db_get($table = '', $limit = null, $offset = null){
186
		return $this->db->get($table, $limit, $offset);
187
	}
188
	function count_all_results($table = ''){
189
		return $this->db->count_all_results($table);
190
	}
191
	function db_get_where($table = '', $where = null, $limit = null, $offset = null){
192
		return $this->db->get_where($table, $where, $limit, $offset);
193
	}
194
	function db_insert($table = '', $set = NULL){
195
		return $this->db->insert($table, $set);
196
	}
197
	function db_update($table = '', $set = NULL, $where = NULL, $limit = NULL){
198
		return $this->db->update($table, $set, $where, $limit);
199
	}
200
	function db_empty_table($table = ''){
201
		return $this->db->empty_table($table);
202
	}
203
	function db_truncate($table = ''){
204
		return $this->db->truncate($table);
205
	}
206
	function db_delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE){
207
		return $this->db->delete($table, $where, $limit, $reset_data);
208
	}
209
	function db_use_table($table){
210
		return $this->db->use_table($table);
211
	}
212
	function &start_cache(){
213
		$this->db->start_cache();
214
		return $this;
215
	}
216
	function &stop_cache(){
217
		$this->db->stop_cache();
218
		return $this;
219
	}
220
	function &flush_cache(){
221
		$this->db->flush_cache();
222
		return $this;
223
	}
224
}
88
}
225
/**
89
/**
226
 * @}
90
 * @}