/**
  * @return Array Map of Snippet IDs
  */
 public function snippetsIncluded()
 {
     $searchEngine = Config::inst()->get('CodeBank', 'snippet_search_engine');
     if ($searchEngine && class_exists($searchEngine) && in_array('ICodeBankSearchEngine', class_implements($searchEngine))) {
         $searchEngine = new $searchEngine();
     } else {
         //Class is missing or invalid so fallback to the default
         $searchEngine = new DefaultCodeBankSearchEngine();
     }
     return $searchEngine->doSnippetSearch($this->params['Term'], $this->params['LanguageID'])->column('ID');
 }
 /**
  * Check the database schema and update it as necessary.
  */
 public function requireTable()
 {
     //Init the search engine
     $searchEngine = Config::inst()->get('CodeBank', 'snippet_search_engine');
     if ($searchEngine && class_exists($searchEngine) && in_array('ICodeBankSearchEngine', class_implements($searchEngine))) {
         $searchEngine::requireTable();
     } else {
         //Class is missing or invalid so fallback to the default
         DefaultCodeBankSearchEngine::requireTable();
     }
     parent::requireTable();
 }
 /**
  * Searches for snippets that match the information the client in the search field
  * @param {stdClass} $data Data passed from ActionScript
  * @return {array} Standard response base
  */
 public function searchSnippets($data)
 {
     $response = CodeBank_ClientAPI::responseBase();
     //Ensure logged in
     if (!Permission::check('CODE_BANK_ACCESS')) {
         $response['status'] = 'EROR';
         $response['message'] = _t('CodeBankAPI.PERMISSION_DENINED', '_Permission Denied');
         return $response;
     }
     $languages = SnippetLanguage::get();
     foreach ($languages as $lang) {
         $searchEngine = Config::inst()->get('CodeBank', 'snippet_search_engine');
         if ($searchEngine && class_exists($searchEngine) && in_array('ICodeBankSearchEngine', class_implements($searchEngine))) {
             $searchEngine = new $searchEngine();
         } else {
             //Class is missing or invalid so fallback to the default
             $searchEngine = new DefaultCodeBankSearchEngine();
         }
         $snippets = $searchEngine->doSnippetSearch($data->query, $lang->ID);
         if ($snippets->Count() > 0) {
             $snippets = $this->arrayUnmap($snippets->filter('FolderID', 0)->map('ID', 'Title')->toArray());
             $response['data'][] = array('id' => $lang->ID, 'language' => $lang->Name, 'folders' => $this->mapFolders($lang->Folders(), $data->query), 'snippets' => $snippets);
         }
     }
     return $response;
 }