Skip to content

Model Design

joemelt101 edited this page Apr 18, 2016 · 4 revisions

Model

Overview

The model will be responsible for storing and distributing all the big data of the system. It will provide function commands to the controller to execute MySQL statements and return the data in a convenient format (see below). The controller will not give direct SQL statements to the model to execute, the model is not just the database, but also the logic for performing database functions (select, insert, delete, etc.). Both AJAX calls and individual page controllers will use the same model.

Model Interface

Enum Status {//1   , 0      , 2 << database
    ONLINE, OFFLINE, BUSY;}
Enum GameType
{
    VIDEOGAME, NONVIDEOGAME;
}
Enum SearchType
{
    ALIAS, LOCATION, GAME, GENRE;
}

User
    - int userID
    - string alias
    - string username
    - string status
    - string email
    - Location location
    - Game[] games;
    + __construct(int userID) //constructor
    + int getUserID()
    + string getAlias()
    + bool setAlias(string alias)
    + string getUsername()
    + bool setUsername(string newUsername)
    + string getStatus()
    + bool setStatus(Status newStatus)
    + string getEmail()
    + bool setEmail(string newEmail)
    + Location getLocation()
    + bool setLocation(string city, string state, string zipcode)
    + User[] getFriends()
    + Game[] getGames()
    + bool setGames(Game[] games)
    + bool addGame(Game game)
    + bool removeGame(Game game)
    + bool sendFriendRequest(User toFriend)
    + bool blockUser(User toBlock)
    + bool unblockUser(User toUnblock)
    + bool acceptFriendRequest(User toAccept)
    + bool declineOrDeleteFriendRequest(User toDecline)
    + User[] search(string searchString, SearchType searchType)
Game
    - int gameID
    - string developer
    - string platform
    - string genre
    - GameType type
    + __construct(string name, string developer, string platform, string genre, GameType type)
    + string getGameName()
    + string getDeveloper()
    + string getPlatform()
    + string getGenre()
    + GameType getType()
Location
    - string city
    - string state
    - string zipcode
    + __construct(string city, string state, string zipcode)
    + string getCity()
    + string setCity(string newCity)
    + string getState()
    + string setState(string newState)
    + string getZipCode()
    + string setZipCode(string newZipCode)

Session Interface

//PURPOSE: Attempts a login with given credentials and updates database to reflect login status as well as the session variable
//RETURNS: A User object if success or null if failed
User login(string email, string password)

//PURPOSE: Attempts to grab the User object from the session variable.
//RETURNS: A reference to the user if success, else null (not logged in)
User getLoggedInUserOrFail()

//PURPOSE: Logs a user out by destroying session variable
//RETURNS: True or False for success or failure
bool logout(User handle)

//PURPOSE: Gets a user associated with a specified ID
//RETURNS: A User or null, depending on whether it's successful or not
User getUserFromUserID(userID id)

//PURPOSE: Creates a user with the specified information
//RETURNS: A user if success, null if failed
User createAccount(string email1, string email2, string username, string password1, string password2)

#JavaScript AJAX Interface

int getCurrentUserID()
string getCurrentUserAlias()
bool setCurrentUserAlias(string alias)
string getCurrentUserUserName(int userID)
bool setCurrentUserUsername(string newUsername)
string getCurrentUserStatus(int userID)
bool setCurrentUserStatus(string newStatus)
string getCurrentUserEmail()
bool setCurrentUserEmail(string newEmail)
Location getCurrentUserLocation()
bool setCurrentUserLocation(string city, string state, string zip)
Friend[] getCurrentUserFriends()
Game[] getCurrentUserGames()
bool addGame(Game newGame)
bool removeGame(Game gameToRemove)
bool blockUser(int userID)
bool unblockUser(int userID)
bool acceptFriendRequest(int acceptedID)
bool declineOrDeleteFriendRequest(int toDecline)

Custom Objects Formats Defined Below 
Game: {string gameID, string developer, string platform, string genre, string type}
Location: {string city, string state, string zipcode}
Friend: {int id, string alias, string username, string status, string availability, string email, Location location, Game[] games}
Clone this wiki locally