Documentation

Add

int
CRatings::Add(
 array fields,
);

The method adds a new rating. Non-static method.

Method parameters

Parameter Description
fields Array of parameter values. The following values are available as the keys for this array:
  • NAME – rating name
  • ACTIVE – rating active status (Y|N)
  • ENTITY_ID – rated object (for example: USER, BLOG, and etc.)
  • CALCULATION_METHOD – type of rating calculation (SUM - sum of criteria, AVG – average criteria value)
  • CONFIGS – array, describing the rating criteria.
All fields are required.

See Also

Examples of use


<?
// create rating with criteria from the blog and forum modules
// consider only the rating votes, without the active status 
$arConfig = array();
$arConfig['FORUM'] = array(
	'VOTE' => array(
		'TOPIC' => array(
			'ACTIVE' => 'Y',
			'COEFFICIENT' => '1',
		),
		'POST' => array(
			'ACTIVE' => 'Y',
			'COEFFICIENT' => '1',
		),
	),
	'RATING' => array(
		'ACTIVITY' => array(
			'ACTIVE' => 'N',
			'TODAY_TOPIC_COEF' => '20',
			'WEEK_TOPIC_COEF' => '10',
			'MONTH_TOPIC_COEF' => '5',
			'TODAY_POST_COEF' => '0.4',
			'WEEK_POST_COEF' => '0.2',
			'MONTH_POST_COEF' => '0.1',
		),
	),
);
$arConfig['BLOG'] = array(
'VOTE' => array(
		'POST' => array(
			'ACTIVE' => 'Y',
			'COEFFICIENT' => '1',
		),
		'COMMENT' => array(
			'ACTIVE' => 'Y',
			'COEFFICIENT' => '1',
		),
	),
	'RATING' => array(
		'ACTIVITY' => array(
			'ACTIVE' => 'N',
			'TODAY_POST_COEF' => '20',
			'WEEK_POST_COEF' => '10',
			'MONTH_POST_COEF' => '5',
			'TODAY_COMMENT_COEF' => '0.4',
			'WEEK_COMMENT_COEF' => '0.2',
			'MONTH_COMMENT_COEF' => '0.1',
		),
	),
);

$arAddRating = array(
	'ACTIVE' => 'Y',
	'NAME' => 'Rating created via the API',
	'ENTITY_ID' => 'USER',
	'CALCULATION_METHOD' => 'SUM',
	'CONFIGS' => $arConfig
);
$ratingId = CRatings::Add($arAddRating);
if (intval($ratingId) > 0)
    echo "Rating is added successfully.";
?>


© «Bitrix24», 2001-2022
Up