forked from bagisto/bagisto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c88273c
commit d4a643d
Showing
5 changed files
with
337 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Webkul\DataGrid; | ||
|
||
/** | ||
* Initial implementation of the action class. Stay tuned for more features coming soon. | ||
*/ | ||
class Action | ||
{ | ||
/** | ||
* Create a column instance. | ||
*/ | ||
public function __construct( | ||
public string $icon, | ||
public string $title, | ||
public string $method, | ||
public mixed $url, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
|
||
namespace Webkul\DataGrid; | ||
|
||
use Webkul\DataGrid\Enums\ColumnTypeEnum; | ||
|
||
class Column | ||
{ | ||
/** | ||
* Fully qualified database column name. | ||
*/ | ||
public ?string $databaseColumnName; | ||
|
||
/** | ||
* Form input type. | ||
* | ||
* @var string | ||
*/ | ||
public ?string $formInputType = null; | ||
|
||
/** | ||
* Form options. | ||
*/ | ||
public ?array $formOptions = null; | ||
|
||
/** | ||
* Create a column instance. | ||
*/ | ||
public function __construct( | ||
public string $index, | ||
public string $label, | ||
public string $type, | ||
public bool $searchable = false, | ||
public bool $filterable = false, | ||
public bool $sortable = false, | ||
public mixed $closure = null, | ||
) { | ||
$this->setDatabaseColumnName(); | ||
} | ||
|
||
/** | ||
* Define the database column name. Initially, it will match the index. However, after adding an alias, | ||
* the column name may change. | ||
*/ | ||
public function setDatabaseColumnName(?string $databaseColumnName = null): void | ||
{ | ||
$this->databaseColumnName = $databaseColumnName ?: $this->index; | ||
} | ||
|
||
/** | ||
* Set column type. | ||
*/ | ||
public function setColumnType(): void | ||
{ | ||
switch ($this->type) { | ||
case ColumnTypeEnum::DATE_RANGE->value: | ||
$this->formInputType = 'date'; | ||
|
||
$this->formOptions = $this->getDateOptions(); | ||
|
||
break; | ||
|
||
case ColumnTypeEnum::DATE_TIME_RANGE->value: | ||
$this->formInputType = 'datetime-local'; | ||
|
||
$this->formOptions = $this->getDateOptions('Y-m-d H:i:s'); | ||
|
||
break; | ||
} | ||
} | ||
|
||
/** | ||
* Get date options. | ||
*/ | ||
public function getDateOptions(string $format = 'Y-m-d'): array | ||
{ | ||
return [ | ||
[ | ||
'name' => 'today', | ||
'label' => 'Today', | ||
'from' => now()->today()->format($format), | ||
'to' => now()->today()->format($format), | ||
], | ||
[ | ||
'name' => 'yesterday', | ||
'label' => 'Yesterday', | ||
'from' => now()->yesterday()->format($format), | ||
'to' => now()->yesterday()->format($format), | ||
], | ||
[ | ||
'name' => 'this_week', | ||
'label' => 'This Week', | ||
'from' => now()->startOfWeek()->format($format), | ||
'to' => now()->endOfWeek()->format($format), | ||
], | ||
[ | ||
'name' => 'this_month', | ||
'label' => 'This Month', | ||
'from' => now()->startOfMonth()->format($format), | ||
'to' => now()->endOfMonth()->format($format), | ||
], | ||
[ | ||
'name' => 'last_month', | ||
'label' => 'Last Month', | ||
'from' => now()->subMonth(1)->startOfMonth()->format($format), | ||
'to' => now()->subMonth(1)->endOfMonth()->format($format), | ||
], | ||
[ | ||
'name' => 'last_three_months', | ||
'label' => 'Last 3 Months', | ||
'from' => now()->subMonth(3)->startOfMonth()->format($format), | ||
'to' => now()->subMonth(1)->endOfMonth()->format($format), | ||
], | ||
[ | ||
'name' => 'last_six_months', | ||
'label' => 'Last 6 Months', | ||
'from' => now()->subMonth(6)->startOfMonth()->format($format), | ||
'to' => now()->subMonth(1)->endOfMonth()->format($format), | ||
], | ||
[ | ||
'name' => 'this_year', | ||
'label' => 'This Year', | ||
'from' => now()->startOfYear()->format($format), | ||
'to' => now()->endOfYear()->format($format), | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.