Beispiel #1
0
 /**
  * Triggers a search event in Big.
  *
  * @param string|null $value a value to search for.
  * @param boolean $dynamicUrls whether to enable dynamic url in the search.
  * @return array list of search results. The array keys are section names
  * and the values are zero indexed arrays of search results.
  */
 public static function search($value = null, $dynamicUrls = false)
 {
     $event = Yii::createObject(['class' => SearchEvent::className(), 'value' => $value]);
     $results = Yii::$app->big->search($event, SearchEvent::EVENT_SEARCH, $dynamicUrls);
     $sections = [];
     foreach ($results as $item) {
         $sections[$item['section']][] = $item;
     }
     return $sections;
 }
Beispiel #2
0
 /**
  * Registers menus when big triggers a search.
  * See [[bigbrush\big\core\Big::search()]] for more information about the search process.
  *
  * @param SearchEvent $event the event being triggered
  */
 public function onSearch($event)
 {
     $depthAttribute = $this->getDatabaseColumnName('depth');
     foreach ($this->getMenus(true) as $root) {
         foreach ($this->getItems($root->id) as $menu) {
             if (!empty($event->value) && strpos($menu->title, $event->value) === false) {
                 continue;
             }
             if ($menu->lft != 1) {
                 $event->addItem(['title' => str_repeat('- ', $menu->{$depthAttribute} - 1) . $menu->title, 'route' => $menu->route, 'text' => '', 'date' => '', 'section' => Yii::t('big', 'Menus')]);
             }
         }
     }
 }