Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Back/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Back/TfViewList.php

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

namespace TechFry\Library\View\Back;

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;

// View Class for Backend List - Model Required
class TfViewList extends TfView
{
    public $view_type = 'list';
    
    protected $items = [];

    protected $pagination;

    protected $state;
    
    public $filterForm;

    public $activeFilters = [];
    
    public $isEmptyState = false;
    protected $hits = false;

    // Define in View or Template file
    public $columns = []; // Standard Joomla Columns
    public $theads = [];
    public $tbody = [];
    public $tr = [];

    public $table_name;
    public $form_view;

    public $total;

    public $listOrder;
    public $listDirn = 'ASC';

    public $form_action_sfx = '';

    //public $childbar;

    public function display($tpl = null)
    {
        $this->initiate_list();

        parent::display($tpl);
    }

    public function initiate_list()
    {
        $this->addTemplatePath(JPATH_LIBRARIES . '/techfry/html/backlist');
        
        $this->initiate_view();

        // Table name from model
        $this->table_name = $this->getModel()->table_name;

        // 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->pagination = $this->get('Pagination');
        $this->state = $this->get('State');

        // Adding Filters
        $filter_xml = JPATH_ADMINISTRATOR . '/components/' . $this->option . '/forms/filter_' . $this->view_name . '.xml';
        if (file_exists($filter_xml))
        {
            $this->filterForm = $this->get('FilterForm');
            $this->activeFilters = $this->get('ActiveFilters');
        }
        
        $this->total = $this->get('Total');

        // Empty state layout
        if (\is_countable($this->items))
        {
            if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState'))
            {
                $this->setLayout('emptystate');
            }
        }
/*
        // Check for errors
        $errors = $this->get('Errors');
        if (\is_countable($errors) && \count($errors))
        {
            throw new GenericDataException(implode("\n", $errors), 500);
        }
        */

        if ($this->filterForm)
        {
            $this->listOrder = $this->escape($this->state->get('list.ordering'));
            $this->listDirn = $this->escape($this->state->get('list.direction'));
        }
    }

