|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: sheldon |
|
5
|
|
|
* Date: 18-3-27 |
|
6
|
|
|
* Time: 下午4:12. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Yeelight\Traits; |
|
10
|
|
|
|
|
11
|
|
|
use Illuminate\Pagination\LengthAwarePaginator; |
|
12
|
|
|
use Illuminate\Pagination\Paginator; |
|
13
|
|
|
use Illuminate\Support\Facades\Input; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Trait BackendPagination |
|
17
|
|
|
* |
|
18
|
|
|
* @category Yeelight |
|
19
|
|
|
* |
|
20
|
|
|
* @package Yeelight\Traits |
|
21
|
|
|
* |
|
22
|
|
|
* @author Sheldon Lee <[email protected]> |
|
23
|
|
|
* |
|
24
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
|
25
|
|
|
* |
|
26
|
|
|
* @link https://www.yeelight.com |
|
27
|
|
|
*/ |
|
28
|
|
|
trait BackendPagination |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var \Illuminate\Pagination\LengthAwarePaginator |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $backendPagination = null; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Create a new RepositoryInterface instance. |
|
37
|
|
|
* |
|
38
|
|
|
* @param array $lists |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public function backendPagination($lists) |
|
43
|
|
|
{ |
|
44
|
|
|
//Initialize work for BackendPagination. |
|
45
|
|
|
$this->backendPagination = new LengthAwarePaginator( |
|
46
|
|
|
$lists['data'], |
|
47
|
|
|
$lists['meta']['pagination']['total'], |
|
48
|
|
|
$lists['meta']['pagination']['per_page'], |
|
49
|
|
|
$lists['meta']['pagination']['current_page'], |
|
50
|
|
|
[ |
|
51
|
|
|
'path' => Paginator::resolveCurrentPath(), //注释2 |
|
52
|
|
|
'pageName' => config('yeelight.backend.pagination.pageName'), |
|
53
|
|
|
] |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$this->backendPagination->appends(Input::all()); |
|
57
|
|
|
|
|
58
|
|
|
return $this->paginationRanger(). |
|
59
|
|
|
$this->paginationLinks(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get Pagination links. |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function paginationLinks() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->backendPagination->render('backend.pagination'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get range infomation of BackendPagination. |
|
74
|
|
|
* |
|
75
|
|
|
* @return string|\Symfony\Component\Translation\TranslatorInterface |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function paginationRanger() |
|
78
|
|
|
{ |
|
79
|
|
|
$parameters = [ |
|
80
|
|
|
'first' => $this->backendPagination->firstItem(), |
|
81
|
|
|
'last' => $this->backendPagination->lastItem(), |
|
82
|
|
|
'total' => $this->backendPagination->total(), |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
$parameters = collect($parameters)->flatMap(function ($parameter, $key) { |
|
86
|
|
|
return [$key => "<b>$parameter</b>"]; |
|
87
|
|
|
}); |
|
88
|
|
|
|
|
89
|
|
|
return trans('backend.pagination.range', $parameters->all()); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|