Menu

Step4CreatingFilters

Federico

Step 4: Creating Filters

Class Vtiger_Filter provides API to work with a Module's custom view or filter. The list view display is controlled via these filters.

The example given below describes the way of creating new filter for the module:

include_once('vtlib/Vtecrm/Filter.php');
include_once('vtlib/Vtecrm/Module.php');

$moduleInstance=Vtecrm_Module::getInstance('InstalledBase');

$filterInstance = new Vtecrm_Filter();
$filterInstance->name = 'All';
$filterInstance->isdefault = true;
$moduleInstance->addFilter($filterInstance);

Configure fields

To add fields to the filter you can use the following API:

include_once('vtlib/Vtecrm/Module.php');
include_once('vtlib/Vtecrm/Block.php');
include_once('vtlib/Vtecrm/Field.php');
include_once('vtlib/Vtecrm/Filter.php');

$moduleInstance=Vtecrm_Module::getInstance('InstalledBase');
$blockInstance=Vtecrm_Block::getInstance('LBL_InstalledBase_INFORMATION',$moduleInstance);
$filterInstance=Vtecrm_Filter::getInstance('All',$moduleInstance);

$fieldInstance1=Vtecrm_Field::getInstance('installedbasename',$moduleInstance);
$fieldInstance2=Vtecrm_Field::getInstance('installedbasetype',$moduleInstance);
$fieldInstance3=Vtecrm_Field::getInstance('account_id',$moduleInstance);

$filterInstance->addField($fieldInstance1, 1);
$filterInstance->addField($fieldInstance2, 2);
$filterInstance->addField($fieldInstance3, 3);

Setup Rules

Once the field is added to filter you can setup rule (condition) for filtering as well using the
following API:

$filterInstance->addRule($fieldInstance, $comparator, $compareValue,
$columnIndex);

Where comparator could be one of the following:

  • EQUALS
  • NOT_EQUALS
  • STARTS_WITH
  • ENDS_WITH
  • CONTAINS
  • DOES_NOT_CONTAINS
  • LESS_THAN
  • GREATER_THAN
  • LESS_OR_EQUAL
  • GREATER_OR_EQUAL

$compareValue is the value against with the field needs to be compared.

$columnIndex (optional) is the order at which this rule condition should be applied.