<?php 
//namespace modules\mod_jchat_messaging\tmpl
/**
 * @package JCHAT::modules
 * @subpackage mod_jchat_messaging
 * @subpackage tmpl
 * @author Joomla! Extensions Store
 * @copyright (C) 2013 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
 */
defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\String\StringHelper;
?>
<div id="jes_mod_jchatpm">
	<?php 
		// Manage error conditions
		if(is_array($pmData)):
	?>
			<ul class="list-group">
				<li class="list-group-item title">
					<a href="<?php echo Route::_('index.php?option=com_jchat&view=messaging');?>">
					<?php echo Text::sprintf('COM_JCHAT_MODPM_TOTAL_MESSAGES', $totalPmMessages);?>
					</a>
				</li>
				<?php foreach ($pmData as $pmUserMessage):?>
				<li class="list-group-item">
				 	<a href="<?php echo JRoute::_('index.php?option=com_jchat&view=messaging');?>">
					<?php
						$userName = Factory::getContainer()->get(\Joomla\CMS\User\UserFactoryInterface::class)->loadUserById($pmUserMessage['fromuser'])->name;
						$stringName = StringHelper::substr($userName, 0, 22);
						if(StringHelper::strlen($userName > $stringName)) {
							$stringName .= '...';
						}
						echo Text::sprintf('COM_JCHAT_MODPM_USER_MESSAGES', $stringName, $pmUserMessage['newmessages']);
					?>
					</a>
				</li>
				<?php endforeach;?>
			</ul>
	<?php 
		elseif(!is_array($pmData)):
	?>
			<ul class="list-group">
				<li class="list-group-item title">
					<?php echo Text::sprintf('COM_JCHAT_MODPM_ANERROR_OCCURRED', $pmData);?>
				</li>
			</ul>
	<?php
		endif;
	?>
</div>