"ajout du modele et du controleur de teacher"

php
Patrick BRUGIERE 1 year ago
parent afe2328743
commit e8c99b9413

@ -8,23 +8,21 @@ use config\Connection;
class StudentController class StudentController
{ {
public function __construct(){ public function __construct()
{
global $twig; global $twig;
global $gtw;
global $con;
$con = new Connection('mysql:host=localhost;dbname=dbanrichard7','anrichard7','achanger');
$gtw = new UserGateway($con);
$actionList = ['showUsers'];
$dVueEreur= [];
session_start(); session_start();
$actionList = ['showVocab', 'getByName'];
$dVueEreur = [];
try { try {
$action = $_REQUEST['action'] ?? null; $action = $_REQUEST['action'] ?? null;
switch ($action) { switch ($action) {
case "AllVocab": case 'allVocab':
affAllVocab(); case null:
$this->affAllVocab();
break; break;
case "getByName": case 'getByName':
getByName(); $this->getByName($_REQUEST['nom']);
break; break;
default: default:
@ -32,19 +30,26 @@ class StudentController
echo $twig->render('vuephp1.html', ['dVueEreur' => $dVueEreur]); echo $twig->render('vuephp1.html', ['dVueEreur' => $dVueEreur]);
break; break;
} }
} } catch (\PDOException $e) {
catch(\PDOException $e){
$dataVueEreur[] = "Erreur inattendue"; $dataVueEreur[] = "Erreur inattendue";
$twig->render("vuephp1.html", ['dVueErreur' => $dataVueEreur]); $twig->render("vuephp1.html", ['dVueErreur' => $dataVueEreur]);
} } catch (Exception $e2) {
catch (Exception $e2)
{
$dataVueEreur[] = "Erreur inattendue!!! "; $dataVueEreur[] = "Erreur inattendue!!! ";
require($dataVueEreur['erreur']); require($dataVueEreur['erreur']);
} }
} }
public function affAllVocab():void{ public function affAllVocab(): void
{
global $twig;
$mdl = new MdlStudent();
$student = $mdl->getAll();
echo $twig->render('usersView.html', ['users' => $student]);
}
public function affAllStudent(): void
{
global $twig; global $twig;
$mdl = new MdlStudent(); $mdl = new MdlStudent();
$student = $mdl->getAll(); $student = $mdl->getAll();
@ -52,14 +57,15 @@ class StudentController
} }
public function getByName($name):void{ public function getByName($name): void
{
global $twig; global $twig;
$mdl = new MdlStudent(); $mdl = new MdlStudent();
$vocab = $mdl->getVocabByName($name); $vocab = $mdl->getVocabByName($name);
echo $twig->render('usersView.html', ['users' => $vocab]); echo $twig->render('usersView.html', ['users' => $vocab]);
} }
} }

@ -0,0 +1,89 @@
<?php
namespace controller;
use model\MdlTeacher;
use gateway\UserGateway;
use config\Connection;
class TeacherController
{
public function __construct()
{
global $twig;
session_start();
$actionList = ['getAllStudent','getAllVocab','getVocabByName','AddVocab', 'DelVocab'];
$dVueEreur = [];
try {
$action = $_REQUEST['action'] ?? null;
switch ($action) {
case null:
case 'getAllStudent':
$this->affAllStudent();
break;
case 'allVocab':
$this->affAllVocab();
break;
case 'getVocabByName':
$this->getByName($_REQUEST['name']);
break;
case 'addVocab':
break;
/* case 'delVoc':
$this->delById($_REQUEST['id']);
break;*/
default:
$dVueEreur[] = "Erreur d'appel php";
echo $twig->render('vuephp1.html', ['dVueEreur' => $dVueEreur]);
break;
}
}
catch (\PDOException $e) {
$dataVueEreur[] = "Erreur inattendue";
$twig->render("vuephp1.html", ['dVueErreur' => $dataVueEreur]);
} catch (Exception $e2) {
$dataVueEreur[] = "Erreur inattendue!!! ";
require($dataVueEreur['erreur']);
}
}
public function affAllStudent(): void
{
global $twig;
$mdl = new MdlTeacher();
$student = $mdl->getAllStudent();
echo $twig->render('usersView.html', ['users' => $student]);
}
public function affAllVocab(): void
{
global $twig;
$mdl = new MdlTeacher();
$student = $mdl->getAll();
echo $twig->render('usersView.html', ['users' => $student]);
}
public function getByName($name): void
{
global $twig;
$mdl = new MdlTeacher();
$vocab = $mdl->getVocabByName($name);
echo $twig->render('usersView.html', ['users' => $vocab]);
}
public function DelById($id):void{
global $twig;
$mdl = new MdlTeacher();
$vocab = $mdl->removeVocById($id);
echo $twig->render('usersView.html', ['users' => $vocab]);
}
}

@ -0,0 +1,48 @@
<?php
namespace model;
//use http\Client\Curl\User;
use model\AbsModel;
use config\Connection;
use gateway\UserGateway;
use gateway\VocabularyGateway;
class MdlTeacher extends AbsModel
{
public function __construct()
{
parent::__construct("teacher");
}
public function getAll():array{
$gtw = new VocabularyGateway(new Connection('mysql:host=localhost;dbname=dbanrichard7','anrichard7','achanger'));
return $gtw->findAll();
/*
foreach ($data as $row){
$AllStudent[] = User($row['id'],$row['password'],$row['email'],$row['name'],$row['surname'],$row['nickname'],$row['image'],$row['extraTime'],$row['group'],$row['roles']);
}
return $AllStudent;
*/
}
public function getAllStudent():array {
$gtw = new UserGateway(new Connection('mysql:host=localhost;dbname=dbanrichard7','anrichard7','achanger'));
return $gtw->findAll();
}
public function getVocabByName($name):array{
$gtw = new VocabularyGateway(new Connection('mysql:host=localhost;dbname=dbanrichard7','anrichard7','achanger'));
$res = $gtw->findByName($name);
return $res;
}
public function RemoveVocById($id):void{
$gtw = new VocabularyGateway(new Connection('mysql:host=localhost;dbname=dbanrichard7','anrichard7','achanger'));
$res = $gtw->remove($id);
}
}
Loading…
Cancel
Save