PageRenderTime 305ms CodeModel.GetById 121ms app.highlight 15ms RepoModel.GetById 166ms app.codeStats 0ms

/halogy/application/modules/halogy/models/halogy_model.php

https://bitbucket.org/haloweb/halogy-1.0/
PHP | 402 lines | 302 code | 63 blank | 37 comment | 20 complexity | 65b523a46822031934424b662b28d1cd MD5 | raw file
  1<?php
  2/**
  3 * Halogy
  4 *
  5 * A user friendly, modular content management system for PHP 5.0
  6 * Built on CodeIgniter - http://codeigniter.com
  7 *
  8 * @package		Halogy
  9 * @author		Haloweb Ltd.
 10 * @copyright	Copyright (c) 2008-2011, Haloweb Ltd.
 11 * @license		http://halogy.com/license
 12 * @link		http://halogy.com/
 13 * @since		Version 1.0
 14 * @filesource
 15 */
 16
 17// ------------------------------------------------------------------------
 18
 19class Halogy_model extends Model {
 20	
 21	function Halogy_model()
 22	{
 23		parent::Model();
 24
 25		// get siteID, if available
 26		if (defined('SITEID'))
 27		{
 28			$this->siteID = SITEID;
 29		}
 30	}	
 31
 32	function get_num_page_views()
 33	{
 34		// grab
 35		$this->db->select('sum(views) as count');
 36		$this->db->where('siteID', $this->siteID);
 37		$this->db->where('deleted', 0);
 38		$this->db->where('active', 1);
 39		$query = $this->db->get('pages');
 40
 41		if ($query->num_rows() > 0)
 42		{
 43			$row = $query->row_array();
 44			return $row['count'];
 45		}
 46		else
 47		{
 48			return FALSE;
 49		}
 50	}
 51
 52	function get_num_pages()
 53	{
 54		// grab
 55		$this->db->select('count(*) as count');
 56		$this->db->where('siteID', $this->siteID);
 57		$this->db->where('deleted', 0);
 58		$query = $this->db->get('pages');
 59
 60		if ($query->num_rows() > 0)
 61		{
 62			$row = $query->row_array();
 63			return $row['count'];
 64		}
 65		else
 66		{
 67			return FALSE;
 68		}
 69	}
 70
 71	function get_popular_pages()
 72	{
 73		// grab
 74		$this->db->where('siteID', $this->siteID);
 75		$this->db->where('active', 1);
 76		$this->db->where('deleted', 0);
 77		$this->db->order_by('views', 'desc');
 78
 79		$query = $this->db->get('pages', 5);
 80
 81		if ($query->num_rows() > 0)
 82		{
 83			$result = $query->result_array();
 84			return $result;
 85		}
 86		else
 87		{
 88			return FALSE;
 89		}
 90	}
 91
 92	function get_new_tickets()
 93	{
 94		// grab
 95		$this->db->select('count(*) as count');
 96		$this->db->where('deleted', 0);
 97		$this->db->where('viewed', 0);
 98		$this->db->where('siteID', $this->siteID);
 99		$this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('-2 days')));
