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

    public function indexAction() {
    
        $viewer = Engine_Api::_()->user()->getViewer();
        $levelId = ($viewer->getIdentity() ? $viewer->level_id : Engine_Api::_()->getDbtable('levels', 'authorization')->getPublicLevel()->level_id);
        if(!Engine_Api::_()->authorization()->getPermission($levelId, 'bizlist', 'view'))
          return $this->setNoRender();
          
        $tag = Zend_Controller_Front::getInstance()->getRequest()->getParam('search', null);

        $widgetId = Engine_Api::_()->getDbTable('content', 'core')->widgetId('bizlist.hashtag-search-results', 'core_hashtag_index');

        $this->view->formValues = array_filter(array('search' => $tag, 'tab' => $widgetId));

        $page = 1;
        if(Zend_Controller_Front::getInstance()->getRequest()->getParam('tab') == $widgetId) {
            $page = Zend_Controller_Front::getInstance()->getRequest()->getParam('page', 1);
        }

        $view = $this->view;
        $view->addHelperPath(APPLICATION_PATH . '/application/modules/Fields/View/Helper', 'Fields_View_Helper');

        // Get paginator
        $this->view->paginator = $paginator = Engine_Api::_()->getItemTable('bizlist')->getBizlistsPaginator(array(
            'orderby' => 'creation_date',
            'tag' =>  Engine_Api::_()->getDbTable('tags', 'core')->getTagId($tag),
        ));

        // Set item count per page and current page number
        $paginator->setItemCountPerPage($this->_getParam('itemCountPerPage', 5));
        $paginator->setCurrentPageNumber($page);
    }
}
