public static function Add($arFields) { global $DB; if (!CForumUserPoints::CheckFields("ADD", $arFields)) { return false; } $arInsert = $DB->PrepareInsert("b_forum_user_points", $arFields); $strDatePostField = ""; $strDatePostValue = ""; if (!is_set($arFields, "DATE_UPDATE")) { $strDatePostField .= ", DATE_UPDATE"; $strDatePostValue .= ", " . $DB->GetNowFunction() . ""; } $strSql = "INSERT INTO b_forum_user_points(" . $arInsert[0] . $strDatePostField . ") VALUES(" . $arInsert[1] . $strDatePostValue . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); // Recount user points if (intVal($arFields["TO_USER_ID"]) > 0) { $arUserFields = array("POINTS" => CForumUser::CountUserPoints($arFields["TO_USER_ID"])); $arUser = CForumUser::GetByUSER_ID($arFields["TO_USER_ID"]); if ($arUser) { CForumUser::Update(intVal($arUser["ID"]), $arUserFields); } else { $arUserFields["USER_ID"] = $arFields["TO_USER_ID"]; $ID_tmp = CForumUser::Add($arUserFields); } } return true; }
/******************************************************************** Data ********************************************************************/ /************** Votings ********************************************/ if ($arResult["SHOW_VOTES"] == "Y") { if ($_GET["VOTE_USER"] == "Y" && $USER->IsAuthorized() && check_bitrix_sessid()) { ForumVote4User($arParams["UID"], $_GET["VOTES"], strlen($_GET["CANCEL_VOTE"]) > 0 ? True : False, $strErrorMessage, $strOKMessage); if (empty($strErrorMessage)) { LocalRedirect($arResult["URL"]["~PROFILE_VIEW"]); } } $strNotesText = ""; $bCanVote = CForumUser::IsAdmin(); $bCanUnVote = False; $arUserRank = CForumUser::GetUserRank(intVal($USER->GetParam("USER_ID"))); $arUserPoints = CForumUserPoints::GetByID(intVal($USER->GetParam("USER_ID")), $arParams["UID"]); if ($arUserPoints) { $bCanUnVote = True; $strNotesText .= str_replace("#POINTS#", $arUserPoints["POINTS"], str_replace("#END#", ForumNumberRusEnding($arUserPoints["POINTS"]), GetMessage("F_ALREADY_VOTED1"))) . ". \n"; if (CForumUser::IsAdmin()) { $strNotesText .= GetMessage("F_ALREADY_VOTED_ADMIN"); } elseif (intVal($arUserPoints["POINTS"]) < intVal($arUserRank["VOTES"])) { $bCanVote = True; $strNotesText .= str_replace("#POINTS#", intVal($arUserRank["VOTES"]) - intVal($arUserPoints["POINTS"]), str_replace("#END#", ForumNumberRusEnding(intVal($arUserRank["VOTES"]) - intVal($arUserPoints["POINTS"])), GetMessage("F_ALREADY_VOTED3"))); } } elseif (intVal($arUserRank["VOTES"]) > 0 || CForumUser::IsAdmin()) { $bCanVote = True; $strNotesText .= GetMessage("F_NOT_VOTED"); if (!CForumUser::IsAdmin()) { $strNotesText .= str_replace("#POINTS#", $arUserRank["VOTES"], str_replace("#END#", ForumNumberRusEnding($arUserRank["VOTES"]), GetMessage("F_NOT_VOTED1"))) . ". \n"; } else {
public static function CountUserPoints($USER_ID = 0, $iCnt = false) { $USER_ID = intVal($USER_ID); $iNumUserPosts = intVal($iCnt); $iNumUserPoints = 0; $fPointsPerPost = 0.0; if ($USER_ID <= 0) { return 0; } if ($iCnt === false) { $iNumUserPoints = CForumUser::GetUserPoints($USER_ID); } if ($iNumUserPoints === false || $iCnt != false) { $iNumUserPosts = CForumMessage::GetList(array(), array("AUTHOR_ID" => $USER_ID, "APPROVED" => "Y"), true); $db_res = CForumPoints2Post::GetList(array("MIN_NUM_POSTS" => "DESC"), array("<=MIN_NUM_POSTS" => $iNumUserPosts)); if ($ar_res = $db_res->Fetch()) { $fPointsPerPost = DoubleVal($ar_res["POINTS_PER_POST"]); } $iNumUserPoints = floor($fPointsPerPost * $iNumUserPosts); $iCnt = CForumUserPoints::CountSumPoints($USER_ID); $iNumUserPoints += $iCnt; } return $iNumUserPoints; }
$arFields = array("MIN_NUM_POSTS" => 1, "POINTS_PER_POST" => "0.5000"); CForumPoints2Post::Add($arFields); $arFields = array("MIN_NUM_POSTS" => 50, "POINTS_PER_POST" => "0.8000"); CForumPoints2Post::Add($arFields); } /* User */ $res = CForumUser::GetByUSER_ID(1); if (empty($res) || !is_array($res)) { $arFields = array("=LAST_VISIT" => $DB->GetNowFunction(), "USER_ID" => 1); $ID = CForumUser::Add($arUserFields); } /* Vote */ $res = CForumUserPoints::GetByID(1, 1); if (!$res) { $arFields = array("POINTS" => 1000, "FROM_USER_ID" => 1, "TO_USER_ID" => 1); $ID = CForumUserPoints::Add($arFields); } // Forum group $arGroup = array("PUBLIC" => 0, "PARTNER" => 0, "COMMENTS" => 0); $db_res = CForumGroup::GetListEx(array(), array("LID" => LANGUAGE_ID)); if ($db_res && ($res = $db_res->Fetch())) { do { if (GetMessage("F_GROUP_PUBLIC") == $res["NAME"]) { $arGroup["PUBLIC"] = intVal($res["ID"]); } elseif (GetMessage("F_GROUP_PARTNER") == $res["NAME"]) { $arGroup["PARTNER"] = intVal($res["ID"]); } elseif (GetMessage("F_GROUP_COMMENTS") == $res["NAME"]) { $arGroup["COMMENTS"] = intVal($res["ID"]); } } while ($res = $db_res->Fetch()); }
/** * <p>Изменяет параметры голосования пользователя с кодом FROM_USER_ID за пользователя с кодом TO_USER_ID на значения, указанные в массиве arFields.</p> * * * * * @param int $FROM_USER_ID Пользователь, который голосовал. * * * * @param int $TO_USER_ID Пользователь, за которого голосовали. * * * * @param array $arFields Массив новых значений параметров голосования. * * * * @return bool <p>Возвращает True в случае успешного изменения параметров * голосования и False - в противном случае.</p><a name="examples"></a> * * * <h4>Example</h4> * <pre> * <? * // Изменим количество голосов, отданных текущим пользователем * // за пользователя с кодом $UID на 53 * $arFields = array("POINTS" => 53); * if (CForumUserPoints::Update($USER->GetID(), $UID, $arFields)) * echo "Голосования успешно изменено"; * else * echo "Ошибка изменения голосования"; * ?> * </pre> * * * @static * @link http://dev.1c-bitrix.ru/api_help/forum/developer/cforumuserpoints/cforumuserpoints__update.b9422e8b.php * @author Bitrix */ public static function Update($FROM_USER_ID, $TO_USER_ID, $arFields) { global $DB; $FROM_USER_ID = IntVal($FROM_USER_ID); if ($FROM_USER_ID<=0) return False; $TO_USER_ID = IntVal($TO_USER_ID); if ($TO_USER_ID<=0) return False; if (!CForumUserPoints::CheckFields("UPDATE", $arFields)) return false; $strUpdate = $DB->PrepareUpdate("b_forum_user_points", $arFields); $strDatePostValue = ""; if (!is_set($arFields, "DATE_UPDATE")) { $strDatePostValue .= ", DATE_UPDATE = ".$DB->GetNowFunction()." "; } $strSql = "UPDATE b_forum_user_points SET ".$strUpdate.$strDatePostValue." WHERE FROM_USER_ID = ".$FROM_USER_ID." AND TO_USER_ID = ".$TO_USER_ID; $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); // Recount user points. $arUserFields = array(); $arUserFields["POINTS"] = CForumUser::CountUserPoints($TO_USER_ID); $arUser = CForumUser::GetByUSER_ID($TO_USER_ID); if ($arUser) { CForumUser::Update($arUser["ID"], $arUserFields); } else { $arUserFields["USER_ID"] = $TO_USER_ID; $ID_tmp = CForumUser::Add($arUserFields); } return true; }
function ForumVote4User($UID, $VOTES, $bDelVote, &$strErrorMessage, &$strOKMessage) { global $USER; $arError = array(); $arNote = array(); $UID = IntVal($UID); $VOTES = IntVal($VOTES); $bDelVote = $bDelVote ? true : false; $CurrUserID = 0; if ($UID <= 0) { $arError[] = GetMessage("F_NO_VPERS"); } else { if (!$USER->IsAuthorized()) { $arError[] = GetMessage("FORUM_GV_ERROR_AUTH"); } else { $CurrUserID = IntVal($USER->GetParam("USER_ID")); if ($CurrUserID == $UID && !CForumUser::IsAdmin()) { $arError[] = GetMessage("FORUM_GV_OTHER"); } else { $arUserRank = CForumUser::GetUserRank($CurrUserID); if (IntVal($arUserRank["VOTES"]) <= 0 && !$bDelVote && !CForumUser::IsAdmin()) { $arError[] = GetMessage("FORUM_GV_ERROR_NO_VOTE"); } else { if (!CForumUser::IsAdmin() || $VOTES <= 0) { $VOTES = IntVal($arUserRank["VOTES"]); } if ($VOTES == 0) { $VOTES = 1; } // no ranks configured $arFields = array("POINTS" => $VOTES); $arUserPoints = CForumUserPoints::GetByID($CurrUserID, $UID); if ($arUserPoints) { if ($bDelVote || $VOTES <= 0) { if (CForumUserPoints::Delete($CurrUserID, $UID)) { $arNote[] = GetMessage("FORUM_GV_SUCCESS_UNVOTE"); } else { $arError[] = GetMessage("FORUM_GV_ERROR_VOTE"); } } else { if (IntVal($arUserPoints["POINTS"]) < IntVal($arUserRank["VOTES"]) || CForumUser::IsAdmin()) { if (CForumUserPoints::Update(IntVal($USER->GetParam("USER_ID")), $UID, $arFields)) { $arNote[] = GetMessage("FORUM_GV_SUCCESS_VOTE_UPD"); } else { $arError[] = GetMessage("FORUM_GV_ERROR_VOTE_UPD"); } } else { $arError[] = GetMessage("FORUM_GV_ALREADY_VOTE"); } } } else { if (!$bDelVote && $VOTES > 0) { $arFields["FROM_USER_ID"] = $USER->GetParam("USER_ID"); $arFields["TO_USER_ID"] = $UID; if (CForumUserPoints::Add($arFields)) { $arNote[] = GetMessage("FORUM_GV_SUCCESS_VOTE_ADD"); } else { $arError[] = GetMessage("FORUM_GV_ERROR_VOTE_ADD"); } } else { $arError[] = GetMessage("FORUM_GV_ERROR_A"); } } } } } } if (!empty($arError)) { $strErrorMessage .= implode(".\n", $arError) . ".\n"; } if (!empty($arNote)) { $strOKMessage .= implode(".\n", $arNote) . ".\n"; } if (empty($arError)) { return True; } else { return False; } }
?> </a>]</small> <?php } ?> </h2><?php // ******************** VOTINGS ************************ if (COption::GetOptionString("forum", "SHOW_VOTES", "Y") == "Y" && $USER->IsAuthorized() && ($USER->IsAdmin() || IntVal($USER->GetParam("USER_ID")) != $UID)) { $strNotesText = ""; $bCanVote = False; $bCanUnVote = False; if ($USER->IsAdmin()) { $bCanVote = True; } $arUserRank = CForumUser::GetUserRank(IntVal($USER->GetParam("USER_ID"))); $arUserPoints = CForumUserPoints::GetByID(IntVal($USER->GetParam("USER_ID")), $UID); if ($arUserPoints) { $bCanUnVote = True; $strNotesText .= str_replace("#POINTS#", $arUserPoints["POINTS"], str_replace("#END#", ForumNumberRusEnding($arUserPoints["POINTS"]), GetMessage("FV_ALREADY_VOTED1"))) . ". \n"; if (IntVal($arUserPoints["POINTS"]) < IntVal($arUserRank["VOTES"]) && !$USER->IsAdmin()) { $bCanVote = True; $strNotesText .= str_replace("#POINTS#", IntVal($arUserRank["VOTES"]) - IntVal($arUserPoints["POINTS"]), str_replace("#END#", ForumNumberRusEnding(IntVal($arUserRank["VOTES"]) - IntVal($arUserPoints["POINTS"])), GetMessage("FV_ALREADY_VOTED3"))); } elseif ($USER->IsAdmin()) { $strNotesText .= GetMessage("FV_ALREADY_VOTED_ADMIN"); } } else { if (IntVal($arUserRank["VOTES"]) > 0 || $USER->IsAdmin()) { $bCanVote = True; $strNotesText .= GetMessage("FV_NOT_VOTED"); if (!$USER->IsAdmin()) { $strNotesText .= str_replace("#POINTS#", $arUserRank["VOTES"], str_replace("#END#", ForumNumberRusEnding($arUserRank["VOTES"]), GetMessage("FV_NOT_VOTED1"))) . ". \n";