0

I have a request to create a form filter that has two fields, one a freeform text and the other a select. The value in the select will determine how to handle the value of the text is turned into a criteria.

I can create a custom addXXXColumnCriteria for either field, but how can I access the other field from within this function?

j0k
  • 22,600
  • 28
  • 79
  • 90
Geoff Maddock
  • 1,700
  • 3
  • 26
  • 47

1 Answers1

2

I suggest you not to use de addXXXColumnCriteria, but overwrite the FormFilter doBuildCriteria (Propel) or doBuildQuery(Doctrine) methods. I have never used Propel, but I guess that works as good as for Doctrine.

For example:

class yourPropelFormFilter extends anyKindOfSfFormFilterPropel {

  public function doBuildCriteria(array $values) {

     $criteria = parent::doBuildCriteria($values);

     // ... change the criteria behaviour with the $values array (do some print_r to $values to see how the data array is formatted)

     return $criteria;
  }

}

For Doctrine (remember to use the getRootAlias query method):

class yourDoctrineFormFilter extends anyKindOfSfFormFilterDoctrine {

   public function doBuildQuery(array $values) {
      $q = parent::doBuildQuery($values);
      $rootAlias = $q->getRootAlias();

      if(...) {
        $q->innerJoin($rootAlias.'.RelationX rx')
          ->addWhere('rx.value = ?',$values['...']);
      }

      return $q;
   }

}

Please, remember to return the criteria/query modified object!

j0k
  • 22,600
  • 28
  • 79
  • 90
glerendegui
  • 1,457
  • 13
  • 15