Display user initials when tasks are in collapsed mode

This commit is contained in:
Frederic Guillot 2015-07-04 20:12:17 -04:00
parent 0a9ad08e9e
commit c231b65cfc
3 changed files with 40 additions and 0 deletions

View File

@ -10,6 +10,24 @@ namespace Helper;
*/
class User extends \Core\Base
{
/**
* Get initials from a user
*
* @access public
* @param string $name
* @return string
*/
public function getInitials($name)
{
$initials = '';
foreach (explode(' ', $name) as $string) {
$initials .= mb_substr($string, 0, 1);
}
return mb_strtoupper($initials);
}
/**
* Get user id
*

View File

@ -11,6 +11,11 @@
<?= $this->render('board/task_menu', array('task' => $task)) ?>
<div class="task-board-collapsed" style="display: none">
<?php if (! empty($task['assignee_username'])): ?>
<span title="<?= $this->e($task['assignee_name'] ?: $task['assignee_username']) ?>">
<?= $this->e($this->user->getInitials($task['assignee_name'] ?: $task['assignee_username'])) ?>
</span> -
<?php endif ?>
<?= $this->url->link($this->e($task['title']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'task-board-collapsed-title') ?>
</div>

View File

@ -0,0 +1,17 @@
<?php
require_once __DIR__.'/Base.php';
use Helper\User;
class UserHelperTest extends Base
{
public function testInitials()
{
$h = new User($this->container);
$this->assertEquals('CN', $h->getInitials('chuck norris'));
$this->assertEquals('A', $h->getInitials('admin'));
$this->assertEquals('漢', $h->getInitials('漢字'));
}
}