Пример #1
0
 private function findEntry($entry_id)
 {
     $raw = \ForumEntry::getConstraints($entry_id);
     if ($raw === false) {
         $this->notFound();
     }
     $entry = $this->convertEntry($raw);
     $children = \ForumEntry::getEntries($entry_id, \ForumEntry::WITHOUT_CHILDS, '', 'ASC', 0, false);
     if (isset($children['list'][$entry_id])) {
         unset($children['list'][$entry_id]);
     }
     $entry['children'] = array();
     foreach (array_values($children['list']) as $childentry) {
         $entry['children'][] = $this->convertEntry($childentry);
     }
     return $entry;
 }
Пример #2
0
 /**
  ** returns a list of postings for the passed search-term
  *
  * @param string $parent_id the area to search in (can be a whole seminar)
  * @param string $_searchfor the term to search for
  * @param array $options filter-options: search_title, search_content, search_author
  * @return array array('list' => ..., 'count' => ...);
  */
 static function getSearchResults($parent_id, $_searchfor, $options)
 {
     $start = (ForumHelpers::getPage() - 1) * ForumEntry::POSTINGS_PER_PAGE;
     // if there are quoted parts, they should not be separated
     $suchmuster = '/".*"/U';
     preg_match_all($suchmuster, $_searchfor, $treffer);
     array_walk($treffer[0], function (&$value) {
         $value = trim($value, '"');
     });
     // remove the quoted parts from $_searchfor
     $_searchfor = trim(preg_replace($suchmuster, '', $_searchfor));
     // split the searchstring $_searchfor at every space
     $parts = explode(' ', $_searchfor);
     foreach ($parts as $key => $val) {
         if ($val == '') {
             unset($parts[$key]);
         }
     }
     if (!empty($parts)) {
         $_searchfor = array_merge($parts, $treffer[0]);
     } else {
         $_searchfor = $treffer[0];
     }
     // make an SQL-statement out of the searchstring
     $search_string = array();
     foreach ($_searchfor as $key => $val) {
         if (!$val) {
             unset($_searchfor[$key]);
         } else {
             $search_word = '%' . $val . '%';
             $zw_search_string = array();
             if ($options['search_title']) {
                 $zw_search_string[] .= "name LIKE " . DBManager::get()->quote($search_word);
             }
             if ($options['search_content']) {
                 $zw_search_string[] .= "content LIKE " . DBManager::get()->quote($search_word);
             }
             if ($options['search_author']) {
                 $zw_search_string[] .= "author LIKE " . DBManager::get()->quote($search_word);
             }
             if (!empty($zw_search_string)) {
                 $search_string[] = '(' . implode(' OR ', $zw_search_string) . ')';
             }
         }
     }
     if (!empty($search_string)) {
         $add = "AND (" . implode(' AND ', $search_string) . ")";
         return array_merge(array('highlight' => $_searchfor), ForumEntry::getEntries($parent_id, ForumEntry::WITH_CHILDS, $add, 'DESC', $start));
     }
     return array('num_postings' => 0, 'list' => array());
 }