Location: PHPKode > scripts > Lightweight Club Calendar > lc-calendar-0.9.4/drivers/user/simple.class.php
<?php
/**
* Simple UserDriver for LCC
*
* PHP Version 4, 5
*
* @author <hide@address.com>
* @copyright Copyright (c) 2006, Benedikt Hallinger
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, 51 Franklin St, Fifth Floor,
* Boston, MA  02110-1301  USA
*/

/**
* Simple but flexible configurable UserDriver
*
* The driver supports hard coded (but configurable) user and group data.
* This means that this driver is perfectly for those cases, where you just want to use a username
* from some application that is not supported by a native driver yet togehter with a basic acl.
* It is also very handy for simple cases.
* Note that in group_members, the usernames must not be present. This means that a group leader
* can subscribe non-existant users too, if they are listed in the group_members list!
*
* Config is structured as follows:
* <code>
* $username = 'Testuser';                                  // Username of logged in user
* $user_data = array(
*      'username1' => array(
*           'level'         => 60,                         // Level of 'username1'
*           'groups_leaded' => array('group1')             // Groups this user leads
*      ),
*      'username2' => array(
*           'level'         => 100,                        // Level of 'username2'
*           'groups_leaded' => array('group2')             // Groups this user leads
*      ),
* );
* $group_data = array(
*      'group1' => array('username1', 'username2', 'member3'),
*      'group2' => array('member3', 'member4'),
* );
*
* $simple_config = array(
*      'username'   => $username,
*      'user_data'  => $permissions,
*      'group_data' => $group_members
* );
* </code>
*/
class LCC_UserDriver_Simple extends LCC_UserDriver
{
	/**
	* Default config of the driver
	*
	* This default config can be overridden by calling $object->setConfig().
	* By setting the config you can define the users privileges.
	* Either create a configfile or instanciate the driver yourself
	* followed by passing your custom config to it.
	*
	* @var array
	*/
	var $config = array (
			'username'   => '',             // Username of the current logged in user
			'user_data' => array(),         // Metadata of all users
			'group_data' => array()         // All Members of all groups
		);
	
	/**
	* Return the username of the currently logged in user
	*
	* @return false|string
	*/
	function &fetchLogin()
	{
		return ($this->config['username'])? $this->config['username'] : false;
	}

	/**
	* Get the group names the user is member of
	*
	* This method returns an array of group names the user is part of.
	*
	* @param string $username     Name of the user in question
	* @return false|array
	*/
	function getGroups($username)
	{
		$groups = array();
		if (!is_array($this->config['group_data'])) {
			$false = false;
			return $false;
		}
		foreach ($this->config['group_data'] as $group_name => $group_data) {
			if (in_array($username, $group_data)) {
				array_push($groups, $group_name);
			}
		}
		return $groups;
	}

	/**
	* Get the group names the user leads
	*
	* This is similar to getGroups() but returns only the names of the
	* groups, the user is a leader of.
	*
	* @param string $username     Name of the user in question
	* @return false|array
	*/
	function getGroupsLeaded($username)
	{
		return (is_array($this->config['user_data'][$username]['groups_leaded']))? $this->config['user_data'][$username]['groups_leaded'] : false;
	}
	
	/**
	* Get the group members
	*
	* This method returns an array of usernames the group contains.
	*
	* @param string $groupname     Name of the group in question
	* @return false|array
	*/
	function getGroupMembers($groupname)
	{
		return (is_array($this->config['group_data'][$groupname]))? $this->config['group_data'][$groupname] : false;
	}

	/**
	* Get the "level" of a user
	*
	* @param string $username     Name of the user in question
	* @return false|int
	*/
	function getLevel($username)
	{
		return (is_int($this->config['user_data'][$username]['level']))? $this->config['user_data'][$username]['level'] : false;
	}
}
?>
Return current item: Lightweight Club Calendar