openstamanager/src/API/Common/Allegato.php

63 lines
1.9 KiB
PHP
Raw Normal View History

2018-07-31 14:50:28 +02:00
<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.n.c.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2018-07-31 14:50:28 +02:00
namespace API\Common;
2019-07-19 15:23:00 +02:00
use API\Interfaces\CreateInterface;
2020-07-28 16:37:44 +02:00
use API\Interfaces\RetrieveInterface;
2019-07-19 16:51:52 +02:00
use API\Resource;
2019-08-01 16:02:42 +02:00
use Models\Upload;
2019-07-19 15:23:00 +02:00
use Modules;
2020-07-28 16:37:44 +02:00
class Allegato extends Resource implements RetrieveInterface, CreateInterface
2019-07-19 15:23:00 +02:00
{
public function create($request)
{
2018-07-31 14:50:28 +02:00
$module = Modules::get($request['module']);
2019-08-01 16:02:42 +02:00
$name = !empty($request['name']) ? $request['name'] : null;
$category = !empty($request['category']) ? $request['category'] : null;
$upload = Upload::build($_FILES['upload'], [
2018-07-31 14:50:28 +02:00
'id_module' => $module['id'],
2018-08-20 13:09:27 +02:00
'id_record' => $request['id'],
2019-08-01 16:02:42 +02:00
], $name, $category);
2018-07-31 14:50:28 +02:00
2020-07-28 16:37:44 +02:00
return [
2019-08-01 16:02:42 +02:00
'id' => $upload->id,
'filename' => $upload->filename,
2019-07-19 15:23:00 +02:00
];
}
2020-07-28 16:37:44 +02:00
public function retrieve($request)
{
$upload = Upload::where('name', $request['name'])
->where('id', $request['id'])
->where('id_record', $request['id_record'])
->first();
if (!empty($upload)) {
download(base_dir().'/'.$upload->filepath, $upload->original_name);
2020-07-28 16:37:44 +02:00
}
return [
'custom' => '',
];
}
2018-07-31 14:50:28 +02:00
}