diff --git a/components/com_content/models/archive.php b/components/com_content/models/archive.php index 9772a466af78e..594c5569e8731 100644 --- a/components/com_content/models/archive.php +++ b/components/com_content/models/archive.php @@ -180,4 +180,30 @@ protected function _getList($query, $limitstart=0, $limit=0) return $result; } + + /** + * Gets the archived articles years + * + * @return array + * + * @since 3.5.2 + */ + public function getYears() + { + $db = $this->getDbo(); + $nullDate = $db->quote($db->getNullDate()); + $nowDate = $db->quote(JFactory::getDate()->toSql()); + + $query = $db->getQuery(true); + $years = $query->year($db->qn('created')); + $query->select('DISTINCT (' . $years . ')') + ->from($db->qn('#__content')) + ->where($db->qn('state') . '= 2') + ->where('(publish_up = ' . $nullDate . ' OR publish_up <= ' . $nowDate . ')') + ->where('(publish_down = ' . $nullDate . ' OR publish_down >= ' . $nowDate . ')') + ->order('1 ASC'); + + $db->setQuery($query); + return $db->loadColumn(); + } } diff --git a/components/com_content/views/archive/view.html.php b/components/com_content/views/archive/view.html.php index 8e0907c6ffb24..72ac0b72983fd 100644 --- a/components/com_content/views/archive/view.html.php +++ b/components/com_content/views/archive/view.html.php @@ -24,6 +24,8 @@ class ContentViewArchive extends JViewLegacy protected $pagination = null; + protected $years = null; + /** * Execute and display a template script. * @@ -108,12 +110,13 @@ public function display($tpl = null) ); // Year Field + $this->years = $this->getModel()->getYears(); $years = array(); $years[] = JHtml::_('select.option', null, JText::_('JYEAR')); - for ($year = date('Y'), $i = $year - 10; $i <= $year; $i++) + for ($i = 0; $i < count($this->years); $i++) { - $years[] = JHtml::_('select.option', $i, $i); + $years[] = JHtml::_('select.option', $this->years[$i], $this->years[$i]); } $form->yearField = JHtml::_(