Added user grid columns

This commit is contained in:
Lucas Bartholemy 2017-10-28 22:26:12 +02:00
parent 3a1d0dd409
commit 246b6c38ab
3 changed files with 137 additions and 0 deletions

View File

@ -0,0 +1,44 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\user\grid;
use yii\db\ActiveRecord;
use yii\grid\DataColumn;
/**
* BaseColumn for user grid fields
*
* @since 1.3
* @author Luke
*/
abstract class BaseColumn extends DataColumn
{
/**
* @var string|null name of user attribute
*/
public $userAttribute = null;
/**
* Returns the user record
*
* @param ActiveRecord $record
* @return \humhub\modules\user\models\User the user model
*/
public function getUser(ActiveRecord $record)
{
if ($this->userAttribute === null) {
return $record;
}
$attributeName = $this->userAttribute;
return $record->$attributeName;
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\user\grid;
use Yii;
use yii\bootstrap\Html;
/**
* DisplayNameColumn
*
* @author Luke
*/
class DisplayNameColumn extends BaseColumn
{
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->attribute === null) {
$this->attribute = 'profile.lastname';
}
if ($this->label === null) {
$this->label = Yii::t('UserModule.base', 'Name');
}
}
/**
* @inheritdoc
*/
protected function renderDataCellContent($model, $key, $index)
{
$user = $this->getUser($model);
$badge = '';
if ($user->auth_mode == 'ldap') {
$badge = '&nbsp;<span class="badge">LDAP</span>';
}
return '<div>' . Html::encode($user->displayName) . $badge . '<br> ' .
'<small>' . Html::encode($user->username) . '</small></div>';
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\user\grid;
use humhub\modules\user\widgets\Image as UserImage;
/**
* ImageColumn
*
* @since 1.3
* @author Luke
*/
class ImageColumn extends BaseColumn
{
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->options['style'] = 'width:38px';
}
/**
* @inheritdoc
*/
protected function renderDataCellContent($model, $key, $index)
{
return UserImage::widget(['user' => $this->getUser($model), 'width' => 34]);
}
}