mirror of
https://github.com/Karaka-Management/oms-ClientManagement.git
synced 2026-01-11 15:28:41 +00:00
Add client files
This commit is contained in:
parent
533c6ff4f5
commit
dcb35e94dd
|
|
@ -106,11 +106,6 @@
|
|||
"null": false,
|
||||
"foreignTable": "clientmgmt_client",
|
||||
"foreignKey": "clientmgmt_client_id"
|
||||
},
|
||||
"clientmgmt_client_media_type": {
|
||||
"name": "clientmgmt_client_media_type",
|
||||
"type": "TINYINT",
|
||||
"null": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use Modules\ClientManagement\Models\Client;
|
|||
use Modules\ClientManagement\Models\ClientMapper;
|
||||
use Modules\Profile\Models\ContactElementMapper;
|
||||
use Modules\Profile\Models\Profile;
|
||||
use Modules\Media\Models\PathSettings;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\Message\NotificationLevel;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
|
|
@ -151,4 +152,50 @@ final class ApiController extends Controller
|
|||
);
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Contact Element', 'Contact element successfully created', $contactElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create item files
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiFileCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
$uploadedFiles = $request->getFiles() ?? [];
|
||||
|
||||
if (empty($uploadedFiles)) {
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Item', 'Invalid client image', $uploadedFiles);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
|
||||
$request->getData('name') ?? '',
|
||||
$uploadedFiles,
|
||||
$request->header->account,
|
||||
'Modules/Media/Files/Modules/ClientManagement/' . ($request->getData('client') ?? '0'),
|
||||
'/Modules/ClientManagement/' . ($request->getData('client') ?? '0'),
|
||||
$request->getData('type') ?? '',
|
||||
'',
|
||||
'',
|
||||
PathSettings::FILE_PATH
|
||||
);
|
||||
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
(int) $request->getData('client'),
|
||||
\reset($uploaded)->getId(),
|
||||
ClientMapper::class, 'files', '', $request->getOrigin()
|
||||
);
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Image', 'Image successfully updated', $uploaded);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/ClientManagement/Theme/Backend/client-list');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003102001, $request, $response));
|
||||
|
||||
$client = ClientMapper::getAll();
|
||||
$client = ClientMapper::getAfterPivot(0, null, 25);
|
||||
$view->addData('client', $client);
|
||||
|
||||
return $view;
|
||||
|
|
|
|||
|
|
@ -299,4 +299,45 @@ class Client
|
|||
{
|
||||
$this->contactElements[] = $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get media file by type
|
||||
*
|
||||
* @param string $type Media type
|
||||
*
|
||||
* @return Media
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getFileByType(string $type) : Media
|
||||
{
|
||||
foreach ($this->files as $file) {
|
||||
if ($file->type === $type) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
return new NullMedia();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all media files by type
|
||||
*
|
||||
* @param string $type Media type
|
||||
*
|
||||
* @return Media[]
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getFilesByType(string $type) : array
|
||||
{
|
||||
$files = [];
|
||||
foreach ($this->files as $file) {
|
||||
if ($file->type === $type) {
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,8 +99,8 @@ final class ClientMapper extends DataMapperAbstract
|
|||
'files' => [
|
||||
'mapper' => MediaMapper::class, /* mapper of the related object */
|
||||
'table' => 'clientmgmt_client_media', /* table of the related object, null if no relation table is used (many->1) */
|
||||
'external' => 'clientmgmt_client_media_src',
|
||||
'self' => 'clientmgmt_client_media_dst',
|
||||
'external' => 'clientmgmt_client_media_dst',
|
||||
'self' => 'clientmgmt_client_media_src',
|
||||
],
|
||||
'contactElements' => [
|
||||
'mapper' => ContactElementMapper::class,
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ echo $this->getData('nav')->render(); ?>
|
|||
<table id="iSalesClientList" class="default">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<td><?= $this->getHtml('ID', '0', '0'); ?>
|
||||
<input id="clientList-r1-asc" name="clientList-sort" type="radio"><label for="clientList-r1-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
|
||||
<input id="clientList-r1-desc" name="clientList-sort" type="radio"><label for="clientList-r1-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
|
||||
|
|
@ -46,8 +47,14 @@ echo $this->getData('nav')->render(); ?>
|
|||
<input id="clientList-r8-desc" name="clientList-sort" type="radio"><label for="clientList-r8-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
|
||||
<tbody>
|
||||
<?php $count = 0; foreach ($clients as $key => $value) : ++$count;
|
||||
$url = UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $value->getId()); ?>
|
||||
$url = UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $value->getId());
|
||||
$image = $value->getFileByType('backend_image');
|
||||
?>
|
||||
<tr data-href="<?= $url; ?>">
|
||||
<td><a href="<?= $url; ?>"><img width="30" loading="lazy" class="item-image"
|
||||
src="<?= $image instanceof NullMedia ?
|
||||
UriFactory::build('Web/Backend/img/user_default_' . \mt_rand(1, 6) .'.png') :
|
||||
UriFactory::build('{/prefix}' . $image->getPath()); ?>"></a>
|
||||
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->number); ?></a>
|
||||
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->profile->account->name1); ?> <?= $this->printHtml($value->profile->account->name2); ?></a>
|
||||
<td data-label="<?= $this->getHtml('City'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->mainAddress->city); ?></a>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user