DateCreatedColumn.php
3 years ago
DonationCountColumn.php
1 year ago
DonationRevenueColumn.php
3 years ago
GoalColumn.php
1 year ago
IdColumn.php
3 years ago
LevelsColumn.php
3 years ago
ShortcodeColumn.php
3 years ago
StatusColumn.php
3 years ago
TitleColumn.php
2 years ago
DonationCountColumn.php
72 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Give\DonationForms\V2\ListTable\Columns; |
| 6 | |
| 7 | use Give\DonationForms\V2\Models\DonationForm; |
| 8 | use Give\Framework\ListTable\ModelColumn; |
| 9 | use Give\MultiFormGoals\ProgressBar\Model as ProgressBarModel; |
| 10 | |
| 11 | /** |
| 12 | * @since 2.24.0 |
| 13 | * |
| 14 | * @extends ModelColumn<DonationForm> |
| 15 | */ |
| 16 | class DonationCountColumn extends ModelColumn |
| 17 | { |
| 18 | |
| 19 | protected $sortColumn = 'CAST(formSales AS UNSIGNED)'; |
| 20 | |
| 21 | /** |
| 22 | * @since 2.24.0 |
| 23 | * |
| 24 | * @inheritDoc |
| 25 | */ |
| 26 | public static function getId(): string |
| 27 | { |
| 28 | return 'donationCount'; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @since 2.24.0 |
| 33 | * |
| 34 | * @inheritDoc |
| 35 | */ |
| 36 | public function getLabel(): string |
| 37 | { |
| 38 | return __('Donations', 'give'); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @since 3.14.0 Use the 'getDonationCount()" method from progress bar model to ensure the correct donation count will be used |
| 43 | * @since 2.24.0 |
| 44 | * |
| 45 | * @inheritDoc |
| 46 | * |
| 47 | * @param DonationForm $model |
| 48 | */ |
| 49 | public function getCellValue($model): string |
| 50 | { |
| 51 | $totalDonations = (new ProgressBarModel(['ids' => [$model->id]]))->getDonationCount(); |
| 52 | |
| 53 | $label = $totalDonations > 0 |
| 54 | ? sprintf( |
| 55 | _n( |
| 56 | '%1$s donation', |
| 57 | '%1$s donations', |
| 58 | $totalDonations, |
| 59 | 'give' |
| 60 | ), |
| 61 | $totalDonations |
| 62 | ) : __('No donations', 'give'); |
| 63 | |
| 64 | return sprintf( |
| 65 | '<a href="%s" aria-label="%s">%s</a>', |
| 66 | admin_url("edit.php?post_type=give_forms&page=give-payment-history&form_id=$model->id"), |
| 67 | __('Visit donations page', 'give'), |
| 68 | $label |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 |