Bitrix Site Manager

CAdminFilter

The CAdminFilter class is used with the result filter in Control Panel pages.

Methods

Method Description
CAdminFilter The class constructor.
Begin Displays the filter title.
Buttons Displays the filter buttons.
End Ends the filter display.

Example

The following example shows how to set up a filter.


// Move the filter check to a separate function
function CheckFilter()
{
    global $FilterArr, $lAdmin;
    foreach ($FilterArr as $f) global $$f;

    /* check values of $find_[name] variables and, 
       if an error occurs, call $lAdmin->AddFilterError("error_text"). */ return count($lAdmin->arFilterErrors) == 0; // if there are errors, return false } // describe the filter elements $FilterArr = Array( "find_id", "find_lid", "find_active", "find_visible", "find_auto", ); // initialise the filter $lAdmin->InitFilter($FilterArr); // if all filter values are correct, process it
if (CheckFilter()) { // create a filter array for extracting  
    // CRubric::GetList() according to filter values $arFilter = Array( "ID" => $find_id, "LID" => $find_lid, "ACTIVE" => $find_active, "VISIBLE" => $find_visible, "AUTO" => $find_auto, ); } // then, pass the received array to CRubric::GetList()

To display the filter, you have to create a CAdminFilter class instance passing the list of fields to it, and then build the filter form "manually".



// create a filter object
$oFilter = new CAdminFilter(
  $sTableID."_filter",
  array(
    "ID",
    GetMessage("rub_f_site"),
    GetMessage("rub_f_active"),
    GetMessage("rub_f_public"),
    GetMessage("rub_f_auto"),
  )
);
?>
<form name="find_form" method="get" action="<?echo $APPLICATION->GetCurPage();?>">
<?$oFilter->Begin();?>
<tr>
  <td><?="ID"?>:</td>
  <td>
    <input type="text" name="find_id" size="47" value="<?echo htmlspecialchars($find_id)?>">
  </td>
</tr>
<tr>
  <td><?=GetMessage("rub_f_site").":"?></td>
  <td><input type="text" name="find_lid" size="47" value="<?echo htmlspecialchars($find_lid)?>"></td>
</tr>
<tr>
  <td><?=GetMessage("rub_f_active")?>:</td>
  <td>
    <?
    $arr = array(
      "reference" => array(
        GetMessage("POST_YES"),
        GetMessage("POST_NO"),
      ),
      "reference_id" => array(
        "Y",
        "N",
      )
    );
    echo SelectBoxFromArray("find_active", $arr, $find_active, GetMessage("POST_ALL"), "");
    ?>
  </td>
</tr>
<tr>
  <td><?=GetMessage("rub_f_public")?>:</td>
  <td><?echo SelectBoxFromArray("find_visible", $arr, $find_visible, GetMessage("POST_ALL"), "");?></td>
</tr>
<tr>
  <td><?=GetMessage("rub_f_auto")?>:</td>
  <td><?echo SelectBoxFromArray("find_auto", $arr, $find_auto, GetMessage("POST_ALL"), "");?></td>
</tr>
<?
$oFilter->Buttons(array("table_id"=>$sTableID,"url"=>$APPLICATION->GetCurPage(),"form"=>"find_form"));
$oFilter->End();
?>
</form>