/administrator/components/com_customproperties/models/content.php

https://github.com/Shigaru/shigaru · PHP · 138 lines · 78 code · 21 blank · 39 comment · 16 complexity · 800e9ac5b4b104d6bf8309464b83f4b7 MD5 · raw file

  1. <?php
  2. /**
  3. * Custom Properties for Joomla! 1.5.x
  4. * @package Custom Properties
  5. * @subpackage Component
  6. * version 1.98.3.4
  7. * @revision $Revision: 1.4 $
  8. * @author Andrea Forghieri
  9. * @copyright (C) 2007-2011 Andrea Forghieri, Solidsystem - http://www.solidsystem.it
  10. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL version 2
  11. */
  12. // Check to ensure this file is included in Joomla!
  13. defined('_JEXEC') or die();
  14. jimport('joomla.application.component.model');
  15. /**
  16. * Custom Poperties Content Model - retrieves taggable content items
  17. *
  18. * @package Custom Properties
  19. * version 1.98.3.4
  20. * @subpackage Component
  21. */
  22. class CustompropertiesModelContent extends JModel {
  23. /**
  24. * Field id
  25. * @var integer
  26. */
  27. var $_id;
  28. /**
  29. * CP Fields list
  30. * @var array
  31. */
  32. var $_list;
  33. /**
  34. * Pagination
  35. *
  36. * @var array
  37. */
  38. var $_page;
  39. /**
  40. * Retrieves all content elements of choosen type
  41. * @param object cpContentElement $content_element Content elements
  42. * @return array Array of objects containing the data from the database
  43. */
  44. function getList($content_element) {
  45. if(!$content_element) return false;
  46. global $mainframe;
  47. $database = JFactory::getDBO();
  48. if (!empty ($this->_list)) {
  49. return $this->_list;
  50. }
  51. $wherestr = array();
  52. $selstr = array();
  53. $fromstr = array();
  54. $orderstr = array();
  55. $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
  56. $limitstart = $mainframe->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int');
  57. $selstr[] = "c.".$content_element->id." AS id ";
  58. $selstr[] = "c.".$content_element->title." as title ";
  59. $selstr[] = "c.".$content_element->state ." as state ";
  60. $fromstr[]= "#__".$content_element->table." AS c ";
  61. if($content_element->sec_table){
  62. $section_id = JRequest::getVar('filter_sectionid', 0, '', 'int');
  63. $selstr[] = "IFNULL(sec.".$content_element->sec_table_title.", 'Static') AS section ";
  64. $fromstr[] = "LEFT JOIN #__".$content_element->sec_table." AS sec " .
  65. "ON(c.".$content_element->sectionid." = sec.".$content_element->sec_table_id.") ";
  66. if($section_id != "" && $content_element->sec_table) $wherestr[]= "AND c.".$content_element->sectionid." = $section_id ";
  67. $orderstr[] = "c.".$content_element->sectionid;
  68. }
  69. else{
  70. $selstr[] = "'' AS section ";
  71. }
  72. if($content_element->cat_table){
  73. $category_id = JRequest::getVar('filter_categoryid', 0, '', 'int');
  74. $selstr[] = "IFNULL(cat.".$content_element->cat_table_title.", 'Static') AS category ";
  75. $fromstr[] = " LEFT JOIN #__".$content_element->cat_table." cat " .
  76. "ON(c.".$content_element->catid." = cat.".$content_element->cat_table_id.") " ;
  77. if($category_id != "" && $content_element->cat_table) $wherestr[] = "AND c.".$content_element->catid." = $category_id ";
  78. $orderstr[] = "c.".$content_element->catid;
  79. }
  80. else{
  81. $selstr[] = "'' AS category ";
  82. }
  83. $filter_title = JRequest::getVar('filter_title', '');
  84. if($filter_title != "" ) $wherestr[] = "AND c.".$content_element->title." LIKE '%$filter_title%' ";
  85. // default ordering
  86. $orderstr[] = "c.". $content_element->title ;
  87. // put the query together
  88. $selstr = join($selstr, ',');
  89. $fromstr = join($fromstr, ' ');
  90. $wherestr = join($wherestr, ' ');
  91. $orderstr = join($orderstr, ',');
  92. $query = "SELECT SQL_CALC_FOUND_ROWS $selstr " .
  93. "FROM $fromstr " .
  94. "WHERE 1 $wherestr " .
  95. "ORDER BY $orderstr";
  96. $database->setQuery($query, $limitstart, $limit);
  97. $this->_list = $database->loadObjectList();
  98. // If there is a db query error, throw a HTTP 500 and exit
  99. if ($database->getErrorNum()) {
  100. JError::raiseError(500, $database->stderr());
  101. return false;
  102. }
  103. else{
  104. $database->setQuery('SELECT FOUND_ROWS();'); //no reloading the query! Just asking for total without limit
  105. jimport('joomla.html.pagination');
  106. $this->_page = $pageNav = new JPagination($database->loadResult(), $limitstart, $limit);
  107. }
  108. return $this->_list;
  109. }
  110. function getPagination($content_element) {
  111. if(!$content_element) return false;
  112. if (is_null($this->_list) || is_null($this->_page)) {
  113. $this->getList($content_element);
  114. }
  115. return $this->_page;
  116. }
  117. }