Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Define the slideShow key into media
  • Loading branch information
pmPaulis committed Jun 10, 2024
commit 4f28b70956557567d1ebdb065ee2798662853aa1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public function index(Request $request, Process $process)
// Get the embed related
$processes = Process::with('launchpad')
->with(['media' => function ($query) {
$query->orderBy('order_column', 'asc');
$query->where('collection_name', '!=', Media::COLLECTION_SLIDESHOW)
->orderBy('order_column', 'asc');
}])
->with(['embed' => function ($query) {
$query->orderBy('order_column', 'asc');
Expand Down
13 changes: 11 additions & 2 deletions ProcessMaker/Http/Controllers/Api/SlideshowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use ProcessMaker\Http\Resources\ApiCollection;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Http\Resources\ApiResource;
Expand All @@ -19,13 +20,22 @@ public function index (Request $request, Process $process)
}
public function store(Request $request, Process $process)
{
$validator = Validator::make($request->all(), [
'imagesSlideshow' => 'required|array',
'imagesSlideshow.url' => 'image|max:2048',
]);

if ($validator->fails()) {
return response()->json(['errors' => $validator->errors()], 422);
}

try {
// Store the Slideshow images
$content = $request->input('imagesSlideshow');
if (!empty($content)) {
foreach ($content as $row) {
$media = new Media();
$media->saveProcessMedia($process, $row, 'uuid', Media::COLLECTION_SLIDESHOW);
$media->saveProcessMedia($process, $row, 'uuid', 'slideshow');
}
}
} catch (\Exception $e) {
Expand All @@ -35,7 +45,6 @@ public function store(Request $request, Process $process)
return new ApiResource([
'success' => true,
'message' => 'File uploaded successfully',
'data' => $media
], 201);
}

Expand Down
8 changes: 5 additions & 3 deletions ProcessMaker/Models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Media extends MediaLibraryModel

protected $table = 'media';

const COLLECTION_SLIDESHOW = 'slideshow';
const COLLECTION_SLIDESHOW = 'images_slideshow';

/**
* The attributes that are mass assignable.
Expand Down Expand Up @@ -123,10 +123,11 @@ public static function rules($existing = null)

public function determineCollectionName(Process $process, $name)
{
// In order to differentiate them from other process-related images ['launchpad', 'slideshow']
if ($name === 'launchpad') {
return $process->uuid . '_' . 'images_carousel';
} elseif ($name === self::COLLECTION_SLIDESHOW) {
return 'images_slideshow';
} elseif ($name === 'slideshow') {
return self::COLLECTION_SLIDESHOW;
}
return null;
}
Expand Down Expand Up @@ -215,6 +216,7 @@ public function saveProcessMedia(Process $process, $properties, $key = 'uuid', $
}
// Get collection name to save
$collectionName = self::determineCollectionName($process, $subtype);
// Check if exist
$exist = $process->media()->where($key, $properties[$key])->exists();
if (!$exist) {
// Store the images related move to MEDIA
Expand Down