parent::__construct($title, array(
array(
'id' => null,
- 'param' => '',
+ 'param_key' => 'filter_'.$this->column,
+ 'param_value' => null,
'name' => 'All',
'selected' => true,
),
array(
'id' => 'y',
- 'param' => 'filter_'.$this->column.'=y',
+ 'param_key' => 'filter_'.$this->column,
+ 'param_value' => 'y',
'name' => $trueTitle,
'selected' => false,
),
array(
'id' => 'n',
- 'param' => 'filter_'.$this->column.'=n',
+ 'param_key' => 'filter_'.$this->column,
+ 'param_value' => 'n',
'name' => $falseTitle,
'selected' => false,
),
$choices = array();
$choices[] = array(
'id'=>null,
- 'param'=>'',
+ 'param_key'=>'filter_'.$this->name,
+ 'param_value'=>null,
'name'=>'All',
'original_name'=>'All',
'selected'=>false,
$choices[] = array(
'id'=>$id,
- 'param'=>'filter_'.$this->name.'='.$id,
+ 'param_key'=>'filter_'.$this->name,
+ 'param_value'=>$id,
'original_name'=>$o->name,
'name'=>$name,
'selected'=>false,
$this->choices[] = array(
'name' => $r['v'],
'selected' => $current == $v,
- 'param' => 'filter_' . $this->name . '=' . sprintf($this->getFormat(), $v),
+ 'param_key' => 'filter_' . $this->name,
+ 'param_value' => sprintf($this->getFormat(), $v),
);
}
}
$this->choices[] = array(
'name' => $r['v'],
'selected' => false,
- 'param' => 'filter_' . $this->name . '=' . sprintf($format, $v),
+ 'param_key' => 'filter_' . $this->name,
+ 'param_value' => sprintf($format, $v),
);
}
}
array(
'name' => 'All',
'selected' => !$this->year,
- 'param' => ''),
+ 'param_key' => 'filter_' . $this->name,
+ 'param_value' => null,
+ ),
);
if ($this->year) {
$this->choices[] = array(
'name' => $this->year,
'selected' => true,
- 'param' => 'filter_' . $this->name . '=' . $this->year . '-00-00');
+ 'param_key' => 'filter_' . $this->name,
+ 'param_value' => $this->year . '-00-00',
+ );
}
if ($this->month) {
$this->choices[] = array(
'name' => $this->monthName,
'selected' => true,
- 'param' => 'filter_' . $this->name . '=' . sprintf('%04d-%02d-00', $this->year, $this->month));
+ 'param_key' => 'filter_' . $this->name,
+ 'param_value' => sprintf('%04d-%02d-00', $this->year, $this->month),
+ );
}
if ($this->day) {
$this->choices[] = array(
'name' => $this->day,
'selected' => true,
- 'param' => 'filter_' . $this->name . '=' . sprintf('%04d-%02d-%02d', $this->year, $this->month, $this->day));
+ 'param_key' => 'filter_' . $this->name,
+ 'param_value' => sprintf('%04d-%02d-%02d', $this->year, $this->month, $this->day),
+ );
}
if ($this->day) {
$this->ListItemsQuery();
$this->_GetFilters($request);
- $hasSearch = $this->_ListSearchQuery($request);
- if (!$hasSearch || IPF::get('admin_filtered_search', false))
- $this->_ListFilterQuery($request);
+ $this->_ListSearchQuery($request);
+ $this->_ListFilterQuery($request);
$this->ListItemsHeader();
$currentPage = (int)@$request->GET['page'];
protected function _isSearch()
{
- if (method_exists($this,'_searchFields'))
- return true;
- return false;
+ return method_exists($this,'_searchFields');
}
protected function _ListSearchQuery($request)
$whv[] = '%'.$this->search_value.'%';
}
$this->q->addWhere($wh,$whv);
- return true;
}
- return false;
}
protected function _GetFilters($request)
$sel_id = @$request->GET['filter_'.$local];
$choices = array();
$choices[] = array(
- 'id'=>null,
- 'param'=>'',
- 'name'=>'All',
- 'selected'=>($sel_id==''),
+ 'id' => null,
+ 'param_key' => 'filter_'.$local,
+ 'param_value' => null,
+ 'name' => 'All',
+ 'selected' => ($sel_id==''),
);
$table = IPF_ORM::getTable($rels[$f]['class']);
if ($sel_id==$id)
$selected = true;
$choices[] = array(
- 'id'=>$id,
- 'param'=>'filter_'.$local.'='.$id,
- 'name'=>(string)$val,
- 'selected'=>$selected,
+ 'id' => $id,
+ 'param_key' => 'filter_'.$local,
+ 'param_value' => $id,
+ 'name' => (string)$val,
+ 'selected' => $selected,
);
}
$this->filters[$f] = new ListFilter($local, $foreign, $choices, 'By '.IPF_Utils::humanTitle($f));
class IPF_HTTP_URL
{
+ public static function generateParams($params=array(), $encode=true)
+ {
+ $params_list = array();
+ foreach ($params as $key => $value)
+ $params_list[] = urlencode($key).'='.urlencode($value);
+ return implode($encode ? '&' : '&', $params_list);
+ }
+
public static function generate($action, $params=array(), $encode=true)
{
- if ($encode) {
- $amp = '&';
- } else {
- $amp = '&';
- }
- $url = $action;
- if (count($params) > 0) {
- $url .= '?';
- $params_list = array();
- foreach ($params as $key=>$value) {
- $params_list[] = urlencode($key).'='.urlencode($value);
- }
- $url .= implode($amp, $params_list);
- }
- return $url;
+ if (count($params) > 0)
+ $action .= '?' . self::generateParams($params, $encode);
+ return $action;
}
public static function urlForView($view, $params=array(), $get_params=array(), $encoded=true)
}
$e->tags['url'] = 'IPF_Project_Template_Tag_Url';
+ $e->tags['params'] = 'IPF_Project_Template_Tag_Params';
$e->tags['sql'] = 'IPF_Project_Template_Tag_Sql';
// extra tags
$e->tags = array_merge(IPF::get('template_tags', array()), $e->tags);
}
}
+class IPF_Project_Template_Tag_Params extends IPF_Template_Tag
+{
+ private function setParam(&$params, $key, $value)
+ {
+ if ($value === null)
+ unset($params[$key]);
+ else
+ $params[$key] = $value;
+ }
+
+ function start()
+ {
+ $params = array();
+
+ $args = func_get_args();
+ $count = count($args);
+ for ($i = 0; $i < $count; ++$i) {
+ if (is_array($args[$i])) {
+ foreach ($args[$i] as $key => $value)
+ $this->setParam($params, $key, $value);
+ } else {
+ $key = $args[$i];
+ $value = $args[$i+1];
+ $this->setParam($params, $key, $value);
+ ++$i;
+ }
+ }
+
+ echo IPF_HTTP_URL::generateParams($params);
+ }
+}
+
class IPF_Project_Template_Tag_Sql extends IPF_Template_Tag
{
function start()