Advanced search filters

edited June 2014 in Modules
Hi, I have some problems with advanced search in some modules.

In some models, in the function list_items the data that I'm displaying is from a database view instead of the database table of the model. This is due that in some cases I have to display not only the information of the table or its relationships. In some cases my client want to view a field that is two or three tables from separation of the current table.

So I made a view and it's easier. At the beggining I had problems at the moment of edit or delete but I fixed them. Now I have problems with the filters, I've tried to figure out how to make it work but I couldn't. Can you help me with this?

Comments

  • edited 11:07PM
    What problems are you seeing with the filters (e.g. what sort of errors)?

    For reference, the Base_module_model::list_items() method which makes a subsequent call to a protected method "_list_items_query" is what returns the array of results for the list view. You can overwrite the list_items method in your model to add any joins. The blog_posts_model is a good example overwriting that method.
    https://github.com/daylightstudio/FUEL-CMS-Blog-Module/blob/master/models/blog_posts_model.php
  • edited 11:07PM
    Thank you, I'm working on that.

    But now I have another filter problem in other simple module.

    If I search typing the company name it works, but if I do the search through the advanced search with a dropdown it doesn't work.


    public $filters = array('company.name'); public function list_items($limit = NULL, $offset = NULL, $col = 'precedence', $order = 'desc', $just_count = FALSE) { $where = "employees.IDuser = portal_users.id AND portal_users.id = company.IDuser"; $this->db->join('portal_users', 'portal_users.id=employees.IDuser'); $this->db->select('employees.id, company.name as Company, CONCAT(portal_users.first_name, " ", portal_users.last_name ) as Admin, employees.first_name, employees.last_name, employees.email, employees.occupation', FALSE); $this->db->from('company'); $this->db->where($where); $data = parent::list_items($limit, $offset, $col, $order, $just_count = FALSE); return $data; }

    The dropdown first I did it with the option_list method, I thought that was not working because the value of the option was the company.id and the label was the company.name. Then I did an array in which the value and label are the company name but it it still not working.

    This is my filter code

    public function filters(){ if (defined('FUEL_ADMIN')) { $CI =& get_instance(); $CI->load->model('companies_model'); } $companies_data = $this->companies_model->get_companies(); $companies = array(); foreach ($companies_data as $company) { $companies[$company->name] = $company->name; } $filters['company.name'] = array( 'label' => 'Company', 'type' => 'select', 'options' => $companies, 'first_option' => 'Show All' ); return $filters; }
  • edited 11:07PM
    When you say not working do you mean it's simply not filtering? If so, in the Base_module_model::list_items method there is a $this->debug_query() method on line 294 that you can uncomment out to see what query is actually being generated. It will run twice. Once for the total count (for pagination) and a second time for the actual results limited by what is set for the per page value.
  • edited 11:07PM
    Thank you.

    It was a weird thing. If my filter field belongs to the table of the module was not problem and the query displayed the where clause correctly but if the filter belongs to another table like this, the query was the same like if I wasn't filtering. The where clause wasn't displayed.

    With this post I could solve it http://forum.getfuelcms.com/discussion/1270/filter-in-a-simple-module-using-a-join-in-list-items-/p1

    I just replace the period for colons and now it's working. My filter now is $filters['company:name']
Sign In or Register to comment.