<?php
/**
 * ###############################################
 *
 * SWIFT Framework
 * _______________________________________________
 *
 * @author		Varun Shoor
 *
 * @package		SWIFT
 * @copyright	Copyright (c) 2001-2012, Kayako
 * @license		http://www.kayako.com/license
 * @link		http://www.kayako.com
 *
 * ###############################################
 */

/**
 * The Email Queue Pipe Management Class
 *
 * @author Varun Shoor
 */
class SWIFT_EmailQueuePipe extends SWIFT_EmailQueue
{
	/**
	 * Constructor
	 *
	 * @author Varun Shoor
	 * @param SWIFT_Data $_SWIFT_DataObject The SWIFT_Data Object
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Record could not be loaded
	 */
	public function __construct(SWIFT_Data $_SWIFT_DataObject)
	{
		parent::__construct($_SWIFT_DataObject);

		return true;
	}

	/**
	 * Destructor
	 *
	 * @author Varun Shoor
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function __destruct()
	{
		parent::__destruct();

		return true;
	}

	/**
	 * Create a new Email Queue
	 *
	 * @author Varun Shoor
	 * @param string $_queueEmail The Queue Email Address
	 * @param object $_EmailQueueTypeObject The Email Queue Type Object Pointer (NEWS/TICKETS)
	 * @param string $_queuePrefix The Queue Prefix
	 * @param string $_customFromName The Custom From Name
	 * @param string $_customFromEmail The Custom From Email
	 * @param string $_queueSignature The Queue Signature
	 * @param bool $_registrationRequired Whether the user should be registered for message acceptance to work
	 * @param bool $_isEnabled Whether this Queue is Enabled
	 * @return mixed "SWIFT_EmailQueuePipe" (OBJECT) on Success, "false" otherwise
	 * @throws SWIFT_EmailQueue_Exception When Invalid Data is Specified or the Object couldnt be created
	 */
	static public function Create($_queueEmail, SWIFT_EmailQueueType $_EmailQueueTypeObject, $_queuePrefix, $_customFromName, $_customFromEmail,
			$_queueSignature, $_registrationRequired, $_isEnabled)
	{
		$_emailQueueID = parent::Create($_queueEmail, self::FETCH_PIPE, $_EmailQueueTypeObject, $_queuePrefix, $_customFromName, $_customFromEmail,
				$_queueSignature, $_registrationRequired, $_isEnabled, true);

		$_SWIFT_EmailQueuePipeObject = new SWIFT_EmailQueuePipe(new SWIFT_DataID($_emailQueueID));
		if (!$_SWIFT_EmailQueuePipeObject instanceof SWIFT_EmailQueuePipe || !$_SWIFT_EmailQueuePipeObject->GetIsClassLoaded())
		{
			throw new SWIFT_EmailQueue_Exception('Unable to Load Email Queue (PIPE)');

			return false;
		}

		return $_SWIFT_EmailQueuePipeObject;
	}

	/**
	 * Update the Email Queue Record
	 *
	 * @author Varun Shoor
	 * @param string $_queueEmail The Queue Email Address
	 * @param object $_EmailQueueTypeObject The Email Queue Type Object Pointer (NEWS/TICKETS)
	 * @param string $_queuePrefix The Queue Prefix
	 * @param string $_customFromName The Custom From Name
	 * @param string $_customFromEmail The Custom From Email
	 * @param string $_queueSignature The Queue Signature
	 * @param bool $_registrationRequired Whether the user should be registered for message acceptance to work
	 * @param bool $_isEnabled Whether this Queue is Enabled
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_EmailQueue_Exception If the Class is not Loaded
	 */
	public function Update($_queueEmail, SWIFT_EmailQueueType $_EmailQueueTypeObject, $_queuePrefix, $_customFromName, $_customFromEmail,
			$_queueSignature, $_registrationRequired, $_isEnabled)
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_EmailQueue_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		return parent::Update($_queueEmail, $_EmailQueueTypeObject, $_queuePrefix, $_customFromName, $_customFromEmail, $_queueSignature,
				$_registrationRequired, $_isEnabled);
	}
}
?>