/** * @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; }
/** * * @return array */ public function getCharacterList() { /** * @var Character */ $oCharacter = new Character(); $aSchema = $oCharacter->getSchema(); if ($oDb = new \SQLite3($this->oConfig->get('sqlite.file'), SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE)) { foreach ($aSchema as $sTableName => $aTable) { $oQuery = @$oDb->query(sprintf('SELECT * FROM %s;', $sTableName)); if ($oQuery === false) { // got no chars or database error, handle individually return []; } $aChars = []; while ($aChar = $oQuery->fetchArray(SQLITE3_ASSOC)) { array_push($aChars, $aChar); } return $aChars; } } return []; }
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); if (POPULATE_TESTDATA) { $oUser->generateUuid()->setName("demo")->setRole("admin")->save(); $oCharacter->generateUuid()->setUser($oUser->getUuid())->setName("ultraMonk")->setRace("pandaren")->setClass("monk")->setRole("heal")->save(); foreach ($aRaidIds as $sRaidId) { $oAttendance->generateUuid()->setCharacterId($oCharacter->getUuid())->setRaidId($sRaidId)->setStatus(rand(1, 5))->save(); } }