Verified Commit 687b48b7 authored by David Beniamine's avatar David Beniamine
Browse files

Toggle LD extends

parent a8e15c4c
......@@ -514,4 +514,18 @@ class ReportController extends Controller
return readfile($filepath);
}
}
/**
* Toggles all LDs of the report
*
* @param \Illuminate\Http\Request $request
* @param \App\Report $report
* @return \Illuminate\Http\Response
*/
public function toggleAllLD(Request $request, Report $report)
{
$user = Auth::user();
abort_if($user->cannot('view', $report), Helper::pullPolicyErrorCode(), Helper::pullPolicyErrorMessage());
$report->toggleAllLD($user->id_user, (int) $request->input('extend'));
}
}
......@@ -925,4 +925,25 @@ ORDER BY labdoc.id_report_part, labdoc.position"
// dd($new_lds);
return $new_lds->nb_ld;
}
/**
* Toggles all labdocs from a report for a user
* @param int $id_usr
* @param int extend should we extend or close the LDs
*/
public function toggleAllLd($id_user, $extend)
{
$sql = "UPDATE labdoc_status
JOIN labdoc USING(id_labdoc)
SET extend = :extend
WHERE id_user = :id_user
AND id_report = :id_report
AND labdoc.deleted IS NULL
AND id_report_part IS NOT NULL";
DB::update($sql, [
'extend' => $extend,
'id_user' => $id_user,
'id_report' => $this->id_report
]);
}
}
......@@ -232,16 +232,13 @@ function showAllLD() {
icon.attr('title', "Replier le LabDoc");
}
});
/*$.ajax({
method: 'POST',
url: "/report/"+window.global_id_report+"/toggleAllLD",
data: {
"extend": 1
}
TODO : UPDATE labdoc_status JOIN labdoc USING(id_labdoc) SET extend = $extend WHERE id_user = $id_user AND id_report = $id_report AND deleted IS NULL AND id_report_part IS NOT NULL
});*/
$.ajax({
method: 'POST',
url: "/report/"+window.global_id_report+"/toggleAllLD",
data: {
"extend": 1
}
});
}
function hideAll() {
......@@ -255,16 +252,13 @@ function hideAll() {
icon.attr('title', "Déplier le LabDoc");
}
});
/*$.ajax({
method: 'POST',
url: "/report/"+window.global_id_report+"/toggleAllLD",
data: {
"extend": 0
}
TODO : UPDATE labdoc_status JOIN labdoc USING(id_labdoc) SET extend = $extend WHERE id_user = $id_user AND id_report = $id_report AND deleted IS NULL AND id_report_part IS NOT NULL
});*/
$.ajax({
method: 'POST',
url: "/report/"+window.global_id_report+"/toggleAllLD",
data: {
"extend": 0
}
});
}
function hideStar(id_ld) {
......
......@@ -96,6 +96,7 @@ Route::middleware(['auth'])->group(function () {
Route::post('report/{report}/trace', 'ReportController@trace');
Route::post('report/{report}/submit', 'ReportController@submit');
Route::post('report/{report}/displayLDToImport', 'ReportController@displayLDToImport');
Route::post('report/{report}/toggleAllLD', 'ReportController@toggleAllLD');
// Labdoc
Route::get('labdoc/{labdoc}/', 'LabdocController@show');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment