<?php

    /**
	 * \ingroup DAO
	 *
     * The private messages one can add to a user can also be filed under different boxes.
     * This object are the abstraction of those boxes and offer methods to check the value
     * of some of its attributes.
     */
    class PrivateMessageBox extends DbObject
	{

		var $_id;
        var $_userId;
        var $_boxType;
        var $_numUnreadPrivateMessages;
		var $_numPrivateMessages;
		var $_privateMessages;

        /**
         * Constructor.
         *
         * @param userId Identifier of the user to which it belongs
         * @param boxType the private message box type
         * @param id Identifier of the message box
         */
        function PrivateMessageBox( $userId, $boxType, $properties = Array(), $id = -1 )
        {
	        

			$this->DbObject();

            $this->_userId = $userId;
            $this->_boxType = $boxType;
			$this->setProperties( $properties );
            $this->_id = $id;

            $this->_numUnreadPrivateMessages = 0;
            $this->_numPrivateMessages = 0;
            $this->_privateMessages = null;

			$this->_pk = "id";
			$this->_fields = Array(
			   "user_id" => "getUserId",
			   "box_type" => "getBoxType",
			   "properties" => "getProperties",
			   "num_unread_messages" => "getNumUnreadPrivateMessages",
			   "num_messages" => "getNumPrivateMessages"
			);
        }

        /**
         * Returns the identifier assigned to this message box in the database.
         *
         * @return The identifier assigned to this message box in the database.
         */
        function getId()
        {
        	return $this->_id;
        }

        /**
         * Returns the user identifier to which this this message box belongs.
         *
         * @return An integer value.
         */
        function getUserId()
        {
        	return $this->_userId;
        }

        /**
         * Returns the type to which this this message box belongs.
         *
         * @return An integer value.
         */
        function getBoxType()
        {
        	return $this->_boxType;
        }

        /**
         * Returns how many messages no readed under this message box.
         *
         * @return Number of unread messages.
         */
        function getNumUnreadPrivateMessages()
        {
        	return $this->_numUnreadPrivateMessages;
        }

        /**
         * Returns how many messages have been file under this message box.
         *
         * @return Number of messages.
         */
        function getNumPrivateMessages()
        {
        	return $this->_numPrivateMessages;
        }

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

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

        /**
         * @private
         */
        function setBoxType( $boxType )
        {
        	$this->_boxType = $boxType;
        }

        /**
         * Returns assign many unread private messages have been filed under this message box.
         *
         * @param Number of unread messages.
         *
         * @return nothing
         */
        function setNumUnreadPrivateMessages( $numUnreadPrivateMessages )
        {
        	$this->_numUnreadPrivateMessages = $numUnreadPrivateMessages;
        }

        /**
         * Returns assign many private messages have been filed under this message box.
         *
         * @param Number of messages.
         *
         * @return nothing
         */
        function setNumPrivateMessages( $numPrivateMessages )
        {
        	$this->_numPrivateMessages = $numPrivateMessages;
        }

        /**
         * Returns an array of private messages
         *
         * @return Array of PrivateMessage object
         */
        function getPrivateMessagesFromBox( $searchTerms = "", $page = -1, $itemsPerPage = 15 )
        {
			
			$privateMessages = new PrivateMessages();
			$mesages = $privateMessages->getPrivateMessagesFromBoxId( $this->_id, $searchTerms, $page, $itemsPerPage );

			return $mesages;
        }

        /**
         * Returns an array of private messages
         *
         * @return Array of PrivateMessage object
         */
        function getNumPrivateMessagesFromBox( $searchTerms = "" )
        {
			
			$privateMessages = new PrivateMessages();

			return( $privateMessages->getNumPrivateMessagesFromBoxId( $this->_id, $searchTerms ) );
        }
	}
?>