Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion View/Helper/BootstrapFormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ public function input($fieldName, $params = array()) {
if (!isset($options['after'])) {
$options['after'] = '';
}
//$options['after'] .= '</div>';
// add form tip
if(isset($options['tip'])){
$options['after'] .= '<p class="help-block">'.$options['tip'].'<p></div>';
}else{
$options['after'] .= '</div>';
}

if (isset($options['label']) && is_string($options['label'])) {
$options['label'] = array(
Expand All @@ -91,7 +97,7 @@ public function input($fieldName, $params = array()) {
* Adds the class `help-inline` as its required by bootstrap
*
*/
public function error($field, $text, $options = array()) {
public function error($field, $text=NULL, $options = array()) {
$defaults = array(
'class' => 'help-inline',
);
Expand Down
207 changes: 207 additions & 0 deletions View/Helper/BootstrapPaginatorHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
<?php
App::uses('PaginatorHelper', 'View/Helper');
/**
* bootstrap paginator
*
* @author thinking song
*
*/
class BootstrapPaginatorHelper extends PaginatorHelper {
/**
* Returns a set of numbers for the paged result set
* uses a modulus to decide how many numbers to show on each side of the current page (default: 8).
*
* `$this->Paginator->numbers(array('first' => 2, 'last' => 2));`
*
* Using the first and last options you can create links to the beginning and end of the page set.
*
* ### Options
*
* - `before` Content to be inserted before the numbers
* - `after` Content to be inserted after the numbers
* - `model` Model to create numbers for, defaults to PaginatorHelper::defaultModel()
* - `modulus` how many numbers to include on either side of the current page, defaults to 8.
* - `separator` Separator content defaults to ' | '
* - `tag` The tag to wrap links in, defaults to 'span'
* - `first` Whether you want first links generated, set to an integer to define the number of 'first'
* links to generate.
* - `last` Whether you want last links generated, set to an integer to define the number of 'last'
* links to generate.
* - `ellipsis` Ellipsis content, defaults to '...'
*
* @param mixed $options Options for the numbers, (before, after, model, modulus, separator)
* @return string numbers string.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::numbers
*/
public function numbers($options = array()) {
if ($options === true) {
$options = array(
'before' => ' | ', 'after' => ' | ', 'first' => 'first', 'last' => 'last'
);
}

$defaults = array(
'tag' => 'li', 'before' => null, 'after' => null, 'model' => $this->defaultModel(), 'class' => null,
'modulus' => '8', 'separator' => '', 'first' => null, 'last' => null, 'ellipsis' => '...',
);
$options += $defaults;

$params = (array)$this->params($options['model']) + array('page' => 1);
unset($options['model']);

if ($params['pageCount'] <= 1) {
return false;
}

extract($options);
unset($options['tag'], $options['before'], $options['after'], $options['model'],
$options['modulus'], $options['separator'], $options['first'], $options['last'],
$options['ellipsis'], $options['class']
);

$out = '';

if ($modulus && $params['pageCount'] > $modulus) {
$half = intval($modulus / 2);
$end = $params['page'] + $half;

if ($end > $params['pageCount']) {
$end = $params['pageCount'];
}
$start = $params['page'] - ($modulus - ($end - $params['page']));
if ($start <= 1) {
$start = 1;
$end = $params['page'] + ($modulus - $params['page']) + 1;
}

if ($first && $start > 1) {
$offset = ($start <= (int)$first) ? $start - 1 : $first;
if ($offset < $start - 1) {
$out .= $this->first($offset, compact('tag', 'separator', 'ellipsis', 'class'));
} else {
$out .= $this->first($offset, compact('tag', 'separator', 'class') + array('after' => $separator));
}
}

$out .= $before;

for ($i = $start; $i < $params['page']; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'))
. $separator;
}

$currentClass = 'current';
if ($class) {
$currentClass .= ' ' . $class;
}
$out .= $this->Html->tag($tag, $params['page'], array('class' => $currentClass));
if ($i != $params['pageCount']) {
$out .= $separator;
}

$start = $params['page'] + 1;
for ($i = $start; $i < $end; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'))
. $separator;
}

if ($end != $params['page']) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $end), $options), compact('class'));
}

$out .= $after;

if ($last && $end < $params['pageCount']) {
$offset = ($params['pageCount'] < $end + (int)$last) ? $params['pageCount'] - $end : $last;
if ($offset <= $last && $params['pageCount'] - $end > $offset) {
$out .= $this->last($offset, compact('tag', 'separator', 'ellipsis', 'class'));
} else {
$out .= $this->last($offset, compact('tag', 'separator', 'class') + array('before' => $separator));
}
}

} else {
$out .= $before;

for ($i = 1; $i <= $params['pageCount']; $i++) {
if ($i == $params['page']) {
$currentClass = 'active';
if ($class) {
$currentClass .= ' ' . $class;
}
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i)), array('class' => $currentClass));
} else {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'));
}
if ($i != $params['pageCount']) {
$out .= $separator;
}
}

$out .= $after;
}

return $out;
}
/**
* Protected method for generating prev/next links
*
* @param string $which
* @param string $title
* @param array $options
* @param string $disabledTitle
* @param array $disabledOptions
* @return string
*/
protected function _pagingLink($which, $title = null, $options = array(), $disabledTitle = null, $disabledOptions = array()) {
$check = 'has' . $which;
$_defaults = array(
'url' => array(), 'step' => 1, 'escape' => true,
'model' => null, 'tag' => 'li', 'class' => strtolower($which)
);
$options = array_merge($_defaults, (array)$options);
$paging = $this->params($options['model']);
if (empty($disabledOptions)) {
$disabledOptions = $options;
}

if (!$this->{$check}($options['model']) && (!empty($disabledTitle) || !empty($disabledOptions))) {
if (!empty($disabledTitle) && $disabledTitle !== true) {
$title = $disabledTitle;
}
$options = array_merge($_defaults, (array)$disabledOptions);
} elseif (!$this->{$check}($options['model'])) {
return null;
}

foreach (array_keys($_defaults) as $key) {
${$key} = $options[$key];
unset($options[$key]);
}
$url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url);

if ($this->{$check}($model)) {
return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape'))), compact('class'));
} else {
return $this->Html->tag($tag, "<a href=\"#\">$title</a>", array_merge($options, compact('class')));
}
}

public function first($first = '<<', $options = array()) {
$options = array_merge(array('tag' => 'li'), (array)$options);
return parent::first($first, $options);
}

public function last($last = '>>', $options = array()) {
$options = array_merge(array('tag' => 'li'), (array)$options);
return parent::last($last, $options);
}

public function prev($title = '<', $options = array(), $disabledTitle = null, $disabledOptions = array('class' => 'disabled')) {
return parent::prev($title, $options, $disabledTitle, $disabledOptions);
}

public function next($title = '>', $options = array(), $disabledTitle = null, $disabledOptions = array('class' => 'disabled')) {
return parent::next($title, $options, $disabledTitle, $disabledOptions);
}
}