<?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
 *
 * ###############################################
 */

/**
 * Comments Controller: Knowledgebase
 *
 * @author Varun Shoor
 */
class Controller_Comments extends Controller_staff
{
	/**
	 * Constructor
	 *
	 * @author Varun Shoor
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function __construct()
	{
		parent::__construct();

		$this->Load->Library('Comment:CommentManager');
		$this->Load->Library('Render:KnowledgebaseRenderManager');
		$this->Load->Library('Article:KnowledgebaseArticleManager');

		$this->Language->Load('staff_knowledgebase');

		return true;
	}

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

		return true;
	}

	/**
	 * Submit a new Comment
	 *
	 * @author Varun Shoor
	 * @param int $_knowledgebaseArticleID The Knowledgebase Article ID
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function Submit($_knowledgebaseArticleID)
	{
		$_SWIFT = SWIFT::GetInstance();

		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		$_knowledgebaseArticleObjectContainer = $this->KnowledgebaseArticleManager->RetrieveForStaff($_knowledgebaseArticleID);
		if (!$_knowledgebaseArticleObjectContainer)
		{
			return false;
		}

		$_SWIFT_KnowledgebaseArticleObject = $_knowledgebaseArticleObjectContainer[0];
		if (!$_SWIFT_KnowledgebaseArticleObject instanceof SWIFT_KnowledgebaseArticle || !$_SWIFT_KnowledgebaseArticleObject->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_INVALIDDATA);
		}

		$this->CommentManager->ProcessPOSTStaff($_SWIFT->Staff, SWIFT_Comment::TYPE_KNOWLEDGEBASE, $_SWIFT_KnowledgebaseArticleObject->GetKnowledgebaseArticleID(), SWIFT::Get('basename') . '/Knowledgebase/ViewKnowledgebase/Article/' . $_SWIFT_KnowledgebaseArticleObject->GetKnowledgebaseArticleID());

		$this->Load->Controller('ViewKnowledgebase', 'Knowledgebase')->Load->Method('Article', $_knowledgebaseArticleID);

		return true;
	}
}
?>