<?php
namespace Moto\System\Widgets; use Moto; use Zend\Stdlib\ArrayUtils; use Twig_Environment; class Helper { protected static $_devices = [ 'desktop', 'tablet', 'mobile-h', 'mobile-v', ]; public static function convertVisibleOnToArray($value) { if (is_array($value)) { return $value; } if (!is_string($value)) { return null; } $index = array_search($value, static::$_devices, true); if ($index === false) { $index = count(static::$_devices); } $result = []; foreach (static::$_devices as $i => $device) { $result[$device] = ($i <= $index); } return $result; } public static function getCssClassesVisibleOn($value, array $options = []) { $classes = ''; $prefix = (string) Moto\Util::getValue($options, 'prefix', 'moto-visible-on_'); if (is_string($value)) { $classes .= (isset($value) && $value !== 'mobile-v') ? $prefix . $value : ''; } elseif (is_array($value)) { $output = (string) Moto\Util::getValue($options, 'output', 'hidden'); foreach ($value as $device => $visible) { if (!$visible && $output === 'hidden') { $classes .= ' ' . $prefix . $device . '_hidden'; continue; } if ($visible && $output === 'visible') { $classes .= ' ' . $prefix . $device . '_visible'; continue; } if ($output === 'both') { $classes .= ' ' . $prefix . $device . ($visible ? '_visible' : '_hidden'); } } $classes = trim($classes); } return $classes; } public static function getShortVisibleOn($value) { if (is_array($value)) { $value = array_filter($value); $value = array_keys($value); $value = '+' . implode(',', $value); } return $value; } } 