Skip to content

Commit

Permalink
Merge pull request rrze-mmz#171 from rrze-mmz/164-assign-a-series-to-…
Browse files Browse the repository at this point in the history
…a-single-clip-returns-500-page

Bugfix 500 error on assign series to a single clip
  • Loading branch information
stefanosgeo authored Oct 23, 2024
2 parents a0f058f + 37540f6 commit fc0d6c5
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 163 deletions.
3 changes: 0 additions & 3 deletions app/Http/Controllers/Backend/SeriesClipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ public function listSeries(Clip $clip): View

return view('backend.seriesClips.listSeries', [
'clip' => $clip,
'series' => (auth()->user()->isAdmin())
? Series::orderByDesc('updated_at')->paginate(12)
: auth()->user()->accessableSeries()->paginate(12),
]);
}

Expand Down
112 changes: 86 additions & 26 deletions app/Livewire/IndexPagesDatatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class IndexPagesDatatable extends Component

public $organization;

public $actionButton = 'edit';

public $actionObj;

public function sortBy($field): void
{
$this->sortAsc = ! ($this->sortField === $field) || ! $this->sortAsc;
Expand All @@ -46,38 +50,94 @@ public function render()
'type' => $this->type,
'objs' => $objects,
'search' => $search,
'actionButton' => $this->actionButton,
]);
}

protected function determineClipQuery($search)
{
if ($this->type === 'series') {
return Series::query()
->with(['presenters'])
->withLastPublicClip()
->isPublic()
->whereHas('clips.assets')
->where(function ($q) use ($search) {
$search = strtolower($search);
$q->where('id', (int) $search)
->orWhereRaw('lower(title) like ?', ["%{$search}%"])
->orWhereHas('presenters', function ($q) use ($search) {
if (DB::getDriverName() === 'pgsql' || DB::getDriverName() === 'sqlite') {
// PostgresSQL concatenation using "||"
$q->whereRaw('lower(first_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(first_name || \' \' || last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name || \' \' || first_name) like ?', ["%{$search}%"]);
} else {
// MySQL or others using CONCAT()
$q->whereRaw('lower(first_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(CONCAT(first_name, " ", last_name)) like ?', ["%{$search}%"])
->orWhereRaw('lower(CONCAT(last_name, " ", first_name)) like ?', ["%{$search}%"]);
}
});
})
->orderBy('id', 'desc');
//if it is a lecturer fetch all user series to assign them to a clip
if ($this->actionButton === 'assignClip' && ! auth()->user()->isAdmin()) {
if (auth()->user()->isAdmin()) {
return Series::query()
->with(['presenters'])
->withLastPublicClip()
->where(function ($q) use ($search) {
$search = strtolower($search);
$q->where('id', (int) $search)
->orWhereRaw('lower(title) like ?', ["%{$search}%"])
->orWhereHas('presenters', function ($q) use ($search) {
if (DB::getDriverName() === 'pgsql' || DB::getDriverName() === 'sqlite') {
// PostgresSQL concatenation using "||"
$q->whereRaw('lower(first_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(first_name || \' \' || last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name || \' \' || first_name) like ?', ["%{$search}%"]);
} else {
// MySQL or others using CONCAT()
$q->whereRaw('lower(first_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(CONCAT(first_name, " ", last_name)) like ?', ["%{$search}%"])
->orWhereRaw('lower(CONCAT(last_name, " ", first_name)) like ?', ["%{$search}%"]);
}
});
})
->orderBy('id', 'desc');
} else {
return auth()->user()->accessableSeries()->with(['presenters'])
->withLastPublicClip()
->where(function ($q) use ($search) {
$search = strtolower($search);
$q->where('id', (int) $search)
->orWhereRaw('lower(title) like ?', ["%{$search}%"])
->orWhereHas('presenters', function ($q) use ($search) {
if (DB::getDriverName() === 'pgsql' || DB::getDriverName() === 'sqlite') {
// PostgresSQL concatenation using "||"
$q->whereRaw('lower(first_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(first_name || \' \' || last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name || \' \' || first_name) like ?', ["%{$search}%"]);
} else {
// MySQL or others using CONCAT()
$q->whereRaw('lower(first_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(CONCAT(first_name, " ", last_name)) like ?', ["%{$search}%"])
->orWhereRaw('lower(CONCAT(last_name, " ", first_name)) like ?', ["%{$search}%"]);
}
});
})
->orderBy('id', 'desc');
}
} else {
return Series::query()
->with(['presenters'])
->withLastPublicClip()
->isPublic()
->whereHas('clips.assets')
->where(function ($q) use ($search) {
$search = strtolower($search);
$q->where('id', (int) $search)
->orWhereRaw('lower(title) like ?', ["%{$search}%"])
->orWhereHas('presenters', function ($q) use ($search) {
if (DB::getDriverName() === 'pgsql' || DB::getDriverName() === 'sqlite') {
// PostgresSQL concatenation using "||"
$q->whereRaw('lower(first_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(first_name || \' \' || last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name || \' \' || first_name) like ?', ["%{$search}%"]);
} else {
// MySQL or others using CONCAT()
$q->whereRaw('lower(first_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(last_name) like ?', ["%{$search}%"])
->orWhereRaw('lower(CONCAT(first_name, " ", last_name)) like ?', ["%{$search}%"])
->orWhereRaw('lower(CONCAT(last_name, " ", first_name)) like ?', ["%{$search}%"]);
}
});
})
->orderBy('id', 'desc');
}

} elseif ($this->type === 'clips') {
$query = Clip::query();
if ($this->singleClips) {
Expand Down
Loading

0 comments on commit fc0d6c5

Please sign in to comment.