mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 14:18:27 +01:00
Added user grid columns
This commit is contained in:
parent
3a1d0dd409
commit
246b6c38ab
44
protected/humhub/modules/user/grid/BaseColumn.php
Normal file
44
protected/humhub/modules/user/grid/BaseColumn.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
54
protected/humhub/modules/user/grid/DisplayNameColumn.php
Normal file
54
protected/humhub/modules/user/grid/DisplayNameColumn.php
Normal 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 = ' <span class="badge">LDAP</span>';
|
||||
}
|
||||
return '<div>' . Html::encode($user->displayName) . $badge . '<br> ' .
|
||||
'<small>' . Html::encode($user->username) . '</small></div>';
|
||||
}
|
||||
|
||||
}
|
39
protected/humhub/modules/user/grid/ImageColumn.php
Normal file
39
protected/humhub/modules/user/grid/ImageColumn.php
Normal 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]);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user