Skip to content

Commit

Permalink
add missing operators
Browse files Browse the repository at this point in the history
  • Loading branch information
ariaieboy committed Oct 24, 2024
1 parent 7c9cd8a commit 2de03a0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
9 changes: 9 additions & 0 deletions _ide_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ public function jalaliDateTimeTooltip(?string $format = null, ?string $timezone
return $this;
}
}
}
namespace Filament\Tables\Filters\QueryBuilder\Constraints{
class DateConstraint
{
public function jalali(): self
{
return $this;
}
}
}
20 changes: 20 additions & 0 deletions src/DateConstraint/Operators/IsJalaliYearOperator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Ariaieboy\FilamentJalali\DateConstraint\Operators;

use Ariaieboy\Jalali\Jalali;
use Filament\Tables\Filters\QueryBuilder\Constraints\DateConstraint\Operators\IsYearOperator;

class IsJalaliYearOperator extends IsYearOperator
{
public function apply(\Illuminate\Database\Eloquent\Builder $query, string $qualifiedColumn): \Illuminate\Database\Eloquent\Builder
{
$year = $this->getSettings()['year'];
$start = new Jalali($year,1,1);
$days_of_last_month = $start->getDaysOf(12);
$end = new Jalali($year,12,$days_of_last_month);
if (!$this->isInverse())
return $query->whereBetween($qualifiedColumn, [$start->toCarbon(),$end->toCarbon()]);
return $query->whereNotBetween($qualifiedColumn, [$start->toCarbon(),$end->toCarbon()]);
}
}
10 changes: 9 additions & 1 deletion src/FilamentJalaliServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Ariaieboy\FilamentJalali\DateConstraint\Operators\IsJalaliAfterOperator;
use Ariaieboy\FilamentJalali\DateConstraint\Operators\IsJalaliBeforeOperator;
use Ariaieboy\FilamentJalali\DateConstraint\Operators\IsJalaliDateOperator;
use Ariaieboy\FilamentJalali\DateConstraint\Operators\IsJalaliYearOperator;
use Ariaieboy\Jalali\Jalali;
use Carbon\Carbon;
use Filament\Forms\Components\DatePicker;
Expand All @@ -15,6 +16,7 @@
use Filament\Tables\Columns\Column;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\QueryBuilder\Constraints\DateConstraint;
use Filament\Tables\Filters\QueryBuilder\Constraints\Operators\IsFilledOperator;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand Down Expand Up @@ -106,10 +108,16 @@ public function bootingPackage(): void
return $this->jalaliDateTooltip($format, $timezone);
});
DateConstraint::macro('jalali',function (){
/**
* @var DateConstraint $this
*/
$this->operators([
IsJalaliAfterOperator::class,
IsJalaliBeforeOperator::class,
IsJalaliDateOperator::class
IsJalaliDateOperator::class,
IsJalaliYearOperator::class,
IsFilledOperator::make()
->visible(fn (): bool => $this->isNullable()),
]);
return $this;
});
Expand Down

0 comments on commit 2de03a0

Please sign in to comment.