/administrator/components/com_content/models/featured.php

https://bitbucket.org/pastor399/newcastleunifc · PHP · 173 lines · 112 code · 20 blank · 41 comment · 8 complexity · a79c899b2b60f435f0ed6d44356f651d MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_content
  5. *
  6. * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. require_once __DIR__ . '/articles.php';
  11. /**
  12. * About Page Model
  13. *
  14. * @package Joomla.Administrator
  15. * @subpackage com_content
  16. */
  17. class ContentModelFeatured extends ContentModelArticles
  18. {
  19. /**
  20. * Constructor.
  21. *
  22. * @param array An optional associative array of configuration settings.
  23. * @see JController
  24. * @since 1.6
  25. */
  26. public function __construct($config = array())
  27. {
  28. if (empty($config['filter_fields']))
  29. {
  30. $config['filter_fields'] = array(
  31. 'id', 'a.id',
  32. 'title', 'a.title',
  33. 'alias', 'a.alias',
  34. 'checked_out', 'a.checked_out',
  35. 'checked_out_time', 'a.checked_out_time',
  36. 'catid', 'a.catid', 'category_title',
  37. 'state', 'a.state',
  38. 'access', 'a.access', 'access_level',
  39. 'created', 'a.created',
  40. 'created_by', 'a.created_by',
  41. 'created_by_alias', 'a.created_by_alias',
  42. 'ordering', 'a.ordering',
  43. 'featured', 'a.featured',
  44. 'language', 'a.language',
  45. 'hits', 'a.hits',
  46. 'publish_up', 'a.publish_up',
  47. 'publish_down', 'a.publish_down',
  48. 'fp.ordering',
  49. );
  50. }
  51. parent::__construct($config);
  52. }
  53. /**
  54. * @param boolean True to join selected foreign information
  55. *
  56. * @return string
  57. */
  58. protected function getListQuery($resolveFKs = true)
  59. {
  60. // Create a new query object.
  61. $db = $this->getDbo();
  62. $query = $db->getQuery(true);
  63. // Select the required fields from the table.
  64. $query->select(
  65. $this->getState(
  66. 'list.select',
  67. 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid, a.state, a.access, a.created, a.hits,' .
  68. 'a.language, a.created_by_alias, a.publish_up, a.publish_down'
  69. )
  70. );
  71. $query->from('#__content AS a');
  72. // Join over the language
  73. $query->select('l.title AS language_title')
  74. ->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language');
  75. // Join over the content table.
  76. $query->select('fp.ordering')
  77. ->join('INNER', '#__content_frontpage AS fp ON fp.content_id = a.id');
  78. // Join over the users for the checked out user.
  79. $query->select('uc.name AS editor')
  80. ->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
  81. // Join over the asset groups.
  82. $query->select('ag.title AS access_level')
  83. ->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
  84. // Join over the categories.
  85. $query->select('c.title AS category_title')
  86. ->join('LEFT', '#__categories AS c ON c.id = a.catid');
  87. // Join over the users for the author.
  88. $query->select('ua.name AS author_name')
  89. ->join('LEFT', '#__users AS ua ON ua.id = a.created_by');
  90. // Filter by access level.
  91. if ($access = $this->getState('filter.access'))
  92. {
  93. $query->where('a.access = ' . (int) $access);
  94. }
  95. // Filter by published state
  96. $published = $this->getState('filter.published');
  97. if (is_numeric($published))
  98. {
  99. $query->where('a.state = ' . (int) $published);
  100. }
  101. elseif ($published === '')
  102. {
  103. $query->where('(a.state = 0 OR a.state = 1)');
  104. }
  105. // Filter by a single or group of categories.
  106. $baselevel = 1;
  107. $categoryId = $this->getState('filter.category_id');
  108. if (is_numeric($categoryId))
  109. {
  110. $cat_tbl = JTable::getInstance('Category', 'JTable');
  111. $cat_tbl->load($categoryId);
  112. $rgt = $cat_tbl->rgt;
  113. $lft = $cat_tbl->lft;
  114. $baselevel = (int) $cat_tbl->level;
  115. $query->where('c.lft >= ' . (int) $lft)
  116. ->where('c.rgt <= ' . (int) $rgt);
  117. }
  118. elseif (is_array($categoryId))
  119. {
  120. JArrayHelper::toInteger($categoryId);
  121. $categoryId = implode(',', $categoryId);
  122. $query->where('a.catid IN (' . $categoryId . ')');
  123. }
  124. // Filter on the level.
  125. if ($level = $this->getState('filter.level'))
  126. {
  127. $query->where('c.level <= ' . ((int) $level + (int) $baselevel - 1));
  128. }
  129. // Filter by search in title
  130. $search = $this->getState('filter.search');
  131. if (!empty($search))
  132. {
  133. if (stripos($search, 'id:') === 0)
  134. {
  135. $query->where('a.id = ' . (int) substr($search, 3));
  136. }
  137. else
  138. {
  139. $search = $db->quote('%' . $db->escape($search, true) . '%');
  140. $query->where('a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search);
  141. }
  142. }
  143. // Filter on the language.
  144. if ($language = $this->getState('filter.language'))
  145. {
  146. $query->where('a.language = ' . $db->quote($language));
  147. }
  148. // Add the list ordering clause.
  149. $query->order($db->escape($this->getState('list.ordering', 'a.title')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
  150. //echo nl2br(str_replace('#__','jos_',(string)$query));
  151. return $query;
  152. }
  153. }