Skip to content

Instantly share code, notes, and snippets.

@johnsnook
Created July 3, 2018 15:48
Show Gist options
  • Select an option

  • Save johnsnook/52263b222b30dee01d368f6dd2811211 to your computer and use it in GitHub Desktop.

Select an option

Save johnsnook/52263b222b30dee01d368f6dd2811211 to your computer and use it in GitHub Desktop.
Yii2 Bootstrap 4 Card Widget
<?php
namespace johnsnook\ipFilter\widgets;
/**
* @author John Snook
* @date 2018-07-2
* @license https://github.com/johnsnook/yii2-ip-filter/LICENSE
* @copyright 2018 John Snook Consulting
*/
use yii\bootstrap\Html;
class PanelWidget extends \yii\bootstrap\Widget {
/** properties * */
public $containerOptions;
public $title;
public $titleOptions;
public $useHeading = true;
public $headingOptions;
public $body;
public $bodyOptions;
public $footer;
public $footerOptions;
/** methods * */
public function init() {
parent::init();
if (empty($this->containerOptions)) {
Html::addCssClass($this->containerOptions, 'panel-default');
}
Html::addCssClass($this->containerOptions, 'panel');
Html::addCssClass($this->headingOptions, 'panel-heading');
Html::addCssClass($this->titleOptions, 'panel-title');
Html::addCssClass($this->bodyOptions, 'panel-body');
Html::addCssClass($this->footerOptions, 'panel-footer');
}
public function run() {
$out = Html::beginTag('div', $this->containerOptions);
if (isset($this->title)) {
if ($this->useHeading) {
$out .= Html::beginTag('div', $this->headingOptions);
}
$out .= Html::beginTag('div', $this->titleOptions);
$out .= $this->title;
$out .= Html::endTag('div');
if ($this->useHeading) {
$out .= Html::endTag('div');
}
}
if (gettype($this->body) === 'string') {
$this->body = [$this->body];
}
if (gettype($this->body) === 'array') {
foreach ($this->body as $body) {
$out .= Html::beginTag('div', $this->bodyOptions);
$out .= $body;
$out .= Html::endTag('div');
}
}
if (isset($this->footer)) {
$out .= Html::beginTag('div', $this->footerOptions);
$out .= $this->footer;
$out .= Html::endTag('div');
}
$out .= Html::endTag('div');
return $out;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment