Skip to content
Snippets Groups Projects
Commit d9dcced4 authored by SCHULER Killian's avatar SCHULER Killian
Browse files

copie tp2->tp3 et ajout des requetes eloquente dans controller

parent 78b29b81
No related branches found
No related tags found
No related merge requests found
RewriteEngine On
#
# RewriteBase indispensable sur webetu :
# RewriteBase /www/marcolet3u/php-project/
#
# Pour interdire l'accès aux répertoires contenant du code
RewriteRule ^sql(/.|)$ - [NC,F]
RewriteRule ^src(/.|)$ - [NC,F]
RewriteRule ^vendor(/.*|)$ - [NC,F]
#
# réécriture pour slim
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
\ No newline at end of file
{
"require": {
"illuminate/database": "5.5.*",
"slim/slim": "2.*",
"php": ">=7.0"
},
"autoload": {
"psr-4": {
"bdd\\": "./src"
}
}
}
\ No newline at end of file
This diff is collapsed.
<?php
// Import de la class qui a pour but de charger tous les imports du projet
require_once './vendor/autoload.php';
// Liste des tous les imports
use bdd\controllers\ControleurRequete;
use \bdd\views\AccueilView;
use \Illuminate\Database\Capsule\Manager as DB;
use \Slim\Slim;
// instance de la base de données
$db = new DB();
// ajout des informations pour se connecter à la base de données
$db->addConnection(parse_ini_file('conf/conf.ini'));
// demarage de la basse de donnée
$db->setAsGlobal();
$db->bootEloquent();
// demerage d'un session
session_start();
// intance de slim qui a pour but de créer le rootage des urls
$app = new Slim();
/*-----|accueil|-----*/
$app->get('/', function () {
$v = new AccueilView();
$v->render();
})->name('accueil');
$app->get('/tp2req1', function () {
$v = new ControleurRequete();
$v->selectChar();
})->name('tp2req1');
$app->get('/tp2req2', function () {
$v = new ControleurRequete();
$v->selectCharMario();
})->name('tp2req2');
$app->get('/tp2req3', function () {
$v = new ControleurRequete();
$v->gameCompanySony();
})->name('tp2req3');
$app->get('/gameNumber', function () {
$v = new ControleurRequete();
$v->selectGameNumber();
})->name('gameNumber');
$app->get('/page/:p', function ($p) {
$v = new ControleurRequete();
$v->selectPage($p);
})->name('page');
$app->run();
\ No newline at end of file
<?php
namespace bdd\controllers;
use bdd\models\Company;
use bdd\models\Game;
use bdd\models\Platform;
use bdd\models\Character;
use bdd\models\Game2character;
use bdd\models\Game_publisher;
use bdd\views\RequeteView;
class ControleurRequete{
public function selectGame(){
$jeu = Game::select('name')->get();
$vue = new RequeteView($jeu);
$vue->render(1);
}
public function selectMario(){
$jeu = Game::select('name')->where('name','like','%Mario%','or','alias','like','%Mario%')->get();
$vue = new RequeteView($jeu);
$vue->render(1);
}
public function selectCharMario(){
$data = Character::join('game2character','perso.id','=','game2character.character_id')
->join('game','game2character.game_id','=','game.id')
->select('id')
->where('game.name','LIKE','Mario%');
$vue = new RequeteView($data);
$vue->render(1);
}
public function selectCharFirstAppearedMario(){
$data = Character::join('game','perso.first_appeared_in_game_id','=','game.id')
->select('name')
->where('game.name','LIKE','Mario%');
$vue = new RequeteView($data);
$vue->render(1);
}
public function selectGameMarioAndRatingPlus3(){
$data = Game::join('game2rating','game_id','=','game2rating.rating_id')
->join('Rating','game2rating.rating_id','=','rating.id')
->select('name')
->where('game.name','LIKE','Mario%', 'AND', 'game_rating.name' 'LIKE', '%3+%');
$vue = new RequeteView($data);
$vue->render(1);
}
public function selectCharGame12342(){
$data = Character::join('game2character','perso.id','=','game2character.character_id')
->select('name')
->where('game2character.game_id','=','12342');
$vue = new RequeteView($data);
$vue->render(1);
}
public function gameCompanySony(){
$data = Game::join('game_publisher','game.id','=','game_publisher.game_id')
->join('company','game_publisher.comp_id','=','company.id')
->select('id')
->where('company.name','LIKE','%Sony%');
$vue = new RequeteView($data);
$vue->render(1);
}
}
\ No newline at end of file
<?php
namespace bdd\models;
class Character extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'character';
protected $primaryKey = 'id';
public $timestamps = false;
public function platform(){
return $this->belongsTo('bdd\models\character', 'id');
}
}
\ No newline at end of file
<?php
namespace bdd\models;
class Company extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'company';
protected $primaryKey = 'id';
public $timestamps = false;
public function platform(){
return $this->belongsTo('bdd\models\company', 'id');
}
}
\ No newline at end of file
<?php
namespace bdd\models;
class Game extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'game';
protected $primaryKey = 'id';
public $timestamps = false;
public function platform(){
return $this->belongsTo('bdd\models\game', 'id');
}
}
\ No newline at end of file
<?php
namespace bdd\models;
class Game2character extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'Game2character';
protected $primaryKey = 'game_id';
public $timestamps = false;
public function platform(){
return $this->belongsTo('bdd\models\Game2character', 'game_id');
}
}
\ No newline at end of file
<?php
namespace bdd\models;
class Game_publisher extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'game_publisher';
protected $primaryKey = 'game_id';
public $timestamps = false;
public function platform(){
return $this->belongsTo('bdd\models\game_publisher', 'game_id');
}
}
\ No newline at end of file
<?php
namespace bdd\models;
class Platform extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'platform';
protected $primaryKey = 'id';
public $timestamps = false;
public function platform(){
return $this->belongsTo('bdd\models\platform', 'id');
}
}
\ No newline at end of file
<?php
namespace bdd\views;
use Slim\Slim;
class AccueilView
{
protected $app;
public function __construct()
{
$this->app = Slim::getInstance();
}
public function render()
{
$baseURL = $_SERVER['REQUEST_URI'];
$url1 = $this->app->urlFor("tp2req1");
$url2 = $this->app->urlFor("tp2req2");
$url3 = $this->app->urlFor("tp2req3");
$url4 = $this->app->urlFor("gameNumber");
$url5 = $baseURL . "page/1";
$html = <<<HTML
<h1>Page d'accueil</h1>
<p>
lien:<br>
<a href=$url1>$url1</a><br>
<a href=$url2>$url2</a><br>
<a href=$url3>$url3</a><br>
<a href=$url4>$url4</a><br>
<a href=$url5>$url5</a><br>
</p>
HTML;
echo $html;
}
}
<?php
namespace bdd\views;
use Slim\Slim;
class RequeteView
{
protected $tab, $app;
public function __construct($t)
{
$this->tab = $t;
$this->app = Slim::getInstance();
}
public function render($type)
{
$html = "";
switch ($type) {
case 1:
$html = $this->default();
break;
default:
$html = $this->notFound();
break;
}
echo $html;
}
private function notFound()
{
return <<<RES
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
</head>
<body>
<p>data not found</p>
</body>
</html>
RES;
}
private function default()
{
$res = <<<RES
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
</head>
<body>
RES;
foreach ($this->tab as $key => $value) {
$res .= <<<RES
$key:$value<br>
RES;
}
$res .= <<<RES
</body>
</html>
RES;
return $res;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment