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

<script type="text/javascript">
  en4.core.runonce.add(function(){

    <?php if( !$this->renderOne ): ?>
    var anchor = scriptJquery('#profile_groups_polls').parent();
    scriptJquery('#profile_groups_polls_previous').css("display",'<?php echo ( $this->paginator->getCurrentPageNumber() == 1 ? 'none' : '' ) ?>');
    scriptJquery('#profile_groups_polls_next').css("display", '<?php echo ( $this->paginator->count() == $this->paginator->getCurrentPageNumber() ? 'none' : '' ) ?>');

    scriptJquery('#profile_groups_polls_previous').off('click').on('click', function(){
      en4.core.request.send(scriptJquery.ajax({
        url : en4.core.baseUrl + 'widget/index/content_id/' + <?php echo sprintf('%d', $this->identity) ?>,
        method : 'post',
        dataType : 'html',
        data : {
          format : 'html',
          subject : en4.core.subject.guid,
          page : <?php echo sprintf('%d', $this->paginator->getCurrentPageNumber() - 1) ?>
        }
      }), {
        'element' : anchor
      })
    });

    scriptJquery('#profile_groups_polls_next').off('click').on('click', function(){
      en4.core.request.send(scriptJquery.ajax({
        url : en4.core.baseUrl + 'widget/index/content_id/' + <?php echo sprintf('%d', $this->identity) ?>,
        method : 'post',
        dataType : 'html',
        data : {
          format : 'html',
          subject : en4.core.subject.guid,
          page : <?php echo sprintf('%d', $this->paginator->getCurrentPageNumber() + 1) ?>
        }
      }), {
        'element' : anchor
      })
    });
    <?php endif; ?>
  });
</script>


<?php if( $this->canAdd ): ?>
  <div class="profile_tab_options">
    <div>
      <?php echo $this->htmlLink(array('route' => 'poll_general', 'controller' => 'poll', 'action' => 'create', 'parent_type'=> 'group', 'subject_id' => $this->subject()->getIdentity()), $this->translate('Add Polls'), array('class' => 'btn btn-alt icon_add')) ?>
    </div>
  </div>
<?php endif; ?>

<?php if( $this->paginator->getTotalItemCount() > 0 ): ?>
  <div class='polls_browse container no-padding'>
    <div class='grid_listing' id="profile_polls">
      <?php foreach ($this->paginator as $poll): ?>
        <div class="grid_listing_item" id="poll-item-<?php echo $poll->poll_id ?>">
          <article>
            <div class='grid_listing_item_thumb'>
              <?php echo $this->htmlLink($poll->getHref(), $this->itemBackgroundPhoto($poll, 'thumb.profile')) ?>
            </div>
            <div class="grid_listing_item_info">
              <h3 class="grid_listing_item_title">
                <?php echo $this->htmlLink($poll->getHref(), $poll->getTitle()) ?>
                <?php if( $poll->closed ): ?>
                  <i class="icon_closed" data-bs-toggle="tooltip" title="<?php echo $this->translate("Closed")?>"></i>
                <?php endif ?>
              </h3>
              <p class='grid_listing_item_owner d-flex flex-wrap gap-1'>
                <span><?php echo $this->translate('Posted');?>
                <?php echo $this->timestamp(strtotime($poll->creation_date)) ?></span>
                <span><?php echo $this->translate('by');?>
                <?php echo $this->htmlLink($poll->getOwner()->getHref(), $poll->getOwner()->getTitle()) ?></span>
              </p>
              <div class="grid_listing_item_owner">
                <span><i class="far fa-hand-point-up"></i><?php echo $this->translate(array('%s vote', '%s votes', $poll->vote_count), $this->locale()->toNumber($poll->vote_count)) ?></span>
                <span><i class="far fa-eye"></i><?php echo $this->translate(array('%s view', '%s views', $poll->view_count), $this->locale()->toNumber($poll->view_count)) ?></span>
              </div> 
            </div>
          </article>
        </div>
      <?php endforeach; ?>
    </div>
    <div class="profile_paginator">
      <div id="profile_groups_polls_previous" class="paginator_previous">
        <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Previous'), array(
          'onclick' => '',
          'class' => 'buttonlink icon_previous'
        )); ?>
      </div>
      <div id="profile_groups_polls_next" class="paginator_next">
        <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Next'), array(
          'onclick' => '',
          'class' => 'buttonlink_right icon_next'
        )); ?>
      </div>
    </div>
 </div>
<?php else: ?>
  <div class="no_result_tip">
    <i><img src="application/modules/Core/externals/images/no-results.png" height="100" width="100" alt="<?php echo $this->translate("No Result")?>"></i>
    <p><?php echo $this->translate('No polls have been added to this group yet.');?></p>
  </div>
<?php endif; ?>
