User.class.php 1.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php
    class User extends Model {
        // ===========
        // = Statics =
        // ===========
        public static function tryLogin($login) {
            return new static();
        }

        protected static $table_name = 'USER';

        public static function create($post) {
            parent::exec('USER_CREATE', [':firstname' => $post->firstname,
                                         ':lastname' => $post->lastname,
                                         ':login' => $post->login,
raphael.peim's avatar
raphael.peim committed
16 17
                                         ':avatar' => $post->avatar,
                                         ':avatar_url' => $post->avatar_url,
18
                                         ':email' => $post->email,
raphael.peim's avatar
raphael.peim committed
19
                                         ':password' => $post->password,
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
                                         ':role' => $post->role]);
        }

        public static function getList() {
            $stm = parent::exec('USER_GET_LIST');
            return $stm->fetchAll();
        }

        public static function getWithId($id) {
            $stm = parent::exec('USER_GET_WITH_ID', [':id' => $id]);
            return $stm->fetch();
        }

        public static function getWithLogin($login) {
            $stm = parent::exec('USER_GET_WITH_LOGIN', [':login' => $login]);
            return $stm->fetch();
        }

        public static function update($put, $id) {
raphael.peim's avatar
raphael.peim committed
39 40 41 42 43 44 45 46
            parent::exec('USER_UPDATE', [
                ':firstname' => $put->firstname, 
                ':lastname' => $put->lastname, 
                ':login' => $put->login, 
                ':password' => $put->password, 
                ':email' => $put->email, 
                ':role' => $put->role, 
                ':id' => $id]);
47 48 49 50 51 52 53
        }

        public static function delete($id) {
            parent::exec('USER_DELETE', [':id' => $id]);
        }
    }
?>