<?php

	lt_include( PLOG_CLASS_PATH."class/dao/userauthorizationstatus.class.php" );
	lt_include( PLOG_CLASS_PATH."class/dao/friendauthorizationstatus.class.php" );

    /**
	 * \ingroup DAO
	 *
     * Represents one of the friends that can be created for each blog.
     */
	class Friend extends DbObject
	{

		var $_id;
		var $_userId;
		var $_friendId;
        var $_groupId;
		var $_description;
        var $_userAuthorizationStatus;
        var $_friendAuthorizationStatus;
        var $_friendInfo;

        /**
         * Constructor.
         *
         * @param id Internal idenfitier of the friend
         * @param userId Identifier of the user
         * @param friendId User identifier of the friend
         * @param groupId Group identifier of the friend
         * @param description Description of the friend
         * @param userAuthorizationStatus
         * @param friendAuthorizationStatus
         */
		function Friend( $userId, $friendId, $groupId = 0 , $description = "", 
						 $userAuthorizationStatus = USER_AUTHORIZATION_CONFIRMED, $friendAuthorizationStatus = FRIEND_AUTHORIZATION_CONFIRMED, $id = -1)
		{
			$this->DbObject();

			$this->_userId = $userId;
			$this->_friendId = $friendId;
			$this->_groupId  = $groupId;
			$this->_description = $description;
			$this->_userAuthorizationStatus = $userAuthorizationStatus;
			$this->_friendAuthorizationStatus = $friendAuthorizationStatus;
            $this->_id = $id;

            $this->_pk = "id";
			$this->_fields = Array( "id" => "getId",
									"user_id" => "getUserId",
			   						"friend_id" => "getFriendId",
			   						"group_id" => "getGroupId",
			   						"description" => "getDescription",
			   						"user_authorization_status" => "getUserAuthorizationStatus",
			   						"friend_authorization_status" => "getFriendAuthorizationStatus");
		}

        /**
         * @private
         */
		function setId( $newId )
		{
			$this->_id = $newId;
		}

		/**
         * @private
         */
        function setUserId( $newUserId )
        {
        	$this->_userId = $newUserId;
        }

        /**
         * @private
         */
		function setFriendId( $newFriendId )
		{
			$this->_friendId = $newFriendId;
		}

		/**
         * @private
         */
		function setGroupId( $newGroupId )
		{
			$this->_groupId = $newGroupId;
		}

		/**
         * @private
         */
		function setDescription( $newDescription )
		{
			$this->_description = $newDescription;
		}

        /**
         * @private
         */
        function setUserAuthorizationStatus( $newUserAuthorizationStatus )
        {
        	$this->_userAuthorizationStatus = $newUserAuthorizationStatus;
        }

        /**
         * @private
         */
        function setFriendAuthorizationStatus( $newFriendAuthorizationStatus )
        {
        	$this->_friendAuthorizationStatus = $newFriendAuthorizationStatus;
        }

        /**
         * Returns the identifier that this friend has in the database.
         *
         * @return An integer value.
         */
		function getId()
		{
			return $this->_id;
		}

        /**
         * Returns the user identifier that was given to this friend.
         *
         * @return An integer value.
         */
        function getUserId()
        {
        	return $this->_userId;
        }

        /**
         * Returns the friend identifier that was given to this friend.
         *
         * @return An integer value.
         */
        function getFriendId()
        {
        	return $this->_friendId;
        }

        /**
         * Returns the group identifier that was given to this friend.
         *
         * @return An integer value.
         */
        function getGroupId()
        {
        	return $this->_groupId;
        }

        /**
         * Returns the group object that was given to this friend.
         *
         * @return An integer value.
         */
        function getGroup()
        {
        	$groups = new FriendGroups();
        	$group = $groups->getFriendGroup( $this->_groupId );
        	return $group;
        }

        /**
         * Returns the description assigned to this friend.
         *
         * @return An string with the description.
         */
        function getDescription()
		{
			return $this->_description;
		}

        /**
         * Returns the user authorization status assigned to this friend.
         *
         * @return An integer value.
         */
        function getUserAuthorizationStatus()
		{
			return $this->_userAuthorizationStatus;
		}
		
        /**
         * Returns the friend authorization status assigned to this friend.
         *
         * @return An integer value.
         */
        function getFriendAuthorizationStatus()
		{
			return $this->_friendAuthorizationStatus;
		}
		
		function getFriendInfo()
		{
			if( $this->_friendInfo )
				return $this->_friendInfo;
			else {
				
				$users =& new Users();
				$friendInfo = $users->getUserInfoFromId( $this->_friendId );
				if( $friendInfo ) {
					$this->_friendInfo = $friendInfo;
					return $friendInfo;
				}
				else
					return false;
			}
		}
}
?>
