Bitrix Site Manager

CSaleUserAccount::GetList

CDBResult
CSaleUserAccount::GetList(
 array arOrder = array(),
 array arFilter = array(),
 array arGroupBy = false,
 array arNavStartParams = false,
 array arSelectFields = array()
);

The method GetList returns a selection of accounts according to the specified criteria.

Parameters

ParameterDescription
arOrder Associated array used to sort the resulting records. The array has the following format:
array(
"field_name1" => "sort_order1",
"field_name2" => "sort_order2",
. . .
)
The fields field_nameN can be any field of an account. The sort_orderX can be either "ASC" (ascending) or "DESC" (descending). 

If the sorting array has more than one elements, the resulting list is sorted by each element in series (i.e. the list is first sorted by the first element, then the result is sorted by the second element etc). 

The default value is an empty array() which means that the result will not be sorted.
arFilter Associated array used to filter the records of accounts. The array has the following format:
array(
"[modifier1][operator1]field_name1" => "value1",
"[modifier2][operator2]field_name2" => "value2",
. . .
)
Records satisfying the filter conditions are returned as a result, others are truncated.

The following modifiers are possible:
  • ! - negation;
  • + - values null, 0 and empty string also satisfy the filter conditions.
The following operators are possible:
  • >= - the field value is more than or equal to that passed in the filter;
  • > - the field value is more than that passed in the filter;
  • <= - the field value is less than or equal to that passed in the filter;
  • < - the field value is less than that passed in the filter;
  • @ - the field value is stored in the list of comma separated values passed in the filter;
  • ~ - the field value is matched against the wildcard passed to the filter;
  • % - the field value is matched (according to the query language) against the string passed to the filter.
The fields field_nameX can be name of any field containing information about an account.

Example:
array("USER_ID" => 150)
This filter tells to "return all records with the value 150 in the USER_ID field".

The default value is an empty array() which means that the result will not be filtered.
arGroupBy Associated array used to group the records of accounts. The array has the following format:
array("field_name1", 
      "grouping_function2" => "field_name2", ...)
The fields field_nameN can be any field containing information about an account. The grouping_functionX can be one of the following:
  • COUNT - quantity counting;
  • AVG - calculation of the average value;
  • MIN - calculation of the minimum value;
  • MAX - calculation of the maximum value;
  • SUM - calculation of the total value.
If the array is empty, the method will return the number of records satisfying the filter.

The default value is false which means that the result will not be grouped.
arNavStartParams Array of the selection parameters. The following keys are possible in this array:
  • "nTopCount" - number of records returned by the method will be limited to the value of this key;
  • any key that can be passed to CDBResult::NavQuery in the third parameter.
The default value is false which means that no parameter is given.
arSelectFields Array of record fields that will be returned by the method. You may specify the required fields only. If the array contains the value of "*", all available fields will be returned.

The default value is an empty array() which means that all the fields of the main query table will be returned.

Return Values

The method returns an instance of the CDBResult class, containing the list of associated arrays with parameters of accounts:

 If an empty array is passed as an arGroupBy parameter, the method will return the number of records satisfying the filter.

Example



<?
// Select all accounts (with different currencies) of the user #21
$dbAccountCurrency = CSaleUserAccount::GetList(
        array(),
        array("USER_ID" => "21"),
        false,
        false,
        array("CURRENT_BUDGET", "CURRENCY")
    );
while ($arAccountCurrency = $dbAccountCurrency->Fetch())
{
    echo "Current balance ".$arAccountCurrency["CURRENCY"].": ";
    echo SaleFormatCurrency($arAccountCurrency["CURRENT_BUDGET"],
                            $arAccountCurrency["CURRENCY"])."<br>";
}

// Obtain the total amount of the users' accounts
$dbAccountCurrency = CSaleUserAccount::GetList(
        array("CURRENCY" => "ASC"),
        array(),
        array("CURRENCY", "SUM" => "CURRENT_BUDGET"),
        false,
        array("CURRENCY", "SUM" => "CURRENT_BUDGET")
    );
while ($arAccountCurrency = $dbAccountCurrency->Fetch())
{
    echo "Currency ".$arAccountCurrency["CURRENCY"].": ";
    echo SaleFormatCurrency($arAccountCurrency["CURRENT_BUDGET"],
                            $arAccountCurrency["CURRENCY"])."<br>";
}
?>