174 lines
3.9 KiB
PHP
174 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace BC;
|
|
class Alert {
|
|
private $id = null;
|
|
private $text = null;
|
|
private $title = null;
|
|
private $theme = null; // info
|
|
private $css = array();
|
|
private $class = array();
|
|
private $icon = null;
|
|
private $closeBtn = null; // false
|
|
private $columns = null; // 12
|
|
private $offsetColumns = null; // 0
|
|
private $size = null;
|
|
|
|
public function __construct() {
|
|
$this->info()->closeBtn(false);
|
|
}
|
|
|
|
public function _class($v) {
|
|
if (is_array($v)) {
|
|
$this->class = array_merge($this->class, $v);
|
|
} else {
|
|
$this->class[] = $v;
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
public function css($property, $v) {
|
|
$this->css[$property] = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function closeBtn($v = true) {
|
|
$this->closeBtn = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function icon($v) {
|
|
$this->icon = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function sm() {
|
|
$this->size = "sm";
|
|
return $this;
|
|
}
|
|
|
|
public function size($v) {
|
|
$this->columns = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function offset($v = null) {
|
|
$this->offsetColumns = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function title($v) {
|
|
$this->title = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function message($v) { // alias text
|
|
return $this->text($v);
|
|
}
|
|
|
|
public function text($v) {
|
|
$this->text = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function success() {
|
|
return $this->theme("success");
|
|
}
|
|
|
|
public function info() {
|
|
return $this->theme("info");
|
|
}
|
|
|
|
public function warning() {
|
|
return $this->theme("warning");
|
|
}
|
|
|
|
public function danger() {
|
|
return $this->theme("danger");
|
|
}
|
|
|
|
public function primary() {
|
|
return $this->theme("primary");
|
|
}
|
|
|
|
public function secondary() {
|
|
return $this->theme("secondary");
|
|
}
|
|
|
|
public function dark() {
|
|
return $this->theme("dark");
|
|
}
|
|
|
|
public function light() {
|
|
return $this->theme("light");
|
|
}
|
|
|
|
public function theme($v) {
|
|
$this->theme = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function getTheme() {
|
|
return $this->theme;
|
|
}
|
|
|
|
public function getId() {
|
|
return $this->id;
|
|
}
|
|
|
|
public function id($v) {
|
|
$this->id = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function buildHtml() {
|
|
$id = !is_null($this->id) ? "id='" . $this->id . "'" : "";
|
|
|
|
$this->_class("alert-" . $this->theme);
|
|
|
|
$columns = !is_null($this->columns) ? $this->columns : 12;
|
|
$this->_class("col-sm-" . $columns);
|
|
|
|
if (is_null($this->offsetColumns)) {
|
|
$offsetColumns = floor((12 - $columns) / 2);
|
|
} else {
|
|
$offsetColumns = $this->offsetColumns;
|
|
}
|
|
$this->_class("col-sm-offset-" . $offsetColumns);
|
|
|
|
if (!is_null($this->size)) {
|
|
$this->_class("alert-" . $this->size);
|
|
}
|
|
|
|
$closeBtn = $this->closeBtn === true;
|
|
if ($closeBtn) {
|
|
$this->_class("alert-dismissible");
|
|
}
|
|
|
|
$classes = implode(" ", $this->class);
|
|
|
|
$style = "";
|
|
foreach ($this->css as $property => $value) {
|
|
$style .= "$property:$value;";
|
|
}
|
|
|
|
$div = '<div ' . $id . ' class="alert text-left ' . $classes . '" style="' . $style . '">';
|
|
if ($closeBtn) {
|
|
$div .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span>×</span></button>';
|
|
}
|
|
if (!is_null($this->icon)) {
|
|
$div .= "<i class='fa fa-" . $this->icon . "'></i> ";
|
|
}
|
|
if (!is_null($this->title)) {
|
|
$div .= "<strong>" . $this->title . "</strong><br/>";
|
|
}
|
|
|
|
$div .= $this->text . "</div>";
|
|
return \Utility\Str::remove_multiple_spaces($div);
|
|
}
|
|
|
|
public function show() {
|
|
echo $this->buildHtml();
|
|
// echo htmlentities($this->buildHtml());
|
|
}
|
|
} |