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

  public function indexAction() {

    $this->view->viewMore = $this->_getParam('viewMore', 1);

    $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
    
    $this->view->viewer_id = $viewer_id = $viewer->getIdentity();
    if (empty($this->view->viewer_id))
      return $this->setNoRender();

    $this->view->viewmore = $this->_getParam('viewmore', 0);
    if ($this->view->viewmore)
      $this->getElement()->removeDecorator('Container');

    if (Engine_Api::_()->core()->hasSubject()) {
      $this->view->item = $subject = Engine_Api::_()->core()->getSubject();
      $this->view->type = $subject->getType();
      $this->view->id = $id = $subject->getIdentity();
    }

    if (isset($_POST['params']))
      $params = json_decode($_POST['params'], true);
    $itemCount = isset($params['itemCount']) ? $params['itemCount'] : $this->_getParam('itemCount', 5);
    $this->view->showType = isset($params['showType']) ? $params['showType'] : $this->_getParam('showType', 0);
    $this->view->identity = isset($params['identity']) ? $params['identity'] : $this->view->identity;
    $this->view->all_params = array('identity' => $this->view->identity, 'showType' => $this->view->showType, 'itemCount' => $itemCount);

    $select = Engine_Api::_()->getDbtable('pokes', 'poke')->getResults(array('viewer_id' => $viewer_id, 'action' => 'backwidget', 'user_id' => @$id));
    $this->view->results = $paginator = Zend_Paginator::factory($select);
    $paginator->setItemCountPerPage($itemCount);
    $paginator->setCurrentPageNumber($this->_getParam('page', 1));
    $this->view->count = $count = $paginator->getTotalItemCount();
    if (empty($count))
      return $this->setNoRender();
  }
}
