<?php
/**
 * baserCMS :  Based Website Development Project <https://basercms.net>
 * Copyright (c) NPO baser foundation <https://baserfoundation.org/>
 *
 * @copyright     Copyright (c) NPO baser foundation
 * @link          https://basercms.net baserCMS Project
 * @since         5.0.0
 * @license       https://basercms.net/license/index.html MIT License
 */

/**
 * ブログ投稿者一覧
 *
 * 呼出箇所：ウィジェット
 *
 * @var \BcBlog\View\BlogFrontAppView $this
 * @var int $blog_content_id ブログコンテンツID
 * @var string $name タイトル
 * @var bool $use_title タイトルを利用するかどうか
 * @checked
 * @noTodo
 * @unitTest
 */
if (empty($view_count)) {
	$view_count = '0';
}
if (isset($blogContent)) {
	$id = $blogContent->id;
} else {
	$id = $blog_content_id;
}
$data = $this->Blog->getViewVarsForBlogAuthorArchivesWidget($id, $view_count);
if(!$data) return;
$authors = $data['authors'];
$blogContent = $data['blogContent'];
$baseCurrentUrl = $this->BcBaser->getBlogContentsUrl($id) . 'archives/author/';
?>


<div class="bs-widget bs-widget-blog-authors bs-widget-blog-authors-<?php echo h($id) ?> bs-blog-widget">
	<?php if ($name && $use_title): ?>
		<h2 class="bs-widget-head"><?php echo h($name) ?></h2>
	<?php endif ?>
	<?php if ($authors): ?>
		<ul class="bs-widget-list">
			<?php foreach ($authors as $author): ?>
				<?php
				$class = ['bs-widget-list__item'];
				if ($this->getRequest()->getPath() === $baseCurrentUrl . $author->id) {
					$class[] = 'current';
				}
				if ($view_count) {
					$title = h($this->BcBaser->getUserName($author)) . ' (' . $author['count'] . ')';
				} else {
					$title = h($this->BcBaser->getUserName($author));
				}
				?>
				<li class="<?php echo implode(' ', $class) ?>">
          <?php $this->BcBaser->link($title, $baseCurrentUrl . $author->id, [
            'escape' => true,
            'class' => 'bs-widget-list__item-title'
          ]) ?>
				</li>
			<?php endforeach; ?>
		</ul>
	<?php endif; ?>
</div>
