Location: PHPKode > projects > Blandware AtLeap Lite - CMS on PHP > atleaplite/include/dataobject/User.php
<?php
/*
 *  Copyright 2008 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * Table Definition for user
 *
 * @package     AtleapLite
 * @author      Roman Puchkovskiy
 * @license     http://www.apache.org/licenses/LICENSE-2.0  Apache License, Version 2.0
 */

/**
 */
require_once 'dbdo_ext.php';

/**
 * Represents a user in system. User always has role which defines his
 * permissions.
 *
 * @package     AtleapLite
 */
class DataObjects_User extends DB_DataObject_Base 
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    var $__table = 'user';                            // table name
    var $id;                              // int(11)  not_null primary_key auto_increment
    var $login;                           // string(60)  not_null unique_key
    var $password;                        // string(120)  not_null
    var $first_name;                      // string(765)  not_null
    var $last_name;                       // string(765)  
    var $patronymic_name;                 // string(765)  
    var $address;                         // string(765)  
    var $phone;                           // string(765)  
    var $fax;                             // string(765)  
    var $email;                           // string(765)  
    var $role_id;                         // int(11)  not_null multiple_key

    /* ZE2 compatibility trick*/
    function __clone() { return $this;}

    /* Static get */
    function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_User',$k,$v); }

    /* the code above is auto generated do not remove the tag below */
    ###END_AUTOCODE

    /**
     * Sets password encrypting it.
     *
     * @param string $password  password (unencrypted)
     */
    function setPassword($password)
    {
        $this->password = sha1($password);
    }

    /**
     * Returns title of role of this user.
     *
     * @return string role title
     */
    function getRoleTitle()
    {
        $role = DB_DataObject::staticGet('DataObjects_Role', $this->role_id);
        return $role->title;
    }

    /**
     * Returns whether this user is admin.
     *
     * @return bool true if this is admin
     */
    function isAdmin()
    {
        $role = DB_DataObject::staticGet('DataObjects_Role', $this->role_id);
        if ($role->admin == 1) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Returns whether this user is same as current user.
     *
     * @return bool true if this is current user
     */
    function me()
    {
        if (!$_SESSION['login'] || $_SESSION['anonymous']) {
            return false;
        }
        return ($_SESSION['login'] == $this->login);
    }

    /**
     * Returns this user role.
     *
     * @returns object role
     */
    function getRole()
    {
        $role =& DB_DataObject::factory('role');
        $role->get($this->role_id);
        return $role;
    }

    /**
     * Finds a user by login.
     *
     * @param string $login user login
     */
    function findByLogin($login) {
        $this->login = $login;
        $this->find(true);
    }
}
Return current item: Blandware AtLeap Lite - CMS on PHP