Documentation

GetList

CDBResult
CGroup::GetList(
 string &by = "c_sort",
 string &order = "asc",
 array filter,
 string SHOW_USERS_AMOUNT = "N"
)

The method returns list of groups as an object of CDBResult class. Static method.

Parameters

ParameterDescription Available from version
by Reference to the variable containing the sorting field. The following values are possilble:
  • id - group ID;
  • timestamp_x - date of modification;
  • name - name;
  • active - active state;
  • c_sort - sorting order;
  • description - description
  • users - number of user in a group
оrder Reference to the variable containing the sort order. The following values are possible:
  • asc - by ascension;
  • desc - by descension.
filter An array used to filter users. The following keys are possible:
  • ID - group ID (complex logic is allowed);
  • TIMESTAMP_1 - lower bound of the settings modification date range ("from");
  • TIMESTAMP_2 - upper bound of the settings modification date range ("till");
  • ACTIVE - filter by active state (Y|N);
  • ADMIN - filter by group type ("Y" - administrators| "N" - not administrators);
  • NAME - by name (complex logic is allowed);
  • DESCRIPTION - by description (complex logic is allowed);
  • USERS_1 - lower bound of the number of users ("from");
  • USERS_2 - upper bound of the number of users ("to").
  • STRING_ID - ID code
SHOW_USERS_AMOUNT If set to "Y", the selection will include the field "USERS" containing the number of users in the group; if set to "N", the selection will not include such field (default behaviour). 3.3.12

See Also

Examples of use

<?
$filter = Array
(
    "ID"             => "1 | 2",
    "TIMESTAMP_1"    => "04.02.2004", // in the format of the current site
    "TIMESTAMP_2"    => "04.02.2005",
    "ACTIVE"         => "Y",
    "NAME"           => "Techsupport",
    "DESCRITION"     => "special | support",
    "USERS_1"        => "2", // from 2 users 
    "USERS_2"        => "10" // to 10 users
);
$rsGroups = CGroup::GetList(($by="c_sort"), ($order="desc"), $filter); // select groups
$is_filtered = $rsGroups->is_filtered; // whether the selection is filtered
$rsGroups->NavStart(50); // paginate by 50 records
echo $rsGroups->NavPrint(GetMessage("PAGES")); // display per page navigation
while($rsGroups->NavNext(true, "f_")) :
	echo "[".$f_ID."] ".$f_NAME." ".$f_DESCRIPTION."<br>";	
endwhile;
?>

Filtering can be dove by "STRING_ID" field - group ID. For example:

// Returns group by the ID
function GetGroupByCode ($code)
{
   $rsGroups = CGroup::GetList ($by = "c_sort", $order = "asc", Array ("STRING_ID" => $code));
   return $rsGroups->Fetch();
} 

Examples of filtering by the "STRING_ID" field by several groups:

$rsGroups = CGroup::GetList($by = "c_sort", $order = "asc", array("STRING_ID"=>'groupe code|groupe code|groupe code'));
if(intval($rsGroups->SelectedRowsCount()) > 0)
{
   while($arGroups = $rsGroups->Fetch())
   {
      $arUsersGroups[] = $arGroups;
   }
}


© «Bitrix24», 2001-2024
Up