Data Processor - PHP
Data Processor - PHP
php
/**
* @author Gaurav Patel
* @version 202335.00
* @package COMP 10260 Assignment 2
*
* I Gaurav Patel, 000898120, certify that this material is my original work. No
other person's work has been used without suitable acknowledgment and I have not
made my work available to anyone else.
*/
/*
The bellow condition check that is that GET is taking choice and sort and if not it
throw the error
*/
// it check that movieChoice has the pokemon or movies and if not than it send
the error
if ($movieChoice == "pokemon") {
$outputResult = pokemonData();
} elseif ($movieChoice == "movies") {
$outputResult = moviesData();
} else {
$errRes = array("error" => "Invalid request");
echo json_encode($errRes);
exit;
}
// This condition check that the order for the short is assinding for a and
descinding is d and if there is not a any of two it will throw error
if ($storeOutput == "a") {
$outputResult = orderASC($outputResult);
} elseif ($storeOutput == "d") {
$outputResult = orderDSC($outputResult);
} else {
$errRes = array("error" => "Invalid sort");
echo json_encode($errRes);
exit;
}
echo json_encode($outputResult);
} else {
$errRes = array("error" => "Missing param");
echo json_encode($errRes);
}
/**
* Method pokemonData
*
* @return void The given function read the pokemon file and than then it transfer
the data inside the array using the loop
*/
function pokemonData()
{
$outputResult = file("pokemon.txt"); // it stores the pokemon file data inside
the outputResult
// inside the for loop it itterate the loop as long as outputResult and then it
store the name inside name variable and it store the image inside the images
variable then it will store the name and image as the key value pair.
//
/**
* Method moviesData
*
*The bellow function is extract the data form the movies.json and then it decode
that file and return the file.
/**
* Method orderASC
*
* the bellow function short the data in the acsending order and and then return
the outputResult. I use the short method which I learn during the
*
* .net assignment and i just use that one
*
* @param $outputResult it takes the outputResult to to take the data
* @return void this function not return nothing
*/
function orderASC($outputResult)
{
$number = count($outputResult); // it store the outputResult value in number
for ($g = 0; $g < $number - 1; $g++) {
for ($k = $g + 1; $k < $number; $k++) {
$name1 = strtolower($outputResult[$g]['name']); // it store the name in
lowercase
$name2 = strtolower($outputResult[$k]['name']); // it store in the name
which has the next index than name1
// the condition check that name1 is grater than 2 it will swwap the
name and put the name in ascending order
//
/**
* Method orderDSC
*
* This bellow function put all the names in the discending order. and all the
things work same as the above function.
*
* @param $outputResult
*
* @return void this function return nothing
*/
function orderDSC($outputResult)
{
$number = count($outputResult);
for ($g = 0; $g < $number - 1; $g++) {
for ($k = $g + 1; $k < $number; $k++) {
$name1 = strtolower($outputResult[$g]['name']);
$name2 = strtolower($outputResult[$k]['name']);