PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/masportales/application/models/mp_model.php

https://github.com/eloypineda/XHTMLized
PHP | 287 lines | 185 code | 34 blank | 68 comment | 29 complexity | 450e043dd93a59ef7158a3ceefff625a MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Mp_model extends CI_Model
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. }
  8. /**
  9. * mp. saveSiteSettings
  10. *
  11. * @access public
  12. * @since 0.5
  13. *
  14. * @param string|array $setting
  15. * @param string $value
  16. *
  17. * @return array
  18. */
  19. public function saveSiteSettings($setting, $value = null)
  20. {
  21. $error = false;
  22. if (is_string($setting) and $value != null) {
  23. $settings = array($setting => $value);
  24. } elseif (is_array($setting)) {
  25. $settings = $setting;
  26. } else {
  27. return false;
  28. }
  29. foreach ($settings as $setting => $value) {
  30. $sql = "INSERT INTO settings (site_ID, meta_group, meta_key, meta_value)
  31. VALUES (" . site_id() . ", 'site', '" . $setting . "', '" . $value ."')
  32. ON DUPLICATE KEY UPDATE meta_value = '" . $value . "';";
  33. if (!$query = $this->db->query($sql)) {
  34. $error = true;
  35. }
  36. }
  37. return !$error;
  38. }
  39. /**
  40. * mp. getLegalTexts
  41. *
  42. * @access public
  43. * @since 0.9
  44. *
  45. * @param array $params
  46. *
  47. * @return mixed
  48. */
  49. public function getLegalTexts($params = array())
  50. {
  51. $defaults = array(
  52. 'start' => 0,
  53. 'limit' => 20,
  54. 'order_by' => 'order_by DESC',
  55. 'search_by' => false,
  56. 'search' => '',
  57. 'filter_by' => false,
  58. 'filter' => ''
  59. );
  60. $params = array_merge($defaults, $params);
  61. $where = "";
  62. if ($params['search_by']) {
  63. $where.= " AND " . $params['search_by'] . " LIKE '%" . $params['search'] . "%'";
  64. }
  65. if ($params['filter_by']) {
  66. $where.= " AND " . $params['filter_by'] . " = '" . $params['filter'] . "'";
  67. } else {
  68. }
  69. $sql = " SELECT * FROM legal_texts";
  70. $sql.= " WHERE site_ID = '" . site_id() . "'" . $where;
  71. $sql.= ($params['order_by']) ? " ORDER BY " . $params['order_by'] : "";
  72. $sql.= " LIMIT " . $params['start'] . ", " . $params['limit'] . ";";
  73. $query = $this->db->query($sql);
  74. if ($query->num_rows() > 0) {
  75. return $query->result_array();
  76. } else {
  77. return false;
  78. }
  79. }
  80. /**
  81. * mp. getLegalText
  82. *
  83. * @access public
  84. * @since 0.9
  85. *
  86. * @param int $legal_text_id
  87. *
  88. * @return mixed
  89. */
  90. public function getLegalText($legal_text_id)
  91. {
  92. //TODO. diferent legal texts for each site
  93. //$sql = "SELECT * FROM legal_texts WHERE company_ID = '$legal_text_id' AND site_ID = '" . site_id() . "' LIMIT 1";
  94. $sql = "SELECT * FROM legal_texts WHERE legal_text_ID = '$legal_text_id' LIMIT 1";
  95. $query = $this->db->query($sql);
  96. if ($query->num_rows() > 0) {
  97. return $query->row_array();
  98. } else {
  99. return false;
  100. }
  101. }
  102. /**
  103. * mp. slugFor
  104. *
  105. * @access public
  106. * @since 0.5
  107. *
  108. * @param string $slug
  109. *
  110. * @return int
  111. */
  112. public function slugFor($slug)
  113. {
  114. $sql = "SELECT legal_text_ID FROM legal_texts WHERE slug = '$slug' LIMIT 1";
  115. $query = $this->db->query($sql);
  116. if ($query->num_rows() > 0) {
  117. $result = $query->row_array();
  118. return $result['legal_text_ID'];
  119. } else {
  120. return false;
  121. }
  122. }
  123. /**
  124. * mp. getSitemap
  125. *
  126. * @access public
  127. * @since 0.9
  128. *
  129. * @param array $params
  130. *
  131. * @return mixed
  132. */
  133. public function getSitemap($params = array())
  134. {
  135. $sitemap = array();
  136. // main sections to build sitemap
  137. $sitemap['sections'] = array(
  138. 'blog_articles' => array(
  139. 'title' => 'Noticias',
  140. 'slug' => _reg('site_url') . 'noticias',
  141. ),
  142. 'companies' => array(
  143. 'title' => 'GuĂ­a Comercial',
  144. 'slug' => _reg('site_url') . 'empresas'
  145. ),
  146. 'products' => array(
  147. 'title' => 'Productos',
  148. 'slug' => _reg('site_url') . 'tienda'
  149. ),
  150. 'basicads' => array(
  151. 'title' => 'Clasificados',
  152. 'slug' => _reg('site_url') . 'clasificados'
  153. ),
  154. 'events' => array(
  155. 'title' => 'Agenda',
  156. 'slug' => _reg('site_url') . 'agenda'
  157. )
  158. );
  159. $defaults = array(
  160. 'start' => 0,
  161. 'limit' => 999,
  162. 'order_by' => 'order_by DESC',
  163. 'search_by' => false,
  164. 'search' => '',
  165. 'filter_by' => false,
  166. 'filter' => ''
  167. );
  168. $params = array_merge($defaults, $params);
  169. $where = "";
  170. if ($params['search_by']) {
  171. $where.= " AND " . $params['search_by'] . " LIKE '%" . $params['search'] . "%'";
  172. }
  173. if ($params['filter_by']) {
  174. $where.= " AND " . $params['filter_by'] . " = '" . $params['filter'] . "'";
  175. } else {
  176. }
  177. // legal texts
  178. $sql = " SELECT legal_text_ID, title, slug FROM legal_texts";
  179. //$sql.= " WHERE site_ID = '" . site_id() . "'" . $where;
  180. $sql.= ($params['order_by']) ? " ORDER BY " . $params['order_by'] : "";
  181. $sql.= " LIMIT " . $params['start'] . ", " . $params['limit'] . ";";
  182. $query = $this->db->query($sql);
  183. if ($query->num_rows() > 0) {
  184. $sitemap['legal_texts'] = $query->result_array();
  185. } else {
  186. $sitemap['legal_texts'] = false;
  187. }
  188. // blog articles
  189. $sql = " SELECT article_ID, title, slug FROM blog_articles";
  190. $sql.= " WHERE site_ID = '" . site_id() . "'";
  191. $sql.= " ORDER BY date_added";
  192. $sql.= " LIMIT " . $params['start'] . ", " . $params['limit'] . ";";
  193. $query = $this->db->query($sql);
  194. if ($query->num_rows() > 0) {
  195. $sitemap['blog_articles'] = $query->result_array();
  196. } else {
  197. $sitemap['blog_articles'] = false;
  198. }
  199. // companies
  200. $sql = " SELECT company_ID, name AS title, slug FROM companies";
  201. $sql.= " WHERE site_ID = '" . site_id() . "'";
  202. $sql.= " ORDER BY name";
  203. $sql.= " LIMIT " . $params['start'] . ", " . $params['limit'] . ";";
  204. $query = $this->db->query($sql);
  205. if ($query->num_rows() > 0) {
  206. $sitemap['companies'] = $query->result_array();
  207. } else {
  208. $sitemap['companies'] = false;
  209. }
  210. // events
  211. $sql = " SELECT event_ID, title, slug FROM events";
  212. $sql.= " WHERE site_ID = '" . site_id() . "'";
  213. $sql.= " ORDER BY event_start";
  214. $sql.= " LIMIT " . $params['start'] . ", " . $params['limit'] . ";";
  215. $query = $this->db->query($sql);
  216. if ($query->num_rows() > 0) {
  217. $sitemap['events'] = $query->result_array();
  218. } else {
  219. $sitemap['events'] = false;
  220. }
  221. // products
  222. $sql = " SELECT p.product_ID, pd.name AS title, pd.slug FROM products p";
  223. $sql.= " LEFT JOIN products_description pd ON p.product_ID = pd.product_ID";
  224. $sql.= " WHERE p.site_ID = '" . site_id() . "'";
  225. $sql.= " ORDER BY date_added";
  226. $sql.= " LIMIT " . $params['start'] . ", " . $params['limit'] . ";";
  227. $query = $this->db->query($sql);
  228. if ($query->num_rows() > 0) {
  229. $sitemap['products'] = $query->result_array();
  230. } else {
  231. $sitemap['products'] = false;
  232. }
  233. // basicads
  234. $sql = " SELECT basicad_ID, title, slug FROM basicads";
  235. $sql.= " WHERE site_ID = '" . site_id() . "'";
  236. $sql.= " ORDER BY date_added";
  237. $sql.= " LIMIT " . $params['start'] . ", " . $params['limit'] . ";";
  238. $query = $this->db->query($sql);
  239. if ($query->num_rows() > 0) {
  240. $sitemap['basicads'] = $query->result_array();
  241. } else {
  242. $sitemap['basicads'] = false;
  243. }
  244. /*
  245. echo '<pre>';
  246. print_r($sitemap);
  247. echo '</pre>';
  248. */
  249. return $sitemap;
  250. }
  251. }
  252. /* End of file mp_model.php */
  253. /* Location: ./application/models/mp_model.php */