code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function _toQuerystring($parameters) {
$out = '';
$keys = array_keys($parameters);
$count = count($parameters);
for ($i = 0; $i < $count; $i++) {
$out .= $keys[$i] . '=' . $parameters[$keys[$i]];
if ($i < $count - 1) {
$out .= '&';
}
}
return $out;
} | Convert an array of data into a query string
@param array $parameters Array of parameters to convert to a query string
@return string Querystring fragment
@access protected | _toQuerystring | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function get($selector) {
$this->_multipleSelection = false;
if ($selector == 'window' || $selector == 'document') {
$this->selection = "$(" . $selector .")";
return $this;
}
if (preg_match('/^#[^\s.]+$/', $selector)) {
$this->selection = '$("' . substr($selector, 1) . '")';
return $this;
}
$this->_multipleSelection = true;
$this->selection = '$$("' . $selector . '")';
return $this;
} | Create javascript selector for a CSS rule
@param string $selector The selector that is targeted
@return object instance of $this. Allows chained methods. | get | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function event($type, $callback, $options = array()) {
$defaults = array('wrap' => true, 'stop' => true);
$options = array_merge($defaults, $options);
$function = 'function (event) {%s}';
if ($options['wrap'] && $options['stop']) {
$callback = "event.stop();\n" . $callback;
}
if ($options['wrap']) {
$callback = sprintf($function, $callback);
}
$out = $this->selection . ".addEvent(\"{$type}\", $callback);";
return $out;
} | Add an event to the script cache. Operates on the currently selected elements.
### Options
- 'wrap' - Whether you want the callback wrapped in an anonymous function. (defaults true)
- 'stop' - Whether you want the event to stopped. (defaults true)
@param string $type Type of event to bind to the current dom id
@param string $callback The Javascript function you wish to trigger or the function literal
@param array $options Options for the event.
@return string completed event handler | event | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function domReady($functionBody) {
$this->selection = 'window';
return $this->event('domready', $functionBody, array('stop' => false));
} | Create a domReady event. This is a special event in many libraries
@param string $functionBody The code to run on domReady
@return string completed domReady method | domReady | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function each($callback) {
return $this->selection . '.each(function (item, index) {' . $callback . '});';
} | Create an iteration over the current selection result.
@param string $method The method you want to apply to the selection
@param string $callback The function body you wish to apply during the iteration.
@return string completed iteration | each | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function effect($name, $options = array()) {
$speed = null;
if (isset($options['speed']) && in_array($options['speed'], array('fast', 'slow'))) {
if ($options['speed'] == 'fast') {
$speed = '"short"';
} elseif ($options['speed'] == 'slow') {
$speed = '"long"';
}
}
$effect = '';
switch ($name) {
case 'hide':
$effect = 'setStyle("display", "none")';
break;
case 'show':
$effect = 'setStyle("display", "")';
break;
case 'fadeIn':
case 'fadeOut':
case 'slideIn':
case 'slideOut':
list($effectName, $direction) = preg_split('/([A-Z][a-z]+)/', $name, -1, PREG_SPLIT_DELIM_CAPTURE);
$direction = strtolower($direction);
if ($speed) {
$effect .= "set(\"$effectName\", {duration:$speed}).";
}
$effect .= "$effectName(\"$direction\")";
break;
}
return $this->selection . '.' . $effect . ';';
} | Trigger an Effect.
@param string $name The name of the effect to trigger.
@param array $options Array of options for the effect.
@return string completed string with effect.
@see JsBaseEngineHelper::effect() | effect | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function request($url, $options = array()) {
$url = $this->url($url);
$options = $this->_mapOptions('request', $options);
$type = $data = null;
if (isset($options['type']) || isset($options['update'])) {
if (isset($options['type']) && strtolower($options['type']) == 'json') {
$type = '.JSON';
}
if (isset($options['update'])) {
$options['update'] = str_replace('#', '', $options['update']);
$type = '.HTML';
}
unset($options['type']);
}
if (!empty($options['data'])) {
$data = $options['data'];
unset($options['data']);
}
$options['url'] = $url;
$options = $this->_prepareCallbacks('request', $options);
if (!empty($options['dataExpression'])) {
$callbacks[] = 'data';
unset($options['dataExpression']);
} elseif (!empty($data)) {
$data = $this->object($data);
}
$options = $this->_parseOptions($options, array_keys($this->_callbackArguments['request']));
return "var jsRequest = new Request$type({{$options}}).send($data);";
} | Create an new Request.
Requires `Request`. If you wish to use 'update' key you must have ```Request.HTML```
if you wish to do Json requests you will need ```JSON``` and ```Request.JSON```.
@param mixed $url
@param array $options
@return string The completed ajax call. | request | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function sortable($options = array()) {
$options = $this->_processOptions('sortable', $options);
return 'var jsSortable = new Sortables(' . $this->selection . ', {' . $options . '});';
} | Create a sortable element.
Requires the `Sortables` plugin from MootoolsMore
@param array $options Array of options for the sortable.
@return string Completed sortable script.
@see JsBaseEngineHelper::sortable() for options list. | sortable | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function drag($options = array()) {
$options = $this->_processOptions('drag', $options);
return $this->selection . '.makeDraggable({' . $options . '});';
} | Create a Draggable element.
Requires the `Drag` plugin from MootoolsMore
@param array $options Array of options for the draggable.
@return string Completed draggable script.
@see JsHelper::drag() for options list. | drag | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function drop($options = array()) {
if (empty($options['drag'])) {
trigger_error(
__('MootoolsEngine::drop() requires a "drag" option to properly function', true), E_USER_WARNING
);
return false;
}
$options['droppables'] = $this->selection;
$this->get($options['drag']);
unset($options['drag']);
$options = $this->_mapOptions('drag', $this->_mapOptions('drop', $options));
$options = $this->_prepareCallbacks('drop', $options);
$safe = array_merge(array_keys($this->_callbackArguments['drop']), array('droppables'));
$optionString = $this->_parseOptions($options, $safe);
$out = $this->selection . '.makeDraggable({' . $optionString . '});';
$this->selection = $options['droppables'];
return $out;
} | Create a Droppable element.
Requires the `Drag` and `Drag.Move` plugins from MootoolsMore
Droppables in Mootools function differently from other libraries. Droppables
are implemented as an extension of Drag. So in addtion to making a get() selection for
the droppable element. You must also provide a selector rule to the draggable element. Furthermore,
Mootools droppables inherit all options from Drag.
@param array $options Array of options for the droppable.
@return string Completed droppable script.
@see JsBaseEngineHelper::drop() for options list. | drop | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function slider($options = array()) {
$slider = $this->selection;
$this->get($options['handle']);
unset($options['handle']);
if (isset($options['min']) && isset($options['max'])) {
$options['range'] = array($options['min'], $options['max']);
unset($options['min'], $options['max']);
}
$optionString = $this->_processOptions('slider', $options);
if (!empty($optionString)) {
$optionString = ', {' . $optionString . '}';
}
$out = 'var jsSlider = new Slider(' . $slider . ', ' . $this->selection . $optionString . ');';
$this->selection = $slider;
return $out;
} | Create a slider control
Requires `Slider` from MootoolsMore
@param array $options Array of options for the slider.
@return string Completed slider script.
@see JsBaseEngineHelper::slider() for options list. | slider | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function serializeForm($options = array()) {
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
$selection = $this->selection;
if (!$options['isForm']) {
$selection = '$(' . $this->selection . '.form)';
}
$method = '.toQueryString()';
if (!$options['inline']) {
$method .= ';';
}
return $selection . $method;
} | Serialize the form attached to $selector.
@param array $options Array of options.
@return string Completed serializeForm() snippet
@see JsBaseEngineHelper::serializeForm() | serializeForm | php | Datawalke/Coordino | cake/libs/view/helpers/mootools_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/mootools_engine.php | MIT |
function precision($number, $precision = 3) {
return sprintf("%01.{$precision}f", $number);
} | Formats a number with a level of precision.
@param float $number A floating point number.
@param integer $precision The precision of the returned number.
@return float Formatted float.
@access public
@link http://book.cakephp.org/view/1454/precision | precision | php | Datawalke/Coordino | cake/libs/view/helpers/number.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/number.php | MIT |
function toReadableSize($size) {
switch (true) {
case $size < 1024:
return sprintf(__n('%d Byte', '%d Bytes', $size, true), $size);
case round($size / 1024) < 1024:
return sprintf(__('%d KB', true), $this->precision($size / 1024, 0));
case round($size / 1024 / 1024, 2) < 1024:
return sprintf(__('%.2f MB', true), $this->precision($size / 1024 / 1024, 2));
case round($size / 1024 / 1024 / 1024, 2) < 1024:
return sprintf(__('%.2f GB', true), $this->precision($size / 1024 / 1024 / 1024, 2));
default:
return sprintf(__('%.2f TB', true), $this->precision($size / 1024 / 1024 / 1024 / 1024, 2));
}
} | Returns a formatted-for-humans file size.
@param integer $length Size in bytes
@return string Human readable size
@access public
@link http://book.cakephp.org/view/1456/toReadableSize | toReadableSize | php | Datawalke/Coordino | cake/libs/view/helpers/number.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/number.php | MIT |
function toPercentage($number, $precision = 2) {
return $this->precision($number, $precision) . '%';
} | Formats a number into a percentage string.
@param float $number A floating point number
@param integer $precision The precision of the returned number
@return string Percentage string
@access public
@link http://book.cakephp.org/view/1455/toPercentage | toPercentage | php | Datawalke/Coordino | cake/libs/view/helpers/number.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/number.php | MIT |
function format($number, $options = false) {
$places = 0;
if (is_int($options)) {
$places = $options;
}
$separators = array(',', '.', '-', ':');
$before = $after = null;
if (is_string($options) && !in_array($options, $separators)) {
$before = $options;
}
$thousands = ',';
if (!is_array($options) && in_array($options, $separators)) {
$thousands = $options;
}
$decimals = '.';
if (!is_array($options) && in_array($options, $separators)) {
$decimals = $options;
}
$escape = true;
if (is_array($options)) {
$options = array_merge(array('before'=>'$', 'places' => 2, 'thousands' => ',', 'decimals' => '.'), $options);
extract($options);
}
$out = $before . number_format($number, $places, $decimals, $thousands) . $after;
if ($escape) {
return h($out);
}
return $out;
} | Formats a number into a currency format.
@param float $number A floating point number
@param integer $options if int then places, if string then before, if (,.-) then use it
or array with places and before keys
@return string formatted number
@access public
@link http://book.cakephp.org/view/1457/format | format | php | Datawalke/Coordino | cake/libs/view/helpers/number.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/number.php | MIT |
function currency($number, $currency = 'USD', $options = array()) {
$default = $this->_currencyDefaults;
if (isset($this->_currencies[$currency])) {
$default = $this->_currencies[$currency];
} elseif (is_string($currency)) {
$options['before'] = $currency;
}
$options = array_merge($default, $options);
$result = null;
if ($number == 0 ) {
if ($options['zero'] !== 0 ) {
return $options['zero'];
}
$options['after'] = null;
} elseif ($number < 1 && $number > -1 ) {
if ($options['after'] !== false) {
$multiply = intval('1' . str_pad('', $options['places'], '0'));
$number = $number * $multiply;
$options['before'] = null;
$options['places'] = null;
}
} elseif (empty($options['before'])) {
$options['before'] = null;
} else {
$options['after'] = null;
}
$abs = abs($number);
$result = $this->format($abs, $options);
if ($number < 0 ) {
if ($options['negative'] == '()') {
$result = '(' . $result .')';
} else {
$result = $options['negative'] . $result;
}
}
return $result;
} | Formats a number into a currency format.
### Options
- `before` - The currency symbol to place before whole numbers ie. '$'
- `after` - The currency symbol to place after decimal numbers ie. 'c'. Set to boolean false to
use no decimal symbol. eg. 0.35 => $0.35.
- `zero` - The text to use for zero values, can be a string or a number. ie. 0, 'Free!'
- `places` - Number of decimal places to use. ie. 2
- `thousands` - Thousands separator ie. ','
- `decimals` - Decimal separator symbol ie. '.'
- `negative` - Symbol for negative numbers. If equal to '()', the number will be wrapped with ( and )
- `escape` - Should the output be htmlentity escaped? Defaults to true
@param float $number
@param string $currency Shortcut to default options. Valid values are 'USD', 'EUR', 'GBP', otherwise
set at least 'before' and 'after' options.
@param array $options
@return string Number formatted as a currency.
@access public
@link http://book.cakephp.org/view/1453/currency | currency | php | Datawalke/Coordino | cake/libs/view/helpers/number.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/number.php | MIT |
function addFormat($formatName, $options) {
$this->_currencies[$formatName] = $options + $this->_currencyDefaults;
} | Add a currency format to the Number helper. Makes reusing
currency formats easier.
{{{ $number->addFormat('NOK', array('before' => 'Kr. ')); }}}
You can now use `NOK` as a shortform when formatting currency amounts.
{{{ $number->currency($value, 'NOK'); }}}
Added formats are merged with the following defaults.
{{{
array(
'before' => '$', 'after' => 'c', 'zero' => 0, 'places' => 2, 'thousands' => ',',
'decimals' => '.', 'negative' => '()', 'escape' => true
)
}}}
@param string $formatName The format name to be used in the future.
@param array $options The array of options for this format.
@return void
@see NumberHelper::currency()
@access public | addFormat | php | Datawalke/Coordino | cake/libs/view/helpers/number.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/number.php | MIT |
function __construct($config = array()) {
parent::__construct($config);
$ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js';
$this->helpers[] = $ajaxProvider;
$this->_ajaxHelperClass = $ajaxProvider;
App::import('Helper', $ajaxProvider);
$classname = $ajaxProvider . 'Helper';
if (!is_callable(array($classname, 'link'))) {
trigger_error(sprintf(__('%s does not implement a link() method, it is incompatible with PaginatorHelper', true), $classname), E_USER_WARNING);
}
} | Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links.
Use `var $helpers = array('Paginator' => array('ajax' => 'CustomHelper'));` to set a custom Helper
or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
adapter before including PaginatorHelper in your helpers array.
The chosen custom helper must implement a `link()` method.
@return void | __construct | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function beforeRender() {
$this->options['url'] = array_merge($this->params['pass'], $this->params['named']);
parent::beforeRender();
} | Before render callback. Overridden to merge passed args with url options.
@return void
@access public | beforeRender | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function params($model = null) {
if (empty($model)) {
$model = $this->defaultModel();
}
if (!isset($this->params['paging']) || empty($this->params['paging'][$model])) {
return null;
}
return $this->params['paging'][$model];
} | Gets the current paging parameters from the resultset for the given model
@param string $model Optional model name. Uses the default if none is specified.
@return array The array of paging parameters for the paginated resultset.
@access public | params | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function options($options = array()) {
if (is_string($options)) {
$options = array('update' => $options);
}
if (!empty($options['paging'])) {
if (!isset($this->params['paging'])) {
$this->params['paging'] = array();
}
$this->params['paging'] = array_merge($this->params['paging'], $options['paging']);
unset($options['paging']);
}
$model = $this->defaultModel();
if (!empty($options[$model])) {
if (!isset($this->params['paging'][$model])) {
$this->params['paging'][$model] = array();
}
$this->params['paging'][$model] = array_merge(
$this->params['paging'][$model], $options[$model]
);
unset($options[$model]);
}
$this->options = array_filter(array_merge($this->options, $options));
} | Sets default options for all pagination links
@param mixed $options Default options for pagination links. If a string is supplied - it
is used as the DOM id element to update. See PaginatorHelper::$options for list of keys.
@return void
@access public | options | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function current($model = null) {
$params = $this->params($model);
if (isset($params['page'])) {
return $params['page'];
}
return 1;
} | Gets the current page of the recordset for the given model
@param string $model Optional model name. Uses the default if none is specified.
@return string The current page number of the recordset.
@access public | current | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function sortKey($model = null, $options = array()) {
if (empty($options)) {
$params = $this->params($model);
$options = array_merge($params['defaults'], $params['options']);
}
if (isset($options['sort']) && !empty($options['sort'])) {
return $options['sort'];
} elseif (isset($options['order']) && is_array($options['order'])) {
return key($options['order']);
} elseif (isset($options['order']) && is_string($options['order'])) {
return $options['order'];
}
return null;
} | Gets the current key by which the recordset is sorted
@param string $model Optional model name. Uses the default if none is specified.
@param mixed $options Options for pagination links. See #options for list of keys.
@return string The name of the key by which the recordset is being sorted, or
null if the results are not currently sorted.
@access public | sortKey | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function sortDir($model = null, $options = array()) {
$dir = null;
if (empty($options)) {
$params = $this->params($model);
$options = array_merge($params['defaults'], $params['options']);
}
if (isset($options['direction'])) {
$dir = strtolower($options['direction']);
} elseif (isset($options['order']) && is_array($options['order'])) {
$dir = strtolower(current($options['order']));
}
if ($dir == 'desc') {
return 'desc';
}
return 'asc';
} | Gets the current direction the recordset is sorted
@param string $model Optional model name. Uses the default if none is specified.
@param mixed $options Options for pagination links. See #options for list of keys.
@return string The direction by which the recordset is being sorted, or
null if the results are not currently sorted.
@access public | sortDir | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function prev($title = '<< Previous', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
return $this->__pagingLink('Prev', $title, $options, $disabledTitle, $disabledOptions);
} | Generates a "previous" link for a set of paged records
### Options:
- `tag` The tag wrapping tag you want to use, defaults to 'span'
- `escape` Whether you want the contents html entity encoded, defaults to true
- `model` The model to use, defaults to PaginatorHelper::defaultModel()
@param string $title Title for the link. Defaults to '<< Previous'.
@param mixed $options Options for pagination link. See #options for list of keys.
@param string $disabledTitle Title when the link is disabled.
@param mixed $disabledOptions Options for the disabled pagination link. See #options for list of keys.
@return string A "previous" link or $disabledTitle text if the link is disabled.
@access public | prev | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function next($title = 'Next >>', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
return $this->__pagingLink('Next', $title, $options, $disabledTitle, $disabledOptions);
} | Generates a "next" link for a set of paged records
### Options:
- `tag` The tag wrapping tag you want to use, defaults to 'span'
- `escape` Whether you want the contents html entity encoded, defaults to true
- `model` The model to use, defaults to PaginatorHelper::defaultModel()
@param string $title Title for the link. Defaults to 'Next >>'.
@param mixed $options Options for pagination link. See above for list of keys.
@param string $disabledTitle Title when the link is disabled.
@param mixed $disabledOptions Options for the disabled pagination link. See above for list of keys.
@return string A "next" link or or $disabledTitle text if the link is disabled.
@access public | next | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function sort($title, $key = null, $options = array()) {
$options = array_merge(array('url' => array(), 'model' => null), $options);
$url = $options['url'];
unset($options['url']);
if (empty($key)) {
$key = $title;
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)), true);
}
$dir = isset($options['direction']) ? $options['direction'] : 'asc';
unset($options['direction']);
$sortKey = $this->sortKey($options['model']);
$defaultModel = $this->defaultModel();
$isSorted = (
$sortKey === $key ||
$sortKey === $defaultModel . '.' . $key ||
$key === $defaultModel . '.' . $sortKey
);
if ($isSorted) {
$dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc';
$class = $dir === 'asc' ? 'desc' : 'asc';
if (!empty($options['class'])) {
$options['class'] .= ' ' . $class;
} else {
$options['class'] = $class;
}
}
if (is_array($title) && array_key_exists($dir, $title)) {
$title = $title[$dir];
}
$url = array_merge(array('sort' => $key, 'direction' => $dir), $url, array('order' => null));
return $this->link($title, $url, $options);
} | Generates a sorting link. Sets named parameters for the sort and direction. Handles
direction switching automatically.
### Options:
- `escape` Whether you want the contents html entity encoded, defaults to true
- `model` The model to use, defaults to PaginatorHelper::defaultModel()
@param string $title Title for the link.
@param string $key The name of the key that the recordset should be sorted. If $key is null
$title will be used for the key, and a title will be generated by inflection.
@param array $options Options for sorting link. See above for list of keys.
@return string A link sorting default by 'asc'. If the resultset is sorted 'asc' by the specified
key the returned link will sort by 'desc'.
@access public | sort | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function link($title, $url = array(), $options = array()) {
$options = array_merge(array('model' => null, 'escape' => true), $options);
$model = $options['model'];
unset($options['model']);
if (!empty($this->options)) {
$options = array_merge($this->options, $options);
}
if (isset($options['url'])) {
$url = array_merge((array)$options['url'], (array)$url);
unset($options['url']);
}
$url = $this->url($url, true, $model);
$obj = isset($options['update']) ? $this->_ajaxHelperClass : 'Html';
$url = array_merge(array('page' => $this->current($model)), $url);
$url = array_merge(Set::filter($url, true), array_intersect_key($url, array('plugin' => true)));
return $this->{$obj}->link($title, $url, $options);
} | Generates a plain or Ajax link with pagination parameters
### Options
- `update` The Id of the DOM element you wish to update. Creates Ajax enabled links
with the AjaxHelper.
- `escape` Whether you want the contents html entity encoded, defaults to true
- `model` The model to use, defaults to PaginatorHelper::defaultModel()
@param string $title Title for the link.
@param mixed $url Url for the action. See Router::url()
@param array $options Options for the link. See #options for list of keys.
@return string A link with pagination parameters.
@access public | link | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function url($options = array(), $asArray = false, $model = null) {
$paging = $this->params($model);
$url = array_merge(array_filter(Set::diff(array_merge(
$paging['defaults'], $paging['options']), $paging['defaults'])), $options
);
if (isset($url['order'])) {
$sort = $direction = null;
if (is_array($url['order'])) {
list($sort, $direction) = array($this->sortKey($model, $url), current($url['order']));
}
unset($url['order']);
$url = array_merge($url, compact('sort', 'direction'));
}
if ($asArray) {
return $url;
}
return parent::url($url);
} | Merges passed URL options with current pagination state to generate a pagination URL.
@param array $options Pagination/URL options array
@param boolean $asArray Return the url as an array, or a URI string
@param string $model Which model to paginate on
@return mixed By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
@access public | url | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
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' => 'span', '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', 'class'))));
} else {
return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class')));
}
} | Protected method for generating prev/next links
@access protected | __pagingLink | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function hasPrev($model = null) {
return $this->__hasPage($model, 'prev');
} | Returns true if the given result set is not at the first page
@param string $model Optional model name. Uses the default if none is specified.
@return boolean True if the result set is not at the first page.
@access public | hasPrev | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function hasNext($model = null) {
return $this->__hasPage($model, 'next');
} | Returns true if the given result set is not at the last page
@param string $model Optional model name. Uses the default if none is specified.
@return boolean True if the result set is not at the last page.
@access public | hasNext | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function hasPage($model = null, $page = 1) {
if (is_numeric($model)) {
$page = $model;
$model = null;
}
$paging = $this->params($model);
return $page <= $paging['pageCount'];
} | Returns true if the given result set has the page number given by $page
@param string $model Optional model name. Uses the default if none is specified.
@param int $page The page number - if not set defaults to 1.
@return boolean True if the given result set has the specified page number.
@access public | hasPage | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function __hasPage($model, $page) {
$params = $this->params($model);
if (!empty($params)) {
if ($params["{$page}Page"] == true) {
return true;
}
}
return false;
} | Does $model have $page in its range?
@param string $model Model name to get parameters for.
@param integer $page Page number you are checking.
@return boolean Whether model has $page
@access protected | __hasPage | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function defaultModel() {
if ($this->__defaultModel != null) {
return $this->__defaultModel;
}
if (empty($this->params['paging'])) {
return null;
}
list($this->__defaultModel) = array_keys($this->params['paging']);
return $this->__defaultModel;
} | Gets the default model of the paged sets
@return string Model name or null if the pagination isn't initialized.
@access public | defaultModel | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function counter($options = array()) {
if (is_string($options)) {
$options = array('format' => $options);
}
$options = array_merge(
array(
'model' => $this->defaultModel(),
'format' => 'pages',
'separator' => __(' of ', true)
),
$options);
$paging = $this->params($options['model']);
if ($paging['pageCount'] == 0) {
$paging['pageCount'] = 1;
}
$start = 0;
if ($paging['count'] >= 1) {
$start = (($paging['page'] - 1) * $paging['options']['limit']) + 1;
}
$end = $start + $paging['options']['limit'] - 1;
if ($paging['count'] < $end) {
$end = $paging['count'];
}
switch ($options['format']) {
case 'range':
if (!is_array($options['separator'])) {
$options['separator'] = array(' - ', $options['separator']);
}
$out = $start . $options['separator'][0] . $end . $options['separator'][1];
$out .= $paging['count'];
break;
case 'pages':
$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
break;
default:
$map = array(
'%page%' => $paging['page'],
'%pages%' => $paging['pageCount'],
'%current%' => $paging['current'],
'%count%' => $paging['count'],
'%start%' => $start,
'%end%' => $end
);
$out = str_replace(array_keys($map), array_values($map), $options['format']);
$newKeys = array(
'{:page}', '{:pages}', '{:current}', '{:count}', '{:start}', '{:end}'
);
$out = str_replace($newKeys, array_values($map), $out);
break;
}
return $out;
} | Returns a counter string for the paged result set
### Options
- `model` The model to use, defaults to PaginatorHelper::defaultModel();
- `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5'
set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
the following placeholders `%page%`, `%pages%`, `%current%`, `%count%`, `%start%`, `%end%` and any
custom content you would like.
- `separator` The separator string to use, default to ' of '
@param mixed $options Options for the counter string. See #options for list of keys.
@return string Counter string.
@access public | counter | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function numbers($options = array()) {
if ($options === true) {
$options = array(
'before' => ' | ', 'after' => ' | ', 'first' => 'first', 'last' => 'last'
);
}
$defaults = array(
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(),
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null,
);
$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']);
$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, array('tag' => $tag, 'separator' => $separator));
} else {
$out .= $this->first($offset, array('tag' => $tag, 'after' => $separator, 'separator' => $separator));
}
}
$out .= $before;
for ($i = $start; $i < $params['page']; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options))
. $separator;
}
$out .= $this->Html->tag($tag, $params['page'], array('class' => 'current'));
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))
. $separator;
}
if ($end != $params['page']) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $end), $options));
}
$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, array('tag' => $tag, 'separator' => $separator));
} else {
$out .= $this->last($offset, array('tag' => $tag, 'before' => $separator, 'separator' => $separator));
}
}
} else {
$out .= $before;
for ($i = 1; $i <= $params['pageCount']; $i++) {
if ($i == $params['page']) {
$out .= $this->Html->tag($tag, $i, array('class' => 'current'));
} else {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options));
}
if ($i != $params['pageCount']) {
$out .= $separator;
}
}
$out .= $after;
}
return $out;
} | 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)
### 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
@param mixed $options Options for the numbers, (before, after, model, modulus, separator)
@return string numbers string.
@access public | numbers | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function first($first = '<< first', $options = array()) {
$options = array_merge(
array(
'tag' => 'span',
'after'=> null,
'model' => $this->defaultModel(),
'separator' => ' | ',
),
(array)$options);
$params = array_merge(array('page'=> 1), (array)$this->params($options['model']));
unset($options['model']);
if ($params['pageCount'] <= 1) {
return false;
}
extract($options);
unset($options['tag'], $options['after'], $options['model'], $options['separator']);
$out = '';
if (is_int($first) && $params['page'] > $first) {
if ($after === null) {
$after = '...';
}
for ($i = 1; $i <= $first; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options));
if ($i != $first) {
$out .= $separator;
}
}
$out .= $after;
} elseif ($params['page'] > 1) {
$out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options))
. $after;
}
return $out;
} | Returns a first or set of numbers for the first pages
### Options:
- `tag` The tag wrapping tag you want to use, defaults to 'span'
- `after` Content to insert after the link/tag
- `model` The model to use defaults to PaginatorHelper::defaultModel()
- `separator` Content between the generated links, defaults to ' | '
@param mixed $first if string use as label for the link, if numeric print page numbers
@param mixed $options
@return string numbers string.
@access public | first | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function last($last = 'last >>', $options = array()) {
$options = array_merge(
array(
'tag' => 'span',
'before'=> null,
'model' => $this->defaultModel(),
'separator' => ' | ',
),
(array)$options);
$params = array_merge(array('page'=> 1), (array)$this->params($options['model']));
unset($options['model']);
if ($params['pageCount'] <= 1) {
return false;
}
extract($options);
unset($options['tag'], $options['before'], $options['model'], $options['separator']);
$out = '';
$lower = $params['pageCount'] - $last + 1;
if (is_int($last) && $params['page'] < $lower) {
if ($before === null) {
$before = '...';
}
for ($i = $lower; $i <= $params['pageCount']; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options));
if ($i != $params['pageCount']) {
$out .= $separator;
}
}
$out = $before . $out;
} elseif ($params['page'] < $params['pageCount']) {
$out = $before . $this->Html->tag(
$tag, $this->link($last, array('page' => $params['pageCount']), $options
));
}
return $out;
} | Returns a last or set of numbers for the last pages
### Options:
- `tag` The tag wrapping tag you want to use, defaults to 'span'
- `before` Content to insert before the link/tag
- `model` The model to use defaults to PaginatorHelper::defaultModel()
- `separator` Content between the generated links, defaults to ' | '
@param mixed $last if string use as label for the link, if numeric print page numbers
@param mixed $options Array of options
@return string numbers string.
@access public | last | php | Datawalke/Coordino | cake/libs/view/helpers/paginator.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/paginator.php | MIT |
function get($selector) {
$this->_multiple = false;
if ($selector == 'window' || $selector == 'document') {
$this->selection = "$(" . $selector .")";
return $this;
}
if (preg_match('/^#[^\s.]+$/', $selector)) {
$this->selection = '$("' . substr($selector, 1) . '")';
return $this;
}
$this->_multiple = true;
$this->selection = '$$("' . $selector . '")';
return $this;
} | Create javascript selector for a CSS rule
@param string $selector The selector that is targeted
@return object instance of $this. Allows chained methods. | get | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function event($type, $callback, $options = array()) {
$defaults = array('wrap' => true, 'stop' => true);
$options = array_merge($defaults, $options);
$function = 'function (event) {%s}';
if ($options['wrap'] && $options['stop']) {
$callback = "event.stop();\n" . $callback;
}
if ($options['wrap']) {
$callback = sprintf($function, $callback);
}
$out = $this->selection . ".observe(\"{$type}\", $callback);";
return $out;
} | Add an event to the script cache. Operates on the currently selected elements.
### Options
- `wrap` - Whether you want the callback wrapped in an anonymous function. (defaults true)
- `stop` - Whether you want the event to stopped. (defaults true)
@param string $type Type of event to bind to the current 946 id
@param string $callback The Javascript function you wish to trigger or the function literal
@param array $options Options for the event.
@return string completed event handler | event | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function domReady($functionBody) {
$this->selection = 'document';
return $this->event('dom:loaded', $functionBody, array('stop' => false));
} | Create a domReady event. This is a special event in many libraries
@param string $functionBody The code to run on domReady
@return string completed domReady method
@access public | domReady | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function each($callback) {
return $this->selection . '.each(function (item, index) {' . $callback . '});';
} | Create an iteration over the current selection result.
@param string $method The method you want to apply to the selection
@param string $callback The function body you wish to apply during the iteration.
@return string completed iteration
@access public | each | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function effect($name, $options = array()) {
$effect = '';
$optionString = null;
if (isset($options['speed'])) {
if ($options['speed'] == 'fast') {
$options['duration'] = 0.5;
} elseif ($options['speed'] == 'slow') {
$options['duration'] = 2;
} else {
$options['duration'] = 1;
}
unset($options['speed']);
}
if (!empty($options)) {
$optionString = ', {' . $this->_parseOptions($options) . '}';
}
switch ($name) {
case 'hide':
case 'show':
$effect = $this->selection . '.' . $name . '();';
break;
case 'slideIn':
case 'slideOut':
$name = ($name == 'slideIn') ? 'slideDown' : 'slideUp';
$effect = 'Effect.' . $name . '(' . $this->selection . $optionString . ');';
break;
case 'fadeIn':
case 'fadeOut':
$name = ($name == 'fadeIn') ? 'appear' : 'fade';
$effect = $this->selection . '.' . $name .'(' . substr($optionString, 2) . ');';
break;
}
return $effect;
} | Trigger an Effect.
### Note: Effects require Scriptaculous to be loaded.
@param string $name The name of the effect to trigger.
@param array $options Array of options for the effect.
@return string completed string with effect.
@access public
@see JsBaseEngineHelper::effect() | effect | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function request($url, $options = array()) {
$url = '"'. $this->url($url) . '"';
$options = $this->_mapOptions('request', $options);
$type = '.Request';
$data = null;
if (isset($options['type']) && strtolower($options['type']) == 'json') {
unset($options['type']);
}
if (isset($options['update'])) {
$url = '"' . str_replace('#', '', $options['update']) . '", ' . $url;
$type = '.Updater';
unset($options['update'], $options['type']);
}
$safe = array_keys($this->_callbackArguments['request']);
$options = $this->_prepareCallbacks('request', $options, $safe);
if (!empty($options['dataExpression'])) {
$safe[] = 'parameters';
unset($options['dataExpression']);
}
$options = $this->_parseOptions($options, $safe);
if (!empty($options)) {
$options = ', {' . $options . '}';
}
return "var jsRequest = new Ajax$type($url$options);";
} | Create an Ajax or Ajax.Updater call.
@param mixed $url
@param array $options
@return string The completed ajax call.
@access public | request | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function sortable($options = array()) {
$options = $this->_processOptions('sortable', $options);
if (!empty($options)) {
$options = ', {' . $options . '}';
}
return 'var jsSortable = Sortable.create(' . $this->selection . $options . ');';
} | Create a sortable element.
#### Note: Requires scriptaculous to be loaded.
The scriptaculous implementation of sortables does not suppot the 'start'
and 'distance' options.
@param array $options Array of options for the sortable.
@return string Completed sortable script.
@access public
@see JsBaseEngineHelper::sortable() for options list. | sortable | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function drag($options = array()) {
$options = $this->_processOptions('drag', $options);
if (!empty($options)) {
$options = ', {' . $options . '}';
}
if ($this->_multiple) {
return $this->each('new Draggable(item' . $options . ');');
}
return 'var jsDrag = new Draggable(' . $this->selection . $options . ');';
} | Create a Draggable element.
#### Note: Requires scriptaculous to be loaded.
@param array $options Array of options for the draggable.
@return string Completed draggable script.
@access public
@see JsBaseEngineHelper::draggable() for options list. | drag | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function drop($options = array()) {
$options = $this->_processOptions('drop', $options);
if (!empty($options)) {
$options = ', {' . $options . '}';
}
return 'Droppables.add(' . $this->selection . $options . ');';
} | Create a Droppable element.
#### Note: Requires scriptaculous to be loaded.
@param array $options Array of options for the droppable.
@return string Completed droppable script.
@access public
@see JsBaseEngineHelper::droppable() for options list. | drop | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function slider($options = array()) {
$slider = $this->selection;
$this->get($options['handle']);
unset($options['handle']);
if (isset($options['min']) && isset($options['max'])) {
$options['range'] = sprintf('$R(%s,%s)', $options['min'], $options['max']);
unset($options['min'], $options['max']);
}
$options = $this->_mapOptions('slider', $options);
$options = $this->_prepareCallbacks('slider', $options);
$optionString = $this->_parseOptions(
$options, array_merge(array_keys($this->_callbackArguments['slider']), array('range'))
);
if (!empty($optionString)) {
$optionString = ', {' . $optionString . '}';
}
$out = 'var jsSlider = new Control.Slider(' . $this->selection . ', ' . $slider . $optionString . ');';
$this->selection = $slider;
return $out;
} | Creates a slider control widget.
### Note: Requires scriptaculous to be loaded.
@param array $options Array of options for the slider.
@return string Completed slider script.
@access public
@see JsBaseEngineHelper::slider() for options list. | slider | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function serializeForm($options = array()) {
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
$selection = $this->selection;
if (!$options['isForm']) {
$selection = '$(' . $this->selection . '.form)';
}
$method = '.serialize()';
if (!$options['inline']) {
$method .= ';';
}
return $selection . $method;
} | Serialize the form attached to $selector.
@param array $options Array of options.
@return string Completed serializeForm() snippet
@access public
@see JsBaseEngineHelper::serializeForm() | serializeForm | php | Datawalke/Coordino | cake/libs/view/helpers/prototype_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/prototype_engine.php | MIT |
function document($attrib = array(), $content = null) {
if ($content === null) {
$content = $attrib;
$attrib = array();
}
if (!isset($attrib['version']) || empty($attrib['version'])) {
$attrib['version'] = $this->version;
}
return $this->elem('rss', $attrib, $content);
} | Returns an RSS document wrapped in `<rss />` tags
@param array $attrib `<rss />` tag attributes
@return string An RSS document
@access public | document | php | Datawalke/Coordino | cake/libs/view/helpers/rss.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/rss.php | MIT |
function channel($attrib = array(), $elements = array(), $content = null) {
$view =& ClassRegistry::getObject('view');
if (!isset($elements['title']) && !empty($view->pageTitle)) {
$elements['title'] = $view->pageTitle;
}
if (!isset($elements['link'])) {
$elements['link'] = '/';
}
if (!isset($elements['description'])) {
$elements['description'] = '';
}
$elements['link'] = $this->url($elements['link'], true);
$elems = '';
foreach ($elements as $elem => $data) {
$attributes = array();
if (is_array($data)) {
if (strtolower($elem) == 'cloud') {
$attributes = $data;
$data = array();
} elseif (isset($data['attrib']) && is_array($data['attrib'])) {
$attributes = $data['attrib'];
unset($data['attrib']);
} else {
$innerElements = '';
foreach ($data as $subElement => $value) {
$innerElements .= $this->elem($subElement, array(), $value);
}
$data = $innerElements;
}
}
$elems .= $this->elem($elem, $attributes, $data);
}
return $this->elem('channel', $attrib, $elems . $content, !($content === null));
} | Returns an RSS `<channel />` element
@param array $attrib `<channel />` tag attributes
@param mixed $elements Named array elements which are converted to tags
@param mixed $content Content (`<item />`'s belonging to this channel
@return string An RSS `<channel />`
@access public | channel | php | Datawalke/Coordino | cake/libs/view/helpers/rss.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/rss.php | MIT |
function items($items, $callback = null) {
if ($callback != null) {
$items = array_map($callback, $items);
}
$out = '';
$c = count($items);
for ($i = 0; $i < $c; $i++) {
$out .= $this->item(array(), $items[$i]);
}
return $out;
} | Transforms an array of data using an optional callback, and maps it to a set
of `<item />` tags
@param array $items The list of items to be mapped
@param mixed $callback A string function name, or array containing an object
and a string method name
@return string A set of RSS `<item />` elements
@access public | items | php | Datawalke/Coordino | cake/libs/view/helpers/rss.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/rss.php | MIT |
function item($att = array(), $elements = array()) {
$content = null;
if (isset($elements['link']) && !isset($elements['guid'])) {
$elements['guid'] = $elements['link'];
}
foreach ($elements as $key => $val) {
$attrib = array();
$escape = true;
if (is_array($val) && isset($val['convertEntities'])) {
$escape = $val['convertEntities'];
unset($val['convertEntities']);
}
switch ($key) {
case 'pubDate' :
$val = $this->time($val);
break;
case 'category' :
if (is_array($val) && !empty($val[0])) {
foreach ($val as $category) {
$attrib = array();
if (isset($category['domain'])) {
$attrib['domain'] = $category['domain'];
unset($category['domain']);
}
$categories[] = $this->elem($key, $attrib, $category);
}
$elements[$key] = implode('', $categories);
continue 2;
} else if (is_array($val) && isset($val['domain'])) {
$attrib['domain'] = $val['domain'];
}
break;
case 'link':
case 'guid':
case 'comments':
if (is_array($val) && isset($val['url'])) {
$attrib = $val;
unset($attrib['url']);
$val = $val['url'];
}
$val = $this->url($val, true);
break;
case 'source':
if (is_array($val) && isset($val['url'])) {
$attrib['url'] = $this->url($val['url'], true);
$val = $val['title'];
} elseif (is_array($val)) {
$attrib['url'] = $this->url($val[0], true);
$val = $val[1];
}
break;
case 'enclosure':
if (is_string($val['url']) && is_file(WWW_ROOT . $val['url']) && file_exists(WWW_ROOT . $val['url'])) {
if (!isset($val['length']) && strpos($val['url'], '://') === false) {
$val['length'] = sprintf("%u", filesize(WWW_ROOT . $val['url']));
}
if (!isset($val['type']) && function_exists('mime_content_type')) {
$val['type'] = mime_content_type(WWW_ROOT . $val['url']);
}
}
$val['url'] = $this->url($val['url'], true);
$attrib = $val;
$val = null;
break;
}
if (!is_null($val) && $escape) {
$val = h($val);
}
$elements[$key] = $this->elem($key, $attrib, $val);
}
if (!empty($elements)) {
$content = implode('', $elements);
}
return $this->elem('item', $att, $content, !($content === null));
} | Converts an array into an `<item />` element and its contents
@param array $attrib The attributes of the `<item />` element
@param array $elements The list of elements contained in this `<item />`
@return string An RSS `<item />` element
@access public | item | php | Datawalke/Coordino | cake/libs/view/helpers/rss.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/rss.php | MIT |
function time($time) {
return $this->Time->toRSS($time);
} | Converts a time in any format to an RSS time
@param mixed $time
@return string An RSS-formatted timestamp
@see TimeHelper::toRSS | time | php | Datawalke/Coordino | cake/libs/view/helpers/rss.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/rss.php | MIT |
function activate($base = null) {
$this->__active = true;
} | Turn sessions on if 'Session.start' is set to false in core.php
@param string $base
@access public | activate | php | Datawalke/Coordino | cake/libs/view/helpers/session.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/session.php | MIT |
function read($name = null) {
if ($this->__active === true && $this->__start()) {
return parent::read($name);
}
return false;
} | Used to read a session values set in a controller for a key or return values for all keys.
In your view: `$session->read('Controller.sessKey');`
Calling the method without a param will return all session vars
@param string $name the name of the session key you want to read
@return values from the session vars
@access public
@link http://book.cakephp.org/view/1466/Methods | read | php | Datawalke/Coordino | cake/libs/view/helpers/session.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/session.php | MIT |
function check($name) {
if ($this->__active === true && $this->__start()) {
return parent::check($name);
}
return false;
} | Used to check is a session key has been set
In your view: `$session->check('Controller.sessKey');`
@param string $name
@return boolean
@access public
@link http://book.cakephp.org/view/1466/Methods | check | php | Datawalke/Coordino | cake/libs/view/helpers/session.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/session.php | MIT |
function error() {
if ($this->__active === true && $this->__start()) {
return parent::error();
}
return false;
} | Returns last error encountered in a session
In your view: `$session->error();`
@return string last error
@access public
@link http://book.cakephp.org/view/1466/Methods | error | php | Datawalke/Coordino | cake/libs/view/helpers/session.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/session.php | MIT |
function flash($key = 'flash') {
$out = false;
if ($this->__active === true && $this->__start()) {
if (parent::check('Message.' . $key)) {
$flash = parent::read('Message.' . $key);
if ($flash['element'] == 'default') {
if (!empty($flash['params']['class'])) {
$class = $flash['params']['class'];
} else {
$class = 'message';
}
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>';
} elseif ($flash['element'] == '' || $flash['element'] == null) {
$out = $flash['message'];
} else {
$view =& ClassRegistry::getObject('view');
$tmpVars = $flash['params'];
$tmpVars['message'] = $flash['message'];
$out = $view->element($flash['element'], $tmpVars);
}
parent::delete('Message.' . $key);
}
}
return $out;
} | Used to render the message set in Controller::Session::setFlash()
In your view: $session->flash('somekey');
Will default to flash if no param is passed
@param string $key The [Message.]key you are rendering in the view.
@return boolean|string Will return the value if $key is set, or false if not set.
@access public
@link http://book.cakephp.org/view/1466/Methods
@link http://book.cakephp.org/view/1467/flash | flash | php | Datawalke/Coordino | cake/libs/view/helpers/session.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/session.php | MIT |
function valid() {
if ($this->__active === true && $this->__start()) {
return parent::valid();
}
} | Used to check is a session is valid in a view
@return boolean
@access public | valid | php | Datawalke/Coordino | cake/libs/view/helpers/session.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/session.php | MIT |
function write() {
trigger_error(__('You can not write to a Session from the view', true), E_USER_WARNING);
} | Override CakeSession::write().
This method should not be used in a view
@return boolean
@access public | write | php | Datawalke/Coordino | cake/libs/view/helpers/session.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/session.php | MIT |
function __start() {
if (!$this->started()) {
return $this->start();
}
return true;
} | Determine if Session has been started
and attempt to start it if not
@return boolean true if Session is already started, false if
Session could not be started
@access private | __start | php | Datawalke/Coordino | cake/libs/view/helpers/session.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/session.php | MIT |
function highlight($text, $phrase, $options = array()) {
if (empty($phrase)) {
return $text;
}
$default = array(
'format' => '<span class="highlight">\1</span>',
'html' => false
);
$options = array_merge($default, $options);
extract($options);
if (is_array($phrase)) {
$replace = array();
$with = array();
foreach ($phrase as $key => $segment) {
$segment = '(' . preg_quote($segment, '|') . ')';
if ($html) {
$segment = "(?![^<]+>)$segment(?![^<]+>)";
}
$with[] = (is_array($format)) ? $format[$key] : $format;
$replace[] = "|$segment|iu";
}
return preg_replace($replace, $with, $text);
} else {
$phrase = '(' . preg_quote($phrase, '|') . ')';
if ($html) {
$phrase = "(?![^<]+>)$phrase(?![^<]+>)";
}
return preg_replace("|$phrase|iu", $format, $text);
}
} | Highlights a given phrase in a text. You can specify any expression in highlighter that
may include the \1 expression to include the $phrase found.
### Options:
- `format` The piece of html with that the phrase will be highlighted
- `html` If true, will ignore any HTML tags, ensuring that only the correct text is highlighted
@param string $text Text to search the phrase in
@param string $phrase The phrase that will be searched
@param array $options An array of html attributes and options.
@return string The highlighted text
@access public
@link http://book.cakephp.org/view/1469/Text#highlight-1622 | highlight | php | Datawalke/Coordino | cake/libs/view/helpers/text.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/text.php | MIT |
function stripLinks($text) {
return preg_replace('|<a\s+[^>]+>|im', '', preg_replace('|<\/a>|im', '', $text));
} | Strips given text of all links (<a href=....)
@param string $text Text
@return string The text without links
@access public
@link http://book.cakephp.org/view/1469/Text#stripLinks-1623 | stripLinks | php | Datawalke/Coordino | cake/libs/view/helpers/text.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/text.php | MIT |
function autoLinkUrls($text, $htmlOptions = array()) {
$options = var_export($htmlOptions, true);
$text = preg_replace_callback('#(?<!href="|">)((?:https?|ftp|nntp)://[^\s<>()]+)#i', create_function('$matches',
'$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $options . ');'), $text);
return preg_replace_callback('#(?<!href="|">)(?<!http://|https://|ftp://|nntp://)(www\.[^\n\%\ <]+[^<\n\%\,\.\ <])(?<!\))#i',
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . $matches[0],' . $options . ');'), $text);
} | Adds links (<a href=....) to a given text, by finding text that begins with
strings like http:// and ftp://.
@param string $text Text to add links to
@param array $options Array of HTML options.
@return string The text with links
@access public
@link http://book.cakephp.org/view/1469/Text#autoLinkUrls-1619 | autoLinkUrls | php | Datawalke/Coordino | cake/libs/view/helpers/text.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/text.php | MIT |
function autoLinkEmails($text, $options = array()) {
$linkOptions = 'array(';
foreach ($options as $option => $value) {
$value = var_export($value, true);
$linkOptions .= "'$option' => $value, ";
}
$linkOptions .= ')';
$atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]';
return preg_replace_callback(
'/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)+)/i',
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text);
} | Adds email links (<a href="mailto:....) to a given text.
@param string $text Text
@param array $options Array of HTML options.
@return string The text with links
@access public
@link http://book.cakephp.org/view/1469/Text#autoLinkEmails-1618 | autoLinkEmails | php | Datawalke/Coordino | cake/libs/view/helpers/text.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/text.php | MIT |
function autoLink($text, $options = array()) {
return $this->autoLinkEmails($this->autoLinkUrls($text, $options), $options);
} | Convert all links and email adresses to HTML links.
@param string $text Text
@param array $options Array of HTML options.
@return string The text with links
@access public
@link http://book.cakephp.org/view/1469/Text#autoLink-1620 | autoLink | php | Datawalke/Coordino | cake/libs/view/helpers/text.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/text.php | MIT |
function truncate($text, $length = 100, $options = array()) {
$default = array(
'ending' => '...', 'exact' => true, 'html' => false
);
$options = array_merge($default, $options);
extract($options);
if ($html) {
if (mb_strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
$totalLength = mb_strlen(strip_tags($ending));
$openTags = array();
$truncate = '';
preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER);
foreach ($tags as $tag) {
if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2])) {
if (preg_match('/<[\w]+[^>]*>/s', $tag[0])) {
array_unshift($openTags, $tag[2]);
} else if (preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag)) {
$pos = array_search($closeTag[1], $openTags);
if ($pos !== false) {
array_splice($openTags, $pos, 1);
}
}
}
$truncate .= $tag[1];
$contentLength = mb_strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3]));
if ($contentLength + $totalLength > $length) {
$left = $length - $totalLength;
$entitiesLength = 0;
if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $tag[3], $entities, PREG_OFFSET_CAPTURE)) {
foreach ($entities[0] as $entity) {
if ($entity[1] + 1 - $entitiesLength <= $left) {
$left--;
$entitiesLength += mb_strlen($entity[0]);
} else {
break;
}
}
}
$truncate .= mb_substr($tag[3], 0 , $left + $entitiesLength);
break;
} else {
$truncate .= $tag[3];
$totalLength += $contentLength;
}
if ($totalLength >= $length) {
break;
}
}
} else {
if (mb_strlen($text) <= $length) {
return $text;
} else {
$truncate = mb_substr($text, 0, $length - mb_strlen($ending));
}
}
if (!$exact) {
$spacepos = mb_strrpos($truncate, ' ');
if (isset($spacepos)) {
if ($html) {
$bits = mb_substr($truncate, $spacepos);
preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER);
if (!empty($droppedTags)) {
foreach ($droppedTags as $closingTag) {
if (!in_array($closingTag[1], $openTags)) {
array_unshift($openTags, $closingTag[1]);
}
}
}
}
$truncate = mb_substr($truncate, 0, $spacepos);
}
}
$truncate .= $ending;
if ($html) {
foreach ($openTags as $tag) {
$truncate .= '</'.$tag.'>';
}
}
return $truncate;
} | Truncates text.
Cuts a string to the length of $length and replaces the last characters
with the ending if the text is longer than length.
### Options:
- `ending` Will be used as Ending and appended to the trimmed string
- `exact` If false, $text will not be cut mid-word
- `html` If true, HTML tags would be handled correctly
@param string $text String to truncate.
@param integer $length Length of returned string, including ellipsis.
@param array $options An array of html attributes and options.
@return string Trimmed string.
@access public
@link http://book.cakephp.org/view/1469/Text#truncate-1625 | truncate | php | Datawalke/Coordino | cake/libs/view/helpers/text.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/text.php | MIT |
function excerpt($text, $phrase, $radius = 100, $ending = '...') {
if (empty($text) or empty($phrase)) {
return $this->truncate($text, $radius * 2, array('ending' => $ending));
}
$append = $prepend = $ending;
$phraseLen = mb_strlen($phrase);
$textLen = mb_strlen($text);
$pos = mb_strpos(mb_strtolower($text), mb_strtolower($phrase));
if ($pos === false) {
return mb_substr($text, 0, $radius) . $ending;
}
$startPos = $pos - $radius;
if ($startPos <= 0) {
$startPos = 0;
$prepend = '';
}
$endPos = $pos + $phraseLen + $radius;
if ($endPos >= $textLen) {
$endPos = $textLen;
$append = '';
}
$excerpt = mb_substr($text, $startPos, $endPos - $startPos);
$excerpt = $prepend . $excerpt . $append;
return $excerpt;
} | Extracts an excerpt from the text surrounding the phrase with a number of characters on each side
determined by radius.
@param string $text String to search the phrase in
@param string $phrase Phrase that will be searched for
@param integer $radius The amount of characters that will be returned on each side of the founded phrase
@param string $ending Ending that will be appended
@return string Modified string
@access public
@link http://book.cakephp.org/view/1469/Text#excerpt-1621 | excerpt | php | Datawalke/Coordino | cake/libs/view/helpers/text.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/text.php | MIT |
function toList($list, $and = 'and', $separator = ', ') {
if (count($list) > 1) {
return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list);
} else {
return array_pop($list);
}
} | Creates a comma separated list where the last two items are joined with 'and', forming natural English
@param array $list The list to be joined
@param string $and The word used to join the last and second last items together with. Defaults to 'and'
@param string $separator The separator used to join all othe other items together. Defaults to ', '
@return string The glued together string.
@access public
@link http://book.cakephp.org/view/1469/Text#toList-1624 | toList | php | Datawalke/Coordino | cake/libs/view/helpers/text.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/text.php | MIT |
function convertSpecifiers($format, $time = null) {
if (!$time) {
$time = time();
}
$this->__time = $time;
return preg_replace_callback('/\%(\w+)/', array($this, '__translateSpecifier'), $format);
} | Converts a string representing the format for the function strftime and returns a
windows safe and i18n aware format.
@param string $format Format with specifiers for strftime function.
Accepts the special specifier %S which mimics th modifier S for date()
@param string UNIX timestamp
@return string windows safe and date() function compatible format for strftime
@access public | convertSpecifiers | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function __translateSpecifier($specifier) {
switch ($specifier[1]) {
case 'a':
$abday = __c('abday', 5, true);
if (is_array($abday)) {
return $abday[date('w', $this->__time)];
}
break;
case 'A':
$day = __c('day',5,true);
if (is_array($day)) {
return $day[date('w', $this->__time)];
}
break;
case 'c':
$format = __c('d_t_fmt',5,true);
if ($format != 'd_t_fmt') {
return $this->convertSpecifiers($format, $this->__time);
}
break;
case 'C':
return sprintf("%02d", date('Y', $this->__time) / 100);
case 'D':
return '%m/%d/%y';
case 'e':
if (DS === '/') {
return '%e';
}
$day = date('j', $this->__time);
if ($day < 10) {
$day = ' ' . $day;
}
return $day;
case 'eS' :
return date('jS', $this->__time);
case 'b':
case 'h':
$months = __c('abmon', 5, true);
if (is_array($months)) {
return $months[date('n', $this->__time) -1];
}
return '%b';
case 'B':
$months = __c('mon',5,true);
if (is_array($months)) {
return $months[date('n', $this->__time) -1];
}
break;
case 'n':
return "\n";
case 'p':
case 'P':
$default = array('am' => 0, 'pm' => 1);
$meridiem = $default[date('a',$this->__time)];
$format = __c('am_pm', 5, true);
if (is_array($format)) {
$meridiem = $format[$meridiem];
return ($specifier[1] == 'P') ? strtolower($meridiem) : strtoupper($meridiem);
}
break;
case 'r':
$complete = __c('t_fmt_ampm', 5, true);
if ($complete != 't_fmt_ampm') {
return str_replace('%p',$this->__translateSpecifier(array('%p', 'p')),$complete);
}
break;
case 'R':
return date('H:i', $this->__time);
case 't':
return "\t";
case 'T':
return '%H:%M:%S';
case 'u':
return ($weekDay = date('w', $this->__time)) ? $weekDay : 7;
case 'x':
$format = __c('d_fmt', 5, true);
if ($format != 'd_fmt') {
return $this->convertSpecifiers($format, $this->__time);
}
break;
case 'X':
$format = __c('t_fmt',5,true);
if ($format != 't_fmt') {
return $this->convertSpecifiers($format, $this->__time);
}
break;
}
return $specifier[0];
} | Auxiliary function to translate a matched specifier element from a regular expresion into
a windows safe and i18n aware specifier
@param array $specifier match from regular expression
@return string converted element
@access private | __translateSpecifier | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function convert($serverTime, $userOffset) {
$serverOffset = $this->serverOffset();
$gmtTime = $serverTime - $serverOffset;
$userTime = $gmtTime + $userOffset * (60*60);
return $userTime;
} | Converts given time (in server's time zone) to user's local time, given his/her offset from GMT.
@param string $serverTime UNIX timestamp
@param int $userOffset User's offset from GMT (in hours)
@return string UNIX timestamp
@access public | convert | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function serverOffset() {
return date('Z', time());
} | Returns server's offset from GMT in seconds.
@return int Offset
@access public | serverOffset | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function fromString($dateString, $userOffset = null) {
if (empty($dateString)) {
return false;
}
if (is_integer($dateString) || is_numeric($dateString)) {
$date = intval($dateString);
} else {
$date = strtotime($dateString);
}
if ($userOffset !== null) {
return $this->convert($date, $userOffset);
}
if ($date === -1) {
return false;
}
return $date;
} | Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
@param string $dateString Datetime string
@param int $userOffset User's offset from GMT (in hours)
@return string Parsed timestamp
@access public
@link http://book.cakephp.org/view/1471/Formatting | fromString | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function nice($dateString = null, $userOffset = null) {
if ($dateString != null) {
$date = $this->fromString($dateString, $userOffset);
} else {
$date = time();
}
$format = $this->convertSpecifiers('%a, %b %eS %Y, %H:%M', $date);
return $this->_strftime($format, $date);
} | Returns a nicely formatted date string for given Datetime string.
@param string $dateString Datetime string or Unix timestamp
@param int $userOffset User's offset from GMT (in hours)
@return string Formatted date string
@access public
@link http://book.cakephp.org/view/1471/Formatting | nice | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function niceShort($dateString = null, $userOffset = null) {
$date = $dateString ? $this->fromString($dateString, $userOffset) : time();
$y = $this->isThisYear($date) ? '' : ' %Y';
if ($this->isToday($dateString, $userOffset)) {
$ret = sprintf(__('Today, %s',true), $this->_strftime("%H:%M", $date));
} elseif ($this->wasYesterday($dateString, $userOffset)) {
$ret = sprintf(__('Yesterday, %s',true), $this->_strftime("%H:%M", $date));
} else {
$format = $this->convertSpecifiers("%b %eS{$y}, %H:%M", $date);
$ret = $this->_strftime($format, $date);
}
return $ret;
} | Returns a formatted descriptive date string for given datetime string.
If the given date is today, the returned string could be "Today, 16:54".
If the given date was yesterday, the returned string could be "Yesterday, 16:54".
If $dateString's year is the current year, the returned string does not
include mention of the year.
@param string $dateString Datetime string or Unix timestamp
@param int $userOffset User's offset from GMT (in hours)
@return string Described, relative date string
@access public
@link http://book.cakephp.org/view/1471/Formatting | niceShort | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function daysAsSql($begin, $end, $fieldName, $userOffset = null) {
$begin = $this->fromString($begin, $userOffset);
$end = $this->fromString($end, $userOffset);
$begin = date('Y-m-d', $begin) . ' 00:00:00';
$end = date('Y-m-d', $end) . ' 23:59:59';
return "($fieldName >= '$begin') AND ($fieldName <= '$end')";
} | Returns a partial SQL string to search for all records between two dates.
@param string $dateString Datetime string or Unix timestamp
@param string $end Datetime string or Unix timestamp
@param string $fieldName Name of database field to compare with
@param int $userOffset User's offset from GMT (in hours)
@return string Partial SQL string.
@access public
@link http://book.cakephp.org/view/1471/Formatting | daysAsSql | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function dayAsSql($dateString, $fieldName, $userOffset = null) {
$date = $this->fromString($dateString, $userOffset);
return $this->daysAsSql($dateString, $dateString, $fieldName);
} | Returns a partial SQL string to search for all records between two times
occurring on the same day.
@param string $dateString Datetime string or Unix timestamp
@param string $fieldName Name of database field to compare with
@param int $userOffset User's offset from GMT (in hours)
@return string Partial SQL string.
@access public
@link http://book.cakephp.org/view/1471/Formatting | dayAsSql | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function isToday($dateString, $userOffset = null) {
$date = $this->fromString($dateString, $userOffset);
return date('Y-m-d', $date) == date('Y-m-d', time());
} | Returns true if given datetime string is today.
@param string $dateString Datetime string or Unix timestamp
@param int $userOffset User's offset from GMT (in hours)
@return boolean True if datetime string is today
@access public | isToday | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function isThisWeek($dateString, $userOffset = null) {
$date = $this->fromString($dateString, $userOffset);
return date('W Y', $date) == date('W Y', time());
} | Returns true if given datetime string is within this week
@param string $dateString
@param int $userOffset User's offset from GMT (in hours)
@return boolean True if datetime string is within current week
@access public
@link http://book.cakephp.org/view/1472/Testing-Time | isThisWeek | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function isThisMonth($dateString, $userOffset = null) {
$date = $this->fromString($dateString);
return date('m Y',$date) == date('m Y', time());
} | Returns true if given datetime string is within this month
@param string $dateString
@param int $userOffset User's offset from GMT (in hours)
@return boolean True if datetime string is within current month
@access public
@link http://book.cakephp.org/view/1472/Testing-Time | isThisMonth | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function isThisYear($dateString, $userOffset = null) {
$date = $this->fromString($dateString, $userOffset);
return date('Y', $date) == date('Y', time());
} | Returns true if given datetime string is within current year.
@param string $dateString Datetime string or Unix timestamp
@return boolean True if datetime string is within current year
@access public
@link http://book.cakephp.org/view/1472/Testing-Time | isThisYear | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function wasYesterday($dateString, $userOffset = null) {
$date = $this->fromString($dateString, $userOffset);
return date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday'));
} | Returns true if given datetime string was yesterday.
@param string $dateString Datetime string or Unix timestamp
@param int $userOffset User's offset from GMT (in hours)
@return boolean True if datetime string was yesterday
@access public
@link http://book.cakephp.org/view/1472/Testing-Time | wasYesterday | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function isTomorrow($dateString, $userOffset = null) {
$date = $this->fromString($dateString, $userOffset);
return date('Y-m-d', $date) == date('Y-m-d', strtotime('tomorrow'));
} | Returns true if given datetime string is tomorrow.
@param string $dateString Datetime string or Unix timestamp
@param int $userOffset User's offset from GMT (in hours)
@return boolean True if datetime string was yesterday
@access public
@link http://book.cakephp.org/view/1472/Testing-Time | isTomorrow | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function toQuarter($dateString, $range = false) {
$time = $this->fromString($dateString);
$date = ceil(date('m', $time) / 3);
if ($range === true) {
$range = 'Y-m-d';
}
if ($range !== false) {
$year = date('Y', $time);
switch ($date) {
case 1:
$date = array($year.'-01-01', $year.'-03-31');
break;
case 2:
$date = array($year.'-04-01', $year.'-06-30');
break;
case 3:
$date = array($year.'-07-01', $year.'-09-30');
break;
case 4:
$date = array($year.'-10-01', $year.'-12-31');
break;
}
}
return $date;
} | Returns the quarter
@param string $dateString
@param boolean $range if true returns a range in Y-m-d format
@return boolean True if datetime string is within current week
@access public
@link http://book.cakephp.org/view/1471/Formatting | toQuarter | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function toUnix($dateString, $userOffset = null) {
return $this->fromString($dateString, $userOffset);
} | Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
@param string $dateString Datetime string to be represented as a Unix timestamp
@param int $userOffset User's offset from GMT (in hours)
@return integer Unix timestamp
@access public
@link http://book.cakephp.org/view/1471/Formatting | toUnix | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function toAtom($dateString, $userOffset = null) {
$date = $this->fromString($dateString, $userOffset);
return date('Y-m-d\TH:i:s\Z', $date);
} | Returns a date formatted for Atom RSS feeds.
@param string $dateString Datetime string or Unix timestamp
@param int $userOffset User's offset from GMT (in hours)
@return string Formatted date string
@access public
@link http://book.cakephp.org/view/1471/Formatting | toAtom | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function toRSS($dateString, $userOffset = null) {
$date = $this->fromString($dateString, $userOffset);
if(!is_null($userOffset)) {
if($userOffset == 0) {
$timezone = '+0000';
} else {
$hours = (int) floor(abs($userOffset));
$minutes = (int) (fmod(abs($userOffset), $hours) * 60);
$timezone = ($userOffset < 0 ? '-' : '+') . str_pad($hours, 2, '0', STR_PAD_LEFT) . str_pad($minutes, 2, '0', STR_PAD_LEFT);
}
return date('D, d M Y H:i:s', $date) . ' ' . $timezone;
}
return date("r", $date);
} | Formats date for RSS feeds
@param string $dateString Datetime string or Unix timestamp
@param int $userOffset User's offset from GMT (in hours)
@return string Formatted date string
@access public
@link http://book.cakephp.org/view/1471/Formatting | toRSS | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function timeAgoInWords($dateTime, $options = array()) {
$userOffset = null;
if (is_array($options) && isset($options['userOffset'])) {
$userOffset = $options['userOffset'];
}
$now = time();
if (!is_null($userOffset)) {
$now = $this->convert(time(), $userOffset);
}
$inSeconds = $this->fromString($dateTime, $userOffset);
$backwards = ($inSeconds > $now);
$format = 'j/n/y';
$end = '+1 month';
if (is_array($options)) {
if (isset($options['format'])) {
$format = $options['format'];
unset($options['format']);
}
if (isset($options['end'])) {
$end = $options['end'];
unset($options['end']);
}
} else {
$format = $options;
}
if ($backwards) {
$futureTime = $inSeconds;
$pastTime = $now;
} else {
$futureTime = $now;
$pastTime = $inSeconds;
}
$diff = $futureTime - $pastTime;
// If more than a week, then take into account the length of months
if ($diff >= 604800) {
$current = array();
$date = array();
list($future['H'], $future['i'], $future['s'], $future['d'], $future['m'], $future['Y']) = explode('/', date('H/i/s/d/m/Y', $futureTime));
list($past['H'], $past['i'], $past['s'], $past['d'], $past['m'], $past['Y']) = explode('/', date('H/i/s/d/m/Y', $pastTime));
$years = $months = $weeks = $days = $hours = $minutes = $seconds = 0;
if ($future['Y'] == $past['Y'] && $future['m'] == $past['m']) {
$months = 0;
$years = 0;
} else {
if ($future['Y'] == $past['Y']) {
$months = $future['m'] - $past['m'];
} else {
$years = $future['Y'] - $past['Y'];
$months = $future['m'] + ((12 * $years) - $past['m']);
if ($months >= 12) {
$years = floor($months / 12);
$months = $months - ($years * 12);
}
if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] == 1) {
$years --;
}
}
}
if ($future['d'] >= $past['d']) {
$days = $future['d'] - $past['d'];
} else {
$daysInPastMonth = date('t', $pastTime);
$daysInFutureMonth = date('t', mktime(0, 0, 0, $future['m'] - 1, 1, $future['Y']));
if (!$backwards) {
$days = ($daysInPastMonth - $past['d']) + $future['d'];
} else {
$days = ($daysInFutureMonth - $past['d']) + $future['d'];
}
if ($future['m'] != $past['m']) {
$months --;
}
}
if ($months == 0 && $years >= 1 && $diff < ($years * 31536000)) {
$months = 11;
$years --;
}
if ($months >= 12) {
$years = $years + 1;
$months = $months - 12;
}
if ($days >= 7) {
$weeks = floor($days / 7);
$days = $days - ($weeks * 7);
}
} else {
$years = $months = $weeks = 0;
$days = floor($diff / 86400);
$diff = $diff - ($days * 86400);
$hours = floor($diff / 3600);
$diff = $diff - ($hours * 3600);
$minutes = floor($diff / 60);
$diff = $diff - ($minutes * 60);
$seconds = $diff;
}
$relativeDate = '';
$diff = $futureTime - $pastTime;
if ($diff > abs($now - $this->fromString($end))) {
$relativeDate = sprintf(__('on %s',true), date($format, $inSeconds));
} else {
if ($years > 0) {
// years and months and days
$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d year', '%d years', $years, true), $years);
$relativeDate .= $months > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d month', '%d months', $months, true), $months) : '';
$relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d week', '%d weeks', $weeks, true), $weeks) : '';
$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days) : '';
} elseif (abs($months) > 0) {
// months, weeks and days
$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d month', '%d months', $months, true), $months);
$relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d week', '%d weeks', $weeks, true), $weeks) : '';
$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days) : '';
} elseif (abs($weeks) > 0) {
// weeks and days
$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d week', '%d weeks', $weeks, true), $weeks);
$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days) : '';
} elseif (abs($days) > 0) {
// days and hours
$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days);
$relativeDate .= $hours > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d hour', '%d hours', $hours, true), $hours) : '';
} elseif (abs($hours) > 0) {
// hours and minutes
$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d hour', '%d hours', $hours, true), $hours);
$relativeDate .= $minutes > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d minute', '%d minutes', $minutes, true), $minutes) : '';
} elseif (abs($minutes) > 0) {
// minutes only
$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d minute', '%d minutes', $minutes, true), $minutes);
} else {
// seconds only
$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d second', '%d seconds', $seconds, true), $seconds);
}
if (!$backwards) {
$relativeDate = sprintf(__('%s ago', true), $relativeDate);
}
}
return $relativeDate;
} | Returns either a relative date or a formatted date depending
on the difference between the current time and given datetime.
$datetime should be in a <i>strtotime</i> - parsable format, like MySQL's datetime datatype.
### Options:
- `format` => a fall back format if the relative time is longer than the duration specified by end
- `end` => The end of relative time telling
- `userOffset` => Users offset from GMT (in hours)
Relative dates look something like this:
3 weeks, 4 days ago
15 seconds ago
Default date formatting is d/m/yy e.g: on 18/2/09
The returned string includes 'ago' or 'on' and assumes you'll properly add a word
like 'Posted ' before the function output.
@param string $dateString Datetime string or Unix timestamp
@param array $options Default format if timestamp is used in $dateString
@return string Relative time string.
@access public
@link http://book.cakephp.org/view/1471/Formatting | timeAgoInWords | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function relativeTime($dateTime, $options = array()) {
return $this->timeAgoInWords($dateTime, $options);
} | Alias for timeAgoInWords
@param mixed $dateTime Datetime string (strtotime-compatible) or Unix timestamp
@param mixed $options Default format string, if timestamp is used in $dateTime, or an array of options to be passed
on to timeAgoInWords().
@return string Relative time string.
@see TimeHelper::timeAgoInWords
@access public
@deprecated This method alias will be removed in future versions.
@link http://book.cakephp.org/view/1471/Formatting | relativeTime | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function wasWithinLast($timeInterval, $dateString, $userOffset = null) {
$tmp = str_replace(' ', '', $timeInterval);
if (is_numeric($tmp)) {
$timeInterval = $tmp . ' ' . __('days', true);
}
$date = $this->fromString($dateString, $userOffset);
$interval = $this->fromString('-'.$timeInterval);
if ($date >= $interval && $date <= time()) {
return true;
}
return false;
} | Returns true if specified datetime was within the interval specified, else false.
@param mixed $timeInterval the numeric value with space then time type.
Example of valid types: 6 hours, 2 days, 1 minute.
@param mixed $dateString the datestring or unix timestamp to compare
@param int $userOffset User's offset from GMT (in hours)
@return bool
@access public
@link http://book.cakephp.org/view/1472/Testing-Time | wasWithinLast | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function gmt($string = null) {
if ($string != null) {
$string = $this->fromString($string);
} else {
$string = time();
}
$string = $this->fromString($string);
$hour = intval(date("G", $string));
$minute = intval(date("i", $string));
$second = intval(date("s", $string));
$month = intval(date("n", $string));
$day = intval(date("j", $string));
$year = intval(date("Y", $string));
return gmmktime($hour, $minute, $second, $month, $day, $year);
} | Returns gmt, given either a UNIX timestamp or a valid strtotime() date string.
@param string $dateString Datetime string
@return string Formatted date string
@access public
@link http://book.cakephp.org/view/1471/Formatting | gmt | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function format($format, $date = null, $invalid = false, $userOffset = null) {
$time = $this->fromString($date, $userOffset);
$_time = $this->fromString($format, $userOffset);
if (is_numeric($_time) && $time === false) {
$format = $date;
return $this->i18nFormat($_time, $format, $invalid, $userOffset);
}
if ($time === false && $invalid !== false) {
return $invalid;
}
return date($format, $time);
} | Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
This function also accepts a time string and a format string as first and second parameters.
In that case this function behaves as a wrapper for TimeHelper::i18nFormat()
@param string $format date format string (or a DateTime string)
@param string $dateString Datetime string (or a date format string)
@param boolean $invalid flag to ignore results of fromString == false
@param int $userOffset User's offset from GMT (in hours)
@return string Formatted date string
@access public | format | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function i18nFormat($date, $format = null, $invalid = false, $userOffset = null) {
$date = $this->fromString($date, $userOffset);
if ($date === false && $invalid !== false) {
return $invalid;
}
if (empty($format)) {
$format = '%x';
}
$format = $this->convertSpecifiers($format, $date);
return $this->_strftime($format, $date);
} | Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
It take in account the default date format for the current language if a LC_TIME file is used.
@param string $dateString Datetime string
@param string $format strftime format string.
@param boolean $invalid flag to ignore results of fromString == false
@param int $userOffset User's offset from GMT (in hours)
@return string Formatted and translated date string @access public
@access public | i18nFormat | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function _strftime($format, $date) {
$format = strftime($format, $date);
$encoding = Configure::read('App.encoding');
if (!empty($encoding) && $encoding === 'UTF-8') {
if (function_exists('mb_check_encoding')) {
$valid = mb_check_encoding($format, $encoding);
} else {
$valid = !Multibyte::checkMultibyte($format);
}
if (!$valid) {
$format = utf8_encode($format);
}
}
return $format;
} | Multibyte wrapper for strftime.
Handles utf8_encoding the result of strftime when necessary.
@param string $format Format string.
@param int $date Timestamp to format.
@return string formatted string with correct encoding. | _strftime | php | Datawalke/Coordino | cake/libs/view/helpers/time.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/time.php | MIT |
function header($attrib = array()) {
if (Configure::read('App.encoding') !== null) {
$this->encoding = Configure::read('App.encoding');
}
if (is_array($attrib)) {
$attrib = array_merge(array('encoding' => $this->encoding), $attrib);
}
if (is_string($attrib) && strpos($attrib, 'xml') !== 0) {
$attrib = 'xml ' . $attrib;
}
return $this->Xml->header($attrib);
} | Returns an XML document header
@param array $attrib Header tag attributes
@return string XML header
@access public
@link http://book.cakephp.org/view/1476/header | header | php | Datawalke/Coordino | cake/libs/view/helpers/xml.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/xml.php | MIT |
function addNs($name, $url = null) {
return $this->Xml->addNamespace($name, $url);
} | Adds a namespace to any documents generated
@param string $name The namespace name
@param string $url The namespace URI; can be empty if in the default namespace map
@return boolean False if no URL is specified, and the namespace does not exist
default namespace map, otherwise true
@deprecated
@see Xml::addNs() | addNs | php | Datawalke/Coordino | cake/libs/view/helpers/xml.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/xml.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.