Suppression du 'code' de 'machine'
This commit is contained in:
parent
bbcad9c909
commit
6d283b69a7
|
@ -240,7 +240,6 @@
|
||||||
"description": "Création d'une nouvelle machine.",
|
"description": "Création d'une nouvelle machine.",
|
||||||
"permissions": ["warehouse", "admin"],
|
"permissions": ["warehouse", "admin"],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"code": { "description": "Code RFID de la machine.", "type": "rfid" },
|
|
||||||
"name": { "description": "Nom de la machine.", "type": "varchar(1,30,alphanumeric)" }
|
"name": { "description": "Nom de la machine.", "type": "varchar(1,30,alphanumeric)" }
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
|
@ -300,17 +299,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"getByCode": {
|
|
||||||
"description": "Retourne les données d'une machine de code RFID donné.",
|
|
||||||
"permissions": ["warehouse", "admin"],
|
|
||||||
"parameters": {
|
|
||||||
"code": { "description": "Code RFID de la machine.", "type": "rfid" }
|
|
||||||
},
|
|
||||||
"output": {
|
|
||||||
"machine": { "description": "Données de la machine.", "type": "array<mixed>" }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
"getByName": {
|
"getByName": {
|
||||||
"description": "Retourne les données d'une machine de nom donné.",
|
"description": "Retourne les données d'une machine de nom donné.",
|
||||||
"permissions": ["warehouse", "admin"],
|
"permissions": ["warehouse", "admin"],
|
||||||
|
@ -338,7 +326,6 @@
|
||||||
"permissions": ["warehouse", "admin"],
|
"permissions": ["warehouse", "admin"],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"id_machine": { "description": "UID de la machine.", "type": "id" },
|
"id_machine": { "description": "UID de la machine.", "type": "id" },
|
||||||
"code": { "description": "Code RFID de la machine.", "type": "rfid", "optional": true },
|
|
||||||
"name": { "description": "Nom de la machine.", "type": "varchar(1,30,alphanumeric)", "optional": true }
|
"name": { "description": "Nom de la machine.", "type": "varchar(1,30,alphanumeric)", "optional": true }
|
||||||
},
|
},
|
||||||
"output": {}
|
"output": {}
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
|
|
||||||
"getAll",
|
"getAll",
|
||||||
"getById",
|
"getById",
|
||||||
"getByCode",
|
|
||||||
"getByName",
|
"getByName",
|
||||||
|
|
||||||
"checkToken",
|
"checkToken",
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
/* CREATION D'UNE NOUVELLE MACHINE DANS LA BDD
|
/* CREATION D'UNE NOUVELLE MACHINE DANS LA BDD
|
||||||
*
|
*
|
||||||
* @code<String> Code RFID de la machine
|
|
||||||
* @name<String> Identifiant de la machine
|
* @name<String> Identifiant de la machine
|
||||||
*
|
*
|
||||||
* @return status<Boolean> Retourne si oui ou non, tout s'est bien passe
|
* @return status<Boolean> Retourne si oui ou non, tout s'est bien passe
|
||||||
|
@ -25,10 +24,9 @@
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$create_machine = new Repo('machine/create', [
|
$create_machine = new Repo('machine/create', [
|
||||||
$_SESSION['WAREHOUSE']['id'],
|
$_SESSION['WAREHOUSE']['id'],
|
||||||
$code,
|
|
||||||
$name
|
$name
|
||||||
]);
|
]);
|
||||||
$id_machine = $create_machine->answer();
|
$id_machine = $create_machine->answer();
|
||||||
|
|
||||||
// Si une erreur est retournee, on retourne une erreur
|
// Si une erreur est retournee, on retourne une erreur
|
||||||
if( $id_machine === false )
|
if( $id_machine === false )
|
||||||
|
@ -201,35 +199,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* RENVOIE LA MACHINE DE CODE DONNE
|
|
||||||
*
|
|
||||||
* @code<String> Code de la machine en question
|
|
||||||
*
|
|
||||||
* @return machine<Array> Machine de code donne
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static function getByCode($params){
|
|
||||||
extract($params);
|
|
||||||
|
|
||||||
// On recupere les donnees
|
|
||||||
$request = new Repo('machine/getByCode', [
|
|
||||||
$_SESSION['WAREHOUSE']['id'],
|
|
||||||
$code
|
|
||||||
]);
|
|
||||||
$answer = $request->answer();
|
|
||||||
|
|
||||||
// Si aucun resultat, on retourne une erreur
|
|
||||||
if( $answer === false )
|
|
||||||
return [ 'ModuleError' => ManagerError::NoMatchFound ];
|
|
||||||
|
|
||||||
|
|
||||||
return [ 'machine' => $answer ];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* RENVOIE LA MACHINE DE NAME DONNE
|
/* RENVOIE LA MACHINE DE NAME DONNE
|
||||||
*
|
*
|
||||||
* @name<String> Name de l'utilisateur en question
|
* @name<String> Name de l'utilisateur en question
|
||||||
|
@ -292,7 +261,6 @@
|
||||||
/* MODIFIE UNE MACHINE DONNEE
|
/* MODIFIE UNE MACHINE DONNEE
|
||||||
*
|
*
|
||||||
* @id_machine<int> UID de la machine
|
* @id_machine<int> UID de la machine
|
||||||
* @code<String> Code RFID de la machine
|
|
||||||
* @name<String> Identifiant l'utilisateur
|
* @name<String> Identifiant l'utilisateur
|
||||||
*
|
*
|
||||||
* @return status<Boolean> Retourne si oui ou non tout s'est bien deroule
|
* @return status<Boolean> Retourne si oui ou non tout s'est bien deroule
|
||||||
|
@ -322,13 +290,11 @@
|
||||||
|
|
||||||
/* (1) Verification des parametres (si correct et different)*/
|
/* (1) Verification des parametres (si correct et different)*/
|
||||||
$correct_param = [
|
$correct_param = [
|
||||||
'code' => !is_null($code) && $machine_data['code'] != $code,
|
|
||||||
'name' => !is_null($name) && $machine_data['name'] != $name
|
'name' => !is_null($name) && $machine_data['name'] != $name
|
||||||
];
|
];
|
||||||
|
|
||||||
/* (2) Gestion des parametres optionnels */
|
/* (2) Gestion des parametres optionnels */
|
||||||
$opt_data = [
|
$opt_data = [
|
||||||
'code' => ($correct_param['code']) ? $code : $machine_data['code'],
|
|
||||||
'name' => ($correct_param['name']) ? $name : $machine_data['name']
|
'name' => ($correct_param['name']) ? $name : $machine_data['name']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -338,7 +304,6 @@
|
||||||
$request = new Repo('machine/edit', [
|
$request = new Repo('machine/edit', [
|
||||||
$_SESSION['WAREHOUSE']['id'],
|
$_SESSION['WAREHOUSE']['id'],
|
||||||
$id_machine,
|
$id_machine,
|
||||||
$opt_data['code'],
|
|
||||||
$opt_data['name']
|
$opt_data['name']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -12,37 +12,35 @@
|
||||||
/* CREATION D'UNE MACHINE
|
/* CREATION D'UNE MACHINE
|
||||||
*
|
*
|
||||||
* @id_warehouse<int> UID de l'entrepot
|
* @id_warehouse<int> UID de l'entrepot
|
||||||
* @code<String> Code de la machine
|
|
||||||
* @name<String> Nom de la machine
|
* @name<String> Nom de la machine
|
||||||
*
|
*
|
||||||
* @return id_machine<int> Renvoie l'UID de la machine cree
|
* @return id_machine<int> Renvoie l'UID de la machine cree
|
||||||
* Renvoie FALSE si une erreur occure
|
* Renvoie FALSE si une erreur occure
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function create($id_warehouse, $code, $name){
|
public static function create($id_warehouse, $name){
|
||||||
/* [1] Verification de l'unicite de code+name
|
/* [1] Verification de l'unicite de name
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$check_unique = ( self::getByCode($code) === false );
|
$check_unique = self::getByName($id_warehouse, $name) === false;
|
||||||
$check_unique = $check_unique && ( self::getByName($name) === false );
|
|
||||||
|
|
||||||
// Si une machine a deja ce code/nom, on renvoie une erreur
|
// Si une machine a deja ce nom, on renvoie une erreur
|
||||||
if( !$check_unique )
|
if( !$check_unique )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
/* [2] Creation de la machine
|
/* [2] Creation de la machine
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$insert_machine = Database::getPDO()->prepare("INSERT INTO machine(id_machine, id_warehouse, code, name)
|
$insert_machine = Database::getPDO()->prepare("INSERT INTO machine(id_machine, id_warehouse, name, token)
|
||||||
VALUES(DEFAULT, :id_warehouse, :code, :name)");
|
VALUES(DEFAULT, :id_warehouse, :name, :token)");
|
||||||
$insert_machine->execute([
|
$insert_machine->execute([
|
||||||
':id_warehouse' => $id_warehouse,
|
':id_warehouse' => $id_warehouse,
|
||||||
':code' => $code,
|
':name' => $name,
|
||||||
':name' => $name
|
':token' => sessionManager::secure_hash( uniqid() )
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/* [3] On retourne l'id_machine ou FALSE si erreur
|
/* [3] On retourne l'id_machine ou FALSE si erreur
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$check_machine = self::getByCode($code);
|
$check_machine = self::getByName($id_warehouse, $name);
|
||||||
|
|
||||||
// Si n'existe pas on retourne FALSE
|
// Si n'existe pas on retourne FALSE
|
||||||
if( $check_machine === false )
|
if( $check_machine === false )
|
||||||
|
@ -67,12 +65,9 @@
|
||||||
*/
|
*/
|
||||||
public static function search($id_warehouse, $keyword){
|
public static function search($id_warehouse, $keyword){
|
||||||
// On recupere les donnees
|
// On recupere les donnees
|
||||||
$searchmachines = Database::getPDO()->prepare("SELECT id_machine, code, name FROM machine
|
$searchmachines = Database::getPDO()->prepare("SELECT id_machine, name FROM machine
|
||||||
WHERE id_warehouse = :id_warehouse
|
WHERE id_warehouse = :id_warehouse
|
||||||
AND ( code LIKE '%".$keyword."%'
|
AND name LIKE '%".$keyword."%'");
|
||||||
OR name LIKE '%".$keyword."%'
|
|
||||||
)
|
|
||||||
");
|
|
||||||
|
|
||||||
$searchmachines->execute([
|
$searchmachines->execute([
|
||||||
':id_warehouse' => $id_warehouse
|
':id_warehouse' => $id_warehouse
|
||||||
|
@ -127,35 +122,30 @@
|
||||||
*
|
*
|
||||||
* @id_warehouse<int> UID de l'entrepot
|
* @id_warehouse<int> UID de l'entrepot
|
||||||
* @id_machine<int> UID de la machine
|
* @id_machine<int> UID de la machine
|
||||||
* @code<String> Code RFID de la machine
|
|
||||||
* @name<String> Identifiant l'utilisateur
|
* @name<String> Identifiant l'utilisateur
|
||||||
*
|
*
|
||||||
* @return status<Boolean> Renvoie si oui ou non tout s'est bien passe
|
* @return status<Boolean> Renvoie si oui ou non tout s'est bien passe
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function edit($id_warehouse, $id_machine=null, $code=null, $name=null){
|
public static function edit($id_warehouse, $id_machine=null, $name=null){
|
||||||
/* [1] Verification de l'unicite de code+name (si differents)
|
/* [1] Verification de l'unicite de name (si differents)
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
// On recupere les machine ayant le meme code ou name (si existent)
|
// On recupere les machine ayant le meme name (si existent)
|
||||||
$getbycode = self::getByCode($id_warehouse, $code);
|
|
||||||
$getbyname = self::getByName($id_warehouse, $name);
|
$getbyname = self::getByName($id_warehouse, $name);
|
||||||
|
|
||||||
$check_unique = is_array($getbycode) && $getbycode['id_machine'] == $id_machine || !is_array($getbycode);
|
$check_unique = is_array($getbyname) && $getbyname['id_machine'] == $id_machine || !is_array($getbyname);
|
||||||
$check_unique = $check_unique && is_array($getbyname) && $getbyname['id_machine'] == $id_machine || !is_array($getbyname);
|
|
||||||
|
|
||||||
// Si un utilisateur a deja ce code ou ce name (sauf lui), on renvoie une erreur
|
// Si un utilisateur a deja ce name (sauf lui), on renvoie une erreur
|
||||||
if( !$check_unique )
|
if( !$check_unique )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* [2] Modification de la machine
|
/* [2] Modification de la machine
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$edit_machine = Database::getPDO()->prepare("UPDATE machine
|
$edit_machine = Database::getPDO()->prepare("UPDATE machine
|
||||||
SET code = :code,
|
SET name = :name
|
||||||
name = :name
|
|
||||||
WHERE id_machine = :id_machine
|
WHERE id_machine = :id_machine
|
||||||
AND id_warehouse = :id_warehouse");
|
AND id_warehouse = :id_warehouse");
|
||||||
$edit_machine->execute([
|
$edit_machine->execute([
|
||||||
':code' => $code,
|
|
||||||
':name' => $name,
|
':name' => $name,
|
||||||
':id_machine' => $id_machine,
|
':id_machine' => $id_machine,
|
||||||
':id_warehouse' => $id_warehouse
|
':id_warehouse' => $id_warehouse
|
||||||
|
@ -168,7 +158,6 @@
|
||||||
$check_machine = self::getById($id_warehouse, $id_machine);
|
$check_machine = self::getById($id_warehouse, $id_machine);
|
||||||
|
|
||||||
$checker = $check_machine['id_machine'] == $id_machine;
|
$checker = $check_machine['id_machine'] == $id_machine;
|
||||||
$checker = $checker && $check_machine['code'] == $code;
|
|
||||||
$checker = $checker && $check_machine['name'] == $name;
|
$checker = $checker && $check_machine['name'] == $name;
|
||||||
|
|
||||||
// On retourne l'etat de la modification
|
// On retourne l'etat de la modification
|
||||||
|
@ -227,7 +216,7 @@
|
||||||
public static function getById($id_warehouse, $id_machine){
|
public static function getById($id_warehouse, $id_machine){
|
||||||
/* [1] On rédige/execute la requête
|
/* [1] On rédige/execute la requête
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
|
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.name
|
||||||
FROM machine as m
|
FROM machine as m
|
||||||
WHERE m.id_warehouse = :id_warehouse
|
WHERE m.id_warehouse = :id_warehouse
|
||||||
AND m.id_machine = :id_machine");
|
AND m.id_machine = :id_machine");
|
||||||
|
@ -255,46 +244,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* RETOURNE UNE MACHINE SPECIFIQUE
|
|
||||||
*
|
|
||||||
* @id_warehouse<id> UID de l'entrepot
|
|
||||||
* @code<String> Code RFID de la machine
|
|
||||||
*
|
|
||||||
* @return machine<Array> Données de la machine
|
|
||||||
* FALSE si aucun résultat
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static function getByCode($id_warehouse, $code){
|
|
||||||
/* [1] On rédige/execute la requête
|
|
||||||
=========================================================*/
|
|
||||||
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
|
|
||||||
FROM machine as m
|
|
||||||
WHERE m.id_warehouse = :id_warehouse
|
|
||||||
AND m.code = :code");
|
|
||||||
$get->execute([
|
|
||||||
':id_warehouse' => $id_warehouse,
|
|
||||||
':code' => $code
|
|
||||||
]);
|
|
||||||
|
|
||||||
/* [2] Gestion des données
|
|
||||||
=========================================================*/
|
|
||||||
$found = $get->fetch();
|
|
||||||
|
|
||||||
// Si aucun résultat
|
|
||||||
if( $found === false )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return Database::delNumeric( $found, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* RETOURNE UNE MACHINE SPECIFIQUE
|
/* RETOURNE UNE MACHINE SPECIFIQUE
|
||||||
*
|
*
|
||||||
* @id_warehouse<id> UID de l'entrepot
|
* @id_warehouse<id> UID de l'entrepot
|
||||||
|
@ -307,7 +256,7 @@
|
||||||
public static function getByName($id_warehouse, $name){
|
public static function getByName($id_warehouse, $name){
|
||||||
/* [1] On rédige/execute la requête
|
/* [1] On rédige/execute la requête
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
|
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.name
|
||||||
FROM machine as m
|
FROM machine as m
|
||||||
WHERE m.id_warehouse = :id_warehouse
|
WHERE m.id_warehouse = :id_warehouse
|
||||||
AND m.name = :name");
|
AND m.name = :name");
|
||||||
|
@ -347,7 +296,7 @@
|
||||||
public static function getByToken($id_warehouse, $token){
|
public static function getByToken($id_warehouse, $token){
|
||||||
/* [1] On rédige/execute la requête
|
/* [1] On rédige/execute la requête
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
|
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.name
|
||||||
FROM machine as m
|
FROM machine as m
|
||||||
WHERE m.id_warehouse = :id_warehouse
|
WHERE m.id_warehouse = :id_warehouse
|
||||||
AND m.token = :token");
|
AND m.token = :token");
|
||||||
|
@ -385,7 +334,7 @@
|
||||||
public static function getAll($id_warehouse){
|
public static function getAll($id_warehouse){
|
||||||
/* [1] On rédige/execute la requête
|
/* [1] On rédige/execute la requête
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.code, m.name
|
$get = Database::getPDO()->prepare("SELECT m.id_machine, m.name
|
||||||
FROM machine as m
|
FROM machine as m
|
||||||
WHERE m.id_warehouse = :id_warehouse");
|
WHERE m.id_warehouse = :id_warehouse");
|
||||||
$get->execute([
|
$get->execute([
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
|
|
||||||
/* [1] Affichage des machines
|
/* [1] Affichage des machines
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
|
debug();
|
||||||
$request = new ModuleRequest('machineDefault/getAll'); // On utilise la methode 'getAll' du module 'machineDefault'
|
$request = new ModuleRequest('machineDefault/getAll'); // On utilise la methode 'getAll' du module 'machineDefault'
|
||||||
$answer = $request->dispatch(); // On recupere la reponse
|
$answer = $request->dispatch(); // On recupere la reponse
|
||||||
|
|
||||||
|
@ -63,7 +64,6 @@
|
||||||
|
|
||||||
// Si aucune erreur, on affiche les resultats
|
// Si aucune erreur, on affiche les resultats
|
||||||
else{
|
else{
|
||||||
|
|
||||||
// Barre de recherche
|
// Barre de recherche
|
||||||
echo "<input type='text' class='searchbar' placeholder='Recherche'>";
|
echo "<input type='text' class='searchbar' placeholder='Recherche'>";
|
||||||
|
|
||||||
|
@ -98,17 +98,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Code RFID
|
|
||||||
echo "<span class='code'>";
|
|
||||||
echo file_get_contents( __ROOT__.'/src/static/container/card.svg' );
|
|
||||||
|
|
||||||
echo "<span>";
|
|
||||||
echo $machine['code'];
|
|
||||||
echo "</span>";
|
|
||||||
echo"</span>";
|
|
||||||
|
|
||||||
// Groupes de la machine
|
// Groupes de la machine
|
||||||
echo "<span class='groups'>";
|
echo "<span class='groups'>";
|
||||||
echo file_get_contents( __ROOT__.'/src/static/container/group.svg' );
|
echo file_get_contents( __ROOT__.'/src/static/container/group.svg' );
|
||||||
|
|
Loading…
Reference in New Issue