Example #1
0
 public static function FromDatabase($row, Colony $c = NULL)
 {
     $user = new User();
     $user->ID($row['ID']);
     $user->Username($row['username']);
     $user->AuthorisationLevel(Database::Instance()->ExecuteQuery("SELECT * FROM authorisation WHERE ID = " . (int) $row['authorisationID'] . ";", "SELECT"));
     $user->PrimaryEmail($row['primary_email']);
     $user->SecondaryEmail($row['secondary_email']);
     $user->RegistrationTime($row['registration_time']);
     $user->LastOnline($row['last_online']);
     $user->IsBanned($row['is_banned']);
     $user->BannedUntil($row['banned_until']);
     // Load authorisation level name
     $levelNameRow = Database::Instance()->ExecuteQuery("SELECT name FROM authorisation WHERE level = " . $user->AuthorisationLevel() . ";", "SELECT");
     $user->AuthorisationLevelName($levelNameRow['name']);
     // Load home colony
     if ($c == NULL) {
         $colonyDatabaseRow = Database::Instance()->ExecuteQuery("SELECT * FROM colony WHERE userID = " . $user->ID() . " AND is_home_colony = 1", "SELECT");
         $user->CurrentColony(Colony::FromDatabase($colonyDatabaseRow, $user));
     } else {
         $user->CurrentColony($c);
     }
     // Load user's technologies
     $technologyDatabaseRow = Database::Instance()->ExecuteQuery("SELECT * FROM user_technology WHERE userID = " . $user->ID(), "SELECT");
     $user->Technologies(TechnologyGroup::FromDatabase($technologyDatabaseRow, $user));
     // Load user's officers
     $officerDatabaseRow = Database::Instance()->ExecuteQuery("SELECT * FROM user_officers WHERE userID = " . $user->ID(), "SELECT");
     $user->Officers(OfficerGroup::FromDatabase($officerDatabaseRow, $user));
     // Return user
     return $user;
 }