function RecalcTeamResultFromTeamLevelPoints($raidid, $teamid) { if (empty($teamid) and empty($raidid)) { return; } $teamRaidCondition = !empty($teamid) ? " t.team_id = {$teamid}" : "d.raid_id = {$raidid}"; if (empty($teamid)) { CMmbLogger::enable(0); //CMmbLogger::enable(1); } $tm0 = microtime(true); // Обнуляем данные расчета $sql = " update TeamLevelPoints tlp\n\t\t join Teams t\n\t\t\t on tlp.team_id = t.team_id\n \t\t inner join Distances d\n\t\t\t on t.distance_id = d.distance_id\n\t\t set tlp.teamlevelpoint_penalty = NULL,\n\t\t tlp.teamlevelpoint_duration = NULL,\n\t\t t.team_maxlevelpointorderdone = NULL,\n\t\t t.team_minlevelpointorderwitherror = NULL,\n\t\t t.team_donelevelpoint = NULL,\n\t\t t.team_comment = NULL\n \t\t where {$teamRaidCondition}"; $rs = MySqlQuery($sql); $tm1 = CMmbLogger::addInterval(' 1 ', $tm0); RecalcTeamLevelPointsDuration($raidid, $teamid); $tm2 = CMmbLogger::addInterval(' 2', $tm1); RecalcTeamLevelPointsPenaltyWithDiscount($raidid, $teamid); $tm3 = CMmbLogger::addInterval(' 3', $tm2); RecalcTeamLevelPointsPenaltyWithoutDiscount($raidid, $teamid); $tm4 = CMmbLogger::addInterval(' 4', $tm3); // echo 'RecalcTeamLevelPointsResult '.$raidid.','.$teamid; RecalcTeamLevelPointsResult($raidid, $teamid); $tm5 = CMmbLogger::addInterval(' 5', $tm4); // return; // Находим ключ ММБ, если указана только команда if (empty($raidid)) { $sql = "select d.raid_id\n\t\t\t\tfrom Teams t\n\t\t\t\t\tinner join Distances d\n\t\t\t\t\ton t.distance_id = d.distance_id\n\t\t\t\twhere t.team_id = {$teamid}\n\t\t\t\tLIMIT 0,1"; $raidid = CSql::singleValue($sql, 'raid_id'); } //Ставим ошибки //FindErrors($raidid, $teamid); $tm6 = CMmbLogger::addInterval(' 6', $tm5); // $raidid мог измениться $teamRaidCondition = !empty($teamid) ? "t.team_id = {$teamid}" : "d.raid_id = {$raidid}"; // Результат команды - это результат в максимальной точке // Перевод в секунды нужен для корректной работы MAX $sql = " update Teams t\n\t\t\t\tinner join\n\t\t \t(select tlp.team_id,\n\t\t\t\t\t MAX(COALESCE(lp.levelpoint_order, 0)) as progress,\n\t\t\t\t\t\t\tMAX(t.distance_id) as distance_id,\n\t\t\t\t\t MAX(TIME_TO_SEC(COALESCE(tlp.teamlevelpoint_result, 0))) as secresult\n\t\t\t\t\t from TeamLevelPoints tlp\n\t\t\t\t\t inner join Teams t\n\t\t\t\t\t on tlp.team_id = t.team_id\n\t\t\t\t\t inner join Distances d\n\t\t\t\t\t on t.distance_id = d.distance_id\n\t\t\t\t\t inner join LevelPoints lp\n\t\t\t\t\t on tlp.levelpoint_id = lp.levelpoint_id\n\t\t\t\t\t where {$teamRaidCondition}\n\t\t\t\t\t group by tlp.team_id\n\t\t\t\t\t) a\n\t\t \t\ton t.team_id = a.team_id\n\t\t \t\tinner join\n\t\t\t\t\t(select lp.distance_id,\n\t\t\t\t\t MAX(lp.levelpoint_order) as maxlporder\n\t\t\t\t\tfrom LevelPoints lp\n\t\t\t\t\tgroup by lp.distance_id\n\t\t\t\t\t) b\n\t\t\t \ton a.distance_id = b.distance_id\n \t set team_result = CASE WHEN b.maxlporder = COALESCE(a.progress, 0) THEN SEC_TO_TIME(COALESCE(a.secresult, 0)) ELSE NULL END\n\t\t\t\t, team_maxlevelpointorderdone = COALESCE(a.progress, 0) "; // echo $sql; $rs = MySqlQuery($sql); $tm7 = CMmbLogger::addInterval(' 7', $tm6); // теперь можно посчитать рейтинг RecalcTeamUsersRank($raidid); $tm8 = CMmbLogger::addInterval(' 8', $tm7); // // Находим минимальную точку с ошибкой (COALESCE(tlp.error_id, 0) > 0) // < 0 - это не ошибка - предупреждение $sql = " update Teams t\n\t\t\t\t inner join\n\t \t\t \t(select tlp.team_id,\n\t\t\t\t\t MIN(COALESCE(lp.levelpoint_order, 0)) as error\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t\tinner join Teams t\n\t\t\t\t\t\t\t on tlp.team_id = t.team_id\n\t\t\t \t\t\t\tinner join Distances d\n\t\t\t \t\t\t\ton t.distance_id = d.distance_id\n\t\t\t \t\t\t\tinner join LevelPoints lp\n\t\t\t \t\t\t\ton tlp.levelpoint_id = lp.levelpoint_id\n\t\t\t\t\t\twhere COALESCE(tlp.error_id, 0) > 0\n\t\t \t\t\tand {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n\t\t\t\t\t\t) a\n\t\t \t\t\ton t.team_id = a.team_id\n \tset team_minlevelpointorderwitherror = COALESCE(a.error, 0)"; // echo $sql; $rs = MySqlQuery($sql); $tm9 = CMmbLogger::addInterval(' 9', $tm8); // Находим невзятые КП // расчет закомментирован, так ка Сергей строит список другим способом /* $sql = " update Teams t inner join (select t.team_id, GROUP_CONCAT(lp.levelpoint_name ORDER BY lp.levelpoint_order, ' ') as skippedlevelpoint from Teams t inner join Distances d on t.distance_id = d.distance_id join LevelPoints lp on t.distance_id = lp.distance_id and COALESCE(t.team_maxlevelpointorderdone, 0) >= lp.levelpoint_order left outer join TeamLevelPoints tlp on lp.levelpoint_id = tlp.levelpoint_id and t.team_id = tlp.team_id where tlp.levelpoint_id is NULL and d.distance_hide = 0 and t.team_hide = 0 and $teamRaidCondition group by t.team_id ) a on t.team_id = a.team_id set team_skippedlevelpoint = COALESCE(a.skippedlevelpoint, '')"; // echo $sql; $rs = MySqlQuery($sql);*/ // Обновляем комментарий у команды $sql = " update Teams t\n inner join\n (select tlp.team_id \n\t\t\t\t\t\t,group_concat(COALESCE(teamlevelpoint_comment, '')) as team_comment\n\t\t\t\t from TeamLevelPoints tlp\n\t\t\t\t\t\t\tleft outer join Errors err\n\t\t\t\t\t\t\ton tlp.error_id = err.error_id\n\t\t\t\t\t\t inner join Teams t\n\t\t\t\t\t\t on t.team_id = tlp.team_id\n\t\t\t\t\t\t inner join Distances d\n\t\t\t \t\t\ton t.distance_id = d.distance_id\n where COALESCE(tlp.teamlevelpoint_comment, '') <> ''\n and {$teamRaidCondition}\n group by tlp.team_id\n ) a\n\t\t \t\ton t.team_id = a.team_id\n\t\t set t.team_comment = a.team_comment"; // echo $sql; $rs = MySqlQuery($sql); $tm10 = CMmbLogger::addInterval(' 10', $tm9); //Теперь в это поле добавляем ошибки tlp.error_id > 0 $sql = " update Teams t\n inner join\n (select tlp.team_id \n\t\t\t\t\t\t,group_concat(COALESCE(error_name, '')) as team_error\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t\tleft outer join Errors err\n\t\t\t\t\t\t\t\ton tlp.error_id = err.error_id\n\t\t\t\t\t\t\t inner join Teams t\n\t\t\t\t\t\t\t on t.team_id = tlp.team_id\n\t\t\t\t\t\t\t inner join Distances d\n\t\t\t\t\t\t\t on t.distance_id = d.distance_id\n\t\t\t\t\t\twhere COALESCE(tlp.error_id, 0) > 0\n\t\t and {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n ) a\n\t\t \t\ton t.team_id = a.team_id\n\t\t set t.team_comment = CASE WHEN a.team_error <> '' THEN CONCAT('Ошибки: ', a.team_error, '; ', COALESCE(t.team_comment, '')) ELSE t.team_comment END"; // echo $sql; $rs = MySqlQuery($sql); $tm11 = CMmbLogger::addInterval(' 11', $tm10); //Теперь в это поле добавляем предупреждения tlp.error_id < 0 $sql = " update Teams t\n inner join\n (select tlp.team_id \n\t\t\t\t\t\t,group_concat(COALESCE(error_name, '')) as team_error\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t\tleft outer join Errors err\n\t\t\t\t\t\t\t\ton tlp.error_id = err.error_id\n\t\t\t\t\t\t\t inner join Teams t\n\t\t\t\t\t\t\t on t.team_id = tlp.team_id\n\t\t\t\t\t\t\t inner join Distances d\n\t\t\t\t\t\t\t on t.distance_id = d.distance_id\n\t\t\t\t\t\twhere COALESCE(tlp.error_id, 0) < 0\n\t\t and {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n ) a\n\t\t \t\ton t.team_id = a.team_id\n\t\t set t.team_comment = CASE WHEN a.team_error <> '' THEN CONCAT('Предупреждения: ', a.team_error, '; ', COALESCE(t.team_comment, '')) ELSE t.team_comment END"; // echo $sql; $rs = MySqlQuery($sql); $tm12 = CMmbLogger::addInterval(' 12', $tm11); //Теперь в это поле добавляем предупреждения tlp.error_id < 0 $sql = " update Teams t\n inner join\n (select tlp.team_id \n\t\t\t\t\t\t,group_concat(COALESCE(error_name, '')) as team_error\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t\tleft outer join Errors err\n\t\t\t\t\t\t\t\ton tlp.error_id = err.error_id\n\t\t\t\t\t\t\t inner join Teams t\n\t\t\t\t\t\t\t on t.team_id = tlp.team_id\n\t\t\t\t\t\t\t inner join Distances d\n\t\t\t\t\t\t\t on t.distance_id = d.distance_id\n\t\t\t\t\t\twhere COALESCE(tlp.error_id, 0) < 0\n\t\t and {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n ) a\n\t\t \t\ton t.team_id = a.team_id\n\t\t set t.team_comment = CASE WHEN a.team_error <> '' THEN CONCAT('Предупреждения: ', a.team_error, '; ', COALESCE(t.team_comment, '')) ELSE t.team_comment END"; // echo $sql; $rs = MySqlQuery($sql); $tm13 = CMmbLogger::addInterval(' 13', $tm12); //считаем (только для интерфейса список вщзятых КП $sql = " update Teams t\n inner join\n (select tlp.team_id \n\t\t\t,group_concat(DATE_FORMAT(COALESCE(tlp.teamlevelpoint_datetime, ''),'%H:%i') order by teamlevelpoint_datetime separator ', ') as team_donelevelpoint\n\t\t\t\t\t\tfrom TeamLevelPoints tlp\n\t\t\t\t\t\t\t inner join Teams t\n\t\t\t\t\t\t\t on t.team_id = tlp.team_id\n\t\t\t\t\t\t\t inner join Distances d\n\t\t\t\t\t\t\t on t.distance_id = d.distance_id\n\t\t\t\t\t\twhere COALESCE(tlp.teamlevelpoint_datetime, 0) > 0\n\t\t and {$teamRaidCondition}\n\t\t\t\t\t\tgroup by tlp.team_id\n ) a\n\t\t \t\ton t.team_id = a.team_id\n\t\t set t.team_donelevelpoint = a.team_donelevelpoint "; // echo $sql; $rs = MySqlQuery($sql); $tm14 = CMmbLogger::addInterval(' 14', $tm13); // теперь можно посчитать рейтинг RecalcUsersRank($raidid); $tm14 = CMmbLogger::addInterval(' 15', $tm13); $msg = CMmbLogger::getText(); //CMmb::setShortResult($msg, ''); CMmb::setMessage($msg); }
if (!$inviteId) { CMmb::setErrorMessage('Приглашение команды невозможно'); return; } else { $sql = "update Teams set team_outofrange = 0, invitation_id = {$inviteId}, invitation_usedt = NOW() where team_id = {$TeamId}"; $rs = MySqlQuery($sql); } $view = "ViewRaidTeams"; } elseif ($action == "CancelChangeTeamData") { $view = "ViewTeamData"; } elseif ($action == "ViewRaidTeams") { $view = "ViewRaidTeams"; } elseif ($action == 'JsonExport') { $RaidId = mmb_validateInt($_REQUEST, 'RaidId', -1); if ($RaidId <= 0) { CMmb::setMessage('Не выбран марш-бросок'); return; } // Сбор данных для дампа $data = array(); // Raids: raid_id, raid_name, raid_registrationenddate $Sql = "select raid_id, raid_name \n\t from Raids \n\t\t\twhere raid_id = {$RaidId}"; $Result = MySqlQuery($Sql); while ($Row = mysql_fetch_assoc($Result)) { $data["Raids"][] = $Row; } mysql_free_result($Result); // Distances: distance_id, raid_id, distance_name $Sql = "select distance_id, raid_id, distance_name \n\t\t\tfrom Distances\n\t\t\twhere distance_hide = 0 and raid_id = {$RaidId}"; $Result = MySqlQuery($Sql); while ($Row = mysql_fetch_assoc($Result)) {
} $sql = "update TeamLevelPoints set levelpoint_id = {$pLevelPointId}\n\t ,team_id = {$pTeamId}\n\t ,error_id = {$pErrorId}\n\t ,teamlevelpoint_comment = '{$pTlpComment}'\n\t ,teamlevelpoint_datetime = {$TlpYDTs}\n\t where teamlevelpoint_id = {$pTeamLevelPointId}"; //echo $sql; MySqlQuery($sql); RecalcTeamResultFromTeamLevelPoints(0, $pTeamId); // RecalcTeamResultFromTeamLevelPoints(25, 0); /* $statustext = CheckLevelPoints($DistanceId); if (!empty($error)) { $alert = 1; } */ } elseif ($action == 'HideTlp') { if (!$Administrator && !$Moderator) { CMmb::setMessage('Нет прав на правку результата для точки'); return; } $pTeamLevelPointId = $_POST['TeamLevelPointId']; $pTeamId = $_POST['TeamId']; if ($pTeamId <= 0) { teamEditError('Не определён ключ команды.'); return; } if ($pTeamLevelPointId <= 0) { teamEditError('Не определён ключ результата для точки.'); return; } $sql = "delete from TeamLevelPoints where teamlevelpoint_id = {$pTeamLevelPointId}"; MySqlQuery($sql); RecalcTeamResultFromTeamLevelPoints(0, $pTeamId);
for ($inv_type = 1; $inv_type <= 3; $inv_type++) { $sql = "SELECT COUNT(*) AS invited_count FROM\n\t\t\t(SELECT DISTINCT t.team_id FROM Teams t\n\t\t\t\tINNER JOIN Invitations inv ON inv.invitation_id = t.invitation_id\n\t\t\t\tINNER JOIN TeamUsers tu ON tu.team_id = t.team_id AND tu.teamuser_hide = 0\n\t\t\t\tINNER JOIN InvitationDeliveries invd ON invd.invitationdelivery_id = inv.invitationdelivery_id\n\t\t\t\tWHERE {$DistanceTeams} AND invd.invitationdelivery_type = {$inv_type}) AS TeamsInvited"; $invited[$inv_type] = CSql::singleValue($sql, 'invited_count'); } // отдельно считаем количество команд, приглашенных по рейтингу своими участниками $sql = "SELECT COUNT(*) AS invited_count FROM\n\t\t(SELECT DISTINCT t.team_id FROM Teams t\n\t\t\tINNER JOIN Invitations inv ON inv.invitation_id = t.invitation_id\n\t\t\tINNER JOIN TeamUsers tu ON tu.team_id = t.team_id AND tu.teamuser_hide = 0\n\t\t\tINNER JOIN InvitationDeliveries invd ON invd.invitationdelivery_id = inv.invitationdelivery_id\n\t\t\tWHERE {$DistanceTeams} AND invd.invitationdelivery_type = 1 AND tu.user_id = inv.user_id) AS TeamsInvited"; $invited_self = CSql::singleValue($sql, 'invited_count'); // выводим статистику print " <td colspan={$colspan}>Участвует команд <span title=\"всего команд с приглашениями\">{$teamInRangeCount}</span> " . "(<span title=\"пригласившие сами себя\">{$invited_self}</span>" . "/<span title=\"приглашенные другими участниками\">" . ($invited[1] - $invited_self) . "</span>" . "/<span title=\"выгравшие в лотерею\">" . $invited[2] . "</span>" . "/<span title=\"с приглашениями, выданными вручную\">" . $invited[3] . "</span>), "; print "ожидают приглашения <span title=\"всего команд без приглашений\">{$teamOutOfRangeCount}</span>, "; print "участников <span title=\"в приглашенных командах\">{$teamUserInRangeCount}</span>/<span title=\"в командах, ожидающих приглашение\">{$teamUserOutOfRangeCount}</span>, "; print "карт <span title=\"в приглашенных командах\">{$mapsInRangeCount}</span>/<span title=\"в командах, ожидающих приглашение\">{$mapsOutOfRangeCount}</span></td>\n</tr>\n"; } // Проверяем, что передали идентификатор ММБ if ($RaidId <= 0) { CMmb::setMessage('Не указан ММБ'); return; } ?> <form name = "RaidTeamsForm" action = "<?php echo $MyPHPScript; ?> " method = "post"> <input type = "hidden" name = "action" value = "ViewRaidTeams"> <input type = "hidden" name = "TeamId" value = "0"> <input type = "hidden" name = "UserId" value = "0"> <input type = "hidden" name = "RaidId" value = "<?php echo $RaidId; ?> ">
} elseif ($action == 'HideLevelPointDiscount') { if (!$Administrator && !$Moderator) { CMmb::setMessage('Нет прав на правку интервала'); return; } $pLevelPointDiscountId = mmb_validateInt($_POST, 'LevelPointDiscountId'); if ($pLevelPointDiscountId <= 0) { raidError('Не определён ключ интервала.'); return; } $sql = "update LevelPointDiscounts set levelpointdiscount_hide = 1\r\n\t where levelpointdiscount_id = {$pLevelPointDiscountId}"; MySqlQuery($sql); CMmb::setViews('ViewLevelPointDiscounts', 'Add'); } elseif ($action == 'RecalculateLevels') { if (!$Administrator && !$Moderator) { CMmb::setMessage('Нет прав на правку'); return; } CMmb::setViews('ViewLevelPoints', 'Add'); $pDistanceId = (int) $_POST['DistanceId']; if ($pDistanceId <= 0) { CMmb::setErrorSm('Не определена дистанция.'); return; } $statustext = CheckLevelPoints($pDistanceId); if (!empty($error)) { CMmb::setErrorSm("Нельзя создавать этапы: {$statustext}"); return; } // Нет проверки, что на одном этапе ровно одна амнистия // удаляем существующие этапы