nighty commit
This commit is contained in:
parent
02d189bec8
commit
49e2421171
@ -602,7 +602,7 @@ abstract class Base extends ActionController
|
||||
switch ($render_type) {
|
||||
case 'action':
|
||||
# Cut the 'Controller' part of the class name.
|
||||
$path = Rails::services()->get('inflector')->underscore(substr(get_called_class(), 0, -10)) . '/' . $main_param . '.php';
|
||||
$path = Rails::services()->get('inflector')->underscore(substr(get_called_class(), 0, -10)) . '/' . $main_param;
|
||||
|
||||
// if ($route->namespaces())
|
||||
// $path = implode('/', $route->namespaces()) . '/' . $path;
|
||||
@ -611,7 +611,10 @@ abstract class Base extends ActionController
|
||||
# Fallthrough
|
||||
|
||||
case 'template':
|
||||
$respParams = [];
|
||||
|
||||
$layout = !empty($this->render_params['layout']) ? $this->render_params['layout'] : $this->layout;
|
||||
$respParams['layout'] = $layout;
|
||||
|
||||
$ext = pathinfo($main_param, PATHINFO_EXTENSION);
|
||||
|
||||
@ -621,8 +624,9 @@ abstract class Base extends ActionController
|
||||
if ($this->request()->format() == 'html') {
|
||||
$ext = 'php';
|
||||
} else {
|
||||
if ($this->request()->format() == 'xml')
|
||||
$this->_response_params['is_xml'] = true;
|
||||
if ($this->request()->format() == 'xml') {
|
||||
$respParams['is_xml'] = true;
|
||||
}
|
||||
$ext = [$this->request()->format(), 'php'];
|
||||
|
||||
$this->response()->headers()->contentType($this->request()->format());
|
||||
@ -639,11 +643,10 @@ abstract class Base extends ActionController
|
||||
$template_name = $pinfo['dirname'] . '/' . $pinfo['filename'];
|
||||
}
|
||||
|
||||
$this->_response_params = [
|
||||
'layout' => $layout,
|
||||
'template_name' => $template_name,
|
||||
'extension' => $ext
|
||||
];
|
||||
$respParams['template_name'] = $template_name;
|
||||
$respParams['extension'] = $ext;
|
||||
|
||||
$this->_response_params = $respParams;
|
||||
|
||||
# Here we could choose a different responder according to extensions(?).
|
||||
$class = 'Rails\ActionController\Response\Template';
|
||||
|
@ -81,19 +81,20 @@ class Parameters implements \IteratorAggregate
|
||||
if ($var) {
|
||||
global ${$var};
|
||||
|
||||
if (is_array(${$var}[$prop])) {
|
||||
// if (is_array(${$var}[$prop])) {
|
||||
// if (isset($this->files[$prop])) {
|
||||
// ${$var}[$prop] = array_merge(${$var}[$prop], $this->files[$prop]);
|
||||
// }
|
||||
$this->$prop = new GlobalVar(${$var}[$prop], $var, $prop);
|
||||
// $this->$prop = new GlobalVar(${$var}[$prop], $var, $prop);
|
||||
# Return here.
|
||||
return $this->$prop;
|
||||
} elseif (is_object(${$var}[$prop])) {
|
||||
$this->$prop = ${$var}[$prop];
|
||||
$ret = $this->$prop;
|
||||
} else {
|
||||
// return
|
||||
// return $this->$prop;
|
||||
// } elseif (is_object(${$var}[$prop])) {
|
||||
// $this->$prop = ${$var}[$prop];
|
||||
// $ret = $this->$prop;
|
||||
// } else {
|
||||
$ret = ${$var}[$prop];
|
||||
}
|
||||
// }
|
||||
} else {
|
||||
if (isset($this->putVars[$prop]))
|
||||
$ret = $this->putVars[$prop];
|
||||
|
@ -8,10 +8,20 @@ trait Tag
|
||||
return '<' . $name . ' ' . $this->_options($options, $escape) . ($open ? '>' : ' />');
|
||||
}
|
||||
|
||||
/**
|
||||
* $content could be a Closure that can either return a string or
|
||||
* echo the contents itself.
|
||||
*/
|
||||
public function contentTag($name, $content, array $options = array(), $escape = false)
|
||||
{
|
||||
if ($content instanceof \Closure) {
|
||||
$content = $content($this->view());
|
||||
ob_start();
|
||||
$tmpContent = $content();
|
||||
$content = ob_get_clean();
|
||||
if ($tmpContent !== null) {
|
||||
$content = $tmpContent;
|
||||
unset($tmpContent);
|
||||
}
|
||||
}
|
||||
return $this->_content_tag_string($name, $content, $options, $escape);
|
||||
}
|
||||
|
@ -1,168 +0,0 @@
|
||||
<?php
|
||||
namespace Rails\ActionView\Helper\WillPaginate;
|
||||
|
||||
use Rails;
|
||||
use Rails\ActiveRecord\Collection;
|
||||
|
||||
abstract class AbstractRenderer
|
||||
{
|
||||
protected $collection;
|
||||
|
||||
protected $options;
|
||||
|
||||
protected $helper;
|
||||
|
||||
protected $pages;
|
||||
|
||||
protected $page;
|
||||
|
||||
protected $url;
|
||||
|
||||
public function __construct($helper, Collection $collection, array $options = [])
|
||||
{
|
||||
$this->collection = $collection;
|
||||
$this->helper = $helper;
|
||||
$this->options = array_merge($this->defaultOptions(), $options);
|
||||
}
|
||||
|
||||
public function toHtml()
|
||||
{
|
||||
$html = implode(array_map(function($item){
|
||||
if (is_int($item))
|
||||
return $this->pageNumber($item);
|
||||
else
|
||||
return $this->$item();
|
||||
}, $this->pagination()), $this->options['link_separator']);
|
||||
|
||||
return $this->options['container'] ? $this->htmlContainer($html) : $html;
|
||||
}
|
||||
|
||||
protected function defaultOptions()
|
||||
{
|
||||
return [
|
||||
'previous_label' => '← ' . $this->helper->t('actionview.helper.will_paginate.previous'),
|
||||
'next_label' => $this->helper->t('actionview.helper.will_paginate.next') . ' →',
|
||||
'container' => true,
|
||||
'link_separator' => ' '
|
||||
];
|
||||
}
|
||||
|
||||
protected function pageNumber($page)
|
||||
{
|
||||
if ($page != $this->collection->currentPage())
|
||||
return $this->link($page, $page, ['rel' => $this->relValue($page)]);
|
||||
else
|
||||
return $this->tag('span', $page, ['class' => 'current']);
|
||||
}
|
||||
|
||||
protected function gap()
|
||||
{
|
||||
return '<span class="gap">…</span>';
|
||||
}
|
||||
|
||||
protected function previousPage()
|
||||
{
|
||||
$num = $this->collection->currentPage() > 1 ?
|
||||
$this->collection->currentPage() - 1 : false;
|
||||
return $this->previousOrNextPage($num, $this->options['previous_label'], 'previousPage');
|
||||
}
|
||||
|
||||
protected function nextPage()
|
||||
{
|
||||
$num = $this->collection->currentPage() < $this->collection->totalPages() ?
|
||||
$this->collection->currentPage() + 1 : false;
|
||||
return $this->previousOrNextPage($num, $this->options['next_label'], 'nextPage');
|
||||
}
|
||||
|
||||
protected function previousOrNextPage($page, $text, $classname)
|
||||
{
|
||||
if ($page)
|
||||
return $this->link($text, $page, ['class' => $classname]);
|
||||
else
|
||||
return $this->tag('span', $text, ['class' => $classname . ' disabled']);
|
||||
}
|
||||
|
||||
protected function htmlContainer($html)
|
||||
{
|
||||
return $this->tag('div', $html, $this->containerAttributes());
|
||||
}
|
||||
|
||||
protected function containerAttributes()
|
||||
{
|
||||
return ['class' => 'pagination'];
|
||||
}
|
||||
|
||||
protected function relValue($page)
|
||||
{
|
||||
if ($this->collection->currentPage() - 1 == $page)
|
||||
return 'prev' . ($page == 1 ? ' start' : '');
|
||||
elseif ($this->collection->currentPage() + 1 == $page)
|
||||
return 'next';
|
||||
elseif ($page == 1)
|
||||
return 'start';
|
||||
}
|
||||
|
||||
protected function pagination()
|
||||
{
|
||||
$pages = $this->collection->totalPages();
|
||||
$page = $this->collection->currentPage();
|
||||
$pagination = [];
|
||||
|
||||
$pagination[] = 'previousPage';
|
||||
$pagination[] = 1;
|
||||
|
||||
if ($pages < 10){
|
||||
for ($i = 2; $i <= $pages; $i++){
|
||||
$pagination[] = $i;
|
||||
}
|
||||
} elseif ($page > ($pages - 4)) {
|
||||
$pagination[] = 'gap';
|
||||
for ($i = ($pages - 4); $i < ($pages); $i++) {
|
||||
$pagination[] = $i;
|
||||
}
|
||||
} elseif ($page > 4) {
|
||||
$pagination[] = 'gap';
|
||||
for ($i = ($page - 1); $i <= ($page + 2); $i++) {
|
||||
$pagination[] = $i;
|
||||
}
|
||||
$pagination[] = 'gap';
|
||||
} else {
|
||||
if ($page >= 3){
|
||||
for ($i = 2; $i <= $page+2; $i++) {
|
||||
$pagination[] = $i;
|
||||
}
|
||||
} else {
|
||||
for ($i = 2; $i <= 5; $i++) {
|
||||
$pagination[] = $i;
|
||||
}
|
||||
}
|
||||
$pagination[] = 'gap';
|
||||
}
|
||||
|
||||
if ($pages >= 10) {
|
||||
if ($pages == $page)
|
||||
$pagination[] = $i;
|
||||
else
|
||||
$pagination[] = $pages;
|
||||
}
|
||||
|
||||
$pagination[] = 'nextPage';
|
||||
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
protected function link($text, $page, array $attrs = [])
|
||||
{
|
||||
return $this->helper->linkTo($text, array_merge(['#index'], $this->params()->query_parameters(), ['page' => $page]), $attrs);
|
||||
}
|
||||
|
||||
protected function tag($type, $content, array $attrs = [])
|
||||
{
|
||||
return $this->helper->contentTag($type, $content, $attrs);
|
||||
}
|
||||
|
||||
protected function params()
|
||||
{
|
||||
return Rails::application()->dispatcher()->parameters();
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
namespace Rails\ActionView\Helper\WillPaginate;
|
||||
|
||||
class BootstrapRenderer extends AbstractRenderer
|
||||
{
|
||||
public function toHtml()
|
||||
{
|
||||
$html = implode(array_map(function($item){
|
||||
if (is_int($item))
|
||||
return $this->pageNumber($item);
|
||||
else
|
||||
return $this->$item();
|
||||
}, $this->pagination()), $this->options['link_separator']);
|
||||
|
||||
return $this->htmlContainer($this->tag('ul', $html));
|
||||
}
|
||||
|
||||
protected function pageNumber($page)
|
||||
{
|
||||
if ($page != $this->collection->currentPage())
|
||||
return $this->tag('li', $this->link($page, $page, ['rel' => $this->relValue($page)]));
|
||||
else
|
||||
return $this->tag('li', $this->tag('span', $page), ['class' => 'current']);
|
||||
}
|
||||
|
||||
protected function gap()
|
||||
{
|
||||
return $this->tag('li', $this->link('…', "#"), ['class' => 'disabled']);
|
||||
}
|
||||
|
||||
protected function previousPage()
|
||||
{
|
||||
$num = $this->collection->currentPage() > 1 ?
|
||||
$this->collection->currentPage() - 1 : false;
|
||||
return $this->previousOrNextPage($num, $this->options['previous_label'], 'prev');
|
||||
}
|
||||
|
||||
protected function nextPage()
|
||||
{
|
||||
$num = $this->collection->currentPage() < $this->collection->totalPages() ?
|
||||
$this->collection->currentPage() + 1 : false;
|
||||
return $this->previousOrNextPage($num, $this->options['next_label'], 'next');
|
||||
}
|
||||
|
||||
protected function previousOrNextPage($page, $text, $classname)
|
||||
{
|
||||
if ($page)
|
||||
return $this->tag('li', $this->link($text, $page), ['class' => $classname]);
|
||||
else
|
||||
return $this->tag('li', $this->tag('span', $text), ['class' => $classname . ' disabled']);
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
namespace Rails\ActionView\Helper\WillPaginate;
|
||||
|
||||
use Rails\ActiveRecord\Collection;
|
||||
|
||||
class LegacyRenderer extends AbstractRenderer
|
||||
{
|
||||
}
|
@ -52,6 +52,13 @@ class Template extends Base
|
||||
|
||||
private $_lambda;
|
||||
|
||||
// /**
|
||||
// * Template Extension to search for.
|
||||
// * Eg: xml => file_name.xml.php
|
||||
// * If null, no extra extension is appended.
|
||||
// */
|
||||
// private $tplExtension;
|
||||
|
||||
/**
|
||||
* $render_params could be:
|
||||
* - A string, that will be taken as "file".
|
||||
|
@ -45,10 +45,10 @@ class Xml
|
||||
|
||||
if (is_string($content))
|
||||
$this->_buffer .= $content;
|
||||
elseif ($content instanceof Closure)
|
||||
elseif ($content instanceof \Closure)
|
||||
$this->_buffer .= $content();
|
||||
else
|
||||
throw new Exception\InvalidArgumentError(
|
||||
throw new Exception\InvalidArgumentException(
|
||||
sprintf('Expecting Closure or string as third argument, %s passed.', gettype($content))
|
||||
);
|
||||
|
||||
|
@ -71,8 +71,14 @@ class QueryBuilder extends AbstractQueryBuilder
|
||||
# Case: ["foo" => $foo, "bar_baz" => $bar];
|
||||
if (is_array($condition)) {
|
||||
foreach ($condition as $column => $value) {
|
||||
$where[] = $column . ' = ?';
|
||||
$where_params[] = $value;
|
||||
if (is_array($value)) {
|
||||
$k = 1;
|
||||
$where[] = '`' . $column . '` IN (' . implode(', ', array_fill(0, count($value), '?')) . ')';
|
||||
$where_params = array_merge($where_params, $value);
|
||||
} else {
|
||||
$where[] = '`' . $column . '` = ?';
|
||||
$where_params[] = $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($count = substr_count($condition, '?')) {
|
||||
|
@ -32,7 +32,7 @@ abstract class Base implements \ArrayAccess, \IteratorAggregate
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->_get_array());
|
||||
return new \ArrayIterator($this->_get_array());
|
||||
}
|
||||
|
||||
public function merge()
|
||||
|
Reference in New Issue
Block a user