Add the front-end of the page

This commit is contained in:
2018-12-12 15:04:47 +09:00
parent 3dfce942aa
commit 38c619544e
35 changed files with 8044 additions and 7966 deletions

View File

@ -6,35 +6,40 @@ use Exception;
use PDO;
class BDD {
const SQL_SERVER = 'http://web3.pulseheberg.net'; // BDD Server
const SQL_LOGIN = 'why7n0_fitness'; // BDD Login
const SQL_PASSWORD = 'KpB728zu'; // BDD Password
const SQL_DB = 'why7n0_fitness'; // BDD Name
// const SQL_SERVER = 'http://web3.pulseheberg.net'; // BDD Server
// const SQL_LOGIN = 'why7n0_fitness'; // BDD Login
// const SQL_PASSWORD = 'KpB728zu'; // BDD Password
// const SQL_DB = 'why7n0_fitness'; // BDD Name
private static $bdd;
const SQL_SERVER = 'localhost'; // BDD Server
const SQL_LOGIN = 'root'; // BDD Login
const SQL_PASSWORD = ''; // BDD Password
const SQL_DB = 'fitness'; // BDD Name
public function __construct() {
try {
$pdo_options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
];
private static $bdd;
self::$bdd = new PDO( 'mysql:host=' . self::SQL_SERVER . ';dbname=' . self::SQL_DB . ';charset=utf8',
self::SQL_LOGIN, self::SQL_PASSWORD, $pdo_options );
} catch ( Exception $e ) {
die( 'Erreur : ' . $e->getMessage() );
}
}
public function __construct() {
try {
$pdo_options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
];
public static function instance() {
return self::$bdd;
}
self::$bdd = new PDO( 'mysql:host=' . self::SQL_SERVER . ';dbname=' . self::SQL_DB . ';charset=utf8',
self::SQL_LOGIN, self::SQL_PASSWORD, $pdo_options );
} catch ( Exception $e ) {
die( 'Erreur : ' . $e->getMessage() );
}
}
public static function lastInsertId() {
return self::$bdd->lastInsertId();
}
public static function instance() {
return self::$bdd;
}
public static function lastInsertId() {
return self::$bdd->lastInsertId();
}
}
?>

View File

