2

My project is using Symfony 1.3.11, PHP version is 5.3.3.

Let me explain my case and my problem:

  1. We wanted to add another kind of user, not just "user" and "admin" (using sfGuardPlugin). I did add "business" and I did give him permissions to only ONE admin module -- "purchases" (accessing own and under some conditions -- other people's purchases made on the site).
  2. The "business" user can be associated to one or more Partners (firms) registered in the site, effectively allowing us to handle business owners or representatives a wee bit differently.
  3. When the "business" user accesses the admin section, the list of purchases he sees must be this: All Purchases for all Products of all Partners he has associated with him. (Not exactly a trivial query).
  4. I did that, in my opinion, in a stupid manner, but it does work -- namely overriding the "apps/backend/modules/purchase/actions/actions.class.php#executeIndex". I had to first copy-paste some code from the version of that method in the cache.
  5. In short, I did hook myself to the "executeIndex" and added a code to do the proper Criteria, and the code works.

The problem now is this:

The filter field above the list (the one containing the Product list) does contain all possible Products. We want it to only contain all Products for all Partners the current user is associated with.

Thing is, it's my first time having to override the admin's filters and I am lost as to where should I plug my code.

Any help is appreciated. Thanks for your time.

UPDATE: Strangely very unpopular question. Nobody ever had to do this? Wow.

dimitarvp
  • 2,316
  • 2
  • 20
  • 29
  • I guess nobody likes to use symfony 1.x anymore ;P – Tommy Bravo Dec 02 '14 at 12:01
  • True that. Happily, I moved on long ago. ;) – dimitarvp Dec 03 '14 at 11:32
  • Sadly I haven't got that luxury yet (still some legacy code) :( – Tommy Bravo Dec 05 '14 at 15:00
  • 1
    @TommyBravo believe it or not, I managed to convince a customer to move away off Symfony after I wrote a minimal set of scripts automatating the move from a lot of the old PHP functionality to a Rails app. Basically my own small code generator. Did it for free, but now I am a much happier person in this project, and they are too. ;) – dimitarvp Dec 05 '14 at 15:17

1 Answers1

1

You have to unset the product_list and set another widget with the filtered choices.

Check this post where I explain something like that but using doctrine. In your case the sfGuardUserForm is your somthingFilterForm.

You could also filter data using this method. This is a little more elegant but both would work.

Community
  • 1
  • 1
Pabloks
  • 1,484
  • 1
  • 14
  • 15
  • I am little lost. This is in the backend. How do I apply your advice in this scenario? As you know, most of the magic in the backend is hidden in `generator.yml`. I do have the peer methods to filter the data; now I need a concrete place to go and put a code to call them. In this case: I have a `product_id` filter in the generator, but I want it's choices to be limited further with my peer methods. Could you be a bit more specific? Where should the form be? Where do I unset the widget? Etc.? – dimitarvp Jun 24 '11 at 10:04
  • When you create the admin module you used a model. I think you used purchase as model, so, you have to find (try in /lib/filter/propel/) the purchaseFormFilter. There you can tweak as you want. – Pabloks Jun 24 '11 at 15:10
  • 1
    Thanks. Managed to do it by going into `PurchaseFormFilter#configure`, like that: `$this->setWidget('product_id', new sfWidgetFormPropelChoice(array('model' => 'Product', 'add_empty' => true, 'criteria' => $product_criteria)));`, where `product_criteria` is exactly the criteria I need for limiting the values of the filtering combo box. – dimitarvp Jun 25 '11 at 07:04