2019-07-19 15:23:00 +02:00
< ? php
namespace Modules\Interventi\API\v1 ;
use API\Interfaces\CreateInterface ;
use API\Interfaces\DeleteInterface ;
use API\Interfaces\RetrieveInterface ;
2019-07-19 16:51:52 +02:00
use API\Resource ;
2019-07-19 15:23:00 +02:00
2019-07-19 16:51:52 +02:00
class Sessioni extends Resource implements RetrieveInterface , CreateInterface , DeleteInterface
2019-07-19 15:23:00 +02:00
{
public function retrieve ( $request )
{
2019-07-19 16:51:52 +02:00
$user = $this -> getUser ();
2019-07-19 15:23:00 +02:00
$query = 'SELECT id, idtecnico AS id_tecnico, idintervento AS id_intervento, orario_inizio, orario_fine FROM in_interventi_tecnici WHERE `idintervento` = :id_intervento' ;
$parameters = [
':id_intervento' => $request [ 'id_intervento' ],
];
if ( $user [ 'gruppo' ] == 'Tecnici' ) {
$query .= ' AND `idtecnico` = :id_tecnico' ;
$parameters [ ':id_tecnico' ] = $user [ 'idanagrafica' ];
}
return [
'query' => $query ,
'parameters' => $parameters ,
];
}
public function create ( $request )
{
2019-07-19 16:51:52 +02:00
$user = $this -> getUser ();
2019-07-19 15:23:00 +02:00
$data = $request [ 'data' ];
add_tecnico ( $data [ 'id_intervento' ], $user [ 'idanagrafica' ], $data [ 'orario_inizio' ], $data [ 'orario_fine' ]);
}
public function delete ( $request )
{
$database = database ();
2019-07-19 16:51:52 +02:00
$user = $this -> getUser ();
2019-07-19 15:23:00 +02:00
$database -> query ( 'DELETE FROM `in_interventi_tecnici` WHERE `idintervento` = :id_intervento AND `idtecnico` = :id_tecnico' , [
':id_intervento' => $request [ 'id_intervento' ],
':id_tecnico' => $user [ 'idanagrafica' ],
]);
}
}