- Implemented CRUD operations for order attachments, including adding, listing, downloading, and deleting. - Updated `db_object_t` and `attachments` to enhance object-attachment interactions with new methods for formatting, creating, and managing attachments. - Added new routes (`/orders/attachments` and `/attachments/upload`) for attachment-related functionality. - Adjusted `file_server.php` to handle temp file downloads and attachment storage. - Improved typing and error handling across attachment helper methods and classes.
44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
use attachments\helpers\attachment;
|
|
use attachments\helpers\attachment_content;
|
|
use classes\attachment_store;
|
|
use classes\attachments;
|
|
use classes\response;
|
|
use objects\orders_o;
|
|
use traits\route_t;
|
|
|
|
class attachmentsRoute
|
|
{
|
|
use route_t;
|
|
|
|
public function run(): void
|
|
{
|
|
$this->get('/attachments/example', function () {
|
|
global $response;
|
|
throw new \Exception('EXAMPLE ROUTE, SHOULD BE IMPLEMENTED IN THE INDIVIDUAL OBJECT ROUTES');
|
|
$orders_o = new orders_o();
|
|
$orders_o->select(22636);
|
|
// Debug: Create an attachment
|
|
$orders_o->addAttachment((new attachment_content())->setOther('Hello World!'));
|
|
$response->success($orders_o->listAttachments());
|
|
});
|
|
$this->post('/attachments/upload', function () {
|
|
global $response;
|
|
self::requireParameters(['base64_image']);
|
|
$base64_image = self::getParameter('base64_image');
|
|
//self::requirePermission('modules_scanner_lpr');
|
|
if (empty($base64_image)) {
|
|
$response->error('Base64 image is required.');
|
|
}
|
|
$uploads = new attachment_store();
|
|
$object_name = $uploads->storeTempImageFromBase64(
|
|
$base64_image
|
|
);
|
|
echo $object_name;
|
|
$response->success(['object_name' => $object_name]);
|
|
});
|
|
}
|
|
} |