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\Front;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use TechFry\Library\View\Sky\Date;
use TechFry\Library\View\Html\TBody;
trait TViewDisplayTrait
{
// get_div, get_alert, get_badge, get_binary, get_button, get_date, get_icon, get_image, get_link
// action_buttons, action_button
// 01.
public function get_div($content, $config = [])
{
// $config - class
$output = '';
if (isset($config['class']) && $config['class'])
{
$output .= '<div class="' . $config['class'] . '">' . $content . '</div>';
}
else
{
$output .= '<div>' . $content . '</div>';
}
return $output;
}
// 01. Display alert message
public function get_alert($message, $config = [])
{
$output = '';
$type = $config['type'] ?? '';
$icon = $config['icon'] ?? '';
$output .= '<div class="alert alert-' . $type . '">';
if ($icon)
{
$output .= '<span class="' . $icon . '" aria-hidden="true"></span> ';
}
$output .= $message;
$output .= '</div>';
return $output;
}
// 02. Display badges or labels
public function get_badge($labels, $config = [])
{
// $config - class
$output = '';
if (!$labels)
{
return;
}
$class = $config['class'] ? $config['class'] : 'primary';
if (\is_array($labels))
{
foreach ($labels as $label)
{
$output .= '<span class="badge text-bg-' . $class . '">' . $label . '</span> ';
}
}
else
{
$output .= '<span class="badge text-bg-' . $class . '">' . $labels . '</span> ';
}
return $output;
}
// 03. Display data in the form of 0 or 1
public function get_binary($value, $config = [])
{
$color = $value ? 'Green' : 'Red';
$output = '';
$output .= '<span style="color: ' . $color . ';" class="fas fa-';
$output .= $value ? 'check' : 'times';
$output .= '" aria-hidden="true"></span>';
return $output;
}
// 04. Display link button
public function get_button($link, $config = [])
{
$type = $config['type'] ?? 'primary';
$text = $config['text'] ?? 'JGLOBAL_READ_MORE';
$output = '';
$output .= '<a class="btn btn-sm btn-' . $type . '" href="' . Route::_($link) . '">' . Text::_($text) . '</a> ';
return $output;
}
// 05. Display date
public function get_date($date, $config = [])
{
$output = '';
$date_params = array(
'format' => $this->params->get('date_format', 'DATE_FORMAT_LC3'),
'tag' => 'div',
'class' => $config['class'],
);
$d = new Date($date, $date_params);
$output .= $d->display();
return $output;
}
public function get_icon($icon, $config = [])
{
// $config - class
$output = '<i class="' . $icon . ' ' . $config['class'] . '"></i>';
return $output;
}
public function get_image($src, $config = [])
{
// $config - class
$html = new TBody();
$output = $html->img($src, ['class' => $config['class']]);
return $output;
}
// 08. Display title with link to view
public function get_link($title, $config = [])
{
// $config - class, url
$output = '<a class="' . $config['class'] . '" href="' . $config['url'] . '" title="' . $title . '">' . $title . '</a>';
return $output;
}
// 09.
public function action_buttons($actions = [])
{
$output = '';
foreach ($actions as $action)
{
$output .= $this->action_button($action);
}
return $output;
}
// 10. Action button for Joomla task (controller.method)
public function action_button($task, $config = [])
{
// $config - option, text, class, icon, hidden
$option = $config['option'] ?? $this->option;
$hidden = $config['hidden'] ?? [];
$class = $config['class'] ?? 'btn btn-sm btn-primary';
$text = $config['text'] ?? '';
if (!$text)
{
$parts = explode('.', $task);
$text = ucwords($parts[1]);
}
$icon = $config['icon'] ?? '';
$output = '<form method="post" class="d-inline">';
$output .= '<input type="hidden" name="option" value="' . $option . '">';
$output .= '<input type="hidden" name="task" value="' . $task . '">';
foreach ($hidden as $k => $v)
{
$output .= '<input type="hidden" name="' . $k . '" value="' . $v . '">';
}
$output .= '<button type="submit" class="me-2 mb-2 ' . $class . '">';
if (!empty($icon))
{
$output .= '<i class="' . $icon . '"></i> ';
}
if (!empty($text))
{
$output .= Text::_($text);
}
$output .= '</button>';
$output .= '</form>';
return $output;
}
}