Example #1
0
 /**
  * Register a source with the system.
  * Normal usage is within a Listener or a bootstrap file
  *
  * @param unknown $name
  */
 public static function registerSource(\Search\Models\Source $new_source = null)
 {
     $sources = \Base::instance()->get('dsc.search.sources');
     if (empty($sources) || !is_array($sources)) {
         $sources = array();
     }
     if (empty($new_source)) {
         return $sources;
     }
     if (!array_key_exists($new_source->id, $sources)) {
         // TODO check that the new_source->class exists AND that it has the toSearchItem() function
         $sources[$new_source->id] = $new_source->cast();
     }
     \Base::instance()->set('dsc.search.sources', $sources);
     return $sources;
 }
Example #2
0
 /**
  * Gets paginated results from a source
  */
 protected function filteredSearch()
 {
     $current_source = array('id' => 'invalid', 'title' => '');
     $paginated = null;
     $q = trim($this->input->get('q', null, 'default'));
     try {
         if (!empty($q)) {
             $current_source = \Search\Models\Source::current();
             $paginated = \Search\Models\Source::paginate($current_source, $q);
             \Dsc\Activities::track('Performed Search', array('Search Term' => $q, 'Search Source' => $current_source['title'], 'page_number' => $paginated->current_page, 'app' => 'search'));
         }
     } catch (\Exception $e) {
         \Dsc\System::addMessage($e->getMessage(), 'error');
     }
     $this->app->set('current_source', $current_source);
     $this->app->set('paginated', $paginated);
     $this->app->set('q', $q);
     $this->app->set('meta.title', trim('Search ' . $current_source['title']));
     echo $this->theme->render('Search/Site/Views::search/index.php');
 }
Example #3
0
 protected function filteredSearch()
 {
     $q = $this->input->get('q', null, 'default');
     try {
         $current_source = \Search\Models\Source::current();
         $paginated = \Search\Models\Source::paginate($current_source, $q);
         $count = 0;
         foreach (\Search\Factory::sources() as $key => $source) {
             $count = $count + \Search\Models\Source::count($source, $q);
         }
     } catch (\Exception $e) {
         $this->app->error(404, 'Search Type Not Found');
         return;
     }
     $this->app->set('current_source', $current_source);
     $this->app->set('paginated', $paginated);
     $this->app->set('count', $count);
     $this->app->set('q', $q);
     $this->app->set('meta.title', trim('Search ' . $current_source['title']));
     echo $this->theme->render('Search/Admin/Views::search/index.php');
 }
Example #4
0
                        All
                    </a>
                </li>
                <?php 
foreach (\Search\Factory::sources() as $source) {
    ?>
                <li>
                    <a href="./search?q=<?php 
    echo $q;
    ?>
&filter[search]=<?php 
    echo $source['id'];
    ?>
">
                        <span class="badge pull-right"><?php 
    echo \Search\Models\Source::count($source, $q);
    ?>
</span>
                        <?php 
    echo $source['title'];
    ?>
                    </a>
                </li>
                <?php 
}
?>
            </ul>
        </aside>
        <div class="col-sm-10 col-md-10">

            <div class="row">