@ -4,10 +4,10 @@ namespace WebProjectFitness\Model;
abstract class BDTables {
// const NOM = 'bd_nom'
// Ex : const ABONNEMENT = 'abonnement';
// const NOM = 'bd_nom'
// Ex : const ABONNEMENT = 'abonnement';
const LOGS = "logs";
const LOGS = "logs";
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -6,179 +6,180 @@ use PDO;
class Logs {
const ERROR_LEVEL = [
1 => 'E_ERROR',
2 => 'E_WARNING',
4 => 'E_PARSE',
8 => 'E_NOTICE',
16 => 'E_CORE_ERROR',
32 => 'E_CORE_WARNING',
64 => 'E_COMPILE_ERROR',
128 => 'E_COMPILE_WARNING',
256 => 'E_USER_ERROR',
512 => 'E_USER_WARNING',
1024 => 'E_USER_NOTICE',
2048 => 'E_STRICT',
4096 => 'E_RECOVERABLE_ERROR',
8192 => 'E_DEPRECATED',
16384 => 'E_USER_DEPRECATED',
32767 => 'E_ALL'
];
public $id;
public $level;
public $message;
public $file;
public $line;
public $date;
const ERROR_LEVEL = [
1 => 'E_ERROR',
2 => 'E_WARNING',
4 => 'E_PARSE',
8 => 'E_NOTICE',
16 => 'E_CORE_ERROR',
32 => 'E_CORE_WARNING',
64 => 'E_COMPILE_ERROR',
128 => 'E_COMPILE_WARNING',
256 => 'E_USER_ERROR',
512 => 'E_USER_WARNING',
1024 => 'E_USER_NOTICE',
2048 => 'E_STRICT',
4096 => 'E_RECOVERABLE_ERROR',
8192 => 'E_DEPRECATED',
16384 => 'E_USER_DEPRECATED',
32767 => 'E_ALL'
];
public $id;
public $level;
public $message;
public $file;
public $line;
public $date;
/**
* Logs constructor.
*
* @param int|null $id
* @param string|null $level
* @param string|null $message
* @param string|null $file
* @param string|null $line
* @param string|null $date
*/
public function __construct( int $id = null, string $level = null, string $message = null, string $file = null, string $line = null, string $date = null ) {
if ( $id === null ) {
return;
}
$this->id = $id;
$this->level = $level;
$this->message = $message;
$this->file = $file;
$this->line = $line;
$this->date = $date;
}
/**
* Logs constructor.
*
* @param int|null $id
* @param string|null $level
* @param string|null $message
* @param string|null $file
* @param string|null $line
* @param string|null $date
*/
public function __construct( int $id = null, string $level = null, string $message = null, string $file = null,
string $line = null, string $date = null ) {
if ( $id === null ) {
return;
}
$this->id = $id;
$this->level = $level;
$this->message = $message;
$this->file = $file;
$this->line = $line;
$this->date = $date;
}
public static function insert( $level, $message, $file, $line, $date ) {
Model::insert( BDTables::LOGS, [
'level' => $level,
'message' => $message,
'file' => $file,
'line' => $line,
'date' => date( "Y-m-d H:i:s", strtotime( $date ) )
] );
}
public static function insert( $level, $message, $file, $line, $date ) {
Model::insert( BDTables::LOGS, [
'level' => $level,
'message' => $message,
'file' => $file,
'line' => $line,
'date' => date( "Y-m-d H:i:s", strtotime( $date ) )
] );
}
/**
* Retourne un tableau des derniers logs (limite en param)
*
* @param int $limit
*
* @return array
*/
public static function getLastLogs( int $limit ) {
$req = BDD::instance()->prepare( 'SELECT *
/**
* Retourne un tableau des derniers logs (limite en param)
*
* @param int $limit
*
* @return array
*/
public static function getLastLogs( int $limit ) {
$req = BDD::instance()->prepare( 'SELECT *
FROM ' . BDTables::LOGS . '
ORDER BY date DESC
ORDER BY `date` DESC
LIMIT :limit' );
$req->bindValue( 'limit', $limit, PDO::PARAM_INT );
$req->execute();
$return = [];
$req->bindValue( 'limit', $limit, PDO::PARAM_INT );
$req->execute();
$return = [];
foreach ( $req->fetchAll() as $l ) {
$log = new Logs( $l['id'], $l['level'], $l['message'], $l['file'], $l['line'], $l['date'] );
$return[] = $log;
}
foreach ( $req->fetchAll() as $l ) {
$log = new Logs( $l[ 'id' ], $l[ 'level' ], $l[ 'message' ], $l[ 'file' ], $l[ 'line' ], $l[ 'date' ] );
$return[] = $log;
}
return $return;
}
return $return;
}
/**
* @return int
*/
public function getId() {
return $this->id;
}
/**
* @return int
*/
public function getId() {
return $this->id;
}
/**
* @param int $id
*/
public function setId( $id ) {
$this->id = $id;
}
/**
* @param int $id
*/
public function setId( $id ) {
$this->id = $id;
}
/**
* @return string
*/
public function getLevel() {
return $this->level;
}
/**
* @return string
*/
public function getLevel() {
return $this->level;
}
/**
* @param string $level
*/
public function setLevel( $level ) {
$this->level = $level;
}
/**
* @param string $level
*/
public function setLevel( $level ) {
$this->level = $level;
}
/**
* @return string
*/
public function getMessage() {
return htmlspecialchars( $this->message );
}
/**
* @return string
*/
public function getMessage() {
return htmlspecialchars( $this->message );
}
/**
* @param string $message
*/
public function setMessage( $message ) {
$this->message = $message;
}
/**
* @param string $message
*/
public function setMessage( $message ) {
$this->message = $message;
}
/**
* @return string
*/
public function getFile() {
return htmlspecialchars( $this->file );
}
/**
* @return string
*/
public function getFile() {
return htmlspecialchars( $this->file );
}
/**
* @param string $file
*/
public function setFile( $file ) {
$this->file = $file;
}
/**
* @param string $file
*/
public function setFile( $file ) {
$this->file = $file;
}
/**
* @return string
*/
public function getLine() {
return htmlspecialchars( $this->line );
}
/**
* @return string
*/
public function getLine() {
return htmlspecialchars( $this->line );
}
/**
* @param string $line
*/
public function setLine( $line ) {
$this->line = $line;
}
/**
* @param string $line
*/
public function setLine( $line ) {
$this->line = $line;
}
/**
* @return string
*/
public function getDate() {
return $this->date;
}
/**
* @return string
*/
public function getDate() {
return $this->date;
}
/**
* @param string $date
*/
public function setDate( $date ) {
$this->date = $date;
}
/**
* @param string $date
*/
public function setDate( $date ) {
$this->date = $date;
}
/**
* Retourne le type d'erreur en string (label)
* @return string
*/
public function getErrorLabel() {
return htmlspecialchars( self::ERROR_LEVEL[ $this->level ] );
}
/**
* Retourne le type d'erreur en string (label)
* @return string
*/
public function getErrorLabel() {
return htmlspecialchars( self::ERROR_LEVEL[ $this->level ] );
}
}
?>

View File

@ -4,47 +4,47 @@ namespace WebProjectFitness\Model;
class Model {
/**
* Crée une reqette d'insertion en base àpartir du nom de la table et d'un tableau associatif et l'exécute
*
* @param string $tableName
* @param array $data
*
* @return int lastInsertId
*/
public static function insert( string $tableName, array $data ) {
$req = BDD::instance()->prepare( 'INSERT INTO ' . $tableName . ' (' . implode( ', ', array_keys( $data ) ) . ')
/**
* Crée une reqette d'insertion en base àpartir du nom de la table et d'un tableau associatif et l'exécute
*
* @param string $tableName
* @param array $data
*
* @return int lastInsertId
*/
public static function insert( string $tableName, array $data ) {
$req = BDD::instance()->prepare( 'INSERT INTO ' . $tableName . ' (' . implode( ', ', array_keys( $data ) ) . ')
VALUES (' . ':' . implode( ', :', array_keys( $data ) ) . ')' );
$req->execute( $data );
$req->execute( $data );
return BDD::lastInsertId();
}
return BDD::lastInsertId();
}
/**
* Met à jour les données d'une ligne d'un table données
*
* @param string $tableName
* @param array $data
* @param string $idColumn
* @param int $idValue
*/
public static function update( string $tableName, array $data, string $idColumn, int $idValue ) {
$reqStr = 'UPDATE ' . $tableName . ' SET ';
$lastKey = endKey( $data );
foreach ( $data as $key => $value ) {
$reqStr .= $key . ' = :' . $key;
if ( $key != $lastKey ) {
$reqStr .= ', ';
}
}
$reqStr .= ' WHERE ' . $idColumn . ' = :' . $idColumn;
$data[ $idColumn ] = $idValue;
/**
* Met à jour les données d'une ligne d'un table données
*
* @param string $tableName
* @param array $data
* @param string $idColumn
* @param int $idValue
*/
public static function update( string $tableName, array $data, string $idColumn, int $idValue ) {
$reqStr = 'UPDATE ' . $tableName . ' SET ';
$lastKey = endKey( $data );
foreach ( $data as $key => $value ) {
$reqStr .= $key . ' = :' . $key;
if ( $key != $lastKey ) {
$reqStr .= ', ';
}
}
$reqStr .= ' WHERE ' . $idColumn . ' = :' . $idColumn;
$data[ $idColumn ] = $idValue;
//echo $reqStr; exit();
//echo $reqStr; exit();
$req = BDD::instance()->prepare( $reqStr );
$req->execute( $data );
}
$req = BDD::instance()->prepare( $reqStr );
$req->execute( $data );
}
}
?>