Skip to content

Commit 476b667

Browse files
committed
Restore files.
1 parent 9497839 commit 476b667

File tree

2 files changed

+276
-0
lines changed

2 files changed

+276
-0
lines changed

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
CakePHP 3.x Helpers for Bootstrap
2+
=================================
3+
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
5+
[![Travis](https://img.shields.io/travis/Holt59/cakephp3-bootstrap-helpers.svg?style=flat-square)](https://travis-ci.org/Holt59/cakephp3-bootstrap-helpers)
6+
7+
CakePHP 3.0 Helpers to generate HTML with @Twitter Boostrap style: `Html`, `Form`, `Modal` and `Paginator` helpers available!
8+
9+
How to... ?
10+
===========
11+
12+
**Installation**
13+
14+
If you want the latest **Bootstrap 3** version of the plugin:
15+
```
16+
composer require holt59/cakephp3-bootstrap-helpers:dev-master
17+
```
18+
```php
19+
// in config/bootstrap.php
20+
Plugin::load('Bootstrap') ;
21+
```
22+
23+
```php
24+
// in your AppController
25+
public $helpers = [
26+
'Form' => [
27+
'className' => 'Bootstrap.BootstrapForm'
28+
],
29+
/* ... */
30+
] ;
31+
```
32+
---
33+
34+
35+
If you want to test the **Bootstrap 4** version of the plugin (alpha):
36+
```
37+
composer require holt59/cakephp3-bootstrap-helpers:dev-v4.0.0-alpha
38+
```
39+
40+
**Documentation**
41+
42+
The full plugin documentation is available at https://holt59.github.io/cakephp3-bootstrap-helpers/.
43+
44+
**Contributing**
45+
46+
Do not hesitate to [**post a github issue**](https://github.com/Holt59/cakephp3-bootstrap-helpers/issues/new) or [**submit a pull request**](https://github.com/Holt59/cakephp3-bootstrap-helpers/pulls) if you find a bug or want a new feature.
47+
48+
Who is using it?
49+
================
50+
51+
Non-exhaustive list of projects using these helpers, if you want to be in this list, do not hesitate to [email me](mailto:[email protected]) or post a comment on [this issue](https://github.com/Holt59/cakephp3-bootstrap-helpers/issues/32).
52+
53+
- [**CakeAdmin**] (https://github.com/cakemanager/cakeadmin-lightstrap), LightStrap Theme for CakeAdmin
54+
55+
Copyright and license
56+
=====================
57+
58+
The MIT License (MIT)
59+
60+
Copyright (c) 2013-2016, Mikaël Capelle.
61+
62+
Permission is hereby granted, free of charge, to any person obtaining a copy
63+
of this software and associated documentation files (the "Software"), to deal
64+
in the Software without restriction, including without limitation the rights
65+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
66+
copies of the Software, and to permit persons to whom the Software is
67+
furnished to do so, subject to the following conditions:
68+
69+
The above copyright notice and this permission notice shall be included in all
70+
copies or substantial portions of the Software.
71+
72+
See [LICENSE](LICENSE).
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
<?php
2+
3+
/**
4+
* Bootstrap Paginator Helper
5+
*
6+
*
7+
* PHP 5
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
*
16+
* @copyright Copyright (c) Mikaël Capelle (http://mikael-capelle.fr)
17+
* @link http://mikael-capelle.fr
18+
* @package app.View.Helper
19+
* @since Apache v2
20+
* @license http://www.apache.org/licenses/LICENSE-2.0
21+
*/
22+
23+
namespace Bootstrap\View\Helper;
24+
25+
use Cake\View\Helper\PaginatorHelper;
26+
27+
class BootstrapPaginatorHelper extends PaginatorHelper {
28+
29+
use BootstrapTrait ;
30+
31+
/**
32+
* Default config for this class
33+
*
34+
* Options: Holds the default options for pagination links
35+
*
36+
* The values that may be specified are:
37+
*
38+
* - `url` Url of the action. See Router::url()
39+
* - `url['sort']` the key that the recordset is sorted.
40+
* - `url['direction']` Direction of the sorting (default: 'asc').
41+
* - `url['page']` Page number to use in links.
42+
* - `model` The name of the model.
43+
* - `escape` Defines if the title field for the link should be escaped (default: true).
44+
*
45+
* Templates: the templates used by this class
46+
*
47+
* @var array
48+
*/
49+
protected $_defaultConfig = [
50+
'options' => [],
51+
'templates' => [
52+
'nextActive' => '<li><a href="{{url}}">{{text}}</a></li>',
53+
'nextDisabled' => '<li class="disabled"><a>{{text}}</a></li>',
54+
'prevActive' => '<li><a href="{{url}}">{{text}}</a></li>',
55+
'prevDisabled' => '<li class="disabled"><a>{{text}}</a></li>',
56+
'counterRange' => '{{start}} - {{end}} of {{count}}',
57+
'counterPages' => '{{page}} of {{pages}}',
58+
'first' => '<li><a href="{{url}}">{{text}}</a></li>',
59+
'last' => '<li><a href="{{url}}">{{text}}</a></li>',
60+
'number' => '<li><a href="{{url}}">{{text}}</a></li>',
61+
'current' => '<li class="active"><a href="{{url}}">{{text}}</a></li>',
62+
'ellipsis' => '<li class="ellipsis disabled"><a>...</a></li>',
63+
'sort' => '<a href="{{url}}">{{text}}</a>',
64+
'sortAsc' => '<a class="asc" href="{{url}}">{{text}}</a>',
65+
'sortDesc' => '<a class="desc" href="{{url}}">{{text}}</a>',
66+
'sortAscLocked' => '<a class="asc locked" href="{{url}}">{{text}}</a>',
67+
'sortDescLocked' => '<a class="desc locked" href="{{url}}">{{text}}</a>',
68+
]
69+
];
70+
71+
/**
72+
*
73+
* Get pagination link list.
74+
*
75+
* @param $options Options for link element
76+
*
77+
* Extra options:
78+
* - size small/normal/large (default normal)
79+
*
80+
**/
81+
public function numbers (array $options = []) {
82+
83+
$defaults = [
84+
'before' => null, 'after' => null, 'model' => $this->defaultModel(),
85+
'modulus' => 8, 'first' => null, 'last' => null, 'url' => [],
86+
'prev' => null, 'next' => null, 'class' => '', 'size' => false
87+
];
88+
$options += $defaults;
89+
90+
$options = $this->addClass($options, 'pagination');
91+
92+
switch ($options['size']) {
93+
case 'small':
94+
$options = $this->addClass($options, 'pagination-sm') ;
95+
break ;
96+
case 'large':
97+
$options = $this->addClass($options, 'pagination-lg') ;
98+
break ;
99+
}
100+
unset($options['size']) ;
101+
102+
$options['before'] .= $this->Html->tag('ul', null, ['class' => $options['class']]);
103+
$options['after'] = '</ul>'.$options['after'] ;
104+
unset($options['class']);
105+
106+
$params = (array)$this->params($options['model']) + ['page' => 1];
107+
if ($params['pageCount'] <= 1) {
108+
return false;
109+
}
110+
111+
$templater = $this->templater();
112+
if (isset($options['templates'])) {
113+
$templater->push();
114+
$method = is_string($options['templates']) ? 'load' : 'add';
115+
$templater->{$method}($options['templates']);
116+
}
117+
118+
$first = $prev = $next = $last = '';
119+
120+
/* Previous and Next buttons (addition from standard PaginatorHelper). */
121+
122+
if ($options['prev']) {
123+
$title = $options['prev'] ;
124+
$opts = [] ;
125+
if (is_array($title)) {
126+
$title = $title['title'] ;
127+
unset ($options['prev']['title']) ;
128+
$opts = $options['prev'] ;
129+
}
130+
$prev = $this->prev($title, $opts) ;
131+
}
132+
unset($options['prev']);
133+
134+
if ($options['next']) {
135+
$title = $options['next'] ;
136+
$opts = [] ;
137+
if (is_array($title)) {
138+
$title = $title['title'];
139+
unset ($options['next']['title']);
140+
$opts = $options['next'];
141+
}
142+
$next = $this->next($title, $opts);
143+
}
144+
unset($options['next']);
145+
146+
/* Custom First and Last. */
147+
148+
list($start, $end) = $this->_getNumbersStartAndEnd($params, $options);
149+
150+
if ($options['last']) {
151+
$ellipsis = isset($options['ellipsis']) ?
152+
$options['ellipsis'] : is_int($options['last']);
153+
$ellipsis = $ellipsis ? $templater->format('ellipsis', []) : '';
154+
$last = $this->_lastNumber($ellipsis, $params, $end, $options);
155+
}
156+
157+
if ($options['first']) {
158+
$ellipsis = isset($options['ellipsis']) ?
159+
$options['ellipsis'] : is_int($options['first']);
160+
$ellipsis = $ellipsis ? $templater->format('ellipsis', []) : '';
161+
$first = $this->_firstNumber($ellipsis, $params, $start, $options);
162+
}
163+
164+
unset($options['ellipsis']);
165+
166+
$before = is_int($options['first']) ? $prev.$first : $first.$prev;
167+
$after = is_int($options['last']) ? $last.$next : $next.$last;
168+
$options['before'] = $options['before'].$before;;
169+
$options['after'] = $after.$options['after'];
170+
$options['first'] = $options['last'] = false;
171+
172+
if ($options['modulus'] !== false && $params['pageCount'] > $options['modulus']) {
173+
$out = $this->_modulusNumbers($templater, $params, $options);
174+
} else {
175+
$out = $this->_numbers($templater, $params, $options);
176+
}
177+
178+
if (isset($options['templates'])) {
179+
$templater->pop();
180+
}
181+
182+
183+
return $out;
184+
}
185+
186+
public function prev ($title = '<< Previous', array $options = []) {
187+
return $this->_easyIcon('parent::prev', $title, $options);
188+
}
189+
190+
public function next ($title = 'Next >>', array $options = []) {
191+
return $this->_easyIcon('parent::next', $title, $options);
192+
}
193+
194+
public function first($first = '<< first', array $options = []) {
195+
return $this->_easyIcon('parent::first', $first, $options);
196+
}
197+
198+
public function last($last = 'last >>', array $options = []) {
199+
return $this->_easyIcon('parent::last', $last, $options);
200+
}
201+
202+
}
203+
204+
?>

0 commit comments

Comments
 (0)