| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Give\Donors\ListTable\Columns; |
| 6 |
|
| 7 |
use Give\Donors\Models\Donor; |
| 8 |
use Give\Framework\ListTable\ModelColumn; |
| 9 |
use Give\Framework\Support\Facades\DateTime\Temporal; |
| 10 |
use Give\Helpers\Date; |
| 11 |
|
| 12 |
/** |
| 13 |
* @since 2.24.0 |
| 14 |
* |
| 15 |
* @extends ModelColumn<Donor> |
| 16 |
*/ |
| 17 |
class LatestDonationColumn extends ModelColumn |
| 18 |
{ |
| 19 |
|
| 20 |
/** |
| 21 |
* @since 2.24.0 |
| 22 |
* |
| 23 |
* @inheritDoc |
| 24 |
*/ |
| 25 |
public static function getId(): string |
| 26 |
{ |
| 27 |
return 'latestDonation'; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* @since 2.24.0 |
| 32 |
* |
| 33 |
* @inheritDoc |
| 34 |
*/ |
| 35 |
public function getLabel(): string |
| 36 |
{ |
| 37 |
return __('Latest Donation', 'give'); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* @since 4.13.0 updated date format |
| 42 |
* @since 2.24.0 |
| 43 |
* |
| 44 |
* @inheritDoc |
| 45 |
* |
| 46 |
* @param Donor $model |
| 47 |
*/ |
| 48 |
public function getCellValue($model): string |
| 49 |
{ |
| 50 |
$latestDonation = give()->donors->getDonorLatestDonationDate($model->id); |
| 51 |
|
| 52 |
if (!$latestDonation) { |
| 53 |
return '-'; |
| 54 |
} |
| 55 |
|
| 56 |
return Temporal::getFormattedDateTimeUsingTimeZoneAndFormatSettings(Temporal::toDateTime($latestDonation)); |
| 57 |
} |
| 58 |
} |
| 59 |
|