Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
823 changes: 823 additions & 0 deletions restful/Pokemon Go.csv

Large diffs are not rendered by default.

Binary file added restful/Pokemon Go.xlsx
Binary file not shown.
17 changes: 17 additions & 0 deletions restful/config/core.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
// show error reporting
ini_set('display_errors', 1);
error_reporting(E_ALL);

// home page url
$home_url="http://localhost/restful/";

// page given in URL parameter, default page is one
$page = isset($_GET['page']) ? $_GET['page'] : 1;

// set number of records per page
$records_per_page = 50;

// calculate for the query LIMIT clause
$from_record_num = ($records_per_page * $page) - $records_per_page;
?>
25 changes: 25 additions & 0 deletions restful/config/database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class Database {

private $host = "localhost";
private $db = "pokemon";
private $usuario = "root";
private $senha = "";
public $conn;

public function getConn(){
$this->conn = null;

try{
$this->conn = new PDO("mysql:host=" .$this->host.";dbname=".$this->db,$this->usuario,$this->senha);
$this->conn->exec("set names utf8");
}catch(PDOException $exception){
echo "Erro de conexão: " . $exception->getMessage();
}

return $this->conn;
}
}

?>
7 changes: 7 additions & 0 deletions restful/css/bootstrap.min.css

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions restful/objects/pokemon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
class Pokemon{
private $conn;
private $tabela = "poke";

public $columns = array('Row','Name','Pokedex Number','Img name', 'Generation', 'Evolution Stage', 'Evolved', 'FamilyID', 'Cross Gen', 'Type 1', 'Type 2',
'Weather 1', 'Weather 2', 'STAT TOTAL', 'ATK', 'DEF', 'STA', 'Legendary', 'Aquireable', 'Spawns', 'Regional', 'Raidable', 'Hatchable',
'Shiny', 'Nest', 'New', 'Not-Gettable', 'Future Evolve', '100% CP @ 40', '100% CP @ 39');

public $row;
public $name;
public $pokedex;
public $img;
public $gen;
public $evolutionStage;
public $evolved;
public $familyID;
public $crossGen;
public $type1;
public $type2;
public $weather1;
public $weather2;
public $statTotal;
public $atk;
public $def;
public $sta;
public $legend;
public $aquireable;
public $spawn;
public $regional;
public $raidable;
public $hatchable;
public $shiny;
public $nest;
public $new;
public $notGettable;
public $futureEvolve;
public $cp40;
public $cp39;

public function __construct($db){
$this->conn = $db;
}

function read(){
$query = "SELECT * FROM `". $this->tabela. "`";

$stmt = $this->conn->prepare($query);

$stmt->execute();

return $stmt;
}

function readOne(){
$query = "SELECT * FROM `" . $this->tabela . "` WHERE row = ? LIMIT 0,1";

$stmt = $this->conn->prepare($query);

$stmt->bindParam(1, $this->row);

$stmt->execute();

$row = $stmt->fetch(PDO::FETCH_ASSOC);

$this->row = $row['Row'];
$this->name = $row['Name'];
$this->pokedex = $row['Pokedex Number'];
$this->img = $row['Img name'];
$this->gen = $row['Generation'];
$this->evolutionStage = $row['Evolution Stage'];
$this->evolved = $row['Evolved'];
$this->familyID = $row['FamilyID'];
$this->crossGen = $row['Cross Gen'];
$this->type1 = $row['Type 1'];
$this->type2 = $row['Type 2'];
$this->weather1 = $row['Weather 1'];
$this->weather2 = $row['Weather 2'];
$this->statTotal = $row['STAT TOTAL'];
$this->atk = $row['ATK'];
$this->def = $row['DEF'];
$this->sta = $row['STA'];
$this->legend = $row['Legendary'];
$this->aquireable = $row['Aquireable'];
$this->spawn = $row['Spawns'];
$this->regional = $row['Regional'];
$this->raidable = $row['Raidable'];
$this->hatchable = $row['Hatchable'];
$this->shiny = $row['Shiny'];
$this->nest = $row['Nest'];
$this->new = $row['New'];
$this->notGettable = $row['Not-Gettable'];
$this->futureEvolve = $row['Future Evolve'];
$this->cp40 = $row['100% CP @ 40'];
$this->cp39 = $row['100% CP @ 39'];
}

function search($option, $keywords){

$option = htmlspecialchars(strip_tags($option));
$keywords = htmlspecialchars(strip_tags($keywords));
$keywords = "%{$keywords}%";

$query = "SELECT * FROM `" . $this->tabela . "` WHERE `".$option."` LIKE '".$keywords."'";

$stmt = $this->conn->prepare($query);

$stmt->execute();



return $stmt;
}

function readPaging($from_record_num, $records_per_page){

$query = "SELECT * FROM " . $this->tabela . " LIMIT ?, ?";

$stmt = $this->conn->prepare( $query );

$stmt->bindParam(1, $from_record_num, PDO::PARAM_INT);
$stmt->bindParam(2, $records_per_page, PDO::PARAM_INT);

$stmt->execute();

return $stmt;
}

function count(){
$query = "SELECT COUNT(*) as total_rows FROM " . $this->tabela . "";

$stmt = $this->conn->prepare( $query );
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);

return $row['total_rows'];
}
}
32 changes: 32 additions & 0 deletions restful/product/read.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/*
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
*/
include_once('../config/database.php');
include_once('../objects/pokemon.php');

