/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. class Halogy_model extends Model {
  18. function Halogy_model()
  19. {
  20. parent::Model();
  21. // get siteID, if available
  22. if (defined('SITEID'))
  23. {
  24. $this->siteID = SITEID;
  25. }
  26. }
  27. function get_num_page_views()
  28. {
  29. // grab
  30. $this->db->select('sum(views) as count');
  31. $this->db->where('siteID', $this->siteID);
  32. $this->db->where('deleted', 0);
  33. $this->db->where('active', 1);
  34. $query = $this->db->get('pages');
  35. if ($query->num_rows() > 0)
  36. {
  37. $row = $query->row_array();
  38. return $row['count'];
  39. }
  40. else
  41. {
  42. return FALSE;
  43. }
  44. }
  45. function get_num_pages()
  46. {
  47. // grab
  48. $this->db->select('count(*) as count');
  49. $this->db->where('siteID', $this->siteID);
  50. $this->db->where('deleted', 0);
  51. $query = $this->db->get('pages');
  52. if ($query->num_rows() > 0)
  53. {
  54. $row = $query->row_array();
  55. return $row['count'];
  56. }
  57. else
  58. {
  59. return FALSE;
  60. }
  61. }
  62. function get_popular_pages()
  63. {
  64. // grab
  65. $this->db->where('siteID', $this->siteID);
  66. $this->db->where('active', 1);
  67. $this->db->where('deleted', 0);
  68. $this->db->order_by('views', 'desc');
  69. $query = $this->db->get('pages', 5);
  70. if ($query->num_rows() > 0)
  71. {
  72. $result = $query->result_array();
  73. return $result;
  74. }
  75. else
  76. {
  77. return FALSE;
  78. }
  79. }
  80. function get_new_tickets()
  81. {
  82. // grab
  83. $this->db->select('count(*) as count');
  84. $this->db->where('deleted', 0);
  85. $this->db->where('viewed', 0);
  86. $this->db->where('siteID', $this->siteID);
  87. $this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('-2 days')));
  88. $query = $this->db->get('tickets');
  89. if ($query->num_rows() > 0)
  90. {
  91. $row = $query->row_array();
  92. return $row['count'];
  93. }
  94. else
  95. {
  96. return FALSE;
  97. }
  98. }
  99. function get_blog_posts_count()
  100. {
  101. // grab
  102. $this->db->select('count(*) as count');
  103. $this->db->where('deleted', 0);
  104. $this->db->where('siteID', $this->siteID);
  105. $query = $this->db->get('blog_posts');
  106. if ($query->num_rows() > 0)
  107. {
  108. $row = $query->row_array();
  109. return $row['count'];
  110. }
  111. else
  112. {
  113. return FALSE;
  114. }
  115. }
  116. function get_blog_new_comments()
  117. {
  118. // grab
  119. $this->db->select('count(*) as count');
  120. $this->db->where('deleted', 0);
  121. $this->db->where('active', 0);
  122. $this->db->where('siteID', $this->siteID);
  123. $this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('-4 days')));
  124. $query = $this->db->get('blog_comments');
  125. if ($query->num_rows() > 0)
  126. {
  127. $row = $query->row_array();
  128. return $row['count'];
  129. }
  130. else
  131. {
  132. return FALSE;
  133. }
  134. }
  135. function get_blog_latest_post()
  136. {
  137. // grab
  138. $this->db->select('postTitle');
  139. $this->db->where('deleted', 0);
  140. $this->db->where('siteID', $this->siteID);
  141. $this->db->order_by('dateCreated', 'desc');
  142. $query = $this->db->get('blog_posts', 1);
  143. if ($query->num_rows() > 0)
  144. {
  145. $row = $query->row_array();
  146. return $row;
  147. }
  148. else
  149. {
  150. return FALSE;
  151. }
  152. }
  153. function get_popular_blog_posts()
  154. {
  155. // grab
  156. $this->db->where('siteID', $this->siteID);
  157. $this->db->where('deleted', 0);
  158. $this->db->order_by('views', 'desc');
  159. $query = $this->db->get('blog_posts', 5);
  160. if ($query->num_rows() > 0)
  161. {
  162. $result = $query->result_array();
  163. return $result;
  164. }
  165. else
  166. {
  167. return FALSE;
  168. }
  169. }
  170. function get_popular_shop_products()
  171. {
  172. // grab
  173. $this->db->where('siteID', $this->siteID);
  174. $this->db->where('deleted', 0);
  175. $this->db->order_by('views', 'desc');
  176. $query = $this->db->get('shop_products', 5);
  177. if ($query->num_rows() > 0)
  178. {
  179. $result = $query->result_array();
  180. return $result;
  181. }
  182. else
  183. {
  184. return FALSE;
  185. }
  186. }
  187. function get_num_sites()
  188. {
  189. // grab
  190. $this->db->where('resellerID', $this->site->config['resellerID']);
  191. $query = $this->db->get('sites');
  192. return $query->num_rows();
  193. }
  194. function get_activity($when = '')
  195. {
  196. // default wheres
  197. $this->db->where('siteID', $this->siteID);
  198. // when?
  199. if ($when == 'today')
  200. {
  201. $this->db->where('date >=', date("Y-m-d 00:00:00", strtotime('today')));
  202. }
  203. elseif ($when == 'yesterday')
  204. {
  205. $this->db->where('date <=', date("Y-m-d 00:00:00", strtotime('today')));
  206. $this->db->where('date >=', date("Y-m-d 00:00:00", strtotime('1 day ago')));
  207. }
  208. else
  209. {
  210. $this->db->where('date <=', date("Y-m-d 00:00:00", strtotime('today')));
  211. $this->db->where('date >=', date("Y-m-d 00:00:00", strtotime('1 day ago')));
  212. }
  213. $this->db->where('date <', date("Y-m-d H:i:s", strtotime('5 minutes ago')));
  214. $this->db->select('COUNT(*) as guests, date, SUM(views) AS views, referer, userdata');
  215. $this->db->group_by('userdata');
  216. $this->db->order_by('date', 'desc');
  217. $query = $this->db->get('tracking');
  218. if ($query->num_rows() > 0)
  219. {
  220. $result = $query->result_array();
  221. return $result;
  222. }
  223. else
  224. {
  225. return FALSE;
  226. }
  227. }
  228. function get_recent_activity()
  229. {
  230. $this->db->where('siteID', $this->siteID);
  231. $this->db->where('date >', date("Y-m-d H:i:s", strtotime('5 minutes ago')));
  232. $this->db->order_by('date', 'desc');
  233. $query = $this->db->get('tracking');
  234. if ($query->num_rows() > 0)
  235. {
  236. $result = $query->result_array();
  237. return $result;
  238. }
  239. else
  240. {
  241. return FALSE;
  242. }
  243. }
  244. function get_num_users()
  245. {
  246. // default wheres
  247. $this->db->where('siteID', $this->siteID);
  248. $this->db->where('active', 1);
  249. $this->db->select('COUNT(*) as numUsers');
  250. $query = $this->db->get('users');
  251. if ($query->num_rows() > 0)
  252. {
  253. $row = $query->row_array();
  254. return $row['numUsers'];
  255. }
  256. else
  257. {
  258. return FALSE;
  259. }
  260. }
  261. function get_num_users_today()
  262. {
  263. // default wheres
  264. $this->db->where('siteID', $this->siteID);
  265. $this->db->where('active', 1);
  266. // when?
  267. $this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('today')));
  268. $this->db->select('COUNT(*) as numUsers');
  269. $query = $this->db->get('users');
  270. if ($query->num_rows() > 0)
  271. {
  272. $row = $query->row_array();
  273. return $row['numUsers'];
  274. }
  275. else
  276. {
  277. return FALSE;
  278. }
  279. }
  280. function get_num_users_yesterday()
  281. {
  282. // default wheres
  283. $this->db->where('siteID', $this->siteID);
  284. $this->db->where('active', 1);
  285. // when?
  286. $this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('yesterday')));
  287. $this->db->where('dateCreated <=', date("Y-m-d 00:00:00", strtotime('today')));
  288. $this->db->select('COUNT(*) as numUsers');
  289. $query = $this->db->get('users');
  290. if ($query->num_rows() > 0)
  291. {
  292. $row = $query->row_array();
  293. return $row['numUsers'];
  294. }
  295. else
  296. {
  297. return FALSE;
  298. }
  299. }
  300. function get_num_users_week()
  301. {
  302. // default wheres
  303. $this->db->where('siteID', $this->siteID);
  304. $this->db->where('active', 1);
  305. // when?
  306. $this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('-1 week sun')));
  307. $this->db->select('COUNT(*) as numUsers');
  308. $query = $this->db->get('users');
  309. if ($query->num_rows() > 0)
  310. {
  311. $row = $query->row_array();
  312. return $row['numUsers'];
  313. }
  314. else
  315. {
  316. return FALSE;
  317. }
  318. }
  319. function get_num_users_last_week()
  320. {
  321. // default wheres
  322. $this->db->where('siteID', $this->siteID);
  323. $this->db->where('active', 1);
  324. // when?
  325. $this->db->where('dateCreated >=', date("Y-m-d 00:00:00", strtotime('-2 week sun')));
  326. $this->db->where('dateCreated <=', date("Y-m-d 00:00:00", strtotime('-1 week sun')));
  327. $this->db->select('COUNT(*) as numUsers');
  328. $query = $this->db->get('users');
  329. if ($query->num_rows() > 0)
  330. {
  331. $row = $query->row_array();
  332. return $row['numUsers'];
  333. }
  334. else
  335. {
  336. return FALSE;
  337. }
  338. }
  339. }