2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Datatables;
|
2016-05-23 18:52:20 +02:00
|
|
|
|
|
|
|
use URL;
|
|
|
|
|
|
|
|
class UserDatatable extends EntityDatatable
|
|
|
|
{
|
|
|
|
public $entityType = ENTITY_USER;
|
|
|
|
|
|
|
|
public function columns()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'first_name',
|
|
|
|
function ($model) {
|
|
|
|
return $model->public_id ? link_to('users/'.$model->public_id.'/edit', $model->first_name.' '.$model->last_name)->toHtml() : ($model->first_name.' '.$model->last_name);
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'email',
|
|
|
|
function ($model) {
|
|
|
|
return $model->email;
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'confirmed',
|
|
|
|
function ($model) {
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! $model->public_id) {
|
2016-05-23 18:52:20 +02:00
|
|
|
return self::getStatusLabel(USER_STATE_OWNER);
|
|
|
|
} elseif ($model->deleted_at) {
|
|
|
|
return self::getStatusLabel(USER_STATE_DISABLED);
|
|
|
|
} elseif ($model->confirmed) {
|
2017-01-30 17:05:31 +01:00
|
|
|
if ($model->is_admin) {
|
2016-05-23 18:52:20 +02:00
|
|
|
return self::getStatusLabel(USER_STATE_ADMIN);
|
|
|
|
} else {
|
|
|
|
return self::getStatusLabel(USER_STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return self::getStatusLabel(USER_STATE_PENDING);
|
|
|
|
}
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actions()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
uctrans('texts.edit_user'),
|
|
|
|
function ($model) {
|
|
|
|
return URL::to("users/{$model->public_id}/edit");
|
|
|
|
},
|
|
|
|
function ($model) {
|
|
|
|
return $model->public_id;
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
uctrans('texts.send_invite'),
|
|
|
|
function ($model) {
|
|
|
|
return URL::to("send_confirmation/{$model->public_id}");
|
|
|
|
},
|
|
|
|
function ($model) {
|
|
|
|
return $model->public_id && ! $model->confirmed;
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
|
|
|
],
|
2016-05-23 18:52:20 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getStatusLabel($state)
|
|
|
|
{
|
|
|
|
$label = trans("texts.{$state}");
|
|
|
|
$class = 'default';
|
|
|
|
switch ($state) {
|
|
|
|
case USER_STATE_PENDING:
|
|
|
|
$class = 'default';
|
|
|
|
break;
|
|
|
|
case USER_STATE_ACTIVE:
|
|
|
|
$class = 'info';
|
|
|
|
break;
|
|
|
|
case USER_STATE_DISABLED:
|
|
|
|
$class = 'warning';
|
|
|
|
break;
|
|
|
|
case USER_STATE_OWNER:
|
|
|
|
$class = 'success';
|
|
|
|
break;
|
|
|
|
case USER_STATE_ADMIN:
|
|
|
|
$class = 'primary';
|
|
|
|
break;
|
|
|
|
}
|
2017-01-30 20:40:43 +01:00
|
|
|
|
2016-05-23 18:52:20 +02:00
|
|
|
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
|
|
|
|
}
|
|
|
|
}
|