Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * Execute the search for the given SearchCommand
  *
  * @param  SearchCommand $search
  * @return SearchResult
  */
 public function fire(SearchCommand $search)
 {
     global $REX;
     $search_result = new SearchResult();
     $searchResults = array();
     $command_parts = $search->getCommandParts();
     // Artikelnamen in der Struktur durchsuchen
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     $fields = array('a.name');
     $where = $search->getSqlWhere($fields);
     if (count($command_parts) == 1 && (int) $command_parts[0] >= 1) {
         $where = 'a.id = "' . (int) $command_parts[0] . '"';
     }
     $sql_query = ' SELECT      a.id,
                                 a.clang,
                                 CONCAT(a.id, "|", a.clang) as bulldog
                     FROM        ' . Watson::getTable('article') . ' AS a
                     WHERE       ' . $where . '
                     GROUP BY    bulldog
                     ';
     $results = $this->getDatabaseResults($sql_query);
     if (count($results)) {
         foreach ($results as $result) {
             $searchResults[$result['bulldog']] = $result;
         }
     }
     // Slices der Artikel durchsuchen
     // Werden Slices gefunden, dann die Strukturartikel überschreiben
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     $fields = array('s.value' => range('1', '20'), 's.file' => range('1', '10'), 's.filelist' => range('1', '10'));
     $searchFields = array();
     foreach ($fields as $field => $numbers) {
         foreach ($numbers as $number) {
             $searchFields[] = $field . $number;
         }
     }
     $fields = $searchFields;
     $sql_query = ' SELECT      s.article_id AS id,
                                 s.clang,
                                 s.ctype,
                                 CONCAT(s.article_id, "|", s.clang) as bulldog
                     FROM        ' . Watson::getTable('article_slice') . ' AS s
                         LEFT JOIN
                                 ' . Watson::getTable('article') . ' AS a
                             ON  (s.article_id = a.id AND s.clang = a.clang)
                     WHERE       ' . $search->getSqlWhere($fields) . '
                     GROUP BY    bulldog';
     $results = $this->getDatabaseResults($sql_query);
     if (count($results)) {
         foreach ($results as $result) {
             $searchResults[$result['bulldog']] = $result;
         }
     }
     // Ergebnisse auf Rechte prüfen und bereitstellen
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     if (count($searchResults)) {
         foreach ($searchResults as $result) {
             $clang = $result['clang'];
             $article = \OOArticle::getArticleById($result['id'], $clang);
             $category_id = $article->getCategoryId();
             // Rechte prüfen
             if (in_array($clang, $REX['USER']->getClangPerm()) && $REX['USER']->hasCategoryPerm($category_id)) {
                 $path = array();
                 $tree = $article->getParentTree();
                 foreach ($tree as $o) {
                     $path[] = $o->getName();
                 }
                 if (!$article->isStartArticle()) {
                     $path[] = $article->getName();
                 }
                 $path = '/' . implode('/', $path);
                 $url = Watson::getUrl(array('page' => 'structure', 'category_id' => $article->getCategoryId(), 'clang' => $clang));
                 if (isset($result['ctype'])) {
                     $url = Watson::getUrl(array('page' => 'content', 'article_id' => $article->getId(), 'mode' => 'edit', 'clang' => $clang, 'ctype' => $result['ctype']));
                 }
                 $suffix = array();
                 if ($REX['USER']->hasPerm('advancedMode[]')) {
                     $suffix[] = $article->getId();
                 }
                 if (count($REX['CLANG']) > 1) {
                     $suffix[] = $REX['CLANG'][$clang];
                 }
                 $suffix = implode(', ', $suffix);
                 $suffix = $suffix != '' ? '(' . $suffix . ')' : '';
                 $entry = new SearchResultEntry();
                 $entry->setValue($article->getName(), $suffix);
                 $entry->setDescription($path);
                 $entry->setIcon('icon_article.png');
                 $entry->setUrl($url);
                 $entry->setQuickLookUrl('../index.php?article_id=' . $article->getId() . '&clang=' . $clang);
                 $search_result->addEntry($entry);
             }
         }
     }
     return $search_result;
 }
Пример #4
0
 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;
     }
 }