addColumn('checkbox', function ($model) {
$can_edit = Auth::user()->hasPermission('edit_all') || (isset($model->user_id) && Auth::user()->id == $model->user_id);
return !$can_edit?'':'';
});
}
foreach ($columns as $column) {
// set visible to true by default
if (count($column) == 2) {
$column[] = true;
}
list($field, $value, $visible) = $column;
if ($visible) {
$table->addColumn($field, $value);
if ($calculateOrderColumns) {
$orderColumns[] = $field;
}
}
}
if ($actions) {
$this->createDropdown($entityType, $table, $actions);
}
return $table->orderColumns($orderColumns)->make();
}
private function createDropdown($entityType, $table, $actions)
{
$table->addColumn('dropdown', function ($model) use ($entityType, $actions) {
$hasAction = false;
$str = '
';
$can_edit = Auth::user()->hasPermission('edit_all') || (isset($model->user_id) && Auth::user()->id == $model->user_id);
if (property_exists($model, 'is_deleted') && $model->is_deleted) {
$str .= '';
} elseif ($model->deleted_at && $model->deleted_at !== '0000-00-00') {
$str .= '';
} else {
$str .= '';
}
$dropdown_contents = '';
$lastIsDivider = false;
if (!$model->deleted_at || $model->deleted_at == '0000-00-00') {
foreach ($actions as $action) {
if (count($action)) {
if (count($action) == 2) {
$action[] = function() {
return true;
};
}
list($value, $url, $visible) = $action;
if ($visible($model)) {
if($value == '--divider--'){
$dropdown_contents .= "";
$lastIsDivider = true;
}
else {
$urlVal = $url($model);
$urlStr = is_string($urlVal) ? $urlVal : $urlVal['url'];
$attributes = '';
if (!empty($urlVal['attributes'])) {
$attributes = ' '.$urlVal['attributes'];
}
$dropdown_contents .= "{$value}";
$hasAction = true;
$lastIsDivider = false;
}
}
} elseif ( ! $lastIsDivider) {
$dropdown_contents .= "";
$lastIsDivider = true;
}
}
if ( ! $hasAction) {
return '';
}
if ( $can_edit && ! $lastIsDivider) {
$dropdown_contents .= "";
}
if (($entityType != ENTITY_USER || $model->public_id) && $can_edit) {
$dropdown_contents .= "public_id})\">"
. trans("texts.archive_{$entityType}") . "";
}
} else if($can_edit) {
if ($entityType != ENTITY_ACCOUNT_GATEWAY || Auth::user()->account->canAddGateway(\App\Models\Gateway::getPaymentType($model->gateway_id))) {
$dropdown_contents .= "public_id})\">"
. trans("texts.restore_{$entityType}") . "";
}
}
if (property_exists($model, 'is_deleted') && !$model->is_deleted && $can_edit) {
$dropdown_contents .= "public_id})\">"
. trans("texts.delete_{$entityType}") . "";
}
if (!empty($dropdown_contents)) {
$str .= '
';
}
return $str.'
';
});
}
}