code quality

This commit is contained in:
Alessandro Ferro
2022-07-24 11:10:43 +02:00
parent f075c81ddd
commit 3dc728a282
59 changed files with 63 additions and 62 deletions

View File

@ -1,21 +1,21 @@
<html> <html>
<head> <head>
<link rel="stylesheet" href="../bootstrap-5.1.3-dist/css/bootstrap.min.css"> <link rel="stylesheet" href="../bootstrap-5.1.3-dist/css/bootstrap.min.css">
<title>Card example</title> <title>BreadCrumb example</title>
</head> </head>
<body> <body>
<?php <?php
include "../phpxpress/breadcrumb.php"; include "../phpxpress/Breadcrumb.php";
$links["Github"] = "https://www.github.com"; $links["Github"] = "https://www.github.com";
$links["xfarrow"] = "https://www.github.com/xfarrow"; $links["xfarrow"] = "https://www.github.com/xfarrow";
$links["PhpXpress"] = "https://www.github.com/xfarrow/phoxpress"; $links["PhpXpress"] = "https://www.github.com/xfarrow/phoxpress";
$breadcrumb = new BreadCrumb; $breadcrumb = new PhpXpress\BreadCrumb;
$breadcrumb->setDataSource($links); $breadcrumb->setDataSource($links);
$breadcrumb->draw(); $breadcrumb->draw();
?> ?>
</body> </body>
</html> </html>

View File

