Ejemplo n.º 1
0
 /**
  * Function that adds the User object to the User table in the database.
  * 
  * @param \GameMania\Model\User $userObject
  * @return boolean
  * @throws \Exception
  */
 public function addUser($userObject)
 {
     //Establish database connection
     $dbConn = new DbConn();
     $db = $dbConn->getConnection();
     //Check if the username already exists
     if ($this->exists('usr_username', 'User', $userObject->getUsername())) {
         throw new \Exception("The username is already taken.");
     } else {
         //Prepare insert statement for the database.
         $stmt = $db->prepare("insert into User (usr_username, usr_email, usr_password) VALUES (?, ?, ?)");
         $result = $stmt->execute(array($userObject->getUsername(), $userObject->getEmail(), $userObject->getPassword()));
         //If the execution succeeds, return true
         if ($result) {
             return true;
         } else {
             throw new \Exception("Doh! The User could not be added. Please " . "look over the submission, correct any errors, and " . "try again.");
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Function that takes in a Game object and inserts the data into the database.
  * 
  * @param \GameMania\Model\Game $gameObject
  * @return boolean
  * @throws \Exception
  */
 public function addGame($gameObject)
 {
     //Establishing a database connection.
     $dbConn = new DbConn();
     $db = $dbConn->getConnection();
     //Check to see if title exists
     if ($this->exists('gme_title', 'Game', $gameObject->getTitle())) {
         throw new \Exception("The game title already exists.");
     } else {
         //Preparing the insert statement.
         $stmt = $db->prepare("insert into Game " . "(gme_title, gme_developer, gme_console, gme_price, gme_rating, gme_comments) " . "VALUES " . "(?,?,?,?,?,?) ");
         $result = $stmt->execute(array($gameObject->getTitle(), $gameObject->getDeveloper(), $gameObject->getConsole(), $gameObject->getPrice(), $gameObject->getRating(), $gameObject->getComments()));
         //Result Logic
         if ($result) {
             return true;
             //Successfully added the Game.
         } else {
             throw new \Exception("Doh! Something went wrong! We couldn't add " . "the new product. Please look over the product, " . "correct any errors, and try again.");
         }
     }
 }