Merge branch '428-cmb-new-api-calls' into '424-cmb-release'
Add other_images parameter to upload photos API calls. #428 See merge request jankstudio/resq!496
This commit is contained in:
commit
131bc9c3f6
2 changed files with 163 additions and 8 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
|
|
@ -48,6 +49,22 @@ class JOExtra
|
|||
*/
|
||||
protected $after_batt_image_filename;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="array", nullable=true)
|
||||
*/
|
||||
protected $before_other_images;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="array", nullable=true)
|
||||
*/
|
||||
protected $after_other_images;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->before_other_images = new ArrayCollection();
|
||||
$this->after_other_images = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
|
|
@ -59,7 +76,7 @@ class JOExtra
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getBeforeSpeedImageFilename($image_filename)
|
||||
public function getBeforeSpeedImageFilename()
|
||||
{
|
||||
return $this->before_speed_image_filename;
|
||||
}
|
||||
|
|
@ -70,7 +87,7 @@ class JOExtra
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getBeforePlateNumImageFilename($image_filename)
|
||||
public function getBeforePlateNumImageFilename()
|
||||
{
|
||||
return $this->before_plate_num_image_filename;
|
||||
}
|
||||
|
|
@ -81,7 +98,7 @@ class JOExtra
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getBeforeBattImageFilename($image_filename)
|
||||
public function getBeforeBattImageFilename()
|
||||
{
|
||||
return $this->before_batt_image_filename;
|
||||
}
|
||||
|
|
@ -91,7 +108,7 @@ class JOExtra
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getAfterSpeedImageFilename($image_filename)
|
||||
public function getAfterSpeedImageFilename()
|
||||
{
|
||||
return $this->after_speed_image_filename;
|
||||
}
|
||||
|
|
@ -102,7 +119,7 @@ class JOExtra
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getAfterPlateNumImageFilename($image_filename)
|
||||
public function getAfterPlateNumImageFilename()
|
||||
{
|
||||
return $this->after_plate_num_image_filename;
|
||||
}
|
||||
|
|
@ -113,10 +130,55 @@ class JOExtra
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getAfterBattImageFilename($image_filename)
|
||||
public function getAfterBattImageFilename()
|
||||
{
|
||||
return $this->after_batt_image_filename;
|
||||
}
|
||||
|
||||
public function getBeforeOtherImages()
|
||||
{
|
||||
return $this->before_other_images;
|
||||
}
|
||||
|
||||
public function setBeforeOtherImages(array $images)
|
||||
{
|
||||
$this->before_other_images = new ArrayCollection();
|
||||
|
||||
foreach ($images as $image_filename)
|
||||
{
|
||||
$this->before_other_images->add($image_filename);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearBeforeOtherImages()
|
||||
{
|
||||
$this->before_other_images = new ArrayCollection();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAfterOtherImages()
|
||||
{
|
||||
return $this->after_other_images;
|
||||
}
|
||||
|
||||
public function setAfterOtherImages(array $images)
|
||||
{
|
||||
$this->after_other_images = new ArrayCollection();
|
||||
|
||||
foreach ($images as $image_filename)
|
||||
{
|
||||
$this->after_other_images->add($image_filename);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearAfterOtherImages()
|
||||
{
|
||||
$this->after_other_images = new ArrayCollection();
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1417,6 +1417,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$speed_img_file = $req->files->get('speedomtr_img');
|
||||
$batt_img_file = $req->files->get('battery_img');
|
||||
$plate_num_img_file = $req->files->get('plate_number_img');
|
||||
$other_img_files[]= $req->files->get('other_images');
|
||||
|
||||
if ((empty($speed_img_file)) &&
|
||||
(empty($batt_img_file)) &&
|
||||
|
|
@ -1433,6 +1434,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$new_speed_filename = '';
|
||||
$new_batt_filename = '';
|
||||
$new_plate_num_filename = '';
|
||||
$other_filenames = [];
|
||||
|
||||
if (!empty($speed_img_file))
|
||||
{
|
||||
|
|
@ -1489,6 +1491,32 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($other_img_files as $other_img_file)
|
||||
{
|
||||
if (!(empty($other_img_file)))
|
||||
{
|
||||
foreach($other_img_file as $other_img)
|
||||
{
|
||||
$orig_other_filename = pathinfo($other_img->getClientOriginalName(), PATHINFO_FILENAME);
|
||||
$new_other_filename = uniqid() . '-'. $orig_other_filename . '.' . $other_img->guessClientExtension();
|
||||
|
||||
$other_filenames[] = $new_other_filename;
|
||||
|
||||
try
|
||||
{
|
||||
$other_img->move($dest, $new_other_filename);
|
||||
}
|
||||
catch (FileException $e)
|
||||
{
|
||||
$data = [
|
||||
'error' => 'Error saving image files.'
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$jo_extra = $jo->getJOExtra();
|
||||
if ($jo_extra == null)
|
||||
{
|
||||
|
|
@ -1499,6 +1527,15 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$jo_extra->setBeforeBattImageFilename($new_batt_filename);
|
||||
$jo_extra->setBeforePlateNumImageFilename($new_plate_num_filename);
|
||||
|
||||
if (empty($other_filenames))
|
||||
{
|
||||
$jo_extra->clearBeforeOtherImages();
|
||||
}
|
||||
else
|
||||
{
|
||||
$jo_extra->setBeforeOtherImages($other_filenames);
|
||||
}
|
||||
|
||||
$jo->setJOExtra($jo_extra);
|
||||
|
||||
$this->em->persist($jo_extra);
|
||||
|
|
@ -1508,10 +1545,20 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$jo_extra->setBeforeSpeedImageFilename($new_speed_filename);
|
||||
$jo_extra->setBeforeBattImageFilename($new_batt_filename);
|
||||
$jo_extra->setBeforePlateNumImageFilename($new_plate_num_filename);
|
||||
|
||||
if (empty($other_filenames))
|
||||
{
|
||||
$jo_extra->clearBeforeOtherImages();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$jo_extra->setBeforeOtherImages($other_filenames);
|
||||
}
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
}
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
@ -1533,6 +1580,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$speed_img_file = $req->files->get('speedomtr_img');
|
||||
$batt_img_file = $req->files->get('battery_img');
|
||||
$plate_num_img_file = $req->files->get('plate_number_img');
|
||||
$other_img_files[]= $req->files->get('other_images');
|
||||
|
||||
if ((empty($speed_img_file)) &&
|
||||
(empty($batt_img_file)) &&
|
||||
|
|
@ -1549,6 +1597,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$new_speed_filename = '';
|
||||
$new_batt_filename = '';
|
||||
$new_plate_num_filename = '';
|
||||
$other_filenames = [];
|
||||
|
||||
if (!empty($speed_img_file))
|
||||
{
|
||||
|
|
@ -1605,6 +1654,32 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($other_img_files as $other_img_file)
|
||||
{
|
||||
if (!(empty($other_img_file)))
|
||||
{
|
||||
foreach($other_img_file as $other_img)
|
||||
{
|
||||
$orig_other_filename = pathinfo($other_img->getClientOriginalName(), PATHINFO_FILENAME);
|
||||
$new_other_filename = uniqid() . '-'. $orig_other_filename . '.' . $other_img->guessClientExtension();
|
||||
|
||||
$other_filenames[] = $new_other_filename;
|
||||
|
||||
try
|
||||
{
|
||||
$other_img->move($dest, $new_other_filename);
|
||||
}
|
||||
catch (FileException $e)
|
||||
{
|
||||
$data = [
|
||||
'error' => 'Error saving image files.'
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$jo_extra = $jo->getJOExtra();
|
||||
if ($jo_extra == null)
|
||||
{
|
||||
|
|
@ -1615,6 +1690,15 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$jo_extra->setAfterBattImageFilename($new_batt_filename);
|
||||
$jo_extra->setAfterPlateNumImageFilename($new_plate_num_filename);
|
||||
|
||||
if (empty($other_filenames))
|
||||
{
|
||||
$jo_extra->clearAfterOtherImages();
|
||||
}
|
||||
else
|
||||
{
|
||||
$jo_extra->setAfterOtherImages($other_filenames);
|
||||
}
|
||||
|
||||
$jo->setJOExtra($jo_extra);
|
||||
|
||||
$this->em->persist($jo_extra);
|
||||
|
|
@ -1624,6 +1708,15 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$jo_extra->setAfterSpeedImageFilename($new_speed_filename);
|
||||
$jo_extra->setAfterBattImageFilename($new_batt_filename);
|
||||
$jo_extra->setAfterPlateNumImageFilename($new_plate_num_filename);
|
||||
|
||||
if (empty($other_filenames))
|
||||
{
|
||||
$jo_extra->clearAfterOtherImages();
|
||||
}
|
||||
else
|
||||
{
|
||||
$jo_extra->setAfterOtherImages($other_filenames);
|
||||
}
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
|
|
|||
Loading…
Reference in a new issue