public function responseRaidsAdd(Request $request, Response $response) { $aRequest = $request->getParsedBody(); $aHeader = $request->getHeaders(); // @todo: validation of input params $sUserName = $aHeader['HTTP_X_AUTH_USER']; $sToken = $aHeader['HTTP_X_AUTH_TOKEN']; if (!$this->oUser->checkUserToken($sToken)) { return $response->withStatus(401); } /** * @var Raid */ $oRaid = new Raid(); $bSuccess = $oRaid->generateUuid()->setTitle($aRequest['title'])->setStart($aRequest['raidDate'], $aRequest['startTime'])->setEnd($aRequest['raidDate'], $aRequest['endTime'])->setMaxAttendees($aRequest['maxAttendees'])->save(); $aResponse = [self::RESPONSE_SUCCESS => $bSuccess, 'uuid' => $oRaid->getUuid()]; $response->getBody()->write(json_encode($aResponse)); return $response; }
/** * @return array */ public function getRaidList() { /** * @var Raid */ $oRaid = new Raid(); /** * @var Attendance */ $oAttendance = new Attendance(); /** * @var Character */ $oCharacter = new Character(); /** * @var User */ $oMe = $this->oConfig->getMe(); /** * @var Db */ $oDb = Db::getInstance(); // @todo: only show raids >= today (maybe think about history support for checking attendance etc.) $aRaids = $oDb->getArray(Db::prepare("SELECT * FROM %s WHERE date(startDate) > date('now', '-1 day') ORDER BY startDate;", [$oRaid->getTableName()])); array_walk($aRaids, function (&$aRaid) use($oDb, $oAttendance, $oCharacter, $oMe) { $aAttendees = $oDb->getArray($oDb->prepare("SELECT ch.*, att.status FROM %s as att, %s as ch\n WHERE att.raidId = '%s' AND att.characterId LIKE ch.uuid AND att.status IN (2, 4, 5);", [$oAttendance->getTableName(), $oCharacter->getTableName(), $aRaid['uuid']])); $aRaid['attend'] = array_reduce($aAttendees, function ($bFound, $aAtt) use($oMe) { if ($bFound) { return $bFound; } return $aAtt['userId'] == $oMe['uuid'] ? $aAtt['status'] : false; }, false); $aRaid['state'] = 'open'; // @fix: remove declined from count $aRaid['attendeesCount'] = count($aAttendees); $aRaid['attendees'] = $aAttendees; }); return $aRaids; }
* * @author Mark Oswald <*****@*****.**> * @date 30.12.15 20:26 */ namespace mroswald\invme; error_reporting(E_ALL ^ E_NOTICE); ini_set('date.timezone', 'Europe/Berlin'); require 'vendor/autoload.php'; use mroswald\invme\models\Attendance; use mroswald\invme\models\Character; use mroswald\invme\models\Raid; use mroswald\invme\models\User; define('POPULATE_TESTDATA', true); $aRaidIds = []; $oRaid = new Raid(); $oRaid->installModel(true); // this could be used to populate test data if (POPULATE_TESTDATA) { for ($i = 1; $i < 12; $i++) { $date = date("Y-m-d", time() + $i * 2 * 60 * 60 * 24); $oRaid->generateUuid()->setTitle("Höllenfeuerzitadelle")->setMaxAttendees(20)->setStart($date, '20:00')->setEnd($date, '22:30')->save(); array_push($aRaidIds, $oRaid->getUuid()); } } $oUser = new User(); $oUser->installModel(true); $oCharacter = new Character(); $oCharacter->installModel(true); $oAttendance = new Attendance(); $oAttendance->installModel(true);