From 2da06652d9cb78f4c12ce4d1ea343065ed1329bb Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 12 Jun 2020 13:00:28 +0200 Subject: [PATCH] =?UTF-8?q?Filtro=20per=20far=20visualizzare=20al=20tecnic?= =?UTF-8?q?o=20loggato=20nell'APP=20solo=20le=20sue=20attivit=C3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/interventi/src/API/v1/Interventi.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/interventi/src/API/v1/Interventi.php b/modules/interventi/src/API/v1/Interventi.php index 99eb14188..c9dacf0eb 100755 --- a/modules/interventi/src/API/v1/Interventi.php +++ b/modules/interventi/src/API/v1/Interventi.php @@ -11,6 +11,7 @@ use Modules\Anagrafiche\Anagrafica; use Modules\Interventi\Intervento; use Modules\Interventi\Stato; use Modules\TipiIntervento\Tipo as TipoSessione; +use Auth; class Interventi extends Resource implements RetrieveInterface, CreateInterface, UpdateInterface { @@ -20,6 +21,7 @@ class Interventi extends Resource implements RetrieveInterface, CreateInterface, $today = date('Y-m-d'); $period_end = date('Y-m-d', strtotime($today.' +7 days')); $period_start = date('Y-m-d', strtotime($today.' -2 months')); + $user = Auth::user(); // AND `in_statiintervento`.`is_completato`=0 $query = "SELECT `in_interventi`.`id`, @@ -46,24 +48,39 @@ class Interventi extends Resource implements RetrieveInterface, CreateInterface, INNER JOIN `in_statiintervento` ON `in_interventi`.`idstatointervento` = `in_statiintervento`.`idstatointervento` INNER JOIN `an_anagrafiche` ON `in_interventi`.`idanagrafica` = `an_anagrafiche`.`idanagrafica` LEFT JOIN `an_sedi` ON `in_interventi`.`idsede_destinazione` = `an_sedi`.`id` + LEFT JOIN `in_interventi_tecnici` ON `in_interventi_tecnici`.`idintervento` = `in_interventi`.`id` WHERE EXISTS(SELECT `orario_fine` FROM `in_interventi_tecnici` WHERE `in_interventi_tecnici`.`idintervento` = `in_interventi`.`id` AND `orario_fine` BETWEEN :period_start AND :period_end)"; + //Filtro per far visualizzare al tecnico loggato solo le sue attività + $filters = []; + $filters[] = 'in_interventi_tecnici.idtecnico ='.$user->idanagrafica; + $query .= !empty($filters) ? ' AND ('.implode('OR ', $filters).')' : ''; + $query .= ' HAVING 2=2 ORDER BY `in_interventi`.`data_richiesta` DESC'; - + $parameters = [ ':period_end' => $period_end, ':period_start' => $period_start, ]; + + + $module = Modules::get('Interventi'); + + $query = Modules::replaceAdditionals($module->id, $query); + + return [ 'query' => $query, 'parameters' => $parameters, ]; + + } public function create($request)