15 de julho de 2011

Distinct backend Filters for users

Simple way of showing different backend filters for different users:

lib/filter/doctrine/YourFormFilter.class.php
class YourFormFilter extends BaseYourFormFilter {
  public function setup() {
    // ...

    $context = sfContext::getInstance(); /* @var $context sfContext */
    $request = $context->getRequest(); /* @var $request sfWebRequest */
    $user = $context->getUser(); /* @var $user sfBasicSecurityUser */
        
    if ($user->hasCredential('credential_to_check')) {
      $this->setWidget('your_field', new sfWidgetFormFilterInput());
      $this->setValidator('your_field', new sfValidatorPass(array('required' => false)));
      $this->widgetSchema->moveField('your_field', sfWidgetFormSchema::AFTER, 'other_field'); // this is good to re-arrange the filters order
    }
  }

  // ...

Nenhum comentário:

Postar um comentário