<?php
/*
 * This file is part of the Easy-CMS project.
 * Easy-CMS 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.
 * 
 * Easy-CMS 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 Easy-CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/**
 * @package    Core
 * @subpackage Groups
 */

/**
 */
include_once('classes/core/CoreObject.class.php');
include_once('classes/core/users/User.class.php');

/**
 * Group Class
 *
 * @author     vinadelmar <vinadelmar@users.sourceforge.net>
 * @since      2006-02-15
 * @package    Core
 * @subpackage Groups
 */
class Group extends CoreObject {
	/**#@+
	 * @access private
	 */
	/**
	 * @var integer
	 */
	var $groupId;
	
	/**
	 * @var string
	 */
	var $groupName;
	
	/**
	 * @var string
	 */
	var $groupDescription;
	
	/**
	 * @var integer
	 */
	var $groupDisabled;
	
	/**
	 * @var array direct access array
	 */
	var $groupUsersIdList;
	/**#@-*/
	
	/**#@+
	 * @access public
	 */
	/**
	 * Constructor
	 *
	 * @param integer $id
	 * @param string  $name
	 * @param string  $description
	 * @param integer $disabled
	 */
	function Group($id=0, $name='', $description='', $disabled=0) {
		$this->setGroupId($id);
		$this->setGroupName($name);
		$this->setGroupDescription($description);
		$this->setGroupDisabled($disabled);
		$this->groupUsersIdList = array();
	}
	 
	/**
	 * Gets Group Id
	 *
	 * @return integer
	 */
	function getGroupId() {
		return $this->groupId;
	}
	
	/**
	 * Sets Group Id
	 *
	 * @param integer $id Group Id
	 */
	function setGroupId($id) {
		$this->groupId = $id;
	}
	
	/**
	 * Gets Group Name
	 *
	 * @return string
	 */
	function getGroupName() {
		return $this->groupName;
	}
	
	/**
	 * Sets Group Name
	 *
	 * @param string $name Group Name
	 */
	function setGroupName($name) {
		$this->groupName = $name;
	}
	
	/**
	 * Gets Group Description
	 *
	 * @return string
	 */
	function getGroupDescription() {
		return $this->groupDescription;
	}
	
	/**
	 * Sets Group Description
	 *
	 * @param string $description Group Description
	 */
	function setGroupDescription($description) {
		$this->groupDescription = $description;
	}
	
	/**
	 * Gets Group Disabled
	 *
	 * @return integer
	 */
	function getGroupDisabled() {
		return $this->groupDisabled;
	}
	
	/**
	 * Sets Group Disabled
	 *
	 * @param integer $disabled Group Disabled
	 */
	function setGroupDisabled($disabled) {
		$this->groupDisabled = $disabled;
	}
	
	/**
	 * Sets Group Values
	 *
	 * @param array $array
	 */
	function setGroupValues($array) {
		if(!is_array($array)) {
			return;
		}

		if(isset($array['id'])) {
			$this->setGroupId($array['id']);
		}
		if(isset($array['name'])) {
			$this->setGroupName($array['name']);
		}
		if(isset($array['description'])) {
			$this->setGroupDescription($array['description']);
		}
		if(isset($array['disabled'])) {
			$this->setGroupDisabled($array['disabled']);
		}
	}

	/**
	 * Adds User Membership
	 *
	 * @param integer $userId User Id
	 */
	function addUserMembership($userId) {
		$this->groupUsersIdList[$userId] = true;
	}
	
	/**
	 * Deletes User Membership
	 *
	 * @param integer $userId
	 */
	function delUserMembership($userId) {
		if ($this->checkUserMembership($userId)) {
			unset($this->groupUsersIdList[$userId]);
		}
		return true;
	}
	
	/**
	 * Checks User Membership
	 *
	 * @return boolean
	 */
	function checkUserMembership($userId) {
		return isset($this->groupUsersIdList[$userId]);
	}
	
	function &getUsersIdList() {
		$usersIdList = array();
		foreach($this->groupUsersIdList as $userId => $memberShip) {
			if($memberShip) {
				$usersIdList[] = $userId;
			}
		}
		return $usersIdList;
	}

	/**
	 * Gets Users Membership List
	 *
	 * @return array direct access array
	 */
	function &getUsersMembershipList() {
		return $this->groupUsersIdList;
	}
	
	/**
	 * Gets Users Membership Count
	 *
	 * @return integer
	 */
	function getUsersMembershipCount() {
		return count($this->groupUsersIdList);
	}
	/**#@-*/
	
}

?>