Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions lib/GaletteAuto/Auto.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Galette\Core\Plugins;
use Galette\Entity\Adherent;
use Laminas\Db\Sql\Expression;
use Psr\Http\Message\UploadedFileInterface;

/**
* Automobile Transmissions class for galette Auto plugin
Expand Down Expand Up @@ -386,10 +387,6 @@ public function store(bool $new = false): bool
strtoupper($this->name)
);
$this->history->load((int)$this->id);

//handle picture for newly added cars
$this->picture = new Picture($this->plugins, (int)$this->id);
$this->handlePicture();
} else {
$hist->add(_T("Fail to add new car.", "auto"));
throw new \Exception(
Expand Down Expand Up @@ -799,11 +796,6 @@ public function check(array $post): bool
}//switch
}//foreach

if (isset($this->id)) {
//handle picture for updated cars
$this->handlePicture();
}

//delete photo
if (isset($post['del_photo'])) {
if (!$this->picture->delete()) {
Expand Down Expand Up @@ -844,20 +836,18 @@ public function getRequired(): array
/**
* Handle car picture upload
*
* @return void
* @param array<UploadedFileInterface> $files Files sent
*
* @return bool
*/
private function handlePicture(): void
public function handleFiles(array $files): bool
{
// picture upload
if (isset($_FILES['photo'])) {
if ($_FILES['photo']['tmp_name'] != '') {
if (is_uploaded_file($_FILES['photo']['tmp_name'])) {
$res = $this->picture->store($_FILES['photo']);
if ($res < 0) {
$this->errors[] = $this->picture->getErrorMessage($res);
}
}
}
$this->errors = [];
$this->picture = new Picture($this->plugins, (int)$this->id);
if (!$this->picture->upload(request_files: $files, key: 'photo')) {
$this->errors = array_merge($this->errors, $this->picture->uploadErrors());
}

return !count($this->errors);
}
}
13 changes: 13 additions & 0 deletions lib/GaletteAuto/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ public function doAddEditVehicle(Request $request, Response $response, string $a

// initialize warnings
$error_detected = [];
$warning_detected = [];
$success_detected = [];

if (isset($post['id_adh'])) {
Expand Down Expand Up @@ -447,6 +448,9 @@ public function doAddEditVehicle(Request $request, Response $response, string $a
if (!$this->checkAclsFor($response, $id_adh, false) || $this->login->id == $id_adh) {
$route = $this->routeparser->urlFor('myVehiclesList');
}
if (!$auto->handleFiles($request->getUploadedFiles())) {
$warning_detected = $auto->getErrors();
}
}
}

Expand All @@ -467,6 +471,15 @@ public function doAddEditVehicle(Request $request, Response $response, string $a
}
}

if (count($warning_detected) > 0) {
foreach ($warning_detected as $warning) {
$this->flash->addMessage(
'warning_detected',
$warning
);
}
}

if (count($success_detected) > 0) {
foreach ($success_detected as $success) {
$this->flash->addMessage(
Expand Down