Beispiel #1
0
 private function login($sUserName, $sPassword)
 {
     if ($this->oConfig->get('demoMode') && $sUserName == 'demo' && $sPassword == 'demo' || $this->oUser->loginLdap($sUserName, $sPassword)) {
         return [self::RESPONSE_SUCCESS => true, self::RESPONSE_TOKEN => $this->oUser->generateToken(sha1($sUserName . $sPassword))];
     }
     return [self::RESPONSE_SUCCESS => false];
 }
Beispiel #2
0
 /**
  * @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;
 }
Beispiel #3
0
 /**
  *
  * @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 [];
 }
Beispiel #4
0
 /**
  *
  * @todo: save/update or insert
  * @todo: map types from schema on SqlData to automatically cast types / add quotes / prepare
  *
  * @return boolean
  */
 public function save()
 {
     $aSchema = $this->getSchema();
     $aSqlData = $this->getSqlData();
     // @refactor: write code more readble -> this functional stuff is quite hard to understand
     foreach ($aSchema as $sTableName => $aTable) {
         if ($oDb = new \SQLite3($this->oConfig->get('sqlite.file'), SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE)) {
             $sSqlStatement = sprintf('INSERT INTO %s (%s) VALUES (%s)', $sTableName, implode(",", array_map(function (DbColumn $oColumn) {
                 return $oColumn->getName();
             }, $aTable)), implode(",", array_map(function (DbColumn $oColumn) use($aSqlData) {
                 // @todo: validation if column has data in input array
                 return "'" . $aSqlData[$oColumn->getName()] . "'";
             }, $aTable)));
             if (!$oDb->query($sSqlStatement)) {
                 throw new \RuntimeException(sprintf("could not insert into table %s\n\nStatement: %s", $sTableName, $sSqlStatement));
             }
         }
     }
     return true;
 }
Beispiel #5
0
 public function __construct()
 {
     $this->oConfig = Config::getInstance();
     $this->oUser = new User();
 }