1
votes

I am working on an admin dashboard, which will be mainly based on the current user that is logged in usingsfDoctrineGuardPlugin

What I'm looking to do though, is to have links in the dashboard, that are basically filters to other modules.

The problem is, I'm not sure how I'd do that.

For example, I'd like to have the following as links:

  • List New Users - This link needs to list all users added in the last 30 days
  • List Suppliers - This needs to list all users that are a group with a group_id of 2
  • List Manufactureres - This needs to list all users that are in a group with group_id of 3

How would I go about doing this?

Thanks

2
Are all these different modules or one, admin generator or not?Dziamid
These links are on the main admin page, dashoboard. The links need to filter users in sfDoctrineGuard, sfGuardUsersipher_z

2 Answers

2
votes

I truly don't think you should use filters in your case. Filters are temporary conditions to your data list. Here's a more elegant solution. We will reuse the functionality of sfGuardUser index action, and set its table_method "on the fly" (based on url).

//exetent the configuration class to override getTable method
class sfGuardUserGeneratorConfiguration extends BaseSfGuardUserGeneratorConfiguration
{
  protected $tableMethod = null;

  public function setTableMethod($name)
  {
    $this->tableMethod = $name;
  }

  public function getTableMethod()
  {
    return null !== $this->tableMethod ? $this->tableMethod : parent::getTableMethod();
  }
}

//now we need to set the tableMethod based on a route param (list):
class sfGuardUserActions extends autoSfGuardUserActions
{
  public function executeIndex(sfWebRequest $request)
  {
    //create a mapping between an url and table method
    $map = array(
      'clients' => 'getClientsList',
      'suppliers' => 'getSuppliersList',
      'manufacturers' => 'getManufacturersList',
    );
    $list = $request->getParameter('list');
    $table_method = isset($map[$list]) ? $map[$list] : null;
    $this->configuration->setTableMethod($table_method);
    parent::executeIndex($request);
  }
}

//create a custom url for your lists:
sf_guard_user_list:
  url:   /guard/users/:list
  param: { module: sfGuardUser, action: index}
  requirements:
    list: clients|suppliers|manufacturers

//and model methods for each of your lists:
class sfGuardUserTable extends PluginsfGuardUserTable
{
  /**
   * List of clients query
   *
   */
  public function getClientsList()
  {
    $q = $this->createQuery('u')
      ->leftJoin('u.Groups g')
      ->where('g.name = ?', 'client');

    return $q;
  }
  //and others
}

That's it. Now you can add links to your dashboard like this:

<?php echo link_to('Clients', 'sf_guard_user_list', array('list'=>'clients')) ?>

P.S. this approach now allows you to use filters (for their true reasons) on top of these lists. But, you will also have to adjust the appropriate links.

0
votes

Here is one issue: Admin generator remembers all filters data as user's attribute (read as "stores this information in session").

So if you dont care about all remembered data of filters, you may create one module that recieve GET parameters, set this parameters as user attribute (sfUser->setAttribute(...)) overriding filters data of needed module, and redirects to module.

Or

You may use GET parameters adding them to an module URL (example.com/users?filter[group_id]=123) that overrides filter params. At this case you should handle this information in each needed module.