First PUsh
This commit is contained in:
40
src/Model/BDD.php
Normal file
40
src/Model/BDD.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace CAUProject3Contact\Model;
|
||||
|
||||
use Exception;
|
||||
use PDO;
|
||||
|
||||
class BDD {
|
||||
const SQL_SERVER = 'sql.sanchez-mathieu.fr'; // BDD Server
|
||||
const SQL_LOGIN = 'why7n0_contact'; // BDD Login
|
||||
const SQL_PASSWORD = 'fC3c87Gy'; // BDD Password
|
||||
const SQL_DB = 'why7n0_contact'; // BDD Name
|
||||
|
||||
private static $bdd;
|
||||
|
||||
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
|
||||
];
|
||||
|
||||
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 instance() {
|
||||
return self::$bdd;
|
||||
}
|
||||
|
||||
public static function lastInsertId() {
|
||||
return self::$bdd->lastInsertId();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
13
src/Model/BDTables.php
Normal file
13
src/Model/BDTables.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace CAUProject3Contact\Model;
|
||||
|
||||
abstract class BDTables {
|
||||
|
||||
// const NOM = 'bd_nom'
|
||||
// Ex : const ABONNEMENT = 'abonnement';
|
||||
|
||||
const LOGS = "logs";
|
||||
}
|
||||
|
||||
?>
|
1913
src/Model/FPDF.php
Normal file
1913
src/Model/FPDF.php
Normal file
File diff suppressed because it is too large
Load Diff
184
src/Model/Logs.php
Normal file
184
src/Model/Logs.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace CAUProject3Contact\Model;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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 ) )
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
LIMIT :limit' );
|
||||
$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;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*/
|
||||
public function setId( $id ) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLevel() {
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $level
|
||||
*/
|
||||
public function setLevel( $level ) {
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage() {
|
||||
return htmlspecialchars( $this->message );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function setMessage( $message ) {
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFile() {
|
||||
return htmlspecialchars( $this->file );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*/
|
||||
public function setFile( $file ) {
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLine() {
|
||||
return htmlspecialchars( $this->line );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $line
|
||||
*/
|
||||
public function setLine( $line ) {
|
||||
$this->line = $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDate() {
|
||||
return $this->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 ] );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
50
src/Model/Model.php
Normal file
50
src/Model/Model.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace CAUProject3Contact\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 ) ) . ')
|
||||
VALUES (' . ':' . implode( ', :', array_keys( $data ) ) . ')' );
|
||||
$req->execute( $data );
|
||||
|
||||
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;
|
||||
|
||||
//echo $reqStr; exit();
|
||||
|
||||
$req = BDD::instance()->prepare( $reqStr );
|
||||
$req->execute( $data );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user