Your IP : 216.73.216.240
<?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\Text;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Router\Route;
use TechFry\Library\TDb;
class TfViewDashboard extends TfView
{
// Messages, Tiles, Version Info
public $view_type = 'dashboard';
public $tiles = [];
public $alerts = [];
public $pro_url = '';
public $custom_fields_section;
public $current_version;
public $new_version;
public $mode; // Lite or Pro
public function display($tpl = null)
{
$this->icon = 'fa-solid fa-th';
parent::display($tpl);
//$this->addToolbar();
}
// Fucntion to start displaying dashboard layout
public function start_dashboard_layout()
{
// INITIAL VARIABLES
$model = $this->getModel();
$this->current_version = $model->get_current_version();
$this->new_version = $model->get_new_version();
$this->mode = $model->is_pro() ? 'Pro' : 'Lite';
// START LAYOUT
echo '<div id="j-main-container">';
$this->add_general_tiles();
$this->add_message();
echo '<div class="card mb-3">';
echo '<div class="card-body">';
echo '<nav class="quick-icons">';
echo '<ul class="nav flex-wrap">';
foreach ($this->tiles as $tile)
{
echo $this->get_tile($tile);
}
echo '</ul>';
echo '</nav>';
echo '</div>';
echo '</div>';
}
// Function to finish dashboard layout
public function end_dashboard_layout()
{
echo '<small><strong>Extension Version:</strong> ' . $this->current_version . ' ' . $this->mode . '<br>';
echo '<strong>Joomla Version:</strong> ' . JVERSION . '<br>';
echo '<strong>PHP Version:</strong> ' . PHP_VERSION . '</small>';
echo '</div>';
}
public function get_tile($tile)
{
// $tile - link, icon, text, table, target, type, view
if (isset($tile['view']))
{
$tile['link'] = 'index.php?option=' . $this->option . '&view=' . $tile['view'];
if (!isset($tile['text']))
{
$tile['text'] = strtoupper($this->option) . '_' . strtoupper($tile['view']);
}
}
$target = $tile['target'] ?? false;
$type = $tile['type'] ?? '';
$total_rows = 0;
if (isset($tile['table']))
{
$db = new TDb($tile['table']);
if ($db->table_exists())
{
$total_rows = $db->total_rows();
}
else
{
$total_rows = 'Database Table Missing';
}
}
// Icon class based on Joomla version
$icon = $tile['icon'] ?? 'check-circle';
$icon_class = ($this->jmajor > 4) ? 'fa-solid fa-' . $icon : 'fas fa-' . $icon;
$output = '<li class="quickicon-group">';
$output .= '<ul class="list-unstyled d-flex w-100">';
$output .= '<li class="quickicon">';
$output .= '<a href="' . $tile['link'] . '" class="pt-3 ' . $type . '"';
if ($target)
{
$output .= ' target="_blank"';
}
$output .= '>';
$output .= '<div class="quickicon-info"><div class="quickicon-icon">';
$output .= '<div class="' . $icon_class . '" aria-hidden="true"></div>';
$output .= '</div></div>';
$output .= '<div class="quickicon-name d-flex align-items-center">' . Text::_($tile['text']);
if ($total_rows)
{
$output .= ' (' . $total_rows . ')';
}
$output .= '</div>';
$output .= '</a>';
$output .= '</li>';
$output .= '</ul>';
$output .= '</li>';
return $output;
}
// Add message
public function add_message()
{
$model = $this->getModel();
// Messages from component dashboard model
$this->alerts = $this->get('Alerts');
if (!empty($this->alerts))
{
foreach ($this->alerts as $type => $alert)
{
$model->set_message('<strong>' . $alert . '</strong>', $type);
}
}
}
// Add general tiles common to all components
public function add_general_tiles()
{
// Field Groups, Fields Tiles
if ($this->custom_fields_section)
{
$link = 'index.php?option=com_fields&view=fields&context=' . $this->option . '.' . $this->custom_fields_section;
$this->tiles[] = array('text' => 'JGLOBAL_FIELDS', 'icon' => 'puzzle-piece', 'link' => $link);
$link = 'index.php?option=com_fields&view=groups&context=' . $this->option . '.' . $this->custom_fields_section;
$this->tiles[] = array('text' => 'JGLOBAL_FIELD_GROUPS', 'icon' => 'puzzle-piece', 'link' => $link);
}
// Import
$link = 'index.php?option=' . $this->option . '&view=select&select_type=import';
$this->tiles[] = array('text' => 'COM_TF_IMPORT', 'icon' => 'upload', 'link' => $link);
// Export
$link = 'index.php?option=' . $this->option . '&view=select&select_type=export';
$this->tiles[] = array('text' => 'COM_TF_EXPORT', 'icon' => 'download', 'link' => $link);
// Query
$link = 'index.php?option=' . $this->option . '&view=select&select_type=query';
$this->tiles[] = array('text' => 'COM_TF_QUERY', 'icon' => 'database', 'link' => $link);
// Support Tile
$this->tiles[] = array('text' => 'COM_TF_SUPPORT', 'icon' => 'question-circle', 'link' => 'https://joomlafry.com/forum', 'target' => 'true');
// Pro Tile
if (!empty($this->pro_url))
{
$this->tiles[] = array('text' => 'COM_TF_PRO_VERSION', 'icon' => 'star', 'link' => 'https://joomlafry.com/' . $this->pro_url, 'target' => 'true');
}
}
public function custom_toolbar_buttons()
{
if ($this->new_version != false && $this->current_version != $this->new_version)
{
$this->toolbar->linkButton('updatecom')
->url(Route::_('index.php?option=com_installer&view=update'))
->text('Update')
->icon('icon-upload')
->buttonClass('btn btn-danger')
->listCheck(false);
}
$this->toolbar->linkButton('installlang')
->url(Route::_('index.php?option=' . $this->option . '&task=dashboard.install_languages'))
->text('Install Languages')
->icon('icon-refresh')
->listCheck(false);
}
}