function parseRaidQuery($aRequest, $aQueryResult, $aLimit) { $Out = Out::getInstance(); $RaidData = array(); $RoleInfo = array(); $NumAttends = array(); $aQueryResult->loop(function ($Data) use(&$RaidData, &$RoleInfo, &$NumAttends) { array_push($RaidData, $Data); $RaidId = $Data['RaidId']; // Create used slot counts if (!isset($RoleInfo[$RaidId])) { $RoleInfo[$RaidId] = array(); } if (!isset($NumAttends[$RaidId])) { $NumAttends[$RaidId] = 0; } // Count used slots if ($Data['Status'] == 'ok' || $Data['Status'] == 'available') { $Role = $Data['Role']; if (!isset($RoleInfo[$RaidId][$Role])) { $RoleInfo[$RaidId][$Role] = 0; } ++$NumAttends[$RaidId]; ++$RoleInfo[$RaidId][$Role]; } }); $LastRaidId = -1; $RaidDataCount = count($RaidData); $NumRaids = 0; $Raids = array(); for ($DataIdx = 0; $DataIdx < $RaidDataCount; ++$DataIdx) { $Data = $RaidData[$DataIdx]; $RaidId = $Data['RaidId']; if ($LastRaidId != $RaidId) { // If no user assigned for this raid // or row belongs to this user // or it's the last entry // or the next entry is a different raid $IsCorrectUser = $Data['UserId'] == UserProxy::getInstance()->UserId; if ($IsCorrectUser || $Data['UserId'] == NULL || $DataIdx + 1 == $RaidDataCount || $RaidData[$DataIdx + 1]['RaidId'] != $RaidId) { $Status = 'notset'; $AttendanceIndex = 0; $Role = ''; $Class = ''; $Comment = ''; if ($IsCorrectUser) { $Status = $Data['Status']; $AttendanceIndex = $Status == 'unavailable' ? -1 : intval($Data['CharacterId']); $Role = $Data['Role']; $Class = $Data['Class']; $Comment = $Data['Comment']; } $StartDate = getdate($Data['StartUTC']); $EndDate = getdate($Data['EndUTC']); $Raid = array('id' => $RaidId, 'location' => $Data['Name'], 'game' => $Data['Game'], 'stage' => $Data['Stage'], 'size' => $Data['Size'], 'startDate' => $StartDate['year'] . '-' . leadingZero10($StartDate['mon']) . '-' . leadingZero10($StartDate['mday']), 'start' => leadingZero10($StartDate['hours']) . ':' . leadingZero10($StartDate['minutes']), 'endDate' => $EndDate['year'] . '-' . leadingZero10($EndDate['mon']) . '-' . leadingZero10($EndDate['mday']), 'end' => leadingZero10($EndDate['hours']) . ':' . leadingZero10($EndDate['minutes']), 'image' => $Data['Image'], 'description' => $Data['Description'], 'status' => $Status, 'attendanceIndex' => $AttendanceIndex, 'comment' => $Comment, 'role' => $Role, 'classId' => $Class, 'slotMax' => array(), 'slotCount' => array(), 'attended' => $NumAttends[$RaidId], 'mode' => $Data['Mode']); $Roles = explode(':', $Data['SlotRoles']); $Count = explode(':', $Data['SlotCount']); for ($i = 0; $i < count($Roles); ++$i) { $RoleId = $Roles[$i]; $Raid['slotMax'][$RoleId] = $Count[$i]; $Raid['slotCount'][$RoleId] = isset($RoleInfo[$RaidId][$RoleId]) ? $RoleInfo[$RaidId][$RoleId] : 0; } array_push($Raids, $Raid); $LastRaidId = $RaidId; ++$NumRaids; if ($aLimit > 0 && $NumRaids == $aLimit) { break; } } } } $Out->pushValue('raid', $Raids); }
function msgRaidDetail($aRequest) { if (validUser()) { global $gGame; loadGameSettings(); $Out = Out::getInstance(); $Connector = Connector::getInstance(); $Out->pushValue('show', $aRequest['showPanel']); $ListRaidQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'Raid.*, ' . RP_TABLE_PREFIX . 'Location.Name AS LocationName, ' . RP_TABLE_PREFIX . 'Location.Image AS LocationImage, ' . RP_TABLE_PREFIX . 'Attendance.AttendanceId, ' . RP_TABLE_PREFIX . 'Attendance.UserId, ' . RP_TABLE_PREFIX . 'Attendance.CharacterId, ' . RP_TABLE_PREFIX . 'Attendance.Status, ' . RP_TABLE_PREFIX . 'Attendance.Role, ' . RP_TABLE_PREFIX . 'Attendance.Class AS ActiveClass, ' . RP_TABLE_PREFIX . 'Attendance.Comment, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Attendance.LastUpdate) AS LastUpdate, ' . RP_TABLE_PREFIX . 'Character.Name, ' . RP_TABLE_PREFIX . 'Character.Class, ' . RP_TABLE_PREFIX . 'Character.Mainchar, ' . RP_TABLE_PREFIX . 'Character.Role1, ' . RP_TABLE_PREFIX . 'Character.Role2, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.Start) AS StartUTC, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.End) AS EndUTC ' . 'FROM `' . RP_TABLE_PREFIX . 'Raid` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` USING(RaidId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING(CharacterId) ' . 'WHERE RaidId = :RaidId ORDER BY `' . RP_TABLE_PREFIX . 'Attendance`.AttendanceId'); $ListRaidQuery->bindValue(':RaidId', $aRequest['id'], PDO::PARAM_INT); $Data = $ListRaidQuery->fetchFirstOfLoop(); if ($Data != null) { $Participants = array(); $StartDate = getdate($Data['StartUTC']); $EndDate = getdate($Data['EndUTC']); $EndTimestamp = $Data['EndUTC']; $Slots = array_combine(explode(':', $Data['SlotRoles']), explode(':', $Data['SlotCount'])); $Out->pushValue('raidId', $Data['RaidId']); $Out->pushValue('locationid', $Data['LocationId']); $Out->pushValue('locationname', $Data['LocationName']); $Out->pushValue('stage', $Data['Stage']); $Out->pushValue('mode', $Data['Mode']); $Out->pushValue('image', $Data['LocationImage']); $Out->pushValue('size', $Data['Size']); $Out->pushValue('startDate', intval($StartDate['year']) . '-' . leadingZero10($StartDate['mon']) . '-' . leadingZero10($StartDate['mday'])); $Out->pushValue('start', leadingZero10($StartDate['hours']) . ':' . leadingZero10($StartDate['minutes'])); $Out->pushValue('endDate', intval($EndDate['year']) . '-' . leadingZero10($EndDate['mon']) . '-' . leadingZero10($EndDate['mday'])); $Out->pushValue('end', leadingZero10($EndDate['hours']) . ':' . leadingZero10($EndDate['minutes'])); $Out->pushValue('description', $Data['Description']); $Out->pushValue('slots', $Slots); $Attendees = array(); $MaxAttendanceId = 1; $NumAttended = 0; if ($Data['UserId'] != NULL) { $ListRaidQuery->loop(function ($Data) use(&$gGame, &$Connector, &$MaxAttendanceId, &$Participants, &$Attendees, &$NumAttended) { // Track max attendance id to give undecided players (without a comment) a distinct one. $MaxAttendanceId = Max($MaxAttendanceId, $Data['AttendanceId']); if ($Data['UserId'] != 0) { array_push($Participants, intval($Data['UserId'])); } if ($Data['CharacterId'] == 0) { // CharacterId is 0 on random players or players that are absent if ($Data['UserId'] != 0) { // Fetch the mainchar of the registered player and display this // character as 'absent' $CharQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'Character.*, ' . RP_TABLE_PREFIX . 'User.Login AS UserName ' . 'FROM `' . RP_TABLE_PREFIX . 'Character` LEFT JOIN `' . RP_TABLE_PREFIX . 'User` USING(UserId) ' . 'WHERE UserId = :UserId AND Game = :Game ' . 'ORDER BY Mainchar, CharacterId ASC'); $CharQuery->bindValue(':UserId', $Data['UserId'], PDO::PARAM_INT); $CharQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR); $CharData = $CharQuery->fetchFirstOfLoop(); if ($CharData != null && $CharData['CharacterId'] != null) { $Classes = explode(':', $CharData['Class']); $AttendeeData = array('id' => $Data['AttendanceId'], 'hasId' => true, 'userId' => $Data['UserId'], 'timestamp' => $Data['LastUpdate'], 'charid' => $CharData['CharacterId'], 'name' => $CharData['Name'], 'mainchar' => $CharData['Mainchar'], 'classname' => $Classes, 'activeclass' => $Classes[0], 'role' => $CharData['Role1'], 'role1' => $CharData['Role1'], 'role2' => $CharData['Role2'], 'status' => $Data['Status'], 'comment' => $Data['Comment'], 'character' => array()); $CharQuery->loop(function ($CharData) use(&$AttendeeData) { $Character = array('id' => $CharData['CharacterId'], 'name' => $CharData['Name'], 'mainchar' => $CharData['Mainchar'], 'classname' => explode(':', $CharData['Class']), 'role1' => $CharData['Role1'], 'role2' => $CharData['Role2']); array_push($AttendeeData['character'], $Character); }); array_push($Attendees, $AttendeeData); } } else { // CharacterId and UserId set to 0 means 'random player' $AttendeeData = array('id' => $Data['AttendanceId'], 'hasId' => true, 'userId' => 0, 'timestamp' => $Data['LastUpdate'], 'charid' => 0, 'name' => $Data['Comment'], 'mainchar' => false, 'classname' => array('___'), 'activeclass' => '___', 'role' => $Data['Role'], 'role1' => $Data['Role'], 'role2' => $Data['Role'], 'status' => $Data['Status'], 'comment' => '', 'character' => array()); array_push($Attendees, $AttendeeData); ++$NumAttended; } } else { // CharacterId is set $AttendeeData = array('id' => $Data['AttendanceId'], 'hasId' => true, 'userId' => $Data['UserId'], 'timestamp' => $Data['LastUpdate'], 'charid' => $Data['CharacterId'], 'name' => $Data['Name'], 'mainchar' => $Data['Mainchar'], 'classname' => explode(':', $Data['Class']), 'activeclass' => $Data['ActiveClass'], 'role' => $Data['Role'], 'role1' => $Data['Role1'], 'role2' => $Data['Role2'], 'status' => $Data['Status'], 'comment' => $Data['Comment'], 'character' => array()); $CharQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'Character.*, ' . RP_TABLE_PREFIX . 'User.Login AS UserName ' . 'FROM `' . RP_TABLE_PREFIX . 'User` LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING(UserId) ' . 'WHERE UserId = :UserId AND Game = :Game ' . 'ORDER BY Mainchar, CharacterId ASC'); $CharQuery->bindValue(':UserId', $Data['UserId'], PDO::PARAM_INT); $CharQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR); $CharQuery->loop(function ($CharData) use(&$AttendeeData) { $Character = array('id' => $CharData['CharacterId'], 'name' => $CharData['Name'], 'mainchar' => $CharData['Mainchar'], 'classname' => explode(':', $CharData['Class']), 'role1' => $CharData['Role1'], 'role2' => $CharData['Role2']); array_push($AttendeeData['character'], $Character); }); if ($Data['Status'] == 'ok' || $Data['Status'] == 'available') { ++$NumAttended; } array_push($Attendees, $AttendeeData); } }); } // Fetch all registered and unblocked users $AllUsersQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'User.UserId ' . 'FROM `' . RP_TABLE_PREFIX . 'User` ' . 'WHERE `Group` != "none"'); $AllUsersQuery->loop(function ($User) use(&$gGame, &$Connector, &$MaxAttendanceId, &$EndTimestamp, &$Participants, &$Attendees) { if (!in_array(intval($User['UserId']), $Participants)) { // Users that are not registered for this raid are undecided // Fetch their character data, maincharacter first $CharQuery = $Connector->prepare('SELECT ' . RP_TABLE_PREFIX . 'Character.*, ' . RP_TABLE_PREFIX . 'User.Login AS UserName ' . 'FROM `' . RP_TABLE_PREFIX . 'Character` LEFT JOIN `' . RP_TABLE_PREFIX . 'User` USING(UserId) ' . 'WHERE UserId = :UserId AND Created < FROM_UNIXTIME(:RaidEnd) AND Game = :Game ' . 'ORDER BY Mainchar, CharacterId ASC'); $CharQuery->bindValue(':UserId', $User['UserId'], PDO::PARAM_INT); $CharQuery->bindValue(':RaidEnd', $EndTimestamp, PDO::PARAM_INT); $CharQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR); $UserData = $CharQuery->fetchFirstOfLoop(); if ($UserData != null) { // Absent user have no attendance Id, so we need to generate one // that is not in use (for this raid). ++$MaxAttendanceId; $Classes = explode(':', $UserData['Class']); $AttendeeData = array('id' => $MaxAttendanceId, 'hasId' => false, 'userId' => $UserData['UserId'], 'timestamp' => time(), 'charid' => $UserData['CharacterId'], 'name' => $UserData['Name'], 'mainchar' => $UserData['Mainchar'], 'classname' => $Classes, 'activeclass' => $Classes[0], 'role' => $UserData['Role1'], 'role1' => $UserData['Role1'], 'role2' => $UserData['Role2'], 'status' => 'undecided', 'comment' => '', 'character' => array()); $CharQuery->loop(function ($UserData) use(&$AttendeeData) { $Character = array('id' => $UserData['CharacterId'], 'name' => $UserData['Name'], 'mainchar' => $UserData['Mainchar'], 'classname' => explode(':', $UserData['Class']), 'role1' => $UserData['Role1'], 'role2' => $UserData['Role2']); array_push($AttendeeData['character'], $Character); }); array_push($Attendees, $AttendeeData); } } }); $Out->pushValue('attendee', $Attendees); $Out->pushValue('attended', $NumAttended); $ExportParameter = Api::normalizeArgsRaid(array('raid' => intval($aRequest['id']), 'attends' => true)); $Out->pushValue('token', Api::getPublicToken($ExportParameter)); } if (validRaidlead()) { msgQueryLocations($aRequest); } } else { $Out = Out::getInstance(); $Out->pushError(L('AccessDenied')); } }
function msgRaidList($aRequest) { if (validUser()) { global $gGame; loadGameSettings(); $Out = Out::getInstance(); $Connector = Connector::getInstance(); // Get next 6 raids $NextRaidQuery = $Connector->prepare('Select ' . RP_TABLE_PREFIX . 'Raid.*, ' . RP_TABLE_PREFIX . 'Location.*, ' . RP_TABLE_PREFIX . 'Attendance.CharacterId, ' . RP_TABLE_PREFIX . 'Attendance.UserId, ' . RP_TABLE_PREFIX . 'Attendance.Status, ' . RP_TABLE_PREFIX . 'Attendance.Class, ' . RP_TABLE_PREFIX . 'Attendance.Role, ' . RP_TABLE_PREFIX . 'Attendance.Comment, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.Start) AS StartUTC, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.End) AS EndUTC ' . 'FROM `' . RP_TABLE_PREFIX . 'Raid` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Attendance` USING(RaidId) ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Character` USING (CharacterId) ' . 'WHERE ' . RP_TABLE_PREFIX . 'Raid.Start >= FROM_UNIXTIME(:Start) ' . 'AND ' . RP_TABLE_PREFIX . 'Location.Game = :Game ' . 'ORDER BY ' . RP_TABLE_PREFIX . 'Raid.Start, ' . RP_TABLE_PREFIX . 'Raid.RaidId'); $NextRaidQuery->bindValue(':Start', mktime(0, 0, 0), PDO::PARAM_INT); $NextRaidQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR); parseRaidQuery($aRequest, $NextRaidQuery, 6); // Load raid history $RaidHistoryQuery = $Connector->prepare('Select ' . RP_TABLE_PREFIX . 'Raid.*, ' . RP_TABLE_PREFIX . 'Location.*, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.Start) AS StartUTC, ' . 'UNIX_TIMESTAMP(' . RP_TABLE_PREFIX . 'Raid.End) AS EndUTC ' . 'FROM `' . RP_TABLE_PREFIX . 'Raid` ' . 'LEFT JOIN `' . RP_TABLE_PREFIX . 'Location` USING(LocationId) ' . 'WHERE ' . RP_TABLE_PREFIX . 'Raid.Start < FROM_UNIXTIME(:Start) ' . 'AND ' . RP_TABLE_PREFIX . 'Location.Game = :Game ' . 'ORDER BY Start DESC LIMIT ' . intval($aRequest['offset']) . ', ' . intval($aRequest['count'])); $RaidHistoryQuery->bindValue(':Start', mktime(0, 0, 0), PDO::PARAM_INT); $RaidHistoryQuery->bindValue(':Game', $gGame['GameId'], PDO::PARAM_STR); $RaidList = array(); $RaidHistoryQuery->loop(function ($Data) use(&$RaidList) { $StartDate = getdate($Data['StartUTC']); $EndDate = getdate($Data['EndUTC']); $Raid = array('id' => $Data['RaidId'], 'location' => $Data['Name'], 'stage' => $Data['Stage'], 'image' => $Data['Image'], 'size' => $Data['Size'], 'startDate' => $StartDate['year'] . '-' . leadingZero10($StartDate['mon']) . '-' . leadingZero10($StartDate['mday']), 'start' => leadingZero10($StartDate['hours']) . ':' . leadingZero10($StartDate['minutes']), 'endDate' => $EndDate['year'] . '-' . leadingZero10($EndDate['mon']) . '-' . leadingZero10($EndDate['mday']), 'end' => leadingZero10($EndDate['hours']) . ':' . leadingZero10($EndDate['minutes'])); array_push($RaidList, $Raid); }); $Out->pushValue('history', $RaidList); } else { $Out = Out::getInstance(); $Out->pushError(L('AccessDenied')); } }