I'm trying to change the way an image is displayed when it is being paginated. Normally the images are in portrait mode and i have the perPage set to 2 (so its 2 images per page so it looks like a book), but then there are landscape images that end up being mixed with the portrait ones. All the images have a width and height column to identify if its landscape or portrait.
I want to be able to tell the paginator to treat all the items that are landscape to be called as a 2 pages rather than a single page.
this is my current code:
/**
* The attributes on which the comic list can be ordered
* @var array
*/
public static $allowedSortingOptions = [
'sort_order desc' => 'Sort Order (descending)',
'random' => 'Random'
];
/**
* Lists images for the front end
*
* @param $query
* @param array $options Display options
*
* @return File
*/
public function scopeListFrontEnd($query, $options)
{
/*
* Default options
*/
extract(array_merge([
'page' => 1,
'perPage' => 1,
'sort' => 'sort_order',
'chapter' => null,
'language' => 'en'
], $options));
if($chapter) {
$query->where('attachment_id', $chapter);
}
$query->where('language', $language);
/*
* Sorting
*/
if (!is_array($sort)) {
$sort = [$sort];
}
foreach ($sort as $_sort) {
if (in_array($_sort, array_keys(self::$allowedSortingOptions))) {
$parts = explode(' ', $_sort);
if (count($parts) < 2) {
array_push($parts, 'desc');
}
list($sortField, $sortDirection) = $parts;
if ($sortField == 'random') {
$sortField = Db::raw('RAND()');
}
$query->orderBy($sortField, $sortDirection);
}
}
$images = $query->paginate($perPage, $page);
return $images;
}
Edit Clearer: A Landscape image is the equivalent of 2 pages. I want to be able to tell the paginator to treat it as such when i have $perPage
set to 2 items per page. That way it wont be showing both a landscape image and a portrait image, just the landscape for that page.
if($chapter) {
$query->where('attachment_id', $chapter);
}
$query->where('language', $language);
$limit = 20;
$query->pagination($limit);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.