2017-10-26 21:50:01 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class SelectlistTransformer
|
|
|
|
*
|
|
|
|
* This handles the standardized formatting of the API response we need to provide for
|
|
|
|
* the rich (text and images) Select2 javascript.
|
|
|
|
*
|
|
|
|
* @package App\Http\Transformers
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.0.16]
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SelectlistTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformSelectlist (LengthAwarePaginator $select_items)
|
|
|
|
{
|
2017-11-04 01:23:50 -07:00
|
|
|
$items_array=[];
|
2017-10-26 21:50:01 -07:00
|
|
|
|
|
|
|
// Loop through the paginated collection to set the array values
|
|
|
|
foreach ($select_items as $select_item) {
|
|
|
|
$items_array[]= [
|
|
|
|
'id' => (int) $select_item->id,
|
2017-10-28 09:21:39 -07:00
|
|
|
'text' => ($select_item->use_text) ? e($select_item->use_text) : e($select_item->name),
|
2017-10-26 21:50:01 -07:00
|
|
|
'image' => ($select_item->use_image) ? e($select_item->use_image) : null,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = [
|
|
|
|
'items' => $items_array,
|
|
|
|
'pagination' =>
|
|
|
|
[
|
|
|
|
'more' => ($select_items->currentPage() >= $select_items->lastPage()) ? false : true,
|
|
|
|
'per_page' => $select_items->perPage()
|
|
|
|
],
|
|
|
|
'total_count' => $select_items->total(),
|
|
|
|
'page' => $select_items->currentPage(),
|
|
|
|
'page_count' => $select_items->lastPage()
|
|
|
|
];
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|