Lilian BRETON 2 years ago
commit 531f494e4a

@ -1,5 +0,0 @@
[![Build Status](https://codefirst.iut.uca.fr/api/badges/lilian.breton/PHP_Project/status.svg)](https://codefirst.iut.uca.fr/lilian.breton/PHP_Project)
# PHP_Project
A simple template for a web page in html css.

@ -0,0 +1,33 @@
<?php
class Connection extends PDO {
private $stmt;
public function __construct(string $dsn, string $username, string $password) {
parent::__construct($dsn,$username,$password);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
/** * @param string $query
* @param array $parameters *
* @return bool Returns `true` on success, `false` otherwise
*/
public function executeQuery(string $query, array $parameters = []) : bool{
$this->stmt = parent::prepare($query);
foreach ($parameters as $name => $value) {
$this->stmt->bindValue($name, $value[0], $value[1]);
}
return $this->stmt->execute();
}
public function getResults() : array {
return $this->stmt->fetchall();
}
}
?>

@ -0,0 +1,59 @@
<html>
<body>
<?php
require_once("connection.php");
require_once('tacheGateway.php');
require_once('userGateway.php');
require_once("listeGateway.php");
require_once('user.php');
//A CHANGER
$user= 'thchazot1';
$pass='achanger';
$dsn='mysql:host=localhost;dbname=dbthchazot1';
$id=1;
$name='Argent';
$content='Argent, Encore de l\'argent';
try{
$con=new Connection($dsn,$user,$pass);
$u=new User(1, "test", "mdp");
$t=new Tache($id, $name, $content, true);
$t1=new Tache(478, "TEST", $content, false);
$l=new Liste(6, "test", false, null, array($t, $t1));
$tacheGateway=new TacheGateway($con);
$userGateway=new UserGateway($con);
$listeGateway=new ListeGateway($con);
$listeGateway->insert($l);
/*
$tacheGateway->delete($t);
$user=$userGateway->insert(new User(1, "test", "mdp"));
$user=$userGateway->findByNamePassword("test", "mdp");
print($user);
$gateway->insert($t, 1);
$tabTache=$gateway->getTacheFromIdList(1);
foreach($tabTache as $tache){
print($tache);
echo "<br>";
}
*/
}
catch( PDOException $Exception ) {
echo 'erreur';
echo $Exception->getMessage();
}
?>
</body>
</html>

@ -0,0 +1,67 @@
<?php
require_once('user.php');
require_once('tache.php');
class Liste
{
private int $id;
private string $name;
private bool $private;
private ?User $creator;
private array $taches;
function __construct(int $id, string $name, bool $private, ?User $creator, array $taches)
{
$this->id=$id;
$this->name=$name;
$this->private=$private;
$this->creator=$creator;
$this->taches=$taches;
}
public function __toString()
{
return $this->id . " " . $this->name . " " . $this->creator;
}
public function getId(){
return $this->id;
}
public function getName(){
return $this->name;
}
public function getCreator(){
return $this->creator;
}
public function getPrivate(){
return $this->private;
}
public function getTaches(){
return $this->taches;
}
public function setName(string $name){
$this->name=$name;
}
public function setPrivate(bool $private){
$this->private=$private;
}
public function setCreator(?User $creator){
$this->creator=$creator;
}
public function setTaches(array $taches){
$this->taches=$taches;
}
}
?>

@ -0,0 +1,68 @@
<?php
require_once('liste.php');
class ListeGateway
{
private $con;
public function __construct(Connection $con){
$this->con = $con;
}
public function insert(Liste $l): void{
$tacheGateway=new TacheGateway($this->con);
foreach($l->getTaches() as $taches){
$tacheGateway->insert($taches, $this->getLastId()+1);
}
if ($l->getCreator()==null){
$query = "INSERT INTO Liste VALUES (null, :name, :private, null)";
$this->con->executeQuery($query, array(':name' => array($l->getName(), PDO::PARAM_STR), ':private' => array($l->getPrivate(), PDO::PARAM_BOOL)));
}
else{
$query = "INSERT INTO Liste VALUES (null, :name, :private, :creator)";
$this->con->executeQuery($query, array(':name' => array($l->getName(), PDO::PARAM_STR), ':private' => array($l->getPrivate(), PDO::PARAM_BOOL), ':creator' => array($l->getCreator()->getId(), PDO::PARAM_STR)));
}
}
public function delete(Liste $l): void{
$tacheGateway=new TacheGateway($this->con);
foreach($l->getTaches() as $taches){
$tacheGateway->delete($taches);
}
$query = "DELETE FROM Liste where id=:id";
$this->con->executeQuery($query, array(':id' => array($l->getId(), PDO::PARAM_INT)));
}
public function update(Liste $l): void{
$query = "UPDATE Liste SET name=:name, private=:private WHERE id=:id";
$this->con->executeQuery($query, array(':id' => array($l->getId(), PDO::PARAM_INT), ':name' => array($l->getName(), PDO::PARAM_STR), ':private' => array($l->getPrivate(), PDO::PARAM_BOOL)));
}
public function getLastId(): int{
$query = "SELECT max(id) as oldId FROM Liste";
$this->con->executeQuery($query, array());
$results=$this->con->getResults();
return $results[0]['oldId'];
}
/*
public function findByName(string $name): array{
if (!empty($name)){
$query = "SELECT * FROM Tache WHERE name=:name";
$this->con->executeQuery($query, array(':name' => array($name, PDO::PARAM_STR)));
$results=$con->getResults();
foreach ($results as $row ) {
$tabTaches[]=new Tache($row['id'], $row['name'], $row['content']);
}
return $tabTaches;
}
}
*/
}
?>

@ -1,32 +0,0 @@
body {
padding-left: 11em;
font-family: Georgia, 'Georgia', "Times New Roman",
Times, serif;
color: darksalmon;
background-color: rgb(39, 39, 84) }
ul.navbar {
list-style-type: none;
padding: 0;
margin: 0;
position: absolute;
top: 2em;
left: 1em;
width: 9em }
h1 {
font-family: Helvetica, Geneva, Arial,
SunSans-Regular, sans-serif }
ul.navbar li {
background: white;
margin: 0.5em 0;
padding: 0.3em;
border-right: 1em solid darksalmon }
ul.navbar a {
text-decoration: none }
a:link {
color: blue }
a:visited {
color: darkblue }
address {
margin-top: 1em;
padding-top: 1em;
border-top: thin dotted }

@ -1,34 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>PHP_Project - One incredible styled html page</title>
<link rel="stylesheet" href="mycoolstyle.css">
</head>
<body>
<!-- Navigation menu -->
<ul class="navbar">
<li><a href="https://codefirst.iut.uca.fr/home">Code#0</a>
<li><a href="http://iut.uca.fr">IUT</a>
<li><a href="https://neilyoungarchives.com/">Very good music</a>
<li><a href="https://www.youtube.com/watch?v=CY5dTBhRxOA">Very good music too!</a>
</ul>
<!-- Main Content -->
<h1>PHP_Project is my first page, and it has got style!</h1>
<p>Welcome on this template html/css project
<p>Very simple, some links, some menu... make it your own
&hellip;
<p>I have nothing more to say
<!-- my footer -->
<address>Template made in 2022<br>
with Code#0 <a href="https://codefirst.iut.uca.fr/home"><img src="images/CodeFirstLogo.png" alt="Code#0" align="middle" border="0" height="40px"/>
</a></address>
</body>
</html>

@ -0,0 +1,55 @@
<?php
require_once('user.php');
class Tache
{
private int $id;
private string $name;
private string $content;
private bool $completed;
function __construct( int $id, string $name, string $content, bool $completed)
{
$this->id=$id;
$this->name=$name;
$this->content=$content;
$this->completed=$completed;
}
public function __toString()
{
return $this->id . " " . $this->name . " " . $this->content . " " . $this->completed;
}
public function getId(){
return $this->id;
}
public function getName(){
return $this->name;
}
public function getContent(){
return $this->content;
}
public function getCompleted(){
return $this->completed;
}
public function setName(string $name){
$this->name=$name;
}
public function setContent(string $content){
$this->content=$content;
}
public function setCompleted(bool $completed){
$this->completed=$completed;
}
}
?>

@ -0,0 +1,64 @@
<?php
require_once('tache.php');
class TacheGateway
{
private $con;
public function __construct(Connection $con){
$this->con = $con;
}
public function insert(Tache $t, int $idList): void{
$query = "INSERT INTO Tache VALUES (null, :name, :content, :completed, :idList)";
$this->con->executeQuery($query, array(':name' => array($t->getName(), PDO::PARAM_STR), ':content' => array($t->getContent(), PDO::PARAM_STR), ':completed' => array($t->getCompleted(), PDO::PARAM_BOOL), ':idList' => array($idList, PDO::PARAM_INT)));
}
public function delete(Tache $t): void{
$query = "DELETE FROM Tache where id=:id";
$this->con->executeQuery($query, array(':id' => array($t->getId(), PDO::PARAM_INT)));
}
public function update(Tache $t): void{
$query = "UPDATE Tache SET name=:name, content=:content, completed=:completed WHERE id=:id";
$this->con->executeQuery($query, array(':id' => array($t->getId(), PDO::PARAM_INT), ':name' => array($t->getName(), PDO::PARAM_STR), ':content' => array($t->getContent(), PDO::PARAM_STR), ':completed' => array($t->getCompleted(), PDO::PARAM_BOOL)));
}
public function getTacheFromIdList(int $id): array{
$tabTaches=[];
$query = "SELECT * FROM Tache t where idListe=:id";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
$results=$this->con->getResults();
foreach ($results as $row) {
$tabTaches[]=new Tache($row['id'], $row['name'], $row['content'], $row['completed']);
}
return $tabTaches;
}
public function getLastId(): int{
$query = "SELECT max(id) as oldId FROM Tache";
$this->con->executeQuery($query, array());
$results=$this->con->getResults();
return $results[0]['oldId'];
}
/*
public function findByName(string $name): array{
if (!empty($name)){
$query = "SELECT * FROM Tache WHERE name=:name";
$this->con->executeQuery($query, array(':name' => array($name, PDO::PARAM_STR)));
$results=$con->getResults();
foreach ($results as $row ) {
$tabTaches[]=new Tache($row['id'], $row['name'], $row['content']);
}
return $tabTaches;
}
}
*/
}
?>

@ -0,0 +1,42 @@
<?php
class User
{
private $id;
private $username;
private $password;
function __construct( int $id, string $username, string $password)
{
$this->id=$id;
$this->username=$username;
$this->password=$password;
}
public function __toString()
{
return $this->id . " " . $this->username;
}
public function getId(){
return $this->id;
}
public function getUsername(){
return $this->username;
}
public function getPassword(){
return $this->password;
}
public function setUsername(string $username){
$this->username=$username;
}
public function setPassword(string $password){
$this->password=$password;
}
}
?>

@ -0,0 +1,64 @@
<?php
require_once('user.php');
class UserGateway
{
private $con;
public function __construct(Connection $con){
$this->con = $con;
}
public function insert(User $u): void{
$query = "INSERT INTO Utilisateur VALUES (null, :username, :password)";
$this->con->executeQuery($query, array(':username' => array($u->getUsername(), PDO::PARAM_STR), ':password' => array($u->getPassword(), PDO::PARAM_STR)));
}
public function delete(User $u): void{
$query = "DELETE FROM Utilisateur where id=:id";
$this->con->executeQuery($query, array(':id' => array($u->getId(), PDO::PARAM_INT)));
}
public function update(User $u): void{
$query = "UPDATE Utilisateur SET username=:username, password=:password WHERE id=:id";
$this->con->executeQuery($query, array(':id' => array($u->getId(), PDO::PARAM_INT), ':username' => array($u->getUsername(), PDO::PARAM_STR), ':password' => array($u->getPassword(), PDO::PARAM_STR)));
}
public function findByNamePassword(string $username, string $password): ?User{
if (!empty($username) && !empty($password)){
$query = "SELECT * FROM Utilisateur WHERE username=:username AND password=:password";
$this->con->executeQuery($query, array(':username' => array($username, PDO::PARAM_STR), ':password' => array($password, PDO::PARAM_STR)));
$results=$this->con->getResults();
if (!empty($results)){
$user=new User($results[0]['id'], $results[0]['username'], $results[0]['password']);
return $user;
}
}
return null;
}
public function getLastId(): int{
$query = "SELECT max(id) as oldId FROM User";
$this->con->executeQuery($query, array());
$results=$this->con->getResults();
return $results[0]['oldId'];
}
/*
public function getTacheFromIdList(int $id): array{
$tabTaches=[];
$query = "SELECT * FROM Tache t where idListe=:id";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
$results=$this->con->getResults();
foreach ($results as $row) {
$tabTaches[]=new Tache($row['id'], $row['name'], $row['content'], $row['completed']);
}
return $tabTaches;
}
*/
}
?>
Loading…
Cancel
Save