[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/modules/mod_articles_archive/src/Helper/ -> ArticlesArchiveHelper.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  mod_articles_archive
   6   *
   7   * @copyright   (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Module\ArticlesArchive\Site\Helper;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Router\Route;
  17  use Joomla\Component\Content\Administrator\Extension\ContentComponent;
  18  use Joomla\Database\ParameterType;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Helper for mod_articles_archive
  26   *
  27   * @since  1.5
  28   */
  29  class ArticlesArchiveHelper
  30  {
  31      /**
  32       * Retrieve list of archived articles
  33       *
  34       * @param   \Joomla\Registry\Registry  &$params  module parameters
  35       *
  36       * @return  array
  37       *
  38       * @since   1.5
  39       */
  40      public static function getList(&$params)
  41      {
  42          $app       = Factory::getApplication();
  43          $db        = Factory::getDbo();
  44          $query     = $db->getQuery(true);
  45  
  46          $query->select($query->month($db->quoteName('created')) . ' AS created_month')
  47              ->select('MIN(' . $db->quoteName('created') . ') AS created')
  48              ->select($query->year($db->quoteName('created')) . ' AS created_year')
  49              ->from($db->quoteName('#__content', 'c'))
  50              ->where($db->quoteName('c.state') . ' = ' . ContentComponent::CONDITION_ARCHIVED)
  51              ->group($query->year($db->quoteName('c.created')) . ', ' . $query->month($db->quoteName('c.created')))
  52              ->order($query->year($db->quoteName('c.created')) . ' DESC, ' . $query->month($db->quoteName('c.created')) . ' DESC');
  53  
  54          // Filter by language
  55          if ($app->getLanguageFilter()) {
  56              $query->whereIn($db->quoteName('language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
  57          }
  58  
  59          $query->setLimit((int) $params->get('count'));
  60          $db->setQuery($query);
  61  
  62          try {
  63              $rows = (array) $db->loadObjectList();
  64          } catch (\RuntimeException $e) {
  65              $app->enqueueMessage(Text::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
  66  
  67              return [];
  68          }
  69  
  70          $menu   = $app->getMenu();
  71          $item   = $menu->getItems('link', 'index.php?option=com_content&view=archive', true);
  72          $itemid = (isset($item) && !empty($item->id)) ? '&Itemid=' . $item->id : '';
  73  
  74          $i     = 0;
  75          $lists = array();
  76  
  77          foreach ($rows as $row) {
  78              $date = Factory::getDate($row->created);
  79  
  80              $createdMonth = $date->format('n');
  81              $createdYear  = $date->format('Y');
  82  
  83              $createdYearCal = HTMLHelper::_('date', $row->created, 'Y');
  84              $monthNameCal   = HTMLHelper::_('date', $row->created, 'F');
  85  
  86              $lists[$i] = new \stdClass();
  87  
  88              $lists[$i]->link = Route::_('index.php?option=com_content&view=archive&year=' . $createdYear . '&month=' . $createdMonth . $itemid);
  89              $lists[$i]->text = Text::sprintf('MOD_ARTICLES_ARCHIVE_DATE', $monthNameCal, $createdYearCal);
  90  
  91              $i++;
  92          }
  93  
  94          return $lists;
  95      }
  96  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer