2021-08-22 10:44:49 +01:00
< ? php
2022-10-29 19:31:34 +01:00
2023-06-08 15:10:27 +01:00
namespace api\timeline ;
2022-10-29 19:31:34 +01:00
2021-12-28 21:20:00 +00:00
use PDO ;
2023-06-08 15:10:27 +01:00
require_once __DIR__ . " /../utils/config.php " ;
2021-08-22 10:44:49 +01:00
2021-08-31 18:50:08 +01:00
/**
* TimelineData class
* Define all functions which either get , update , create or delete timeline data
*/
2021-12-28 21:20:00 +00:00
class timelineData
2021-08-22 10:44:49 +01:00
{
2022-10-09 02:40:06 +01:00
/**
* Get all education data
* @ return array - Array of all education data or error message
*/
2023-06-26 03:54:25 +01:00
public function getEduData () : array
2021-08-23 09:30:08 +01:00
{
$conn = dbConn ();
2022-10-09 23:32:50 +01:00
$stmt = $conn -> prepare ( " SELECT ID, startPeriod, endPeriod, grade, course FROM edu ORDER BY startPeriod DESC; " );
2021-08-23 09:30:08 +01:00
$stmt -> execute ();
2021-08-22 10:44:49 +01:00
2021-08-23 09:30:08 +01:00
// set the resulting array to associative
$result = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
2023-06-26 03:54:25 +01:00
2021-08-23 09:30:08 +01:00
if ( $result )
{
return $result ;
}
2022-07-29 20:00:36 +01:00
return array ( " errorMessage " => " Error, edu data not found " );
2021-08-23 09:30:08 +01:00
}
2023-10-18 23:58:21 +01:00
2022-10-09 02:40:06 +01:00
/**
* Get all work data
* @ return array - Array of all work data or error message
*/
2023-06-26 03:54:25 +01:00
public function getWorkData () : array
2021-08-27 21:18:19 +01:00
{
$conn = dbConn ();
2022-10-29 19:31:34 +01:00
$stmt = $conn -> prepare ( " SELECT ID, startPeriod, endPeriod, companyName, area, title FROM work ORDER BY work.startPeriod DESC; " );
2021-08-27 21:18:19 +01:00
$stmt -> execute ();
// set the resulting array to associative
$result = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
2022-10-29 19:31:34 +01:00
2021-08-27 21:18:19 +01:00
if ( $result )
{
return $result ;
}
2022-07-29 20:00:36 +01:00
return array ( " errorMessage " => " Error, work data not found " );
2021-08-27 21:18:19 +01:00
}
2022-10-09 23:32:50 +01:00
/**
* Update education data
* @ param string $dateFrom - Start date
* @ param string $dateTo - End date
* @ param string $grade - Grade
* @ param string $course - Course
2023-07-12 03:29:56 +01:00
* @ param string $ID - ID of the education data
* @ return string - " not found " if the ID is not found , " ok " if successful , " error " if not
2022-10-09 23:32:50 +01:00
*/
2023-07-12 03:29:56 +01:00
public function updateEduData ( string $dateFrom , string $dateTo , string $grade , string $course , string $ID ) : string
2022-10-09 23:32:50 +01:00
{
$conn = dbConn ();
2023-07-12 03:29:56 +01:00
$chkStmt = $conn -> prepare ( " SELECT ID FROM edu WHERE ID = :id; " );
$chkStmt -> bindParam ( " :id " , $ID );
$chkStmt -> execute ();
$result = $chkStmt -> fetch ( PDO :: FETCH_ASSOC );
if ( ! $result )
{
return " not found " ;
}
2022-10-09 23:32:50 +01:00
$stmt = $conn -> prepare ( " UPDATE edu SET startPeriod = :dateFrom, endPeriod = :dateTo, grade = :grade, course = :course WHERE ID = :id; " );
$stmt -> bindParam ( " :dateFrom " , $dateFrom );
$stmt -> bindParam ( " :dateTo " , $dateTo );
$stmt -> bindParam ( " :grade " , $grade );
$stmt -> bindParam ( " :course " , $course );
2023-07-12 03:29:56 +01:00
$stmt -> bindParam ( " :id " , $ID );
if ( $stmt -> execute ())
{
return " ok " ;
}
return " error " ;
2022-10-09 23:32:50 +01:00
}
2022-10-29 19:31:34 +01:00
/**
* Update work data
* @ param string $dateFrom - Start date
* @ param string $dateTo - End date
* @ param string $companyName - Company name
* @ param string $area - Area
* @ param string $title - Title
2023-07-12 03:29:56 +01:00
* @ param string $ID - ID of the work data
* @ return string - " not found " if the ID is not found , " ok " if successful , " error " if not
2022-10-29 19:31:34 +01:00
*/
2023-07-12 03:29:56 +01:00
public function updateWorkData ( string $dateFrom , string $dateTo , string $companyName , string $area , string $title , string $ID ) : string
2022-10-29 19:31:34 +01:00
{
2023-07-12 03:29:56 +01:00
$conn = dbConn ();
$chkStmt = $conn -> prepare ( " SELECT ID FROM work WHERE ID = :id; " );
$chkStmt -> bindParam ( " :id " , $ID );
$chkStmt -> execute ();
$result = $chkStmt -> fetch ( PDO :: FETCH_ASSOC );
if ( ! $result )
{
return " not found " ;
}
2022-10-29 19:31:34 +01:00
$conn = dbConn ();
$stmt = $conn -> prepare ( " UPDATE work SET startPeriod = :dateFrom, endPeriod = :dateTo, companyName = :companyName, area = :area, title = :title WHERE ID = :id; " );
$stmt -> bindParam ( " :dateFrom " , $dateFrom );
$stmt -> bindParam ( " :dateTo " , $dateTo );
$stmt -> bindParam ( " :companyName " , $companyName );
$stmt -> bindParam ( " :area " , $area );
$stmt -> bindParam ( " :title " , $title );
2023-07-12 03:29:56 +01:00
$stmt -> bindParam ( " :id " , $ID );
if ( $stmt -> execute ())
{
return " ok " ;
}
return " error " ;
2022-10-29 19:31:34 +01:00
}
/**
* Delete education data by ID
2023-07-12 03:29:56 +01:00
* @ param int $ID
* @ return string - " not found " if the ID is not found , " ok " if successful , " error " if not
2022-10-29 19:31:34 +01:00
*/
2023-07-12 03:29:56 +01:00
public function deleteEduData ( int $ID ) : string
2022-10-29 19:31:34 +01:00
{
$conn = dbConn ();
2023-07-12 03:29:56 +01:00
$chkStmt = $conn -> prepare ( " SELECT ID FROM edu WHERE ID = :id; " );
$chkStmt -> bindParam ( " :id " , $ID );
$chkStmt -> execute ();
$result = $chkStmt -> fetch ( PDO :: FETCH_ASSOC );
if ( ! $result )
{
return " not found " ;
}
2022-10-29 19:31:34 +01:00
$stmt = $conn -> prepare ( " DELETE FROM edu WHERE ID = :id; " );
2023-07-12 03:29:56 +01:00
$stmt -> bindParam ( " :id " , $ID );
if ( $stmt -> execute ())
{
return " ok " ;
}
return " error " ;
2022-10-29 19:31:34 +01:00
}
/**
* Delete work data by ID
2023-07-12 03:29:56 +01:00
* @ param int $ID
* @ return string - " not found " if the ID is not found , " ok " if successful , " error " if not
2022-10-29 19:31:34 +01:00
*/
2023-07-12 03:29:56 +01:00
function deleteWorkData ( int $ID ) : string
2022-10-29 19:31:34 +01:00
{
$conn = dbConn ();
2023-07-12 03:29:56 +01:00
$chkStmt = $conn -> prepare ( " SELECT ID FROM work WHERE ID = :id; " );
$chkStmt -> bindParam ( " :id " , $ID );
$chkStmt -> execute ();
$result = $chkStmt -> fetch ( PDO :: FETCH_ASSOC );
if ( ! $result )
{
return " not found " ;
}
2022-10-29 19:31:34 +01:00
$stmt = $conn -> prepare ( " DELETE FROM work WHERE ID = :id; " );
2023-07-12 03:29:56 +01:00
$stmt -> bindParam ( " :id " , $ID );
if ( $stmt -> execute ())
{
return " ok " ;
}
return " error " ;
2022-10-29 19:31:34 +01:00
}
2023-10-18 23:58:21 +01:00
2022-10-29 19:31:34 +01:00
/**
* Create new education data
* @ param string $dateFrom - Start date
* @ param string $dateTo - End date
* @ param string $grade - Grade
* @ param string $course - Course
* @ return bool | int - ID of the new education data or false if not successful
*/
2023-06-26 03:54:25 +01:00
public function addEduData ( string $dateFrom , string $dateTo , string $grade , string $course ) : bool | int
2022-10-29 19:31:34 +01:00
{
$conn = dbConn ();
$stmt = $conn -> prepare ( " INSERT INTO edu (startPeriod, endPeriod, grade, course) VALUES (:dateFrom, :dateTo, :grade, :course); " );
$stmt -> bindParam ( " :dateFrom " , $dateFrom );
$stmt -> bindParam ( " :dateTo " , $dateTo );
$stmt -> bindParam ( " :grade " , $grade );
$stmt -> bindParam ( " :course " , $course );
2023-06-26 03:54:25 +01:00
if ( $stmt -> execute ())
2022-10-29 19:31:34 +01:00
{
return $conn -> lastInsertId ();
}
return false ;
}
2023-10-18 23:58:21 +01:00
2022-10-29 19:31:34 +01:00
/**
* Create new work data
* @ param string $dateFrom - Start date
* @ param string $dateTo - End date
* @ param string $companyName - Company name
* @ param string $area - Area
* @ param string $title - Title
* @ return bool | int - ID of the new work data if successful , false if not
*/
2023-06-26 03:54:25 +01:00
public function addWorkData ( string $dateFrom , string $dateTo , string $companyName , string $area , string $title ) : bool | int
2022-10-29 19:31:34 +01:00
{
$conn = dbConn ();
$stmt = $conn -> prepare ( " INSERT INTO work (startPeriod, endPeriod, companyName, area, title) VALUES (:dateFrom, :dateTo, :companyName, :area, :title); " );
$stmt -> bindParam ( " :dateFrom " , $dateFrom );
$stmt -> bindParam ( " :dateTo " , $dateTo );
$stmt -> bindParam ( " :companyName " , $companyName );
$stmt -> bindParam ( " :area " , $area );
$stmt -> bindParam ( " :title " , $title );
2023-06-26 03:54:25 +01:00
if ( $stmt -> execute ())
2022-10-29 19:31:34 +01:00
{
return $conn -> lastInsertId ();
}
return false ;
}
2021-12-28 21:20:00 +00:00
}