This commit is contained in:
Vincent BRIDIER 2025-10-03 19:30:36 +02:00
parent a9debcee55
commit e0d18321ab
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
8 changed files with 152 additions and 17 deletions

View file

@ -14,6 +14,8 @@
}
],
"require": {
"php": "^8.0",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^7.10"
}
}

View file

@ -1,10 +1,21 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use Uwil\ArcadiaGenesisPhpClient\Datas\EmployeesDatas;
use Uwil\ArcadiaGenesisPhpClient\Datas\IncoDatas;
require_once 'vendor/autoload.php';
$employee = EmployeesDatas::getById("0117670");
// $employee = EmployeesDatas::getById("0115590");
// var_dump($employee);
var_dump($employee);
// $employees = EmployeesDatas::getListModifiedSince("28/08/2025");
// var_dump($employees);
$inco = IncoDatas::getById("2842");
var_dump($inco);
?>

View file

@ -21,10 +21,12 @@ class EmployeesDatas
'planned_end_date' => 'DATE_EFFET_FIC',
'establishment' => 'ETAB_FIC',
'site' => 'SITE_FIC',
'service' => 'SERVICE_FIC'
'service' => 'SERVICE_FIC',
'created_at' => 'DAT_CRE',
'updated_at' => 'DAT_MAJ',
];
public static function getById(string $id)
public static function getById(string $id) : Employee|null
{
$params = [
'TABLE' => self::$table,
@ -40,8 +42,31 @@ class EmployeesDatas
return null;
}
$employee = new Employee();
$employee->fill(self::mapObject($response[0]->values));
return $employee;
$model = new Employee();
$model->fill(self::mapObject($response[0]->values));
return $model;
}
public static function getListModifiedSince(string $date)
{
$params = [
'TABLE' => self::$table,
'S_COLS' => self::getArcadiaDefinition(),
'C_COLS' => self::getArcadiaDefinition(['updated_at']),
'C_OPES' => ['>='],
'C_VALS' => [$date],
];
$response = Transport::call($params);
var_dump($response);exit;
if (empty($response[0]->values)) {
return null;
}
$model = new Employee();
$model->fill(self::mapObject($response[0]->values));
return $model;
}
}

48
src/Datas/IncoDatas.php Normal file
View file

@ -0,0 +1,48 @@
<?php
namespace Uwil\ArcadiaGenesisPhpClient\Datas;
use Uwil\ArcadiaGenesisPhpClient\Models\Inco;
use Uwil\ArcadiaGenesisPhpClient\Traits\ArcadiaTrait;
use Uwil\ArcadiaGenesisPhpClient\Transport;
class IncoDatas
{
use ArcadiaTrait;
private static string $table = "INCO";
private static array $definition = [
'id' => 'NO_ART',
'description' => 'DESCRIPTIF',
'tips' => 'ASTUCES',
'ingredients' => 'LST_ING',
'portions' => 'NB_PORTION',
'portion_type' => 'TYP_PORTION', // FIXME: Lié à une autre table ?
'allergens' => 'LST_ALLERGENE', // FIXME: Lié à une autre table ?
'brand' => 'MARQUE', // FIXME: Lié à une autre table ?
'created_at' => 'DAT_CRE',
'updated_at' => 'DAT_MAJ',
];
public static function getById(string $id)
{
$params = [
'TABLE' => self::$table,
'S_COLS' => self::getArcadiaDefinition(),
'C_COLS' => self::getArcadiaDefinition(['id']),
'C_OPES' => ['='],
'C_VALS' => [$id],
];
$response = Transport::call($params);
if (empty($response[0]->values)) {
return null;
}
$model = new Inco();
$model->fill(self::mapObject($response[0]->values));
return $model;
}
}

View file

@ -4,6 +4,23 @@ namespace Uwil\ArcadiaGenesisPhpClient\Models;
use Uwil\ArcadiaGenesisPhpClient\Traits\ModelTrait;
/**
* Class Employee
*
* Represents an employee with personal and job-related details.
*
* @property string $matricule Unique identifier of the employee
* @property string $lastname Last name of the employee
* @property string $firstname First name of the employee
* @property string $start_date Employment start date (YYYY-MM-DD)
* @property string|null $end_date Employment end date if applicable (YYYY-MM-DD or null)
* @property string|null $planned_end_date Planned termination date if any
* @property string $establishment Establishment where the employee works
* @property string $site Physical site location of the employee
* @property string $service Service or department of the employee
* @property string|null $created_at Record creation timestamp
* @property string|null $updated_at Record last update timestamp
*/
class Employee
{
use ModelTrait;
@ -17,4 +34,6 @@ class Employee
public string $establishment;
public string $site;
public string $service;
public string|null $created_at;
public string|null $updated_at;
}

