List items on a module with different options on different ways

edited May 2012 in Modules
I have a advanced module which I have to show on two different ways with according to a field named archived
By default I am showing the archived=no fields
and on another method on controller other lists should be shown where archived = yes

Model is as so:

function list_items($limit = null, $offset = null, $col = 'id', $order = 'desc')
{
$this->db->where('archived', 'no');
$data = parent::list_items($limit, $offset, $col, $order);

return $data;
}
Controller is as so:

require_once(FUEL_PATH.'controllers/module.php');

class Orders extends Module {

function __construct()
{
parent::__construct();
$this->load->module_model('invoice', 'orders_model');
}
public function _remap($method, $params = array())
{
if (method_exists($this, $method))
{
return call_user_func_array(array($this, $method), $params);
}
show_404();
}

function index(){
$this->items();
}

function items(){
parent::items();
}
function archives(){
// don't know how to show lists with archived=no
}
}
as myste.com/admin/orders is shown I what to show myste.com/admin/orders/archives show the rows with archived=yes option.

Comments

  • edited 9:00PM
    if "is_admin" is a public property on your model, you can change that value in the module controller like so:
    $this->model->is_admin = TRUE;
  • edited 9:00PM
    ok thanks but that is not actually what I was asking.
    I have edited my post and removed the code so that you won't confuse.

    I am wanting to filter data of list_items on different methods as specified above.
  • edited 9:00PM
    Leave the list items and controllers, create a table filter instead. Checkout the /fuel/navigation page to view a working example.
  • edited 9:00PM
    If you look at the fuel/modules/fuel/config/fuel_modules.php file, and look at the configuration for the navigation module, you'll see the filters parameter which takes the an array of form_builder_parameters. You can specify the columns that are filtered in the model (see the fuel/modules/fuel/models/navigation_model as an example).
  • edited 9:00PM
    I have seen the navigation module but I cant do filter according to that.

    I think I have to explain on detail:
    I have orders which have field archived with datatype enum('yes','no')
    by default on fuel cms on list_items it shows all data with option yes and no.

    for data with (archived=no) I want to show on this url:
    http://localhost/invoice/admin/invoice/orders
    and for data with (archived=yes) I want to show on this url:
    http://localhost/invoice/admin/invoice/orders/archives
    I have added a controller named controllers/orders and on its index method I have displayed the data with parent::items of parent controller fuel/module.php

    depending on the two mothods on controller/orders.php
    on index method I want to show data with archived=no
    on archives method I want to show data with archived=yes

    I think I am clear.
  • edited 9:00PM
    You could try removing it from the list_items method and then adding it in your controller methods like below:
    function items(){ $this->model->db()->where(array('archived' => 'no')); $this->items(); } .... function archives(){ $this->model->db()->where(array('archived' => 'yes')); $this->items(); }
    Or you could add a property to the model that you could toggle on and off in each method like so:
    function list_items($limit = null, $offset = null, $col = 'id', $order = 'desc') { if (!$this->show_archived){ { $this->db->where('archived', 'no'); } else { $this->db->where('archived', 'yes'); } $data = parent::list_items($limit, $offset, $col, $order); return $data; }
    Then in the controller:

    function items(){ $this->model->show_archived = FALSE; $this->items(); } .... function archives(){ $this->model->show_archived = TRUE; $this->items(); }
  • edited 9:00PM
    this also didn't worked. may be there is something else misconfigured.

    Can you please check it from here
    http://dl.dropbox.com/u/15106116/modules_invoice.rar

    there are two modules:
    -> group_access
    -> invoice // this is mine module where the error persists
  • edited 9:00PM
    Can you try implementing the second method with the show_archived property on the model and then adding the following near the end of your list_items method to see what the query is to provide some insight:
    $this->debug_query();
    Also, the method "archive" is actually part of the base_module_model and you are overwriting it which may cause some errors elsewhere. I'd recommend giving it a different name.
  • edited 9:00PM
    $this->debug_query();
    shows the query 3 times.
    On first query it does correctly and switched between yes and no of archived

    on other two query it always shows archived=no
  • edited 9:00PM
    So the "show_archived" property on the model isn't working?
  • edited June 2012
    It works on first query shown by $this->debug_query();
    This screenshot shall explain:
    image
  • edited 9:00PM
    I'm not certain what may be going on but may provide some insight as to why it's being run twice which may help direct you where to look. The query gets run twice. The second time is to calculate the total number of items without the limits for pagination and is called by the "list_items_total" method inherited from the base_module_model.

    I would think that setting the model property would follow through to the "list_items_total" method call but maybe not in this case... Can you confirm?
Sign In or Register to comment.