function CalcUserBonus($arConfigs) { global $DB; $err_mess = (CRatings::err_mess())."<br>Function: CalcUserBonus<br>Line: "; $communityLastVisit = COption::GetOptionString("main", "rating_community_last_visit", '90'); CRatings::AddComponentResults($arConfigs); $strSql = "DELETE FROM b_rating_component_results WHERE RATING_ID = '".IntVal($arConfigs['RATING_ID'])."' AND COMPLEX_NAME = '".$DB->ForSql($arConfigs['COMPLEX_NAME'])."'"; $res = $DB->Query($strSql, false, $err_mess.__LINE__); $strSql = "INSERT INTO b_rating_component_results (RATING_ID, MODULE_ID, RATING_TYPE, NAME, COMPLEX_NAME, ENTITY_ID, ENTITY_TYPE_ID, CURRENT_VALUE) SELECT '".IntVal($arConfigs['RATING_ID'])."' RATING_ID, '".$DB->ForSql($arConfigs['MODULE_ID'])."' MODULE_ID, '".$DB->ForSql($arConfigs['RATING_TYPE'])."' RATING_TYPE, '".$DB->ForSql($arConfigs['NAME'])."' NAME, '".$DB->ForSql($arConfigs['COMPLEX_NAME'])."' COMPLEX_NAME, RB.ENTITY_ID as ENTITY_ID, '".$DB->ForSql($arConfigs['ENTITY_ID'])."' ENTITY_TYPE_ID, RB.BONUS*".floatval($arConfigs['CONFIG']['COEFFICIENT'])." CURRENT_VALUE FROM b_rating_user RB LEFT JOIN b_user U ON U.ID = RB.ENTITY_ID AND U.ACTIVE = 'Y' AND U.LAST_LOGIN > DATE_SUB(NOW(), INTERVAL ".intval($communityLastVisit)." DAY) WHERE RB.RATING_ID = ".IntVal($arConfigs['RATING_ID'])." AND U.ID IS NOT NULL "; $res = $DB->Query($strSql, false, $err_mess.__LINE__); return true; }
function CalcUserRatingForumActivity($arConfigs) { global $DB; $err_mess = CRatings::err_mess() . "<br>Function: CalcUserRatingForumActivity<br>Line: "; CRatings::AddComponentResults($arConfigs); $strSql = "DELETE FROM b_rating_component_results WHERE RATING_ID = '" . IntVal($arConfigs['RATING_ID']) . "' AND COMPLEX_NAME = '" . $DB->ForSql($arConfigs['COMPLEX_NAME']) . "'"; $res = $DB->Query($strSql, false, $err_mess . __LINE__); $sqlAllTopic = ''; if (isset($arConfigs['CONFIG']['ALL_TOPIC_COEF']) && $arConfigs['CONFIG']['ALL_TOPIC_COEF'] != 0) { $sqlAllTopic = "\n\t\t\t\tSELECT\n\t\t\t\t\tUSER_START_ID as ENTITY_ID,\n\t\t\t\t\tCOUNT(*)*" . floatval($arConfigs['CONFIG']['ALL_TOPIC_COEF']) . " as CURRENT_VALUE\n\t\t\t\tFROM b_forum_topic\n\t\t\t\tWHERE START_DATE < DATE_SUB(NOW(), INTERVAL 30 DAY)\n\t\t\t\tGROUP BY USER_START_ID\n\t\t\t\tUNION ALL "; } $sqlAllMessage = ''; if (isset($arConfigs['CONFIG']['ALL_POST_COEF']) && $arConfigs['CONFIG']['ALL_POST_COEF'] != 0) { $sqlAllMessage = "\n\t\t\t\tSELECT\n\t\t\t\t\tAUTHOR_ID as ENTITY_ID,\n\t\t\t\t\tCOUNT(*)*" . floatval($arConfigs['CONFIG']['ALL_POST_COEF']) . " as CURRENT_VALUE\n\t\t\t\tFROM b_forum_message\n\t\t\t\tWHERE POST_DATE < DATE_SUB(NOW(), INTERVAL 30 DAY)\n\t\t\t\tGROUP BY AUTHOR_ID\n\t\t\t\tUNION ALL "; } $strSql = "INSERT INTO b_rating_component_results (RATING_ID, MODULE_ID, RATING_TYPE, NAME, COMPLEX_NAME, ENTITY_ID, ENTITY_TYPE_ID, CURRENT_VALUE)\n\t\t\tSELECT\n\t\t\t\t'" . IntVal($arConfigs['RATING_ID']) . "' as RATING_ID,\n\t\t\t\t'" . $DB->ForSql($arConfigs['MODULE_ID']) . "' as MODULE_ID,\n\t\t\t\t'" . $DB->ForSql($arConfigs['RATING_TYPE']) . "' as RATING_TYPE,\n\t\t\t\t'" . $DB->ForSql($arConfigs['NAME']) . "' as NAME,\n\t\t\t\t'" . $DB->ForSql($arConfigs['COMPLEX_NAME']) . "' as COMPLEX_NAME,\n\t\t\t\tENTITY_ID,\n\t\t\t\t'" . $DB->ForSql($arConfigs['ENTITY_ID']) . "' ENTITY_TYPE_ID,\n\t\t\t\tSUM(CURRENT_VALUE) CURRENT_VALUE\n\t\t\tFROM (\n\t\t\t\t" . $sqlAllMessage . "\n\n\t\t\t\tSELECT\n\t\t\t\t\tAUTHOR_ID as ENTITY_ID,\n\t\t\t\t\tSUM(IF(TO_DAYS(POST_DATE) > TO_DAYS(NOW())-1, 1, 0))*" . floatval($arConfigs['CONFIG']['TODAY_POST_COEF']) . " +\n\t\t\t\t\tSUM(IF(TO_DAYS(POST_DATE) > TO_DAYS(NOW())-7, 1, 0))*" . floatval($arConfigs['CONFIG']['WEEK_POST_COEF']) . "+\n\t\t\t\t\tCOUNT(*)*" . floatval($arConfigs['CONFIG']['MONTH_POST_COEF']) . " as CURRENT_VALUE\n\t\t\t\tFROM b_forum_message\n\t\t\t\tWHERE POST_DATE > DATE_SUB(NOW(), INTERVAL 30 DAY)\n\t\t\t\tGROUP BY AUTHOR_ID\n\n\t\t\t\tUNION ALL\n\t\t\t\t" . $sqlAllTopic . "\n\n\t\t\t\tSELECT\n\t\t\t\t\tUSER_START_ID as ENTITY_ID,\n\t\t\t\t\tSUM(IF(TO_DAYS(START_DATE) > TO_DAYS(NOW())-1, 1, 0))*" . floatval($arConfigs['CONFIG']['TODAY_TOPIC_COEF']) . " +\n\t\t\t\t\tSUM(IF(TO_DAYS(START_DATE) > TO_DAYS(NOW())-7, 1, 0))*" . floatval($arConfigs['CONFIG']['WEEK_TOPIC_COEF']) . " +\n\t\t\t\t\tCOUNT(*)*" . floatval($arConfigs['CONFIG']['MONTH_TOPIC_COEF']) . " as CURRENT_VALUE\n\t\t\t\tFROM b_forum_topic\n\t\t\t\tWHERE START_DATE > DATE_SUB(NOW(), INTERVAL 30 DAY)\n\t\t\t\tGROUP BY USER_START_ID\n\t\t\t) q\n\t\t\tWHERE ENTITY_ID > 0\n\t\t\tGROUP BY ENTITY_ID"; $res = $DB->Query($strSql, false, $err_mess . __LINE__); return true; }
public static function CalcActivity($arConfigs) { global $DB; $err_mess = CRatings::err_mess() . "<br>Function: CRatingsComponentsBlog::CalcActivity<br>Line: "; CRatings::AddComponentResults($arConfigs); $strSql = "DELETE FROM b_rating_component_results WHERE RATING_ID = '" . IntVal($arConfigs['RATING_ID']) . "' AND COMPLEX_NAME = '" . $DB->ForSql($arConfigs['COMPLEX_NAME']) . "'"; $res = $DB->Query($strSql, false, $err_mess . __LINE__); $sqlAllPost = ''; if (isset($arConfigs['CONFIG']['ALL_POST_COEF']) && $arConfigs['CONFIG']['ALL_POST_COEF'] != 0) { $sqlAllPost = "\n\t\t\t\tSELECT\n\t\t\t\t\tAUTHOR_ID as ENTITY_ID,\n\t\t\t\t\tCOUNT(*)*" . floatval($arConfigs['CONFIG']['ALL_POST_COEF']) . " as CURRENT_VALUE\n\t\t\t\tFROM b_blog_post\n\t\t\t\tWHERE DATE_PUBLISH < DATE_SUB(NOW(), INTERVAL 30 DAY)\n\t\t\t\t\t\tAND PUBLISH_STATUS = '" . BLOG_PUBLISH_STATUS_PUBLISH . "'\n\t\t\t\tGROUP BY AUTHOR_ID\n\t\t\t\tUNION ALL "; } $sqlAllComment = ''; if (isset($arConfigs['CONFIG']['ALL_COMMENT_COEF']) && $arConfigs['CONFIG']['ALL_COMMENT_COEF'] != 0) { $sqlAllComment = "\n\t\t\t\tSELECT\n\t\t\t\t\tAUTHOR_ID as ENTITY_ID,\n\t\t\t\t\tCOUNT(*)*" . floatval($arConfigs['CONFIG']['ALL_COMMENT_COEF']) . " as CURRENT_VALUE\n\t\t\t\tFROM b_blog_comment\n\t\t\t\tWHERE DATE_CREATE < DATE_SUB(NOW(), INTERVAL 30 DAY)\n\t\t\t\t\tAND PUBLISH_STATUS = '" . BLOG_PUBLISH_STATUS_PUBLISH . "'\n\t\t\t\tGROUP BY AUTHOR_ID\n\t\t\t\tUNION ALL "; } $strSql = "INSERT INTO b_rating_component_results (RATING_ID, MODULE_ID, RATING_TYPE, NAME, COMPLEX_NAME, ENTITY_ID, ENTITY_TYPE_ID, CURRENT_VALUE)\n\t\t\tSELECT\n\t\t\t\t'" . IntVal($arConfigs['RATING_ID']) . "' as RATING_ID,\n\t\t\t\t'" . $DB->ForSql($arConfigs['MODULE_ID']) . "' as MODULE_ID,\n\t\t\t\t'" . $DB->ForSql($arConfigs['RATING_TYPE']) . "' as RATING_TYPE,\n\t\t\t\t'" . $DB->ForSql($arConfigs['NAME']) . "' as NAME,\n\t\t\t\t'" . $DB->ForSql($arConfigs['COMPLEX_NAME']) . "' as COMPLEX_NAME,\n\t\t\t\tENTITY_ID,\n\t\t\t\t'" . $DB->ForSql($arConfigs['ENTITY_ID']) . "' ENTITY_TYPE_ID,\n\t\t\t\tSUM(CURRENT_VALUE) CURRENT_VALUE\n\t\t\tFROM (\n\t\t\t\t" . $sqlAllPost . "\n\t\t\t\tSELECT\n\t\t\t\t\tAUTHOR_ID as ENTITY_ID,\n\t\t\t\t\tSUM(IF(TO_DAYS(DATE_PUBLISH) > TO_DAYS(NOW())-1, 1, 0))*" . floatval($arConfigs['CONFIG']['TODAY_POST_COEF']) . " +\n\t\t\t\t\tSUM(IF(TO_DAYS(DATE_PUBLISH) > TO_DAYS(NOW())-7, 1, 0))*" . floatval($arConfigs['CONFIG']['WEEK_POST_COEF']) . "+\n\t\t\t\t\tCOUNT(*)*" . floatval($arConfigs['CONFIG']['MONTH_POST_COEF']) . " as CURRENT_VALUE\n\t\t\t\tFROM b_blog_post\n\t\t\t\tWHERE DATE_PUBLISH > DATE_SUB(NOW(), INTERVAL 30 DAY)\n\t\t\t\t\t\tAND PUBLISH_STATUS = '" . BLOG_PUBLISH_STATUS_PUBLISH . "'\n\t\t\t\tGROUP BY AUTHOR_ID\n\n\t\t\t\tUNION ALL\n\t\t\t\t" . $sqlAllComment . "\n\t\t\t\tSELECT\n\t\t\t\t\tAUTHOR_ID as ENTITY_ID,\n\t\t\t\t\tSUM(IF(TO_DAYS(DATE_CREATE) > TO_DAYS(NOW())-1, 1, 0))*" . floatval($arConfigs['CONFIG']['TODAY_COMMENT_COEF']) . " +\n\t\t\t\t\tSUM(IF(TO_DAYS(DATE_CREATE) > TO_DAYS(NOW())-7, 1, 0))*" . floatval($arConfigs['CONFIG']['WEEK_COMMENT_COEF']) . " +\n\t\t\t\t\tCOUNT(*)*" . floatval($arConfigs['CONFIG']['MONTH_COMMENT_COEF']) . " as CURRENT_VALUE\n\t\t\t\tFROM b_blog_comment\n\t\t\t\tWHERE DATE_CREATE > DATE_SUB(NOW(), INTERVAL 30 DAY)\n\t\t\t\t\tAND PUBLISH_STATUS = '" . BLOG_PUBLISH_STATUS_PUBLISH . "'\n\t\t\t\tGROUP BY AUTHOR_ID\n\t\t\t) q\n\t\t\tWHERE ENTITY_ID > 0\n\t\t\tGROUP BY ENTITY_ID"; $res = $DB->Query($strSql, false, $err_mess . __LINE__); return true; }
public static function __UpdateComponents($ID, $arFields) { global $DB; $ID = intval($ID); $err_mess = CRatings::err_mess() . "<br>Function: __UpdateComponents<br>Line: "; $DB->Query("DELETE FROM b_rating_component WHERE RATING_ID={$ID}", false, $err_mess . __LINE__); CRatings::__AddComponents($ID, $arFields); return true; }
public static function AutoAssignGroup($groupId, $authorityValueAdd, $authorityValueDelete) { global $DB; $err_mess = (CRatings::err_mess())."<br>Function: AutoAssignGroup<br>Line: "; $groupId = IntVal($groupId); if ($groupId == 0) return false; $ratingId = CRatings::GetAuthorityRating(); $ratingValueAdd = IntVal($authorityValueAdd); $ratingValueDelete = IntVal($authorityValueDelete); $sRatingWeightType = COption::GetOptionString("main", "rating_weight_type", "auto"); if ($sRatingWeightType == 'auto') { $ratingValueAdd = $ratingValueAdd*COption::GetOptionString("main", "rating_vote_weight", 1); $ratingValueDelete = $ratingValueDelete*COption::GetOptionString("main", "rating_vote_weight", 1); } // remove the group from all users who it is, but you need to remove it $strSql = " DELETE ug FROM b_user_group ug INNER JOIN ( SELECT rr.ENTITY_ID as USER_ID FROM b_rating_results rr WHERE rr.RATING_ID = $ratingId AND rr.CURRENT_VALUE < $ratingValueDelete ) R ON ug.USER_ID = R.USER_ID AND ug.GROUP_ID = $groupId"; $DB->Query($strSql, false, $err_mess.__LINE__); // add a group to all users who do not, but you need to add it $strSql = " INSERT INTO b_user_group (USER_ID, GROUP_ID) SELECT rr.ENTITY_ID, '$groupId' FROM b_rating_results rr LEFT JOIN b_user_group ug ON ug.GROUP_ID = $groupId AND ug.USER_ID = rr.ENTITY_ID WHERE rr.RATING_ID = $ratingId and rr.CURRENT_VALUE >= $ratingValueAdd and ug.USER_ID IS NULL"; $DB->Query($strSql, false, $err_mess.__LINE__); return true; }
function AutoAssignGroup($groupId, $authorityValueAdd, $authorityValueDelete) { global $DB; $err_mess = CRatings::err_mess() . "<br>Function: AutoAssignGroup<br>Line: "; $groupId = IntVal($groupId); if ($groupId == 0) { return false; } $ratingId = CRatings::GetAuthorityRating(); $ratingValueAdd = IntVal($authorityValueAdd); $ratingValueDelete = IntVal($authorityValueDelete); $sRatingWeightType = COption::GetOptionString("main", "rating_weight_type", "auto"); if ($sRatingWeightType == 'auto') { $ratingValueAdd = $ratingValueAdd * COption::GetOptionString("main", "rating_vote_weight", 1); $ratingValueDelete = $ratingValueDelete * COption::GetOptionString("main", "rating_vote_weight", 1); } // remove the group from all users who it is, but you need to remove it $strSql = "\n\t\t\tDELETE ug\n\t\t\tFROM b_user_group ug\n\t\t\tINNER JOIN (\n\t\t\t\tSELECT\n\t\t\t\t\trr.ENTITY_ID as USER_ID\n\t\t\t\tFROM\n\t\t\t\t\tb_rating_results rr\n\t\t\t\tWHERE\n\t\t\t\t\trr.RATING_ID = {$ratingId}\n\t\t\t\tAND rr.CURRENT_VALUE < {$ratingValueDelete}\n\t\t\t) R ON\n\t\t\tug.USER_ID = R.USER_ID AND ug.GROUP_ID = {$groupId}"; $DB->Query($strSql, false, $err_mess . __LINE__); // add a group to all users who do not, but you need to add it $strSql = "\n\t\t\tINSERT INTO b_user_group (USER_ID, GROUP_ID)\n\t\t\tSELECT\n\t\t\t\trr.ENTITY_ID, '{$groupId}'\n\t\t\tFROM\n\t\t\t\tb_rating_results rr\n\t\t\t\tLEFT JOIN b_user_group ug ON ug.GROUP_ID = {$groupId} AND ug.USER_ID = rr.ENTITY_ID\n\t\t\tWHERE\n\t\t\t\trr.RATING_ID = {$ratingId}\n\t\t\tand rr.CURRENT_VALUE >= {$ratingValueAdd}\n\t\t\tand ug.USER_ID IS NULL"; $DB->Query($strSql, false, $err_mess . __LINE__); return true; }