User.class.php 1.46 KB
Newer Older
thibaut-felten's avatar
thibaut-felten committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?php

class User extends Model {

   // ===========
   // = Statics =
   // ===========
   protected static $table_name = 'USER';

   // load all users from Db
   public static function getList() {
      $stm = parent::exec('USER_LIST');
      return $stm->fetchAll();
   }
15

thibaut-felten's avatar
thibaut-felten committed
16
   // load one user from the Db
17 18 19 20 21
   public static function getUserByID($id) {
      $stm = parent::exec('USER_BY_ID',array(':user_id' => $id));
      return $stm->fetchAll();
   }

thibaut-felten's avatar
thibaut-felten committed
22
   // update one user from the Db
23 24 25 26 27
   public static function updateUser($values) {
      $stm = parent::exec('USER_UPDATE',$values);
      return "User updated";
   }

thibaut-felten's avatar
thibaut-felten committed
28
   // Create a new user in the Db
29 30 31 32 33
   public static function createUser($values) {
      $stm = parent::exec('USER_CREATE',$values);
      return "User created";
   }

thibaut-felten's avatar
thibaut-felten committed
34
   // Delete a user from the Db
35 36 37 38 39
   public static function deleteUser($id) {
      $stm = parent::exec('USER_DELETE',array(':id' => $id));
      return "User deleted";
   }

thibaut-felten's avatar
thibaut-felten committed
40
   // Retrieve all users having this login
41 42 43 44 45
   public static function getListWithLogin($login) {
      $stm = parent::exec('USER_GET_WITH_LOGIN',array(':login' => $login));
      return $stm->fetchAll();
   }

thibaut-felten's avatar
thibaut-felten committed
46
   // load the user with the login $login
47
   public static function tryLogin($login)
48 49 50 51 52 53 54 55 56 57
   {
      $users = static::getListWithLogin($login);
      return $users[0];
   }
   
   public static function getGames($id)
   {
      $stm = parent::exec('USER_GET_GAMES', array(':USER_ID' => $id));
      return $stm->fetchAll();
   }
58

thibaut-felten's avatar
thibaut-felten committed
59
}