$database = new Database();
$db = $database->getConn();

$pokemon = new Pokemon($db);

$stmt = $pokemon->read();

$num = $stmt->rowCount();
if($num>0){
$pokemon_arr = array();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
array_push($pokemon_arr, $row);
}
$encode = json_encode($pokemon_arr);

}

else{
echo json_encode(
array("message" => "Nenhum pokemon encontrado")
);
}
?>
61 changes: 61 additions & 0 deletions restful/product/read_one.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Credentials: true");
header('Content-Type: application/json');

// include database and object files
include_once '../config/database.php';
include_once '../objects/pokemon.php';

// get database connection
$database = new Database();
$db = $database->getConn();

// prepare product object
$pokemon = new Pokemon($db);

// set ID property of product to be edited
$pokemon->row = isset($_GET['row']) ? $_GET['row'] : die();

// read the details of product to be edited
$pokemon->readOne();

// create array
$pokemon_arr = array(
'Row' => $pokemon->row,
'Name' => $pokemon->name,
'Pokedex Number' => $pokemon->pokedex,
'Img name' => $pokemon->img,
'Generation' => $pokemon->gen,
'Evolution Stage' => $pokemon->evolutionStage,
'Evolved' => $pokemon->evolved,
'FamilyID' => $pokemon->familyID,
'Cross Gen' => $pokemon->crossGen,
'Type 1' => $pokemon->type1,
'Type 2' => $pokemon->type2,
'Weather 1' => $pokemon->weather1,
'Weather 2' => $pokemon->weather2,
'STAT TOTAL' => $pokemon->statTotal,
'ATK' => $pokemon->atk,
'DEF' => $pokemon->def,
'STA' => $pokemon->sta,
'Legendary' => $pokemon->legend,
'Aquireable' => $pokemon->aquireable,
'Spawns' => $pokemon->spawn,
'Regional' => $pokemon->regional,
'Raidable' => $pokemon->raidable,
'Hatchable' => $pokemon->hatchable,
'Shiny' => $pokemon->shiny,
'Nest' => $pokemon->nest,
'New' => $pokemon->new,
'Not-Gettable' => $pokemon->notGettable,
'Future Evolve' => $pokemon->futureEvolve,
'100% CP @ 40' => $pokemon->cp40,
'100% CP @ 39' => $pokemon->cp39
);

// make it json format
print_r(json_encode($pokemon_arr));
?>
49 changes: 49 additions & 0 deletions restful/product/read_paging.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
*/

// include database and object files
include_once '../config/core.php';
include_once '../shared/utilities.php';
include_once '../config/database.php';
include_once '../objects/pokemon.php';

$utilities = new Utilities();

$database = new Database();
$db = $database->getConn();

$pokemon = new Pokemon($db);

$stmt = $pokemon->readPaging($from_record_num, $records_per_page);
$num = $stmt->rowCount();

if($num>0){

$pokemon_arr=array();
$pokemon_arr["records"]=array();
$pokemon_arr["paging"]=array();


while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){

extract($row);

array_push($pokemon_arr["records"], $row);
}


$total_rows=$pokemon->count();
$page_url="{$home_url}view/paging.php?";
$paging=$utilities->getPaging($page, $total_rows, $records_per_page, $page_url);
$pokemon_arr["paging"]=$paging;


//print_r($pokemon_arr);
//echo json_encode($pokemon_arr);
}

?>
34 changes: 34 additions & 0 deletions restful/product/search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

//header("Access-Control-Allow-Origin: *");
//header("Content-Type: application/json; charset=UTF-8");

include_once '../config/database.php';
include_once '../objects/pokemon.php';

$database = new Database();
$db = $database->getConn();

$pokemon = new Pokemon($db);

$option=isset($_GET["o"]) ? $_GET["o"] : "";
$keywords=isset($_GET["s"]) ? $_GET["s"] : "";

$stmt = $pokemon->search($option, $keywords);
$num = $stmt->rowCount();

if($num>0){

$pokemon_arr =array();

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);


array_push($pokemon_arr, $row);
}

//echo json_encode($pokemon_arr);
}

?>
Loading