Commit ed4b719b authored by Kbida Vincent's avatar Kbida Vincent

nouveau dossier tp2

parent 969ebde6
......@@ -2,41 +2,44 @@
namespace bdd\controllers;
use bdd\models\company;
use bdd\models\game;
use bdd\models\platform;
use bdd\models\Company;
use bdd\models\Game;
use bdd\models\Platform;
use bdd\views\RequeteView;
class ControleurRequete{
public function selectMario(){
$jeu = \bdd\models\game::select('name')->where('name','like','%Mario%','or','alias','like','%Mario%')->get();
$jeu = Game::select('name')->where('name','like','%Mario%','or','alias','like','%Mario%')->get();
$vue = new \bdd\views\RequeteView($jeu);
$vue = new RequeteView($jeu);
$vue->render(1);
}
public function selectJapanCompany(){
$company = \bdd\models\company::select('name')->where('location_country','like','%Japan%')->get();
$vue = new \bdd\views\RequeteView($company);
$company = Company::select('name')->where('location_country','like','%Japan%')->get();
$vue = new RequeteView($company);
$vue->render(1);
}
public function selectPlatformBase(){
$platform = \bdd\models\platform::select('name')->where('install_base','>','10000000')->get();
$vue = new \bdd\views\RequeteView($platform);
$platform = Platform::select('name')->where('install_base','>','10000000')->get();
$vue = new RequeteView($platform);
$vue->render(1);
}
public function selectGameNumber(){
$game = \bdd\models\game::select('name')->orderBy('name')->take(442)->skip(21173)->get();
$vue = new \bdd\views\RequeteView($game);
$game = Game::select('name')->orderBy('name')->take(442)->skip(21173)->get();
$vue = new RequeteView($game);
$vue->render(1);
}
public function selectPage($p){
$p = ($p-1)*500;
$jeu = \bdd\models\game::select('id','name')->orderBy('id')->take(500)->skip($p)->get();
$vue = new \bdd\views\RequeteView($jeu);
$jeu = Game::select('id','name')->orderBy('id')->take(500)->skip($p)->get();
$vue = new RequeteView($jeu);
$vue->render(1);
}
}
\ No newline at end of file
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
$ini_file = parse_ini_file('src/conf/conf.ini');
$db->addConnection([
'driver' => $ini_file['driver'],
'host' => $ini_file['host'],
'database' => $ini_file['database'],
'username' => $ini_file['username'],
'password' => $ini_file['password'],
'charset' => $ini_file['charset'],
'collation' => $ini_file['charset'] . '_unicode_ci',
'prefix' => ''
]);
// 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('/mario', function () {
$v = new ControleurRequete();
$v->selectMario();
})->name('mario');
$app->get('/japan', function () {
$v = new ControleurRequete();
$v->selectJapanCompany();
})->name('japan');
$app->get('/platformBase', function () {
$v = new ControleurRequete();
$v->selectPlatformBase();
})->name('platformBase');
$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\views\RequeteView;
class ControleurRequete{
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 selectJapanCompany(){
$company = Company::select('name')->where('location_country','like','%Japan%')->get();
$vue = new RequeteView($company);
$vue->render(1);
}
public function selectPlatformBase(){
$platform = Platform::select('name')->where('install_base','>','10000000')->get();
$vue = new RequeteView($platform);
$vue->render(1);
}
public function selectGameNumber(){
$game = Game::select('name')->orderBy('name')->take(442)->skip(21173)->get();
$vue = new RequeteView($game);
$vue->render(1);
}
public function selectPage($p){
$p = ($p-1)*500;
$jeu = Game::select('id','name')->orderBy('id')->take(500)->skip($p)->get();
$vue = new RequeteView($jeu);
$vue->render(1);
}
public function selectChar(){
$data = Game2character::select('charactter_id')->where('game_id','=','12342');
}
}
\ 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 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("mario");
$url2 = $this->app->urlFor("japan");
$url3 = $this->app->urlFor("platformBase");
$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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment