diff --git a/View/Helper/BootstrapFormHelper.php b/View/Helper/BootstrapFormHelper.php index e420621..52e25bb 100644 --- a/View/Helper/BootstrapFormHelper.php +++ b/View/Helper/BootstrapFormHelper.php @@ -67,7 +67,13 @@ public function input($fieldName, $params = array()) { if (!isset($options['after'])) { $options['after'] = ''; } + //$options['after'] .= ''; + // add form tip + if(isset($options['tip'])){ + $options['after'] .= '

'.$options['tip'].'

'; + }else{ $options['after'] .= ''; + } if (isset($options['label']) && is_string($options['label'])) { $options['label'] = array( @@ -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', ); diff --git a/View/Helper/BootstrapPaginatorHelper.php b/View/Helper/BootstrapPaginatorHelper.php new file mode 100644 index 0000000..bf7e918 --- /dev/null +++ b/View/Helper/BootstrapPaginatorHelper.php @@ -0,0 +1,207 @@ +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, "$title", 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); + } +} \ No newline at end of file