This commit is contained in:
Alessandro Ferro 2022-02-28 13:01:03 +01:00
parent 792eaf578d
commit 56c209eb1e
4 changed files with 121 additions and 3 deletions

View File

@ -1,6 +1,6 @@
<html>
<head>
<title>Table example</title>
<title>Card example</title>
</head>
<body>
<?php
@ -8,6 +8,8 @@
Card::beginCardGroupLayout(36);
// Rome
$card1 = new Card;
$card1->setImageSource("colosseum.jpg");
$card1->setTitle("Rome");
@ -18,8 +20,13 @@
$card1->addField("Inhabitants", "2.763.804");
$card1->AddField("Zip", "001XX");
$card1->setButton("More info", "https://en.wikipedia.org/wiki/Rome");
$card1->addLink("Town", "https://www.comune.roma.it/web/it/welcome.page");
$card1->addLink("ATAC", "https://www.atac.roma.it/");
$card1->draw();
// Paris
class City{
public $Mayor;
public $Inhabitants;
@ -38,6 +45,10 @@
$card2->setInnerText("The following fields' name & data will be acquired by the datasource.");
$card2->setDataSource($paris);
$card2->setButton("More info", "https://en.wikipedia.org/wiki/Paris");
$card2->addArrayList(array("this is", "just a list"));
$card2->addElementList("of various sentences");
$card2->addLink("Link1", "#");
$card2->addLink("Link2", "#");
$card2->draw();
Card::endCardGroupLayout();

View File

@ -9,7 +9,24 @@
private $width = 18;
private $footerText;
private $fieldsArray;
private $list;
private $linksArray;
private $button;
private $borderColor;
private $cardColor;
private $textColor;
function setBorderColor($color){
$this->borderColor = Code::bootstrapColors($color);
}
function setCardColor($color){
$this->cardColor = Code::bootstrapColors($color);
}
function setTextColor($color){
$this->textColor = $color;
}
function setImageSource($imageSource){
if(!is_string($imageSource))
@ -56,8 +73,41 @@
}
}
function addLink($caption, $link){
$this->linksArray[$caption] = $link;
}
function addArrayList(Array $list){
if(isset($this->list)){
$this->list = array_merge($this->list, $list);
}else{
$this->list = $list;
}
}
function addElementList($element){
if(isset($this->list)){
array_push($this->list, $element);
}else{
$list = array($element);
}
}
function draw(){
echo '<div class="card" style="width: ' . $this->width . 'rem;">';
$class = "card";
if(isset($this->borderColor)){
$class.= ' border-' . $this->borderColor;
}
if(isset($this->cardColor)){
$class.= ' bg-' . $this->cardColor;
}
if(isset($this->textColor)){
$class.= ' text-' . $this->borderColor;
}
echo '<div class="' . $class . '" style="width: ' . $this->width . 'rem;">';
// Image
if(isset($this->imageSource)){
@ -75,6 +125,23 @@
}
}
if(isset($this->list)){
echo '</div>'; // close card-body div
echo '<ul class="list-group list-group-flush">';
foreach($this->list as $string){
echo '<li class="list-group-item">' . $string . '</li>';
}
echo '</ul>';
echo '<div class="card-body">';
}
if(isset($this->linksArray)){ // links
foreach($this->linksArray as $caption => $link){
echo '<a href="' . $link . '" class="card-link">'. $caption .'</a>';
}
echo '<br/><br/>';
}
if(isset($this->button))
echo '<a href="' . $this->button["link"] . '" class="btn btn-primary">' . $this->button["text"] . '</a>';

View File

@ -0,0 +1,37 @@
<?php
class Code{
public static function doublequote($string){
return '"' . $string . '"';
}
public static function bootstrapColors($color){
if($color == 'blue')
return 'primary';
if($color == 'gray')
return 'secondary';
if($color == 'green')
return 'success';
if($color == 'red')
return 'danger';
if($color == 'yellow')
return 'warning';
if($color == 'cyan')
return 'info';
if($color == 'white')
return 'light';
if($color == 'black')
return 'dark';
throw new InvalidArgumentException('Color not valid. Available colors: blue, gray, green, red, yellow, cyan, white, black');
}
}
?>

View File

@ -1,5 +1,8 @@
<?php
include_once 'code.php';
?>
<style>
<?php
include_once '../bootstrap-5.1.3-dist/css/bootstrap.min.css';
include_once '../bootstrap-5.1.3-dist/css/bootstrap.min.css';
?>
</style>