<?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 Ticket Post Note Class
 *
 * @author Varun Shoor
 */
class SWIFT_TicketPostNote extends SWIFT_TicketNoteManager
{
	/**
	 * Constructor
	 *
	 * @author Varun Shoor
	 * @param int $_ticketNoteID The Ticket Note ID
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function __construct($_ticketNoteID)
	{
		parent::__construct($_ticketNoteID);

		if ($this->GetProperty('linktype') != self::LINKTYPE_TICKETPOST)
		{
			throw new SWIFT_Note_Exception(SWIFT_INVALIDDATA);
		}

		return true;
	}

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

		return true;
	}

	/**
	 * Create a new Ticket Post Note
	 *
	 * @author Varun Shoor
	 * @param object $_SWIFT_TicketPostObject The SWIFT_TicketPost Object pointer
	 * @param int $_forStaffID The Staff ID for which this note is for (0 = Visible to all)
	 * @param int $_staffID The Staff ID
	 * @param string $_staffName The Staff Name
	 * @param string $_noteContents The Note Contents
	 * @param int $_noteColor (OPTIONAL) The Note Color
	 * @return mixed "_ticketNoteID" on Success, "false" otherwise
	 * @throws SWIFT_Note_Exception If Invalid Data is Provided
	 */
	static public function Create(SWIFT_TicketPost $_SWIFT_TicketPostObject, $_forStaffID, $_staffID, $_staffName, $_noteContents, $_noteColor = 1)
	{
		$_SWIFT = SWIFT::GetInstance();

		if (!$_SWIFT_TicketPostObject instanceof SWIFT_TicketPost || !$_SWIFT_TicketPostObject->GetIsClassLoaded())
		{
			throw new SWIFT_Note_Exception(SWIFT_INVALIDDATA);

			return false;
		}

		$_ticketNoteID = parent::Create(self::LINKTYPE_TICKETPOST, $_SWIFT_TicketPostObject->GetTicketPostID(), $_forStaffID, $_staffID, $_staffName, $_noteContents, $_noteColor);

		return $_ticketNoteID;
	}

	/**
	 * Delete notes on Ticket Post ID list
	 *
	 * @author Varun Shoor
	 * @param array $_ticketPostIDList The Ticket Post ID List
	 * @return bool "true" on Success, "false" otherwise
	 */
	static public function DeleteOnTicketPost($_ticketPostIDList)
	{
		$_SWIFT = SWIFT::GetInstance();

		if (!_is_array($_ticketPostIDList))
		{
			return false;
		}

		$_ticketNoteIDList = array();
		$_SWIFT->Database->Query("SELECT ticketnoteid FROM " . TABLE_PREFIX . "ticketnotes WHERE linktype = '" . intval(self::LINKTYPE_TICKETPOST) . "' AND linktypeid IN (" . BuildIN($_ticketPostIDList) . ")");
		while ($_SWIFT->Database->NextRecord())
		{
			$_ticketNoteIDList[] = intval($_SWIFT->Database->Record['ticketnoteid']);
		}

		if (!count($_ticketNoteIDList))
		{
			return false;
		}

		self::DeleteList($_ticketNoteIDList);

		return true;
	}
}
?>