    // Start displaying list layout - used by tmpl file
    public function display_list_layout()
    {
        $wa = $this->document->getWebAssetManager();
        $wa->useScript('keepalive')
            ->useScript('table.columns')
            ->useScript('multiselect');

        $is_pro = $this->getModel()->is_pro();
        $db_limit = $this->getModel()->db_limit;
        if (!$is_pro && $db_limit)
        {
            $total_rows = $this->getModel()->get_total_rows();
            $pc = round(($total_rows/$db_limit) * 100);

            $progress_text = $total_rows . '/' . $db_limit;

            echo $this->get_progress($pc, $progress_text, 'danger');
        }
        
        echo '<form action="' . Route::_('index.php?option=' . $this->option . '&view=' . $this->view_name . $this->form_action_sfx) . '" method="post" name="adminForm" id="adminForm">';
            echo '<div id="j-main-container" class="j-main-container">';

            // Search tools bar
            if ($this->filterForm)
            {
                echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]);
            }

            // No Results Message
            if (empty($this->items))
            {
                echo $this->get_no_results_msg();
            }
            // Items
            else
            {
                echo '<table class="table table-striped table-hover">';
                    echo $this->add_thead();
                    echo $this->add_tbody();
                echo '</table>';

                // Load the pagination
                echo $this->pagination->getListFooter();
            }

            // Load batch processing form
            echo '<template id="joomla-dialog-batch">' . $this->loadTemplate('batch_body') . '</template>';

            echo '<input type="hidden" name="task" value="">';
            echo '<input type="hidden" name="boxchecked" value="0">';
            echo HTMLHelper::_('form.token');

            echo '</div>';
        echo '</form>';
        
    }

    // Empty state layout
    public function es_layout()
    {
        $displayData = array(
            //'title' => Text::_(strtoupper($this->option) . '_' . strtoupper($this->view_name)),
            'title' => $this->title,
            'textPrefix' => 'COM_TF',
            'helpURL' => 'https://joomlafry.com/' . $this->help_url,
            'icon' => $this->icon,
        );

        if (\in_array('new', $this->toolbar_buttons))
        {
            $displayData['createURL'] = 'index.php?option=' . $this->option . '&task=' . $this->form_view . '.add';
        }

        echo LayoutHelper::render('joomla.content.emptystate', $displayData);
    }

    // Add table head in list layout
    public function add_thead($layout = 'default')
    {
        echo '<thead><tr>';

        if (\in_array('id', $this->columns) && $layout == 'default')
        {
            echo '<td class="w-1 text-center">' . HTMLHelper::_('grid.checkall') . '</td>';
        }

        if (\in_array('ordering', $this->columns))
        {
            echo '<th>' . HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ORDERING', 'a.ordering', $this->listDirn, $this->listOrder) . '</th>';
        }

        if (\in_array('published', $this->columns))
        {
            echo '<th class="w-1 text-center">' . HTMLHelper::_('searchtools.sort', 'JSTATUS', 'a.published', $this->listDirn, $this->listOrder) . '</th>';
        }

        if (\in_array('title', $this->columns))
        {
            echo '<th style="min-width:100px">' . HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $this->listDirn, $this->listOrder) . '</th>';
        }

        foreach ($this->theads as $h => $thead)
        {
            echo '<th>';
                echo empty($thead) ? Text::_($h) : HTMLHelper::_('searchtools.sort', $h, $thead, $this->listDirn, $this->listOrder);
            echo '</th>';
        }

        if (\in_array('access', $this->columns))
        {
            echo '<th class="w-10 d-none d-md-table-cell">' . HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ACCESS', 'a.access', $this->listDirn, $this->listOrder) . '</th>';
        }

        if (\in_array('created_by', $this->columns))
        {
            echo '<th class="w-10 d-none d-md-table-cell">' . HTMLHelper::_('searchtools.sort', 'JAUTHOR', 'a.created_by', $this->listDirn, $this->listOrder) . '</th>';
        }

        if (\in_array('created', $this->columns))
        {
            echo '<th class="w-10 d-none d-md-table-cell text-center">' . HTMLHelper::_('searchtools.sort', 'JGLOBAL_CREATED', 'a.created', $this->listDirn, $this->listOrder) . '</th>';
        }

        if (\in_array('modified', $this->columns))
        {
            echo '<th class="w-10 d-none d-md-table-cell text-center">' . HTMLHelper::_('searchtools.sort', 'JGLOBAL_MODIFIED', 'a.modified', $this->listDirn, $this->listOrder) . '</th>';
        }

        if (\in_array('hits', $this->columns))
        {
            echo '<th class="w-3 d-none d-lg-table-cell text-center">' . HTMLHelper::_('searchtools.sort', 'JGLOBAL_HITS', 'a.hits', $this->listDirn, $this->listOrder) . '</th>';
        }

        if (\in_array('id', $this->columns))
        {
            echo '<th class="w-3 d-none d-lg-table-cell">' . HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $this->listDirn, $this->listOrder) . '</th>';
        }

        echo '</tr></thead>';
    }

    // Add table body in list layouts
    public function add_tbody()
    {
        echo '<tbody>';
        foreach ($this->items as $i => $row)
        {
            echo '<tr>';

            if (\in_array('id', $this->columns))
            {
                echo '<td class="text-center">' . HTMLHelper::_('grid.id', $i, $row->id) . '</td>';
            }

            if (\in_array('ordering', $this->columns))
            {
                echo '<td>' . $row->ordering . '</td>';
            }

            if (\in_array('published', $this->columns))
            {
                if (isset($row->publish_up))
                {
                    echo '<td>' . $this->get_status($row->published, $i, $row->publish_up, $row->publish_down) . '</td>';
                }
                else
                {
                    echo '<td>' . $this->get_status($row->published, $i) . '</td>';
                }
            }

            if ($this->tbody)
            {
                foreach ($this->tbody[$i] as $col)
                {
                    echo '<td>'	. $col . '</td>';
                }
            }

            if (\in_array('access', $this->columns))
            {
                echo '<td class="small d-none d-md-table-cell">' . $this->escape($row->access_level) . '</td>';
            }

            if (\in_array('created_by', $this->columns))
            {
                echo '<td class="small d-none d-md-table-cell">';
                    echo $this->escape($row->author_name) . '<br>';
                    echo $row->author_email . '<br>';
                    echo $row->created_by . '<br>';
                echo '</td>';
            }

            if (\in_array('created', $this->columns))
            {
                echo '<td>' . $this->get_date($row->created) . '</td>';
            }

            if (\in_array('modified', $this->columns))
            {
                echo '<td>' . $this->get_date($row->modified) . '</td>';
            }

            if (\in_array('hits', $this->columns))
            {
                echo '<td class="d-none d-lg-table-cell text-center">' . $this->get_number((int) $row->hits, 'info') . '</td>';
            }

            if (\in_array('id', $this->columns))
            {
                echo '<td class="d-none d-lg-table-cell">' . (int) $row->id . '</td>';
            }
            echo '</tr>';
        }
        echo '</tbody>';
    }

    public function get_lang($item)
    {
        $output .= '<small>' . LayoutHelper::render('joomla.content.language', $item) . '</small>';

        return $output;
    }

    public function get_assoc($item_id, $context)
    {
        $html = '';

        if ($associations = Associations::getAssociations($this->option, '#__' . $this->table_name, $context, (int) $item_id, 'id', 'alias', ''))
        {
            foreach ($associations as $tag => $associated)
            {
                $associations[$tag] = (int) $associated->id;
            }

            // Get the associated menu items
            $db = Factory::getDbo();

            $query = $db->getQuery(true)
                ->select('a.*')
                ->select('l.sef as lang_sef')
                ->select('l.lang_code')
                ->from('#__' . $this->table_name . ' as a')
                ->where('a.id IN (' . implode(',', array_values($associations)) . ')')
                ->join('LEFT', '#__languages as l ON a.language=l.lang_code')
                ->select('l.image')
                ->select('l.title as language_title');

            $db->setQuery($query);

            $items = $db->loadObjectList('id');

            if ($items)
            {
                $languages = LanguageHelper::getContentLanguages(array(0, 1));
                $content_languages = array_column($languages, 'lang_code');

                foreach ($items as &$item)
                {
                    if (in_array($item->lang_code, $content_languages))
                    {
                        $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX';

                        $url = Route::_('index.php?option=' . $this->option . '&view=' . $this->form_view . '&layout=edit&id=' . (int) $item->id);

                        $tooltip = htmlspecialchars($item->greeting, ENT_QUOTES, 'UTF-8') . '<br />' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title);

                        $classes = 'badge bg-info';

                        $item->link = '<a href="' . $url . '" title="' . $item->language_title . '" class="' . $classes
                            . '" data-content="' . $tooltip . '" data-placement="top">'
                            . $text . '</a>';
                    }
                    else
                    {
                        Factory::getApplication()->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning');
                    }
                }
            }

            $html = LayoutHelper::render('joomla.content.associations', $items);
        }

        return $html;
    }
}