<?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_videos').parent();
      scriptJquery('#profile_groups_videos_previous').css("display", '<?php echo ($this->paginator->getCurrentPageNumber() == 1 ? 'none' : '') ?>');
      scriptJquery('#profile_groups_videos_next').css("display", '<?php echo ($this->paginator->count() == $this->paginator->getCurrentPageNumber() ? 'none' : '') ?>');
      scriptJquery('#profile_groups_videos_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_videos_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' => 'video_general', 'controller' => 'video', 'action' => 'create', 'parent_type' => 'group', 'subject_id' => $this->subject()->getIdentity()), $this->translate('Add Videos'), array('class' => 'btn btn-alt icon_add')) ?>
    </div>
  </div>
<?php endif; ?>

<?php if ($this->paginator->getTotalItemCount() > 0): ?>
  <div class="container no-padding video_listing" id="profile_groups_videos">
    <div class="grid_listing">
      <?php foreach ($this->paginator as $video): ?>
        <div class="grid_listing_item">
          <article>
            <div class="grid_listing_item_thumb">
              <?php if ($video->duration): ?>
                <span class="item_length">
                  <?php
                  if ($video->duration >= 3600) {
                    $duration = gmdate("H:i:s", $video->duration);
                  } else {
                    $duration = gmdate("i:s", $video->duration);
                  }
                  echo $duration;
                  ?>
                </span>
              <?php endif; ?>
              <?php echo $this->htmlLink($video->getHref(), $this->itemBackgroundPhoto($video, 'thumb.profile')) ?>
            </div>
            <div class="grid_listing_item_info">
              <div class="grid_listing_item_title">
                <?php echo $this->htmlLink($video->getHref(), $video->getTitle(), array('area-label' => $video->getTitle())) ?>
              </div>
              <div class="grid_listing_item_owner">
                <span><?php echo $this->translate('By') ?> <?php echo $this->htmlLink($video->getOwner()->getHref(), $video->getOwner()->getTitle()) ?></span>
                <span><?php echo $this->translate(array('%s view', '%s views', $video->view_count), $this->locale()->toNumber($video->view_count)) ?></span>
              </div>
            </div>
          </article>
        </div>
      <?php endforeach; ?>
    </div>
  </div>
  <div class="profile_paginator">
    <div id="profile_groups_videos_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_videos_next" class="paginator_next">
      <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Next'), array(
        'onclick' => '',
        'class' => 'buttonlink_right icon_next'
      )
      ); ?>
    </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 videos have been added to this group yet.');?></p>
  </div>
<?php endif; ?>
