function getArchive(&$params) { $user =& JFactory::getUser(); $aid = $user->get('aid'); $db =& JFactory::getDBO(); $jnow =& JFactory::getDate(); $now = $jnow->toMySQL(); $nullDate = $db->getNullDate(); $query = "SELECT DISTINCT MONTH(created) as m, YEAR(created) as y FROM #__k2_items WHERE published=1 AND ( publish_up = " . $db->Quote($nullDate) . " OR publish_up <= " . $db->Quote($now) . " ) AND ( publish_down = " . $db->Quote($nullDate) . " OR publish_down >= " . $db->Quote($now) . " ) AND trash=0 AND access<={$aid} "; $catid = $params->get('archiveCategory', 0); if ($catid > 0) { $query .= "AND catid={$catid} "; } $query .= "ORDER BY created DESC"; $db->setQuery($query, 0, 12); $rows = $db->loadObjectList(); $months = array(JText::_('JANUARY'), JText::_('FEBRUARY'), JText::_('MARCH'), JText::_('APRIL'), JText::_('MAY'), JText::_('JUNE'), JText::_('JULY'), JText::_('AUGUST'), JText::_('SEPTEMBER'), JText::_('OCTOBER'), JText::_('NOVEMBER'), JText::_('DECEMBER')); if (count($rows)) { foreach ($rows as $row) { if ($params->get('archiveItemsCounter')) { $row->numOfItems = modK2ToolsHelper::countArchiveItems($row->m, $row->y, $catid); } else { $row->numOfItems = ''; } $row->name = $months[$row->m - 1]; $archives[] = $row; } return $archives; } }
public static function getArchive(&$params) { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $aid = (int) $user->get('aid'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); $query = "SELECT DISTINCT MONTH(created) as m, YEAR(created) as y FROM #__k2_items WHERE published=1 AND ( publish_up = " . $db->Quote($nullDate) . " OR publish_up <= " . $db->Quote($now) . " ) AND ( publish_down = " . $db->Quote($nullDate) . " OR publish_down >= " . $db->Quote($now) . " ) AND trash=0"; if (K2_JVERSION != '15') { $query .= " AND access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") "; if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") "; } } else { $query .= " AND access<={$aid} "; } $catid = $params->get('archiveCategory', 0); if ($catid > 0) { $query .= " AND catid=" . (int) $catid; } $query .= " ORDER BY created DESC"; $db->setQuery($query, 0, 12); $rows = $db->loadObjectList(); $months = array(JText::_('K2_JANUARY'), JText::_('K2_FEBRUARY'), JText::_('K2_MARCH'), JText::_('K2_APRIL'), JText::_('K2_MAY'), JText::_('K2_JUNE'), JText::_('K2_JULY'), JText::_('K2_AUGUST'), JText::_('K2_SEPTEMBER'), JText::_('K2_OCTOBER'), JText::_('K2_NOVEMBER'), JText::_('K2_DECEMBER')); if (count($rows)) { foreach ($rows as $row) { if ($params->get('archiveItemsCounter')) { $row->numOfItems = modK2ToolsHelper::countArchiveItems($row->m, $row->y, $catid); } else { $row->numOfItems = ''; } $row->name = $months[$row->m - 1]; if ($params->get('archiveCategory', 0) > 0) { $row->link = JRoute::_(K2HelperRoute::getDateRoute($row->y, $row->m, null, $params->get('archiveCategory'))); } else { $row->link = JRoute::_(K2HelperRoute::getDateRoute($row->y, $row->m)); } $archives[] = $row; } return $archives; } }