increase reusability of AppCards
This commit is contained in:
@@ -1,4 +1,128 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Action element of an MaterializeCss (App-)card
|
||||
*/
|
||||
class AppCardAction{
|
||||
private $caption = null; //< Caption for the action
|
||||
private $link = "."; //< link for the action
|
||||
/**
|
||||
* Constructor for the AppAction
|
||||
*
|
||||
* @param string $caption caption for the action
|
||||
* @param string $link link to the action
|
||||
*/
|
||||
function __construct( $caption, $link = "." ){
|
||||
//! @todo input sanitation
|
||||
$this->link = $link;
|
||||
$this->caption = $caption;
|
||||
}
|
||||
/**
|
||||
* Create htmlCode for the action
|
||||
*
|
||||
* @return string with htmlCode of the action
|
||||
*/
|
||||
function htmlCode(){
|
||||
return "<a href=\"".$this->link."\">".$this->caption."</a>";
|
||||
}
|
||||
/**
|
||||
* Create AppCardAction from assoziative array
|
||||
*
|
||||
* @param array $member array with the member values
|
||||
* @return AppCardAction
|
||||
*/
|
||||
static public function fromArray($member){
|
||||
$caption = $member['caption'] ?? null;
|
||||
$link = $member['link'] ?? ".";
|
||||
return new AppCardAction($caption, $link);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MaterializeCss card for an App
|
||||
*/
|
||||
class AppCard{
|
||||
private $title = ""; //< title of the card
|
||||
private $description = ""; //< description of the App
|
||||
private $link = null; //< link for the card-content
|
||||
private $imgUrl = null; //< url for an image right under the title
|
||||
private $actionList = []; //< list of actions for the bottom of the card
|
||||
/**
|
||||
* Constructor for the AppCard
|
||||
*
|
||||
* @param string $title title of the card
|
||||
* @param string $description description of the card
|
||||
* @param string $link link for the card-content
|
||||
* @param string $imgUrl url for an image right under the title
|
||||
* @param array $actionList list of actions at the bottom of the card
|
||||
*/
|
||||
function __construct($title, $description, $link=null, $imgUrl=null, $actionList=[]){
|
||||
//! @todo input sanitation
|
||||
$this->title = $title;
|
||||
$this->description = $description;
|
||||
$this->link = $link;
|
||||
$this->imgUrl = $imgUrl;
|
||||
$this->actionList = $actionList;
|
||||
}
|
||||
/**
|
||||
* Create htmlCode for the AppCard
|
||||
*
|
||||
* @return string html code for the AppCard
|
||||
*/
|
||||
public function htmlCode(){
|
||||
$actionListCode = "";
|
||||
foreach($this->actionList as $a){
|
||||
$actionListCode .= $a->htmlCode();
|
||||
}
|
||||
return
|
||||
"<div style=\"padding:1%;\" class=\"col s12 m6\">".
|
||||
"<div style=\"margin:1%;\" class=\"card blue-grey darken-1\">".
|
||||
(($this->link!=null)?("<a href=\"".$this->appLink."\">"):(""))."<div class=\"card-content white-text\">".
|
||||
"<span class=\"card-title\">".$this->title."</span>".
|
||||
(($this->imgUrl!=null)?("<img style=\"display:block;margin-left:auto;margin-right:auto;max-height:10vh;\" class=\"responsive-img\" src=\"".$this->imgUrl."\" />"):("")).
|
||||
"<p>".$this->description."</p>".
|
||||
"</div>".(($this->link!=null)?("<a>"):("")).
|
||||
"<div class=\"card-action\">".$actionListCode."</div>".
|
||||
"</div>".
|
||||
"</div>";
|
||||
}
|
||||
/**
|
||||
* Create AppCard from an associative array
|
||||
*
|
||||
* @param array $member array with member as keys and values as the member values
|
||||
* @return AppCard from array values
|
||||
*/
|
||||
static public function fromArray($member){
|
||||
$title = $member['title'] ?? "";
|
||||
$description = $member['description'] ?? "";
|
||||
$link = $member['link'] ?? null;
|
||||
$imgUrl = $member['imgUrl'] ?? null;
|
||||
$actionList = $member['actions'] ?? [];
|
||||
|
||||
return new AppCard($title, $description, $link, $imgUrl, $actionList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a html table of the last logins of the users
|
||||
*
|
||||
* @param string $jsonFileName path to the json file with the logged logins
|
||||
* @return string Html table of users last logins
|
||||
*/
|
||||
function lastLoginTable($jsonFileName="lastLogins.json"){
|
||||
$lastLogins=json_decode( file_get_contents($jsonFileName), true);
|
||||
$lastLoginsTable =
|
||||
"<table>".
|
||||
"<thead><tr><th>userName</th><th>lastLogins</th></tr></thead>".
|
||||
"<tbody>";
|
||||
foreach( $lastLogins as $userName => $lastLogins ){
|
||||
$lastLoginsTable .=
|
||||
"<tr><td>".$userName."</td><td>".$lastLogins['lastLogins'][0]."</td></tr>";
|
||||
}
|
||||
$lastLoginsTable .= "</tbody></table>";
|
||||
return $lastLoginsTable;
|
||||
}
|
||||
|
||||
/// Eine Fehler/Warnung/Notiz/Erfolgsmeldung als divBox im String zurückgeben
|
||||
function htmlRetMessage($anRetMessage){
|
||||
$retHtmlString = "";
|
||||
|
||||
Reference in New Issue
Block a user