Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Front/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Front/TViewList.php

<?php
/*
* @package		Tech Fry Library
* @license		https://www.gnu.org/licenses/gpl-3.0.en.html
*/

namespace TechFry\Library\View\Front;

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use TechFry\Library\TAmp;
use TechFry\Library\View\Sky\Collapse;
use TechFry\Library\View\Sky\Pagination;

class TViewList extends TView
{
    // View class for frontend list
    // Methods: escape(), getLayout(), setLayout(), loadTemplate()
    
    public $items = [];
    
    public $state;
    
    public $pagination;
    
    public $total;

    public $listOrder;
    public $listDirn;

    public $searches = [];
    public $search_form;

    public $show_limitbox = false;

    public $form_view;
	
  	// 01. Starting method for list views
    public function initiate_list()
    {
      	$amp = new TAmp();
      
      	// Form view name
        if (empty($this->form_view))
        {
            $this->form_view = substr($this->view_name, 0, -1);
        }
        
        // Get data from model
        $this->items = $this->get('Items');
        $this->state = $this->get('State');
        $this->pagination = $this->get('Pagination');

        // Dont show Search on AMP Pages
        if (!$amp->is_amp())
        {
            $search_output = $this->get('SearchForm');

            $search_data = array(
                'data' => $search_output,
                'button_text' => Text::_('JSEARCH_FILTER'),
            );

            $search_config = array(
                'button_class' => 'btn-primary mb-3',
                'icon' => 'fa-solid fa-search',
            );

            $collapse = new Collapse($search_data, $search_config);
            $this->search_form = $collapse->display();
        }
        
        $this->total = $this->get('Total');

        $this->listOrder = $this->escape($this->state->get('list.ordering'));
        $this->listDirn = $this->escape($this->state->get('list.direction'));
        
        $this->_prepareDocument();
    }
    
    protected function _prepareDocument()
	{
	    parent::_prepareDocument();
	    
	    // Add feed link
	    if ($this->params->get('show_feed_link', 0))
	    {
            $this->add_feed();
	    }
	}
    
    // Start displaying list layout
    public function start_list_layout()
    {   
        if ($this->params->get('show_page_heading'))
        {
            echo '<h1>' . $this->escape($this->params->get('page_heading')) . '</h1>';
        }
        
        if (!empty($this->params->get('description')))
        {
            echo $this->params->get('description');
        }
        
        if (empty($this->items))
        {
            $no_results_msg = $this->get_no_results_msg();
            echo $this->get_alert($no_results_msg, array('type' => 'warning', 'icon' => 'fa-solid fa-circle-exclamation'));
        }
    }

    // Display Sorting Dropdown and Limitbox
    public function display_listing_controls()
    {
        // Dont show on AMP Pages
        $amp = new TAmp();
        if ($amp->is_amp())
        {
            return;
        }
        
        $sorting_fields = $this->getModel()->sorting_fields ?? [];
        
        if (!empty($sorting_fields))
        {
            if ($this->show_limitbox)
            {
                echo '<div class="d-flex justify-content-between">';
            }
            
            $current_ordering = $this->state->get('list.fullordering');
            
            echo '<div class="mb-3">';
                echo '<label id="list_fullordering-lbl" for="fullordering" class="visually-hidden">';
                    echo Text::_('JGLOBAL_SORT_BY');
                echo '</label>';
                    echo '<select id="list_fullordering" name="list[fullordering]" class="form-select" onchange="this.form.submit()">';
                        echo '<option value="">' . Text::_('JTABLE_OPTIONS_ORDERING') . '</option>';
                        foreach ($sorting_fields as $sorting_field)
                        {
                            $asc_selected = '';
                            $desc_selected = '';
                            if ($current_ordering == 'a.' . $sorting_field . ' ASC')
                            {
                                $asc_selected = ' selected';
                            }
                            elseif ($current_ordering == 'a.' . $sorting_field . ' DESC')
                            {
                                $desc_selected = ' selected';
                            }
                            
                            echo '<option value="a.' . $sorting_field . ' ASC"' . $asc_selected . '>' . $sorting_field . ' ascending</option>';
                            echo '<option value="a.' . $sorting_field . ' DESC"' . $desc_selected . '>' . $sorting_field . ' descending</option>';
                        }
                    echo '</select>';
            echo '</div>';
        }
        
        if ($this->show_limitbox)
        {
            echo $this->get_limitbox();

            echo '</div>';;
        }
    }

    public function get_limitbox()
    {
        $output = '<div class="mb-3">';
            $output .= '<label for="limit" class="visually-hidden">';
                $output .= Text::_('JGLOBAL_DISPLAY_NUM');
            $output .= '</label>';
            $output .= $this->pagination->getLimitBox();
        $output .= '</div>';

        return $output;
    }
    
    // Finish displaying list layout
    public function end_list_layout($show_pagination = 1, $show_pagination_results = 1)
    {
        // Add pagination links
      	if (!empty($this->items))
        {
          	if ($show_pagination && ($this->pagination->pagesTotal > 1))
            {
            	$pagination = new Pagination($this->pagination, array('show_pagination_results' => $show_pagination_results));

                echo $pagination->display();
            }  
        }
    }

    public function start_list_form()
    {
        // Dont show on AMP Pages
        $amp = new TAmp();
        if ($amp->is_amp())
        {
            return;
        }
        
        echo '<form method="post" name="adminForm" id="adminForm">';
    }

    public function end_list_form()
    {
        // Dont show on AMP Pages
        $amp = new TAmp();
        if ($amp->is_amp())
        {
            return;
        }
        
        echo '<input type="hidden" name="filter_order" value="" />';
        echo '<input type="hidden" name="filter_order_Dir" value="" />';
        echo '<input type="hidden" name="task" value="">';
        echo '</form>';
    }
    
    public function add_feed()
	{
		$link = '&format=feed&limitstart=';
		
        $attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
        $this->getDocument()->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);  
        
        $attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
        $this->getDocument()->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
	}

    // Override to get custom message
    public function get_no_results_msg()
    {        
        $message = $this->params->get($this->view_name . '_no_items_msg');
        if ($message)
        {
            return $message;
        }

        $message = $this->params->get('no_items_msg');
        if ($message)
        {
            return $message;
        }
        
        return Text::_('JGLOBAL_NO_MATCHING_RESULTS');
    }
}