/halogy/application/modules/files/models/files_model.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 104 lines · 67 code · 16 blank · 21 comment · 6 complexity · c03fdea1aa4da00654d03db7b9ea3daf 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 Files_model extends Model {
  18. function Files_model()
  19. {
  20. parent::Model();
  21. // get siteID, if available
  22. if (defined('SITEID'))
  23. {
  24. $this->siteID = SITEID;
  25. }
  26. }
  27. function search_files($query, $limit = '')
  28. {
  29. if (!$query)
  30. {
  31. return FALSE;
  32. }
  33. $this->db->where(array('siteID' => $this->siteID, 'deleted' => 0));
  34. $this->db->where('(fileRef LIKE "%'.$this->db->escape_like_str($query).'%")');
  35. $this->db->order_by('fileRef', 'asc');
  36. $query = $this->db->get('files', $limit);
  37. if ($query->num_rows())
  38. {
  39. return $query->result_array();
  40. }
  41. else
  42. {
  43. return false;
  44. }
  45. }
  46. function get_folders($folderID = '')
  47. {
  48. // default where
  49. $this->db->where(array('siteID' => $this->siteID, 'deleted' => 0));
  50. $this->db->order_by('folderOrder');
  51. // get based on folder ID
  52. if ($folderID)
  53. {
  54. $query = $this->db->get_where('file_folders', array('folderID' => $folderID), 1);
  55. if ($query->num_rows())
  56. {
  57. return $query->row_array();
  58. }
  59. else
  60. {
  61. return false;
  62. }
  63. }
  64. // or just get all of em
  65. else
  66. {
  67. // template type
  68. $query = $this->db->get('file_folders');
  69. if ($query->num_rows())
  70. {
  71. return $query->result_array();
  72. }
  73. else
  74. {
  75. return false;
  76. }
  77. }
  78. }
  79. function update_children($folderID)
  80. {
  81. // update page draft
  82. $this->db->set('folderID', 0);
  83. $this->db->where('siteID', $this->siteID);
  84. $this->db->where('folderID', $folderID);
  85. $this->db->update('files');
  86. return TRUE;
  87. }
  88. }