wiclear-2007-07-19/inc/classes/user.class.php

<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of WiClear.
# Copyright (c) 2004-2007 David Jobet. All rights
# reserved.
#
# WiClear is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# WiClear 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DotClear; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
#
# ***** END LICENSE BLOCK *****

/**
 * \brief represents a user known by the wiki
 */
class user
{
  var $id;           //!< database id
  var $login;        //!< login
  var $password;     //!< md5 encoded password
  var $admin;        //!< admin level (0=user, 1=moderator, 2=admin as defined in constants.lib.php)
  var $first_name;   //!< first name
  var $last_name;    //!< last name
  var $email;        //!< email
  var $lang;         //!< lang content
  var $ui_lang;      //!< ui lang code (i18n)
  var $timestamp;    //!< timestamp of creation

  var $watches;      //!< array<node_id> list of nodes subscribed

  function user($id, $login, $password, $admin, $first_name, $last_name, $email, $lang, $ui_lang, $timestamp)
  {
    $this->id         = $id;
    $this->login      = $login;
    $this->password   = $password;
    $this->admin      = $admin;
    $this->first_name = $first_name;
    $this->last_name  = $last_name;
    $this->email      = $email;
    $this->lang       = $lang;
    $this->ui_lang    = $ui_lang;
    $this->timestamp  = $timestamp;
  }

  function setWatches($watches)
  {
    $this->watches = $watches;
  }

  /**
   * \brief has user subscribed to this node
   *
   * \param node_id database id of node to look at
   * \return true if user has subscribed, false otherwise
   */
  function isWatching($node_id)
  {
    return in_array($node_id, $this->watches);
  }

  /**
   * \brief is user an admin
   *
   * an admin should be considered a moderator, but isModerator() below will return false
   * as the comparison is not intelligent (only database values are compared)
   *
   * \return true if user is admin, false otherwise
   */
  function isAdmin()
  {
    return $this->admin == admin_value;
  }

  /**
   * \brief is user a moderator
   *
   * \return true if user is moderator, false otherwise
   */
  function isModerator()
  {
    return $this->admin == moderator_value;
  }

  /**
   * \brief is user anonymous or not
   *
   * there is always a user object defined in our world
   * if there is no user logged in, method createAnonymousUser is called on wiki
   * and we can later see if our current user is logged in or not via this method
   *
   * \return true if user is anonymous, false if he is logged in
   */
  function isAnonymous()
  {
    return $this->id == user_anonymous_id;
  }
}
?>