feat: VivesPOS landing on Winter CMS 1.2 — theme + plugin + Dockerfile
Some checks are pending
Module sub-split / Sub-split (push) Waiting to run
Some checks are pending
Module sub-split / Sub-split (push) Waiting to run
- Base: wintercms/winter branch 1.2 (full framework) - Theme vivespos: Canvas 7 + Bootstrap 5 CDN, custom CSS - Layout: deferred GTM/GA4 tracking, JSON-LD SoftwareApplication - Partials: hero (offline-first), features, modes (offline/nube toggle), screenshots, pricing (3 planes), comparison, FAQ, CTA - Plugin VivesPOS.Site with ContactForm - Dockerfile: PHP 8.2 Apache, port 80, healthcheck - Added winter/wn-pages, blog, sitemap, seo plugins - Active theme set to vivespos
This commit is contained in:
291
modules/backend/classes/ListColumn.php
Normal file
291
modules/backend/classes/ListColumn.php
Normal file
@@ -0,0 +1,291 @@
|
||||
<?php namespace Backend\Classes;
|
||||
|
||||
use Winter\Storm\Database\Model;
|
||||
use Winter\Storm\Html\Helper as HtmlHelper;
|
||||
|
||||
/**
|
||||
* List Columns definition
|
||||
* A translation of the list column configuration
|
||||
*
|
||||
* @package winter\wn-backend-module
|
||||
* @author Alexey Bobkov, Samuel Georges
|
||||
*/
|
||||
class ListColumn
|
||||
{
|
||||
/**
|
||||
* @var string List column name.
|
||||
*/
|
||||
public $columnName;
|
||||
|
||||
/**
|
||||
* @var string List column label.
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* @var string Display mode. Text, number
|
||||
*/
|
||||
public $type = 'text';
|
||||
|
||||
/**
|
||||
* @var bool Specifies if this column can be searched.
|
||||
*/
|
||||
public $searchable = false;
|
||||
|
||||
/**
|
||||
* @var bool Specifies if this column is hidden by default.
|
||||
*/
|
||||
public $invisible = false;
|
||||
|
||||
/**
|
||||
* @var bool Specifies if this column can be sorted.
|
||||
*/
|
||||
public $sortable = true;
|
||||
|
||||
/**
|
||||
* @var bool Specifies if this column can be summed.
|
||||
*/
|
||||
public $summable = false;
|
||||
|
||||
/**
|
||||
* @var bool If set to false, disables the default click behavior when the column is clicked.
|
||||
*/
|
||||
public $clickable = true;
|
||||
|
||||
/**
|
||||
* @var string Model attribute to use for the display value, this will
|
||||
* override any `$sqlSelect` definition.
|
||||
*/
|
||||
public $valueFrom;
|
||||
|
||||
/**
|
||||
* @var string Specifies a default value when value is empty.
|
||||
*/
|
||||
public $defaults;
|
||||
|
||||
/**
|
||||
* @var string Custom SQL for selecting this record display value,
|
||||
* the `@` symbol is replaced with the table name.
|
||||
*/
|
||||
public $sqlSelect;
|
||||
|
||||
/**
|
||||
* @var string Relation name, if this column represents a model relationship.
|
||||
*/
|
||||
public $relation;
|
||||
|
||||
/**
|
||||
* @var string sets the column width, can be specified in percents (10%) or pixels (50px).
|
||||
* There could be a single column without width specified, it will be stretched to take the
|
||||
* available space.
|
||||
*/
|
||||
public $width;
|
||||
|
||||
/**
|
||||
* @var string Specify a CSS class to attach to the list cell element.
|
||||
*/
|
||||
public $cssClass;
|
||||
|
||||
/**
|
||||
* @var string Specify a CSS class to attach to the list header cell element.
|
||||
*/
|
||||
public $headCssClass;
|
||||
|
||||
/**
|
||||
* @var string Specify a format or style for the column value, such as a Date.
|
||||
*/
|
||||
public $format;
|
||||
|
||||
/**
|
||||
* @var string Specifies a path for partial-type fields.
|
||||
*/
|
||||
public $path;
|
||||
|
||||
/**
|
||||
* @var string Specifies the alignment of this column.
|
||||
*/
|
||||
public $align;
|
||||
|
||||
/**
|
||||
* @var array Raw field configuration.
|
||||
*/
|
||||
public $config;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param string $columnName
|
||||
* @param string $label
|
||||
*/
|
||||
public function __construct($columnName, $label)
|
||||
{
|
||||
$this->columnName = $columnName;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a list column rendering mode. Supported modes are:
|
||||
* - text - text column, aligned left
|
||||
* - number - numeric column, aligned right
|
||||
* @param string $type Specifies a render mode as described above
|
||||
*/
|
||||
public function displayAs($type, $config)
|
||||
{
|
||||
$this->type = strtolower($type) ?: $this->type;
|
||||
$this->config = $this->evalConfig($config);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process options and apply them to this object.
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function evalConfig($config)
|
||||
{
|
||||
if (isset($config['width'])) {
|
||||
$this->width = $config['width'];
|
||||
}
|
||||
if (isset($config['cssClass'])) {
|
||||
$this->cssClass = $config['cssClass'];
|
||||
}
|
||||
if (isset($config['headCssClass'])) {
|
||||
$this->headCssClass = $config['headCssClass'];
|
||||
}
|
||||
if (isset($config['searchable'])) {
|
||||
$this->searchable = $config['searchable'];
|
||||
}
|
||||
if (isset($config['sortable'])) {
|
||||
$this->sortable = $config['sortable'];
|
||||
}
|
||||
if (isset($config['summable'])) {
|
||||
$this->summable = $config['summable'];
|
||||
}
|
||||
if (isset($config['clickable'])) {
|
||||
$this->clickable = $config['clickable'];
|
||||
}
|
||||
if (isset($config['invisible'])) {
|
||||
$this->invisible = $config['invisible'];
|
||||
}
|
||||
if (isset($config['valueFrom'])) {
|
||||
$this->valueFrom = $config['valueFrom'];
|
||||
}
|
||||
if (isset($config['default'])) {
|
||||
$this->defaults = $config['default'];
|
||||
}
|
||||
if (isset($config['select'])) {
|
||||
$this->sqlSelect = $config['select'];
|
||||
}
|
||||
if (isset($config['relation'])) {
|
||||
$this->relation = $config['relation'];
|
||||
}
|
||||
if (isset($config['format'])) {
|
||||
$this->format = $config['format'];
|
||||
}
|
||||
if (isset($config['path'])) {
|
||||
$this->path = $config['path'];
|
||||
}
|
||||
if (isset($config['align']) && \in_array($config['align'], ['left', 'right', 'center'])) {
|
||||
$this->align = $config['align'];
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a HTML valid name for the column name.
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return HtmlHelper::nameToId($this->columnName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value suitable for the column id property.
|
||||
* @param string $suffix Specify a suffix string
|
||||
* @return string
|
||||
*/
|
||||
public function getId($suffix = null)
|
||||
{
|
||||
$id = 'column';
|
||||
|
||||
$id .= '-'.$this->columnName;
|
||||
|
||||
if ($suffix) {
|
||||
$id .= '-'.$suffix;
|
||||
}
|
||||
|
||||
return HtmlHelper::nameToId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the column specific aligment css class.
|
||||
* @return string
|
||||
*/
|
||||
public function getAlignClass()
|
||||
{
|
||||
return $this->align ? 'list-cell-align-' . $this->align : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a raw config item value.
|
||||
* @param string $value
|
||||
* @param string $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig($value, $default = null)
|
||||
{
|
||||
return array_get($this->config, $value, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this columns value from a supplied data set, which can be
|
||||
* an array or a model or another generic collection.
|
||||
* @param mixed $data
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValueFromData($data, $default = null)
|
||||
{
|
||||
$columnName = $this->valueFrom ?: $this->columnName;
|
||||
return $this->getColumnNameFromData($columnName, $data, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to extract the value of a column name from a data set.
|
||||
* @param string $columnName
|
||||
* @param mixed $data
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getColumnNameFromData($columnName, $data, $default = null)
|
||||
{
|
||||
/*
|
||||
* Array column name, eg: column[key][key2][key3]
|
||||
*/
|
||||
$keyParts = HtmlHelper::nameToArray($columnName);
|
||||
$result = $data;
|
||||
|
||||
/*
|
||||
* Loop the column key parts and build a value.
|
||||
* To support relations only the last column should return the
|
||||
* relation value, all others will look up the relation object as normal.
|
||||
*/
|
||||
foreach ($keyParts as $key) {
|
||||
if ($result instanceof Model && $result->hasRelation($key)) {
|
||||
$result = $result->{$key};
|
||||
}
|
||||
else {
|
||||
if (is_array($result) && array_key_exists($key, $result)) {
|
||||
$result = $result[$key];
|
||||
} elseif (!isset($result->{$key})) {
|
||||
return $default;
|
||||
} else {
|
||||
$result = $result->{$key};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user