return $this->title;
}
- protected function link($params, $value, $title)
+ function paramName()
{
- if ($value !== null)
- $params[$this->paramName] = $value;
- else
- unset($params[$this->paramName]);
-
- return Tag::a()
- ->attr('href', '?'.IPF_HTTP_URL::generateParams($params, false))
- ->append($title);
+ return $this->paramName;
}
}
$q->addWhere($this->relation['local'].' = ?', array($this->selected));
}
- function render($extraParams)
+ function getItems()
{
- $ul = Tag::ul();
+ $items = [];
// reset filter
- $ul->append(Tag::li()
- ->toggleClass('selected', !$this->selected)
- ->append($this->link($extraParams, null, __('All'))));
+ $items[] = array(
+ 'id' => null,
+ 'label' => __('All'),
+ 'selected' => !$this->selected,
+ );
// query related
$table = IPF_ORM::getTable($this->relation['class']);
$foreign = $this->relation['foreign'];
foreach ($query->execute() as $val) {
$id = $val[$foreign];
- $name = (string)$val;
-
- $ul->append(Tag::li()
- ->toggleClass('selected', $this->selected == $id)
- ->append($this->link($extraParams, $id, $name)));
+ $items[] = array(
+ 'id' => $id,
+ 'label' => (string)$val,
+ 'selected' => $this->selected == $id,
+ );
}
- return $ul->html();
+ return $items;
}
}
$q->addWhere($this->column.' = ?', array($this->selected));
}
- function render($extraParams)
+ function getItems()
{
- $ul = Tag::ul();
+ $items = [];
// reset filter
- $ul->append(Tag::li()
- ->toggleClass('selected', !$this->selected)
- ->append($this->link($extraParams, null, __('All'))));
+ $items[] = array(
+ 'id' => null,
+ 'label' => __('All'),
+ 'selected' => !$this->selected,
+ );
foreach (\PFF\Container::auth()->userQuery()->fetchAll() as $val) {
$id = $val->id;
- $name = (string)$val;
-
- $ul->append(Tag::li()
- ->toggleClass('selected', $this->selected == $id)
- ->append($this->link($extraParams, $id, $name)));
+ $items[] = array(
+ 'id' => $id,
+ 'label' => (string)$val,
+ 'selected' => $this->selected == $id,
+ );
}
- return $ul->html();
+ return $items;
}
}
$this->selected = \PFF\Arr::get($params, $this->paramName);
}
- function render($extraParams)
+ function getItems()
{
- return Tag::ul(null,
- Tag::li()
- ->toggleClass('selected', $this->selected !== 'y' && $this->selected !== 'n')
- ->append($this->link($extraParams, null, __('All'))),
- Tag::li()
- ->toggleClass('selected', $this->selected === 'y')
- ->append($this->link($extraParams, 'y', $this->trueTitle)),
- Tag::li()
- ->toggleClass('selected', $this->selected === 'n')
- ->append($this->link($extraParams, 'n', $this->falseTitle)));
+ return [
+ [
+ 'id' => null,
+ 'label' => __('All'),
+ 'selected' => $this->selected !== 'y' && $this->selected !== 'n',
+ ],
+ [
+ 'id' => 'y',
+ 'label' => $this->trueTitle,
+ 'selected' => $this->selected === 'y',
+ ],
+ [
+ 'id' => 'n',
+ 'label' => $this->falseTitle,
+ 'selected' => $this->selected === 'n',
+ ],
+ ];
}
function applyToQuery($q)
}
}
- function render($extraParams)
+ function getItems()
{
- $ul = Tag::ul();
-
- $ul->append(Tag::li()
- ->toggleClass('selected', !$this->year)
- ->append($this->link($extraParams, null, __('All'))));
-
- if ($this->year)
- $ul->append($this->renderChoice($extraParams, $this->year, 0, 0, $this->year)->addClass('selected'));
+ $items = [];
- if ($this->month)
- $ul->append($this->renderChoice($extraParams, $this->year, $this->month, 0, $this->monthName($this->month))->addClass('selected'));
+ $items[] = array(
+ 'id' => null,
+ 'label' => __('All'),
+ 'selected' => !$this->year,
+ );
- if ($this->day)
- $ul->append($this->renderChoice($extraParams, $this->year, $this->month, $this->day, $this->day)->addClass('selected'));
+ if ($this->year) {
+ $items[] = ['id' => sprintf('%04d-00-00', $this->year), 'label' => $this->year, 'selected' => true];
+ }
+ if ($this->month) {
+ $items[] = ['id' => sprintf('%04d-%02d-00', $this->year, $this->month), 'label' => $this->monthName($this->month), 'selected' => true];
+ }
+ if ($this->day) {
+ $items[] = ['id' => sprintf('%04d-%02d-%02d', $this->year, $this->month, $this->day), 'label' => $this->day, 'selected' => true];
+ }
if ($this->day) {
} elseif ($this->month) {
'YEAR(' . $this->name . ')', $this->year,
'MONTH(' . $this->name . ')', $this->month);
foreach ($days as $day) {
- $ul->append($this->renderChoice($extraParams, $this->year, $this->month, $day, $day));
+ $items[] = ['id' => sprintf('%04d-%02d-%02d', $this->year, $this->month, $day), 'label' => $day, 'selected' => false];
}
} elseif ($this->year) {
$months = $this->choices('MONTH(' . $this->name . ')',
'YEAR(' . $this->name . ')', $this->year);
foreach ($months as $month) {
- $ul->append($this->renderChoice($extraParams, $this->year, $month, 0, $this->monthName($month)));
+ $items[] = ['id' => sprintf('%04d-%02d-00', $this->year, $month), 'label' => $this->monthName($month), 'selected' => false];
}
} else {
$years = $this->choices('YEAR(' . $this->name . ')');
foreach ($years as $year) {
- $ul->append($this->renderChoice($extraParams, $year, 0, 0, $year));
+ $items[] = ['id' => sprintf('%04d-00-00', $year), 'label' => $year, 'selected' => false];
}
}
- return $ul->html();
+ return $items;
}
function applyToQuery($q)
return \PFF\Arr::pluck($q->fetchArray(), 'value');
}
- private function renderChoice($extraParams, $year, $month, $day, $label)
- {
- return Tag::li(null,
- $this->link($extraParams, sprintf('%04d-%02d-%02d', $year, $month, $day), $label));
- }
-
protected function monthName($month)
{
return date('F', mktime(0, 0, 0, $month, 1));
}
}
-