100		
101		$query = $this->db->get('tickets');
102
103		if ($query->num_rows() > 0)
104		{
105			$row = $query->row_array();
106			return $row['count'];
107		}
108		else
109		{
110			return FALSE;
111		}
112	}
113	
114	function get_blog_posts_count()
115	{
116		// grab
117		$this->db->select('count(*) as count');
118		$this->db->where('deleted', 0);
119		$this->db->where('siteID', $this->siteID);
120		$query = $this->db->get('blog_posts');
121
122		if ($query->num_rows() > 0)
123		{
124			$row = $query->row_array();
125			return $row['count'];
126		}
127		else
128		{
129			return FALSE;
130		}
131	}
132
133	function get_blog_new_comments()
134	{
135		// grab
136		$this->db->select('count(*) as count');
137		$this->db->where('deleted', 0);
138		$this->db->where('active', 0);		
139		$this->db->where('siteID', $this->siteID);
140		$this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('-4 days')));
141				
142		$query = $this->db->get('blog_comments');
143
144		if ($query->num_rows() > 0)
145		{
146			$row = $query->row_array();
147			return $row['count'];
148		}
149		else
150		{
151			return FALSE;
152		}
153	}
154
155	function get_blog_latest_post()
156	{
157		// grab
158		$this->db->select('postTitle');
159		$this->db->where('deleted', 0);
160		$this->db->where('siteID', $this->siteID);
161		$this->db->order_by('dateCreated', 'desc');
162
163		$query = $this->db->get('blog_posts', 1);
164
165		if ($query->num_rows() > 0)
166		{
167			$row = $query->row_array();
168			return $row;
169		}
170		else
171		{
172			return FALSE;
173		}
174	}
175
176	function get_popular_blog_posts()
177	{
178		// grab
179		$this->db->where('siteID', $this->siteID);
180		$this->db->where('deleted', 0);
181		$this->db->order_by('views', 'desc');
182
183		$query = $this->db->get('blog_posts', 5);
184
185		if ($query->num_rows() > 0)
186		{
187			$result = $query->result_array();
188			return $result;
189		}
190		else
191		{
192			return FALSE;
193		}
194	}
195
196	function get_popular_shop_products()
197	{
198		// grab
199		$this->db->where('siteID', $this->siteID);
200		$this->db->where('deleted', 0);
201		$this->db->order_by('views', 'desc');
202
203		$query = $this->db->get('shop_products', 5);
204
205		if ($query->num_rows() > 0)
206		{
207			$result = $query->result_array();
208			return $result;
209		}
210		else
211		{
212			return FALSE;
213		}
214	}
215
216	function get_num_sites()
217	{
218		// grab
219		$this->db->where('resellerID', $this->site->config['resellerID']);
220		$query = $this->db->get('sites');
221
222		return $query->num_rows();
223	}
224
225	function get_activity($when = '')
226	{
227		// default wheres
228		$this->db->where('siteID', $this->siteID);
229
230		// when?
231		if ($when == 'today')
232		{
233			$this->db->where('date >=', date("Y-m-d 00:00:00", strtotime('today')));
234		}
235		elseif ($when == 'yesterday')
236		{
237			$this->db->where('date <=', date("Y-m-d 00:00:00", strtotime('today')));
238			$this->db->where('date >=', date("Y-m-d 00:00:00", strtotime('1 day ago')));
239		}
240		else
241		{
242			$this->db->where('date <=', date("Y-m-d 00:00:00", strtotime('today')));
243			$this->db->where('date >=', date("Y-m-d 00:00:00", strtotime('1 day ago')));
244		}
245		$this->db->where('date <', date("Y-m-d H:i:s", strtotime('5 minutes ago')));		
246
247		$this->db->select('COUNT(*) as guests, date, SUM(views) AS views, referer, userdata');
248		$this->db->group_by('userdata');
249
250		$this->db->order_by('date', 'desc');
251			
252		$query = $this->db->get('tracking');
253
254		if ($query->num_rows() > 0)
255		{
256			$result = $query->result_array();
257			return $result;
258		}
259		else
260		{
261			return FALSE;
262		}
263	}
264
265	function get_recent_activity()
266	{
267		$this->db->where('siteID', $this->siteID);
268		$this->db->where('date >', date("Y-m-d H:i:s", strtotime('5 minutes ago')));
269		$this->db->order_by('date', 'desc');	
270		$query = $this->db->get('tracking');
271
272		if ($query->num_rows() > 0)
273		{
274			$result = $query->result_array();
275			return $result;
276		}
277		else
278		{
279			return FALSE;
280		}
281	}
282
283	function get_num_users()
284	{
285		// default wheres
286		$this->db->where('siteID', $this->siteID);
287		$this->db->where('active', 1);	
288
289		$this->db->select('COUNT(*) as numUsers');
290			
291		$query = $this->db->get('users');
292
293		if ($query->num_rows() > 0)
294		{
295			$row = $query->row_array();
296			return $row['numUsers'];
297		}
298		else
299		{
300			return FALSE;
301		}
302	}
303
304	function get_num_users_today()
305	{
306		// default wheres
307		$this->db->where('siteID', $this->siteID);
308		$this->db->where('active', 1);
309		
310		// when?
311		$this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('today')));
312
313		$this->db->select('COUNT(*) as numUsers');
314			
315		$query = $this->db->get('users');
316
317		if ($query->num_rows() > 0)
318		{
319			$row = $query->row_array();
320			return $row['numUsers'];
321		}
322		else
323		{
324			return FALSE;
325		}
326	}
327
328	function get_num_users_yesterday()
329	{
330		// default wheres
331		$this->db->where('siteID', $this->siteID);
332		$this->db->where('active', 1);
333		
334		// when?
335		$this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('yesterday')));
336		$this->db->where('dateCreated <=', date("Y-m-d 00:00:00", strtotime('today')));		
337
338		$this->db->select('COUNT(*) as numUsers');
339			
340		$query = $this->db->get('users');
341
342		if ($query->num_rows() > 0)
343		{
344			$row = $query->row_array();
345			return $row['numUsers'];
346		}
347		else
348		{
349			return FALSE;
350		}
351	}
352
353	function get_num_users_week()
354	{
355		// default wheres
356		$this->db->where('siteID', $this->siteID);
357		$this->db->where('active', 1);
358
359		// when?
360		$this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('-1 week sun')));
361
362		$this->db->select('COUNT(*) as numUsers');
363			
364		$query = $this->db->get('users');
365
366		if ($query->num_rows() > 0)
367		{
368			$row = $query->row_array();
369			return $row['numUsers'];
370		}
371		else
372		{
373			return FALSE;
374		}
375	}
376
377	function get_num_users_last_week()
378	{
379		// default wheres
380		$this->db->where('siteID', $this->siteID);
381		$this->db->where('active', 1);
382
383		// when?
384		$this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('-2 week sun')));
385		$this->db->where('dateCreated <=', date("Y-m-d 00:00:00", strtotime('-1 week sun')));
386
387		$this->db->select('COUNT(*) as numUsers');
388			
389		$query = $this->db->get('users');
390
391		if ($query->num_rows() > 0)
392		{
393			$row = $query->row_array();
394			return $row['numUsers'];
395		}
396		else
397		{
398			return FALSE;
399		}
400	}
401
402}