⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 member.php

📁 讲的是网络编程
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
// $Id: member.php 1029 2007-09-09 03:49:25Z phppp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program 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.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  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 General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu)                                          //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //

if (!defined('XOOPS_ROOT_PATH')) {
	exit();
}
require_once XOOPS_ROOT_PATH.'/kernel/user.php';
require_once XOOPS_ROOT_PATH.'/kernel/group.php';

/**
* XOOPS member handler class.
* This class provides simple interface (a facade class) for handling groups/users/
* membership data.
*
*
* @author  Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
* @package kernel
*/

class XoopsMemberHandler{

    /**#@+
    * holds reference to group handler(DAO) class
    * @access private
    */
    var $_gHandler;

    /**
    * holds reference to user handler(DAO) class
    */
    var $_uHandler;

    /**
    * holds reference to membership handler(DAO) class
    */
    var $_mHandler;

    /**
    * holds temporary user objects
    */
    var $_members = array();
    /**#@-*/

    /**
     * constructor
     *
     */
    function XoopsMemberHandler(&$db)
    {
        $this->_gHandler = new XoopsGroupHandler($db);
        $this->_uHandler = new XoopsUserHandler($db);
        $this->_mHandler = new XoopsMembershipHandler($db);
    }

    /**
     * create a new group
     *
     * @return object XoopsGroup reference to the new group
     */
    function &createGroup()
    {
        $inst =& $this->_gHandler->create();
    	return $inst;
    }

    /**
     * create a new user
     *
     * @return object XoopsUser reference to the new user
     */
    function &createUser()
    {
        $inst =& $this->_uHandler->create();
    	return $inst;
    }

    /**
     * retrieve a group
     *
     * @param int $id ID for the group
     * @return object XoopsGroup reference to the group
     */
    function getGroup($id)
    {
        return $this->_gHandler->get($id);
    }

    /**
     * retrieve a user
     *
     * @param int $id ID for the user
     * @return object XoopsUser reference to the user
     */
    function &getUser($id)
    {
        if (!isset($this->_members[$id])) {
            $this->_members[$id] =& $this->_uHandler->get($id);
        }
        return $this->_members[$id];
    }

    /**
     * delete a group
     *
     * @param object $group reference to the group to delete
     * @return bool FALSE if failed
     */
    function deleteGroup(&$group)
    {
        $this->_gHandler->delete($group);
		$this->_mHandler->deleteAll(new Criteria('groupid', $group->getVar('groupid')));
		return true;
    }

    /**
     * delete a user
     *
     * @param object $user reference to the user to delete
     * @return bool FALSE if failed
     */
    function deleteUser(&$user)
    {
        $this->_uHandler->delete($user);
		$this->_mHandler->deleteAll(new Criteria('uid', $user->getVar('uid')));
		return true;
    }

    /**
     * insert a group into the database
     *
     * @param object $group reference to the group to insert
     * @return bool TRUE if already in database and unchanged
     * FALSE on failure
     */
    function insertGroup(&$group)
    {
        return $this->_gHandler->insert($group);
    }

    /**
     * insert a user into the database
     *
     * @param object $user reference to the user to insert
     * @return bool TRUE if already in database and unchanged
     * FALSE on failure
     */
    function insertUser(&$user, $force = false)
    {
        return $this->_uHandler->insert($user, $force);
    }

    /**
     * retrieve groups from the database
     *
     * @param object $criteria {@link CriteriaElement}
     * @param bool $id_as_key use the group's ID as key for the array?
     * @return array array of {@link XoopsGroup} objects
     */
    function getGroups($criteria = null, $id_as_key = false)
    {
        return $this->_gHandler->getObjects($criteria, $id_as_key);
    }

    /**
     * retrieve users from the database
     *
     * @param object $criteria {@link CriteriaElement}
     * @param bool $id_as_key use the group's ID as key for the array?
     * @return array array of {@link XoopsUser} objects
     */
    function getUsers($criteria = null, $id_as_key = false)
    {
        return $this->_uHandler->getObjects($criteria, $id_as_key);
    }

    /**
     * get a list of groupnames and their IDs
     *
     * @param object $criteria {@link CriteriaElement} object
     * @return array associative array of group-IDs and names
     */
    function getGroupList($criteria = null)
    {
        $groups = $this->_gHandler->getObjects($criteria, true);
        $ret = array();
        foreach (array_keys($groups) as $i) {
            $ret[$i] = $groups[$i]->getVar('name');
        }
        return $ret;
    }

    /**
     * get a list of usernames and their IDs
     *
     * @param object $criteria {@link CriteriaElement} object
     * @return array associative array of user-IDs and names
     */
    function getUserList($criteria = null)
    {
        $users = $this->_uHandler->getObjects($criteria, true);
        $ret = array();
        foreach (array_keys($users) as $i) {
            $ret[$i] = $users[$i]->getVar('uname');
        }
        return $ret;
    }

    /**
     * add a user to a group
     *
     * @param int $group_id ID of the group
     * @param int $user_id ID of the user
     * @return object XoopsMembership
     */
    function addUserToGroup($group_id, $user_id)
    {
        $mship =& $this->_mHandler->create();
        $mship->setVar('groupid', $group_id);
        $mship->setVar('uid', $user_id);
        return $this->_mHandler->insert($mship);
    }

    /**
     * remove a list of users from a group
     *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -