websiteWebsite
codingteam CodingTeam
A free forge, lightweight and extensible.

 

Browse the code

Revision log Information on the revision
Revision: 511 (differences)
Author: xbright
Log message: * Enhanced roadmap
Change revision:
<?php
#    This file is a part of CodingTeam. See <http://www.codingteam.net>.
#    Copyright (C) 2007-2010 CodingTeam (See AUTHORS and THANKS for details)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, version 3 only.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
/**
 * @file
 * This file contains the User class
 *
 * Get user datas, edit them and delete the user.
 */
 
 
/**
 * User class
 */
class User {
    protected $id, $nickname, $surname, $name, $date, $email,
              $jid, $url, $avatar, $level, $lang;
    private $password, $apache_password, $keyid, $db;
 
    function __construct($db)
    {
        $this->db = $db;
    }
 
 
    /**
     * Get users list
     *
     * @return
     *
     */
    function getUsersList($where, $limit)
    {
        $req0 = $this->db->select('users', $where, 'id');
        $req1 = $this->db->select('users', $where, '*', 'ORDER BY date DESC '.
                                                        $limit);
 
        return array(count($req0), $req1);
    }
 
 
    /**
     * Get users number
     *
     * @return
     *   An int.
     */
    function getUsersNumber()
    {
        return count($this->db->select('users', FALSE));
    }
 
 
    /**
     * Add an user
     *
     * @param $nickname
     *   Nickname of the user.
     * @param $password
     *   Password of the user.
     * @param $apache_password
     *   Apache-style password for the user.
     * @param $surname
     *   Surname of the user.
     * @param $name
     *   Name of the user.
     * @param $mail
     *   Mail of the user.
     * @param $jabberid
     *   Jabber ID of the user.
     * @param $website
     *   Website URL of the user.
     * @param $avatar
     *   Avatar of the user.
     * @param $level
     *   Level of the user.
     * @param $hash
     *   Unique hash of the user.
     * @param $lang
     *   Speaking-language of the user.
     * @return
     *   The identifier of the new member.
     */
    function addUser($nickname, $password, $apache_password, $surname,
                     $name, $mail, $jabberid, $website, $avatar, $level,
                     $hash, $lang)
    {
        return $this->db->insert('users',
                                  array('nickname' => $nickname,
                                        'password' => md5($password),
                                        'apache_password' => $apache_password,
                                        'surname' => $surname,
                                        'name' => $name,
                                        'date' => date('Y-m-d H:i:s'),
                                        'email' => $mail,
                                        'jid' => $jabberid,
                                        'url' => $website,
                                        'avatar' => $avatar,
                                        'level' => $level,
                                        'keyid' => $hash,
                                        'lang' => $lang));
    }
 
 
    /**
     * Load an user
     *
     * @param $value
     *   One value that can identify the user (id, nickname or hash).
     * @param $where
     *   Database field that corresponds with value.
     * @return
     *   A boolean (TRUE if the user is loaded).
     */
    function load($id, $where)
    {
        if (isset($this->loaded))
            return TRUE;
        else
        {
            $req = $this->db->select('users', array($where => $id),
                                     '*', 'LIMIT 1');
            if (count($req) == 1)
            {
                $user = $req[0];
                $this->id = $user['id'];
                $this->nickname = $user['nickname'];
                $this->surname = $user['surname'];
                $this->name = $user['name'];
                $this->date = $user['date'];
                $this->email = $user['email'];
                $this->jid = $user['jid'];
                $this->url = $user['url'];
                $this->avatar = $user['avatar'];
                $this->level = $user['level'];
                $this->lang = $user['lang'];
 
                $this->password = $user['password'];
                $this->apache_password = $user['apache_password'];
                $this->keyid = $user['keyid'];
 
                $this->loaded = TRUE;
                return TRUE;
            }
            else
                return FALSE;
        }
    }
 
    function removeUser()
    {
        if (isset($this->id))
            $this->db->delete('users', array('id' => $this->id));
    }
 
    function updateField($field, $value)
    {
        if (isset($this->id))
            $this->db->update('users', array($field => $value),
                                       array('id' => $this->id));
    }
 
    function getId()
    {
        if ($this->loaded)
            return $this->id;
    }
 
    function setId($id)
    {
        $this->updateField('id', $id);
        $this->id = $id;
    }
 
    function getNickname()
    {
        if ($this->loaded)
            return $this->nickname;
    }
 
    function setNickname($nickname)
    {
        $this->updateField('nickname', $nickname);
        $this->nickname = $nickname;
    }
 
    function getSurname()
    {
        if ($this->loaded)
            return $this->surname;
    }
 
    function setSurname($surname)
    {
        $this->updateField('surname', $surname);
        $this->surname = $surname;
    }
 
    function getName()
    {
        if ($this->loaded)
            return $this->name;
    }
 
    function setName($name)
    {
        $this->updateField('name', $name);
        $this->name = $name;
    }
 
    function getDate()
    {
        if ($this->loaded)
            return $this->date;
    }
 
    function setDate($date)
    {
        $this->updateField('date', $date);
        $this->date = $date;
    }
 
    function getEmail()
    {
        if ($this->loaded)
            return $this->email;
    }
 
    function setEmail($email)
    {
        $this->updateField('email', $email);
        $this->email = $email;
    }
 
    function getJid()
    {
        if ($this->loaded)
            return $this->jid;
    }
 
    function setJid($jid)
    {
        $this->updateField('jid', $jid);
        $this->jid = $jid;
    }
 
    function getUrl()
    {
        if ($this->loaded)
            return $this->url;
    }
 
    function setUrl($url)
    {
        $this->updateField('url', $url);
        $this->url = $url;
    }
 
    function getAvatar()
    {
        if ($this->loaded)
            return $this->avatar;
    }
 
    function setAvatar($avatar)
    {
        $this->updateField('avatar', $avatar);
        $this->avatar = $avatar;
    }
 
    function getLevel()
    {
        if ($this->loaded)
            return $this->level;
    }
 
    function setLevel($level)
    {
        $this->updateField('level', $level);
        $this->level = $level;
    }
 
    function getLang()
    {
        if ($this->loaded)
            return $this->lang;
    }
 
    function setLang($lang)
    {
        $this->updateField('lang', $lang);
        $this->lang = $lang;
    }
 
    function getPassword()
    {
        if ($this->loaded)
            return $this->password;
    }
 
    function setPassword($password)
    {
        $this->updateField('password', $password);
        $this->password = $password;
    }
 
    function getApache_password()
    {
        if ($this->loaded)
            return $this->apache_password;
    }
 
    function setApache_password($apache_password)
    {
        $this->updateField('apache_password', $apache_password);
        $this->apache_password = $apache_password;
    }
 
    function getKeyid()
    {
        if ($this->loaded)
            return $this->keyid;
    }
 
    function setKeyid($keyid)
    {
        $this->updateField('keyid', $keyid);
        $this->keyid = $keyid;
    }
}
?>