21
src/Models/Inco.php Normal file
View file

@ -0,0 +1,21 @@
<?php
namespace Uwil\ArcadiaGenesisPhpClient\Models;
use Uwil\ArcadiaGenesisPhpClient\Traits\ModelTrait;
class Inco
{
use ModelTrait;
public int $id;
public string $description;
public string|null $tips;
public string $ingredients;
public int $portions;
public string $portion_type;
public string $allergens;
public int $brand;
public string|null $created_at;
public string|null $updated_at;
}

View file

@ -28,10 +28,12 @@ trait ArcadiaTrait
if (empty($value)) {
return null;
}
// If we receive date in FR format instead of ISO one, return ISO conversion.
/* If we receive date in FR format instead of ISO one, return ISO conversion.
** substr($value, 0, 10) to get only the date, because we can receive date with following format : d/m/Y 00:00 ...
*/
$pattern = "/\b(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/[0-9]{4}\b/";
if (preg_match($pattern, $value, $matches)) {
$dateObject = \DateTime::createFromFormat('d/m/Y', $value);
$dateObject = \DateTime::createFromFormat('d/m/Y', substr($value, 0, 10));
return $dateObject->format('Y-m-d');
}
// If just string, return original value.

View file

@ -5,6 +5,7 @@ namespace Uwil\ArcadiaGenesisPhpClient;
use GuzzleHttp\Psr7;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use InvalidArgumentException;
class Transport
@ -12,8 +13,7 @@ class Transport
private static string $endpoint = "https://lab501-arc05402.lesidc.com"; // FIXME : Move this
private static string $apiKey = "11319-1127611241-11748-11917-12156891612247-10244-11653-125778522-1195511335-11382-10886-108424242324222424242322242424232423"; // FIXME : Move this
private static string $apiSecret = "1046012368-8940-10144-1095-12022-10631103331003311372-107631276111238-12022-9129-1202-1223310126-10026957612620-10828100522324232224232414232423232423232324241424232324";
private static string $apiSignature = "TaLY2pzBFdyUd2liBteJPh2E3t6BIbiQuVy6KAgsL5I="; // FIXME : Move this
private static string $apiSecret = "-1046012368-8940-10144-1095-12022-10631103331003311372-107631276111238-12022-9129-1202-1223310126-10026957612620-10828100522324232224232414232423232423232324241424232324";
public function __construct(string $endpoint)
{
@ -22,6 +22,7 @@ class Transport
public static function call(array $params)
{
$client = new Client([
'base_uri' => sprintf(
"%s%s",
@ -37,19 +38,25 @@ class Transport
'headers' => [
'Content-Type' => 'application/json',
'API-KEY' => self::$apiKey,
'API-SIGNATURE' => self::$apiSignature // FIXME : Utiliser la methode getApiSignature() quand on aura le secret fourni comme dans la doc
'API-SIGNATURE' => self::getApiSignature()
]
]);
$body = $response->getBody()->getContents();
return $body ? json_decode($body) : null;
$utf8_string = \mb_convert_encoding($body, 'UTF-8', 'ISO-8859-1'); // FIXME: Non bah non...
var_dump($body);exit;
return $body ? json_decode($utf8_string) : null;
} catch (ClientException $e) {
//echo Psr7\Message::toString($e->getRequest());
$response = json_decode($e->getResponse()->getBody()->getContents());
var_dump($response);
var_dump($e);exit;
echo Psr7\Message::toString($e->getRequest());
echo Psr7\Message::toString($e->getResponse());
//$response = json_decode($e->getResponse()->getBody()->getContents());
//var_dump($response);
exit;
} catch (ServerException $e) { // FIXME: L'API retourne 503 pour certains calls mais pas pour d'autres, le serveur n'est donc pas en maintenance.
var_dump($e);exit;
die('herde');
}
}