@ -5,13 +5,13 @@
</head> </head>
<body> <body>
<?php <?php
include "../phpxpress/card.php"; include "../phpxpress/Card.php";
Card::beginCardGroupLayout(36); PhpXpress\Card::beginCardGroupLayout(36);
// Rome // Rome
$card1 = new Card; $card1 = new PhpXpress\Card;
$card1->setImageSource("./images/colosseum.jpg"); $card1->setImageSource("./images/colosseum.jpg");
$card1->setTitle("Rome"); $card1->setTitle("Rome");
$card1->setSubTitle("Capital of Italy"); $card1->setSubTitle("Capital of Italy");
@ -39,7 +39,7 @@
$paris->Inhabitants = "2.229.095"; $paris->Inhabitants = "2.229.095";
$paris->Zip = "750XX"; $paris->Zip = "750XX";
$card2 = new Card; $card2 = new PhpXpress\Card;
$card2->setImageSource("./images/paris.jpg"); $card2->setImageSource("./images/paris.jpg");
$card2->setTitle("Paris"); $card2->setTitle("Paris");
$card2->setSubTitle("Capital of France"); $card2->setSubTitle("Capital of France");
@ -55,7 +55,7 @@
$card2->draw(); $card2->draw();
Card::endCardGroupLayout(); PhpXpress\Card::endCardGroupLayout();
function onFieldDisplaying(&$field , &$value){ function onFieldDisplaying(&$field , &$value){
if($field == "Inhabitants"){ if($field == "Inhabitants"){
@ -64,4 +64,4 @@
} }
?> ?>
</body> </body>
</html> </html>

View File

@ -1,17 +1,19 @@
<html> <html>
<head> <head>
<link rel="stylesheet" href="../bootstrap-5.1.3-dist/css/bootstrap.min.css"> <link rel="stylesheet" href="../bootstrap-5.1.3-dist/css/bootstrap.min.css">
<script type="text/javascript" src="../bootstrap-5.1.3-dist/js/bootstrap.bundle.js"></script>
<title>Dropdown example</title> <title>Dropdown example</title>
</head> </head>
<body> <body>
<?php <?php
include "../phpxpress/dropdown.php";
$dropdown = new Dropdown; include "../phpxpress/Dropdown.php";
$dropdown = new PhpXpress\Dropdown;
$dropdown->setTitle("Bank Account"); $dropdown->setTitle("Bank Account");
$dropdown->setDataSource(array("Unicredit" => "#" , "United Bank" => "#" , "National Bank" => "#")); $dropdown->setDataSource(array("Unicredit" => "#" , "United Bank" => "#" , "National Bank" => "#"));
$dropdown->draw(); $dropdown->draw();
?> ?>
</body> </body>
</html> </html>

View File

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

Before

Width:  |  Height:  |  Size: 213 KiB

After

Width:  |  Height:  |  Size: 213 KiB

View File

Before

Width:  |  Height:  |  Size: 152 KiB

After

Width:  |  Height:  |  Size: 152 KiB

View File

Before

Width:  |  Height:  |  Size: 144 KiB

After

Width:  |  Height:  |  Size: 144 KiB

View File

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View File

@ -5,7 +5,7 @@
</head> </head>
<body> <body>
<?php <?php
include "../phpxpress/table.php"; include "../phpxpress/Table.php";
class Employee{ class Employee{
public $name; public $name;
@ -27,7 +27,7 @@
$employee2->surname = 'Johnstone'; $employee2->surname = 'Johnstone';
$employee2->dateOfBirth = "02-04-1988"; $employee2->dateOfBirth = "02-04-1988";
$employee2->ssn = "56789"; $employee2->ssn = "56789";
$employee3->name = 'Anna'; $employee3->name = 'Anna';
$employee3->surname = 'Brenson'; $employee3->surname = 'Brenson';
$employee3->dateOfBirth = "10-08-1998"; $employee3->dateOfBirth = "10-08-1998";
@ -35,12 +35,12 @@
$employees = array($employee1,$employee2,$employee3); $employees = array($employee1,$employee2,$employee3);
$table = new Table; $table = new PhpXpress\Table;
$table->addColumn("Extra"); $table->addColumn("Extra");
$table->setDataSource($employees); $table->setDataSource($employees);
$table->setCustomCaptions(array("Extra" , "Name", "Surname", "Date of Birth", "Social Security Number")); $table->setCustomCaptions(array("Extra" , "Name", "Surname", "Date of Birth", "Social Security Number"));
$table->addColumn("Extra2"); $table->addColumn("Extra2");
$table->onValueDisplaying("onValueDisplaying"); $table->onValueDisplaying("onValueDisplaying");
@ -66,4 +66,4 @@
?> ?>
</body> </body>
</html> </html>

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PhpXpress v1.0 * PhpXpress v1.0.1
* *
* @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project * @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project
* *
@ -11,7 +11,7 @@
* FITNESS FOR A PARTICULAR PURPOSE. * FITNESS FOR A PARTICULAR PURPOSE.
*/ */
include "include.php"; namespace PhpXpress;
class BreadCrumb{ class BreadCrumb{
@ -33,7 +33,7 @@
function setDataSource($dataSource){ function setDataSource($dataSource){
if(!is_array($dataSource)) if(!is_array($dataSource))
throw new InvalidArgumentException('Parameter dataSource must be an array.'); throw new InvalidArgumentException('Parameter dataSource must be an array.');
foreach($dataSource as $caption => $link){ foreach($dataSource as $caption => $link){
$this->addElement($caption, $link); $this->addElement($caption, $link);
} }
@ -43,10 +43,10 @@
** Adds an element at the end of the Breadcrumb ** Adds an element at the end of the Breadcrumb
*/ */
function addElement($caption, $link){ function addElement($caption, $link){
if(isset($this->locations)) if(isset($this->locations))
$this->locations[$caption] = $link; $this->locations[$caption] = $link;
else else
$this->locations = array($caption => $link); $this->locations = array($caption => $link);
@ -58,7 +58,7 @@
** or a string (the caption to be activated) ** or a string (the caption to be activated)
*/ */
function setActiveLocation($activeLocation){ function setActiveLocation($activeLocation){
if(!is_scalar($activeLocation) && !is_string($activeLocation)) if(!is_scalar($activeLocation) && !is_string($activeLocation))
throw new InvalidArgumentException('Parameter activeLocation can be either an int or a string. None of these provided.'); throw new InvalidArgumentException('Parameter activeLocation can be either an int or a string. None of these provided.');
@ -79,13 +79,13 @@
echo '<nav style="--bs-breadcrumb-divider: \'' . $this->divider . '\';" aria-label="breadcrumb">'; echo '<nav style="--bs-breadcrumb-divider: \'' . $this->divider . '\';" aria-label="breadcrumb">';
echo '<ol class="breadcrumb">'; echo '<ol class="breadcrumb">';
foreach($this->locations as $caption => $link){ foreach($this->locations as $caption => $link){
// active location // active location
if( if(
(is_int($this->activeLocation) && $this->activeLocation == $iterator) (is_int($this->activeLocation) && $this->activeLocation == $iterator)
|| (is_string($this->activeLocation) && $this->activeLocation == $caption) || (is_string($this->activeLocation) && $this->activeLocation == $caption)
){ ){
echo '<li class="breadcrumb-item active" aria-current="page">' . $caption . '</li>'; echo '<li class="breadcrumb-item active" aria-current="page">' . $caption . '</li>';
} }
@ -102,4 +102,4 @@
echo '</ol></nav>'; echo '</ol></nav>';
} }
} }
?> ?>

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PhpXpress v1.0 * PhpXpress v1.0.1
* *
* @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project * @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project
* *
@ -11,10 +11,12 @@
* FITNESS FOR A PARTICULAR PURPOSE. * FITNESS FOR A PARTICULAR PURPOSE.
*/ */
include "include.php"; namespace PhpXpress;
include "Code.php";
class Card{ class Card{
// Structure // Structure
private $imageSource; private $imageSource;
private $title; private $title;
@ -183,10 +185,10 @@
if(isset($this->linksArray)){ // links if(isset($this->linksArray)){ // links
foreach($this->linksArray as $caption => $link){ foreach($this->linksArray as $caption => $link){
echo '<a href="' . $link . '" class="card-link">'. $caption .'</a>'; echo '<a href="' . $link . '" class="card-link">'. $caption .'</a>';
} }
echo '<br/><br/>'; echo '<br/><br/>';
} }
if(isset($this->button)) if(isset($this->button))
echo '<a href="' . $this->button["link"] . '" class="btn btn-primary">' . $this->button["text"] . '</a>'; echo '<a href="' . $this->button["link"] . '" class="btn btn-primary">' . $this->button["text"] . '</a>';
@ -221,11 +223,10 @@
*/ */
static function beginCardGroupLayout($width=36){ static function beginCardGroupLayout($width=36){
echo '<div class="card-group" style="width:' . $width. 'rem;">'; echo '<div class="card-group" style="width:' . $width. 'rem;">';
} }
static function endCardGroupLayout(){ static function endCardGroupLayout(){
echo '</div>'; echo '</div>';
} }
} }
?> ?>

View File

@ -1,8 +1,7 @@
<script type="text/javascript" src="../bootstrap-5.1.3-dist/js/bootstrap.bundle.js"></script>
<?php <?php
/** /**
* PhpXpress v1.0 * PhpXpress v1.0.1
* *
* @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project * @see https://github.com/xfarrow/phpxpress The PhpXpress GitHub project
* *
@ -12,7 +11,9 @@
* FITNESS FOR A PARTICULAR PURPOSE. * FITNESS FOR A PARTICULAR PURPOSE.
*/ */
include "include.php"; namespace PhpXpress;
include "Code.php";
class Dropdown{ class Dropdown{
@ -38,7 +39,7 @@
public function setSize($size){ public function setSize($size){
if($size == "default") if($size == "default")
$this->size = NULL; $this->size = NULL;
else if($size == "large") else if($size == "large")
$this->size = "btn-lg"; $this->size = "btn-lg";
@ -77,12 +78,12 @@
} }
echo '<ul class="' . $ulClass . '" aria-labelledby="dropdownMenuButton1">'; echo '<ul class="' . $ulClass . '" aria-labelledby="dropdownMenuButton1">';
foreach($this->datasource as $name => $link){ foreach($this->datasource as $name => $link){
echo '<li><a class="dropdown-item" href="' . $link . '">' . $name . '</a></li>'; echo '<li><a class="dropdown-item" href="' . $link . '">' . $name . '</a></li>';
} }
echo '</ul></div>'; echo '</ul></div>';
} }
} }
?> ?>

View File

@ -10,8 +10,8 @@
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. * FITNESS FOR A PARTICULAR PURPOSE.
*/ */
namespace PhpXpress;
include "include.php";
class Table{ class Table{
/* === Structure === */ /* === Structure === */
@ -19,14 +19,14 @@
/** /**
* The datasource to provdide to the table. * The datasource to provdide to the table.
* Must be an array of arrays or an array of objects. * Must be an array of arrays or an array of objects.
* *
* @var array * @var array
*/ */
private $dataSource; private $dataSource;
/** /**
* The column captions * The column captions
* *
* @var array * @var array
*/ */
private $columnCaptions; private $columnCaptions;
@ -35,7 +35,7 @@
* The columns to make invisible. * The columns to make invisible.
* The column whose name is a key of the array * The column whose name is a key of the array
* of the datasource, will not be shown. * of the datasource, will not be shown.
* *
* @var array * @var array
*/ */
private $invisible_columns; private $invisible_columns;
@ -63,7 +63,7 @@
/** /**
* Draw the Table. * Draw the Table.
* *
* @return void * @return void
*/ */
function draw(){ function draw(){
@ -100,7 +100,7 @@
else{ else{
$array_keys = array_keys(get_object_vars($this -> dataSource[0])); $array_keys = array_keys(get_object_vars($this -> dataSource[0]));
} }
$invisible_columns_captions = array(); $invisible_columns_captions = array();
foreach($this->invisible_columns as $invisible_column_name){ foreach($this->invisible_columns as $invisible_column_name){
$column_index = array_search($invisible_column_name, $array_keys); $column_index = array_search($invisible_column_name, $array_keys);
@ -128,7 +128,7 @@
if(!empty($this->invisible_columns) && in_array($name, $this->invisible_columns)){ if(!empty($this->invisible_columns) && in_array($name, $this->invisible_columns)){
continue; continue;
} }
// fire event onValueDisplaying // fire event onValueDisplaying
if(isset( $this -> onValueDisplayingFunctionName)){ if(isset( $this -> onValueDisplayingFunctionName)){
call_user_func_array($this -> onValueDisplayingFunctionName , array($name, &$value, (array)$obj)); call_user_func_array($this -> onValueDisplayingFunctionName , array($name, &$value, (array)$obj));
} }
@ -144,8 +144,8 @@
* Set the table's datasource. * Set the table's datasource.
* Datasource can be either an array of object(s) or * Datasource can be either an array of object(s) or
* an array of array(s). * an array of array(s).
* *
* @param array $datasource An array of arrays or an array of objects. * @param array $datasource An array of arrays or an array of objects.
* *
* @return void * @return void
*/ */
@ -219,8 +219,8 @@
/** /**
* By default, the columns' captions will be the keys of the * By default, the columns' captions will be the keys of the
* array or object provided. * array or object provided.
* *
* You can override them by setting custom captions. * You can override them by setting custom captions.
*/ */
function setCustomCaptions(Array $captions){ function setCustomCaptions(Array $captions){
@ -241,7 +241,7 @@
/** /**
* Add columns to the table (setting it before or after the datasource * Add columns to the table (setting it before or after the datasource
* will show the column before or after the datasource) * will show the column before or after the datasource)
* *
* @param string $captionName The name of the new column * @param string $captionName The name of the new column
*/ */
function addColumn($captionName){ function addColumn($captionName){
@ -268,7 +268,7 @@
* Making a column invisible, rather than removing it from the datasource, might * Making a column invisible, rather than removing it from the datasource, might
* be useful in those circumstances where a value is needed in the datasource * be useful in those circumstances where a value is needed in the datasource
* or in the onValueDisplaying, without actually removing it. * or in the onValueDisplaying, without actually removing it.
* *
* @param string $column_name: the column to remove. * @param string $column_name: the column to remove.
* *
*/ */
@ -291,7 +291,7 @@
if(isset($this->invisible_columns)){ if(isset($this->invisible_columns)){
if(in_array($column_name, $this->invisible_columns)) if(in_array($column_name, $this->invisible_columns))
throw new InvalidArgumentException("The provided column $column_name is already invisible"); throw new InvalidArgumentException("The provided column $column_name is already invisible");
array_push($this->invisible_columns, $column_name); array_push($this->invisible_columns, $column_name);
} }
else{ else{

View File

@ -1,3 +0,0 @@
<?php
include_once 'code.php';
?>