Documentation

CUserCounter Class

This class is used to handle counters.

The following must be considered when working with counters:

  • The counter code can contain not more than 50 characters;
  • The counter value cannot be more than 18 numeric symbols;
  • When calling GetValue and GetValues with the same value of variables $user_id, $site_id, the request for selection is performed on the first hit. This is due to increment methods for specifying values consider and update cache on demand.

How to register counter update

To do it, add an event handler:

BX.addCustomEvent("onPullEvent", BX.delegate(function(module_id,command,params){
   if (module_id == "main" && command == 'user_counter' && params[BX.message('SITE_ID')] && params[BX.message('SITE_ID')]['__YOUR_COUNTER_NAME__'])
   {
      // call a code to update the counter
      // in params[BX.message('SITE_ID')]['__YOUR_COUNTER_NAME__'] - new counter value is returned
   }
}, this));

For mobile version:

BX.addCustomEvent("onPull", BX.delegate(function(data){
   if (data.module_id == "main" && data.command == 'user_counter' && data.params[BX.message('SITE_ID')] && data.params[BX.message('SITE_ID')]['__YOUR_COUNTER_NAME__'])
      {
      // call a code to update the counter
      // in data.params[BX.message('SITE_ID')]['__YOUR_COUNTER_NAME__'] - new counter value is returned
   }
}, this));

Class methods

Method Description Available from version
GetValues Gets all values for user counters. 11.5.2
GetValue Gets a specific user counter. 11.5.2
Increment Counter increment 11.5.2
Set Sets any number for a counter. 11.5.2
Clear Clears a counter. 11.5.2
ClearAll Clears all counters. 11.5.2
ClearByTag Clears all counters by tag. 11.5.6
Decrement Decrements counter for required value. 11.5.6
GetAllValues Returns all values for all available sites. 12.5.8
IncrementWithSelect Increments counters via subquery. 12.5.8


© «Bitrix24», 2001-2024