<?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 Knowledgebase Search Manager Class
 *
 * @author Varun Shoor
 */
class SWIFT_KnowledgebaseSearch extends SWIFT_Library {
	/**
	 * Constructor
	 *
	 * @author Varun Shoor
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function __construct() {
		parent::__construct();

		return true;
	}

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

		return true;
	}

	/**
	 * Search for given query under the provided user group
	 *
	 * @author Varun Shoor
	 * @param string $_searchQuery The Search Query
	 * @param int $_userGroupID The User Group ID
	 * @return array The Search Results Container
	 */
	static public function Search($_searchQuery, $_userGroupID) {
		$_SWIFT = SWIFT::GetInstance();

		if (empty($_searchQuery) || empty($_userGroupID)) {
			return array();
		}

		$_searchResultContainer = array();

		$_knowledgebaseArticleContainer = SWIFT_KnowledgebaseArticle::RetrieveFullText($_searchQuery, SWIFT::Get('usergroupid'));
		if (_is_array($_knowledgebaseArticleContainer)) {
			foreach ($_knowledgebaseArticleContainer as $_knowledgebaseArticle) {
				$_searchResultContainer[$_knowledgebaseArticle['kbarticleid']] = $_knowledgebaseArticle;
				$_searchResultContainer[$_knowledgebaseArticle['kbarticleid']]['cssprefix'] = 'kbsearch';
				$_searchResultContainer[$_knowledgebaseArticle['kbarticleid']]['url'] = SWIFT::Get('basename') . $_SWIFT->Template->GetTemplateGroupPrefix() . '/Knowledgebase/Article/View/' . $_knowledgebaseArticle['kbarticleid'] . '/0/' . $_knowledgebaseArticle['seosubject'];
			}
		}

		return $_searchResultContainer;
	}
}
?>