📄 group.php
字号:
<?php
// $Id: group.php 1102 2007-10-19 02:55:52Z dugris $
// ------------------------------------------------------------------------ //
// 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();
}
/**
* a group of users
*
* @copyright copyright (c) 2000-2003 XOOPS.org
* @author Kazumi Ono <onokazu@xoops.org>
* @package kernel
*/
class XoopsGroup extends XoopsObject
{
/**
* constructor
*/
function XoopsGroup()
{
$this->XoopsObject();
$this->initVar('groupid', XOBJ_DTYPE_INT, null, false);
$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, true, 100);
$this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false);
$this->initVar('group_type', XOBJ_DTYPE_OTHER, null, false);
}
}
/**
* XOOPS group handler class.
* This class is responsible for providing data access mechanisms to the data source
* of XOOPS group class objects.
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
* @package kernel
* @subpackage member
*/
class XoopsGroupHandler extends XoopsObjectHandler
{
/**
* create a new {@link XoopsGroup} object
*
* @param bool $isNew mark the new object as "new"?
* @return object XoopsGroup reference to the new object
*
*/
function &create($isNew = true)
{
$group = new XoopsGroup();
if ($isNew) {
$group->setNew();
}
return $group;
}
/**
* retrieve a specific group
*
* @param int $id ID of the group to get
* @return object XoopsGroup reference to the group object, FALSE if failed
*/
function &get($id)
{
$id = intval($id);
$group = false;
if ($id > 0) {
$sql = 'SELECT * FROM '.$this->db->prefix('groups').' WHERE groupid='.$id;
if (!$result = $this->db->query($sql)) {
return $group;
}
$numrows = $this->db->getRowsNum($result);
if ($numrows == 1) {
$group = new XoopsGroup();
$group->assignVars($this->db->fetchArray($result));
}
}
return $group;
}
/**
* insert a group into the database
*
* @param object reference to the group object
* @return mixed ID of the group if inserted, FALSE if failed, TRUE if already present and unchanged.
*/
function insert(&$group)
{
/**
* @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
*/
if (!is_a($group, 'xoopsgroup')) {
return false;
}
if (!$group->isDirty()) {
return true;
}
if (!$group->cleanVars()) {
return false;
}
foreach ($group->cleanVars as $k => $v) {
${$k} = $v;
}
if ($group->isNew()) {
$groupid = $this->db->genId('group_groupid_seq');
$sql = sprintf("INSERT INTO %s (groupid, name, description, group_type) VALUES (%u, %s, %s, %s)", $this->db->prefix('groups'), $groupid, $this->db->quoteString($name), $this->db->quoteString($description), $this->db->quoteString($group_type));
} else {
$sql = sprintf("UPDATE %s SET name = %s, description = %s, group_type = %s WHERE groupid = %u", $this->db->prefix('groups'), $this->db->quoteString($name), $this->db->quoteString($description), $this->db->quoteString($group_type), $groupid);
}
if (!$result = $this->db->query($sql)) {
return false;
}
if (empty($groupid)) {
$groupid = $this->db->getInsertId();
}
$group->assignVar('groupid', $groupid);
return true;
}
/**
* remove a group from the database
*
* @param object $group reference to the group to be removed
* @return bool FALSE if failed
*/
function delete(&$group)
{
/**
* @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
*/
if (!is_a($group, 'xoopsgroup')) {
return false;
}
$sql = sprintf("DELETE FROM %s WHERE groupid = %u", $this->db->prefix('groups'), $group->getVar('groupid'));
if (!$result = $this->db->query($sql)) {
return false;
}
return true;
}
/**
* retrieve groups from the database
*
* @param object $criteria {@link CriteriaElement} with conditions for the groups
* @param bool $id_as_key should the groups' IDs be used as keys for the associative array?
* @return mixed Array of groups
*/
function getObjects($criteria = null, $id_as_key = false)
{
$ret = array();
$limit = $start = 0;
$sql = 'SELECT * FROM '.$this->db->prefix('groups');
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
$sql .= ' '.$criteria->renderWhere();
$limit = $criteria->getLimit();
$start = $criteria->getStart();
}
$result = $this->db->query($sql, $limit, $start);
if (!$result) {
return $ret;
}
while ($myrow = $this->db->fetchArray($result)) {
$group = new XoopsGroup();
$group->assignVars($myrow);
if (!$id_as_key) {
$ret[] =& $group;
} else {
$ret[$myrow['groupid']] =& $group;
}
unset($group);
}
return $ret;
}
}
/**
* membership of a user in a group
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
* @package kernel
*/
class XoopsMembership extends XoopsObject
{
/**
* constructor
*/
function XoopsMembership()
{
$this->XoopsObject();
$this->initVar('linkid', XOBJ_DTYPE_INT, null, false);
$this->initVar('groupid', XOBJ_DTYPE_INT, null, false);
$this->initVar('uid', XOBJ_DTYPE_INT, null, false);
}
}
/**
* XOOPS membership handler class. (Singleton)
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -