<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/

class Core_Widget_SearchTabsController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
    $searchApi = Engine_Api::_()->getApi('search', 'core');

    // Prepare form
    $this->view->form = $form = new Core_Form_Search();
    // Set Correct Action for the Search Form
    // $this->view->form->setAction("http://" . $_SERVER['HTTP_HOST'] . _ENGINE_R_BASE . 'search');
    $this->view->url = "http://" . $_SERVER['HTTP_HOST'] . _ENGINE_R_BASE . '/search';
    // Get available types
    $availableTypes = $searchApi->getAvailableTypes();
     $options = array('all'=>$this->view->translate("All"));
    if (is_array($availableTypes) && engine_count($availableTypes) > 0) {
     
      foreach ($availableTypes as $index => $type) {
        $options[$type] = $this->view->translate(strtoupper('ITEM_TYPE_' . $type));
      }
    } else {
     
    }
    //  $form->removeElement('type');

    // Check form validity?
    $values = array();
    if ($form->isValid($_GET)) {
      $values = $form->getValues();
    }
    $this->view->options = $options;
    if(engine_count($options) == 0){
      return $this->setNoRender();
    }
    $this->view->query = $query = (string) @$values['query'];
    $this->view->type = $type = (string)  !empty($values['type']) ? $values['type'] : "all";
    $this->view->page = $page = (int) $this->_getParam('page');
    $form->type->setValue($type);
    if ($query) {
      $this->view->paginator = $searchApi->getPaginator($query, $type);
      $this->view->paginator->setCurrentPageNumber($page);
    }

    $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();

    $require_check = Engine_Api::_()->getApi('settings', 'core')->core_general_portal;
    if (!$require_check) {
      if ($viewer->getIdentity()) {
        $this->view->search_check = true;
      } else {
        $this->view->search_check = false;
      }
    } else
      $this->view->search_check = true;
  }
}
?>