1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Ninja/Datatables/EntityDatatable.php

94 lines
2.0 KiB
PHP
Raw Normal View History

2016-07-21 14:35:23 +02:00
<?php namespace App\Ninja\Datatables;
2016-05-23 18:52:20 +02:00
class EntityDatatable
{
public $entityType;
public $isBulkEdit;
public $hideClient;
2016-11-24 10:41:11 +01:00
public $sortCol = 1;
2016-05-23 18:52:20 +02:00
public function __construct($isBulkEdit = true, $hideClient = false, $entityType = false)
2016-05-23 18:52:20 +02:00
{
$this->isBulkEdit = $isBulkEdit;
$this->hideClient = $hideClient;
if ($entityType) {
$this->entityType = $entityType;
}
2016-05-23 18:52:20 +02:00
}
public function columns()
{
return [];
}
public function actions()
{
return [];
}
2016-12-14 20:47:22 +01:00
public function bulkActions()
{
return [
[
'label' => mtrans($this->entityType, 'archive_'.$this->entityType),
'url' => 'javascript:submitForm_'.$this->entityType.'("archive")',
],
[
'label' => mtrans($this->entityType, 'delete_'.$this->entityType),
'url' => 'javascript:submitForm_'.$this->entityType.'("delete")',
]
];
}
public function columnFields()
{
$data = [];
$columns = $this->columns();
if ($this->isBulkEdit) {
$data[] = 'checkbox';
}
foreach ($columns as $column) {
if (count($column) == 3) {
// third column is optionally used to determine visibility
if (!$column[2]) {
continue;
}
}
$data[] = $column[0];
}
$data[] = '';
return $data;
}
public function rightAlignIndices()
{
return $this->alignIndices(['amount', 'balance', 'cost']);
}
public function centerAlignIndices()
{
return $this->alignIndices(['status']);
}
public function alignIndices($fields)
{
$columns = $this->columnFields();
$indices = [];
foreach ($columns as $index => $column) {
if (in_array($column, $fields)) {
$indices[] = $index + 1;
}
}
return $indices;
}
2016-05-23 18:52:20 +02:00
}