Skip to content

Instantly share code, notes, and snippets.

@jjcodes78
Last active October 6, 2017 16:56
Show Gist options
  • Save jjcodes78/0d806e493c3b32464219e9a0a7d756ea to your computer and use it in GitHub Desktop.
Save jjcodes78/0d806e493c3b32464219e9a0a7d756ea to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: Jorge
* Date: 05/10/2017
* Time: 18:30
*/
// Classe que extende a classe utilitária BASE
// Status de Ordens de Serviço
namespace App\Util;
class ServiceOrderStatus extends StatusBase
{
protected $statusText = [
'Aberta',
'Pronta',
'Finalizada',
'Cancelada'
];
protected $statusType = [
'warning',
'primary',
'success',
'danger'
];
}
<?php
/**
* Created by PhpStorm.
* User: Jorge
* Date: 05/10/2017
* Time: 20:06
*/
namespace App\Util;
use Illuminate\Support\HtmlString;
abstract class StatusBase
{
protected $statusText;
protected $statusType;
public static function render()
{
$instance = new static;
return $instance;
}
public function status($status)
{
$type = $this->statusType[$status];
$text = $this->statusText[$status];
return new HtmlString("<span class='label label-{$type}'>{$text}</span>");
}
public function list($current = null, array $override = [])
{
$html = '';
$items = (empty($override)) ? $this->statusText : $override;
foreach ($items as $key => $text)
{
$selected = ($key == $current && !is_null($current)) ? 'selected':'';
$html .= "<option value='{$key}' {$selected}>{$text}</option>";
}
return new HtmlString($html);
}
public function statusText($status)
{
return $this->statusText[$status];
}
public function statusList()
{
return $this->statusText;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment