Skip to content

Commit

Permalink
extracted out filtering of list into it's own protected method to add…
Browse files Browse the repository at this point in the history
… filtering to exported data
  • Loading branch information
David McReynolds committed Oct 18, 2014
1 parent 1baaab6 commit d74da0d
Showing 1 changed file with 41 additions and 26 deletions.
67 changes: 41 additions & 26 deletions fuel/modules/fuel/controllers/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,32 +210,8 @@ function items()
// save page state
$this->fuel->admin->save_page_state($params);

// create search filter
$filters[$this->display_field] = trim($params['search_term']);

// sort of hacky here... to make it easy for the model to just filter on the search term (like the users model)
$this->model->filter_value = trim($params['search_term']);

foreach($this->filters as $key => $val)
{
$filters[$key] = $params[$key];

if ( ! empty($val['filter_join']))
{
if ( ! is_array($this->model->filter_join[$key]))
{
settype($this->model->filter_join, 'array');
}

$this->model->filter_join[$key] = $val['filter_join'];
}
}

// set model filters before pagination and setting table data
if (method_exists($this->model, 'add_filters'))
{
$this->model->add_filters($filters);
}
// filter the list
$this->_filter_list($params);

// to prevent it from being called unnecessarily with ajax
if ( ! is_ajax())
Expand Down Expand Up @@ -682,6 +658,44 @@ protected function _list_process()
/* PROCESS PARAMS END */
return $params;
}

// --------------------------------------------------------------------

/**
* Adds filters to the model
*
* @access protected
* @return void
*/
function _filter_list($params)
{
// create search filter
$filters[$this->display_field] = trim($params['search_term']);

// sort of hacky here... to make it easy for the model to just filter on the search term (like the users model)
$this->model->filter_value = trim($params['search_term']);

foreach($this->filters as $key => $val)
{
$filters[$key] = $params[$key];

if ( ! empty($val['filter_join']))
{
if ( ! is_array($this->model->filter_join[$key]))
{
settype($this->model->filter_join, 'array');
}

$this->model->filter_join[$key] = $val['filter_join'];
}
}

// set model filters before pagination and setting table data
if (method_exists($this->model, 'add_filters'))
{
$this->model->add_filters($filters);
}
}

// --------------------------------------------------------------------

Expand Down Expand Up @@ -1968,6 +1982,7 @@ function export()

$filename = $this->module.'_'.date('Y-m-d').'.csv';
$params = $this->_list_process();
$this->_filter_list($params);
$data = $this->model->export_data($params);

force_download($filename, $data);
Expand Down

0 comments on commit d74da0d

Please sign in to comment.