/** * Execute the search for the given SearchCommand * * @param SearchCommand $search * @return SearchResult */ public function fire(SearchCommand $search) { $search_result = new SearchResult(); $fields = array('name', 'content'); $sql_query = ' SELECT id, name FROM ' . Watson::getTable('template') . ' WHERE ' . $search->getSqlWhere($fields) . ' ORDER BY name LIMIT 20'; $results = $this->getDatabaseResults($sql_query); if (count($results)) { foreach ($results as $result) { $url = Watson::getUrl(array('page' => 'template', 'template_id' => $result['id'], 'function' => 'edit')); $entry = new SearchResultEntry(); $entry->setValue($result['name']); $entry->setDescription(Watson::translate('watson_open_template')); $entry->setIcon('icon_template.png'); $entry->setUrl($url); $entry->setQuickLookUrl($url); $search_result->addEntry($entry); } } return $search_result; }
/** * * @return Documentation */ public function documentation() { $documentation = new Documentation(); $documentation->setDescription(Watson::translate('')); $documentation->setUsage('a keyword'); $documentation->setExample('article content'); $documentation->setExample('a article content'); return $documentation; }
/** * * @return Documentation */ public function documentation() { $documentations = array(); $documentation = new Documentation('t:make'); $documentation->setDescription(Watson::translate('watson_documentation_template_console_make_description')); $documentation->setUsage(Watson::translate('watson_documentation_template_console_make_usage')); $documentation->setExamples(array(Watson::translate('watson_documentation_template_console_make_example_1'), Watson::translate('watson_documentation_template_console_make_example_2'))); $documentations[] = $documentation; $documentation = new Documentation('t:copy'); $documentation->setDescription(Watson::translate('watson_documentation_template_console_copy_description')); $documentation->setUsage(Watson::translate('watson_documentation_template_console_copy_usage')); $documentation->setExamples(array(Watson::translate('watson_documentation_template_console_copy_example_1'), Watson::translate('watson_documentation_template_console_copy_example_2'))); $documentations[] = $documentation; return $documentations; }
/** * Execute the search for the given SearchCommand * * @param SearchCommand $search * @return SearchResult */ public function fire(SearchCommand $search) { $search_result = new SearchResult(); $fields = array('filename', 'title'); $s = \rex_sql::factory(); $s->setQuery('SELECT * FROM ' . Watson::getTable('file') . ' LIMIT 0'); $fieldnames = $s->getFieldnames(); foreach ($fieldnames as $fieldname) { if (substr($fieldname, 0, 4) == 'med_') { $fields[] = $fieldname; } } $sql_query = ' SELECT filename, title FROM ' . Watson::getTable('file') . ' WHERE ' . $search->getSqlWhere($fields) . ' ORDER BY filename'; $results = $this->getDatabaseResults($sql_query); if (count($results)) { foreach ($results as $result) { $title = $result['title'] != '' ? ' (' . Watson::translate('watson_media_title') . ': ' . $result['title'] . ')' : ''; $entry = new SearchResultEntry(); $entry->setValue($result['filename']); $entry->setDescription(Watson::translate('watson_open_media') . $title); $entry->setIcon('icon_media.png'); $entry->setUrl('javascript:newPoolWindow(\'' . Watson::getUrl(array('page' => 'mediapool', 'subpage' => 'detail', 'file_name' => $result['filename'])) . '\')'); $m = \OOMedia::getMediaByFileName($result['filename']); if ($m instanceof \OOMedia) { if ($m->isImage()) { $entry->setQuickLookUrl(Watson::getUrl(array('rex_img_type' => 'rex_mediapool_maximized', 'rex_img_file' => $result['filename']))); } } $search_result->addEntry($entry); } } return $search_result; }
public static function searchRun($params) { global $REX, $I18N; $searchers = $params['searchers']; // registrierte Page Params speichern //watson::saveRegisteredPageParams($searchers); //watson::setPageRequest(); // Phase 2 // User Eingabe parsen in $input $userInput = rex_request('watson_search', 'string'); //\Package\Package::console($userInput); if ($userInput != '') { $searchCommand = new SearchCommand($userInput); // Eingabe auf Keywords überprüfen $saveSearchers = array(); foreach ($searchers as $searcher) { if (in_array($searchCommand->getCommand(), $searcher->commands())) { $saveSearchers[] = $searcher; } } // registriertes Command gefunden if (count($saveSearchers) > 0) { $searchers = $saveSearchers; $searchCommand->deleteCommandFromCommandParts(); } // Eingabe an vorher registrierte Search übergeben und Ergebnisse einsammeln /** @var $searchResults SearchResult */ $searchResults = array(); foreach ($searchers as $searcher) { $searchResults[] = $searcher->fire($searchCommand); } // Ergebnis rendern $renderedResults = array(); foreach ($searchResults as $searchResult) { $renderedResults[] = $searchResult->render($userInput); } $json = array(); foreach ($renderedResults as $values) { foreach ($values as $value) { $json[] = $value; } } if (count($json) == 0) { $json[] = array('value_name' => $I18N->msg('b_no_results'), 'value' => Watson::translate('b_no_results'), 'tokens' => array(Watson::translate('b_no_results'))); } ob_clean(); header('Content-type: application/json'); echo json_encode($json); exit; } }