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

  public function indexAction() {

    $this->view->showIconText = $this->_getParam('showIconText', 1);
    $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
    
    if (empty($viewer->getIdentity()))
      return $this->setNoRender();
      
    if (!Engine_Api::_()->core()->hasSubject()) {
      return $this->setNoRender();
    }
    
    // Get subject and check auth
    $this->view->item = $subject = Engine_Api::_()->core()->getSubject('user');
    if (!$subject->authorization()->isAllowed($viewer, 'view')) {
      return $this->setNoRender();
    }
    
    if( !$subject->authorization()->isAllowed($viewer, 'pokeAction') ) {
      return $this->setNoRender();
    }
      
    $this->view->type = $subject->getType();
    $this->view->id = $id = $subject->getIdentity();
      
    $this->view->viewer_level_id = $viewer->level_id;
    $this->view->viewer_id = $viewer_id = $viewer->getIdentity();

    if ($viewer_id == $id)
      return $this->setNoRender();

    $this->view->results = $results = Engine_Api::_()->getDbtable('manageactions', 'poke')->getResults(array('enabled' => 1));
    if (engine_count($results) == 0)
      return $this->setNoRender();
  }
}
