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\Sky;
defined('_JEXEC') or die;
class Grid
{
// Row is divided into columns - large, medium, small
// Equal columns - column width calculated automatically using number of columns
// Unequal columns - column widths provided by user like 9+3
public $classes = []; // Depreciated
public $grid = []; // Depreciated
public $large = []; // Depreciated
public $medium = []; // Depreciated
public $small = []; // Depreciated
// Depreciated
public function __construct($widths_or_number = '')
{
// $widths_or_number: column widths or number of columns for equal widths
// $widths - 2,6,4
$array = $widths_or_number ? explode(';', $widths_or_number) : [];
if (isset($array[0]))
{
$this->large = str_getcsv($array[0]);
}
if (isset($array[1]))
{
$this->medium = str_getcsv($array[1]);
}
if (isset($array[2]))
{
$this->small = str_getcsv($array[2]);
}
}
// Get classes for columns (Depreciated)
public function get_rwd()
{
$classes = []; // column-wise classes
foreach ($this->large as $k => $lg)
{
$classes[$k] = 'col-lg-' . $lg;
}
foreach ($this->medium as $k => $md)
{
$classes[$k] = 'col-md-' . $md . ' ' . $classes[$k];
}
foreach ($this->small as $k => $sm)
{
$classes[$k] = 'col-' . $sm . ' ' . $classes[$k];
}
return $classes;
}
// Get class for equal width columns (Depreciated)
public function get_grid()
{
$class = 'row';
if ($this->small)
{
$class .= ' row-cols-' . $this->small[0];
}
if ($this->medium)
{
$class .= ' row-cols-md-' . $this->medium[0];
}
if ($this->large)
{
$class .= ' row-cols-lg-' . $this->large[0];
}
return $class;
}
public function equal_columns($config = [])
{
$class = 'row';
if (isset($config['sm']) && $config['sm'])
{
$class .= ' row-cols-' . $config['sm'];
}
if (isset($config['md']) && $config['md'])
{
$class .= ' row-cols-md-' . $config['md'];
}
if (isset($config['lg']) && $config['lg'])
{
$class .= ' row-cols-lg-' . $config['lg'];
}
$gap = (isset($config['gap']) && $config['gap']) ? $config['gap'] : 'g-3';
$class .= ' ' . $gap;
return $class;
}
public function custom_columns($config = [])
{
$config = (array) $config; // sm, md, lg
// Set default if not set
$config['sm'] = isset($config['sm']) && $config['sm'] ? $config['sm'] : 12;
$config['md'] = isset($config['md']) && $config['md'] ? $config['md'] : 12;
$config['lg'] = isset($config['lg']) && $config['lg'] ? $config['lg'] : 12;
$columns = []; // column-wise classes
// Widths for each breakpoint
$sm = explode('+', $config['sm']);
$md = explode('+', $config['md']);
$lg = explode('+', $config['lg']);
$max_cols = max(count($sm), count($md), count($lg));
for ($i = 0; $i < $max_cols; $i++)
{
$classes = [];
if (isset($sm[$i]) && $sm[$i] > 0)
{
$classes[] = 'col-' . intval($sm[$i]);
}
if (isset($md[$i]) && $md[$i] > 0)
{
$classes[] = 'col-md-' . intval($md[$i]);
}
if (isset($lg[$i]) && $lg[$i] > 0)
{
$classes[] = 'col-lg-' . intval($lg[$i]);
}
// Join all breakpoint classes for this column
$columns[] = implode(' ', $classes);
}
return $columns;
}
}