<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
class Event_Widget_BrowseMenuController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
    // Get navigation
    $this->view->navigation = $navigation = Engine_Api::_()
      ->getApi('menus', 'core')
      ->getNavigation('event_main', array());
      
    $p = Zend_Controller_Front::getInstance()->getRequest()->getParams();
    $active = $navigation->findOneBy('active', true);
    if( empty($active) || $active->getRoute() !== 'event_general' ) {
      $filter = !empty($p['filter']) ? $p['filter'] : 'future';
      if( $filter != 'past' && $filter != 'future' ) $filter = 'future';
    
      foreach( $navigation->getPages() as $page ) {
        if( ($page->label == "Upcoming Events" && $filter == "future") || 
            ($page->route == "event_past" && $filter == "past")) {
          $page->active = true;
        }
      }
      
    }
        
    if ( !empty($p['parent_type']) ) {
      $this->view->parent_type = $p['parent_type'];
    }
    
    if( engine_count($this->view->navigation) == 1 ) {
      $this->view->navigation = null;
    }
  }
}
