Skip to content

Commit

Permalink
Merge branch 'epic/campaigns' into refactor/campaigns-migration-1178
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohnson authored Sep 9, 2024
2 parents fe3f605 + e288b63 commit b8d25a2
Show file tree
Hide file tree
Showing 39 changed files with 1,678 additions and 5 deletions.
41 changes: 41 additions & 0 deletions src/Campaigns/Actions/LoadCampaignDetailsAssets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Give\Campaigns\Actions;

use Give\Campaigns\Models\Campaign;
use Give\Campaigns\ViewModels\CampaignDetailsPage;

/**
* @unreleased
*/
class LoadCampaignDetailsAssets
{
/**
* @unreleased
*/
public function __invoke(Campaign $campaign)
{
$handleName = 'givewp-admin-campaign-details';

wp_register_script(
$handleName,
GIVE_PLUGIN_URL . 'assets/dist/js/give-admin-campaign-details.js',
[],
GIVE_VERSION,
true
);

wp_localize_script($handleName, 'GiveCampaignDetails',
[
'apiRoot' => esc_url_raw(rest_url('give-api/v2/campaigns')),
'apiNonce' => wp_create_nonce('wp_rest'),
'adminUrl' => admin_url(),
'pluginUrl' => GIVE_PLUGIN_URL,
'campaignDetailsPage' => (new CampaignDetailsPage($campaign))->exports(),
]
);

wp_enqueue_script($handleName);
wp_enqueue_style('givewp-design-system-foundation');
}
}
41 changes: 41 additions & 0 deletions src/Campaigns/Actions/LoadCampaignsListTableAssets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Give\Campaigns\Actions;

use Give\Campaigns\ListTable\CampaignsListTable;

/**
* @unreleased
*/
class LoadCampaignsListTableAssets
{
/**
* @unreleased
*/
public function __invoke()
{
$handleName = 'givewp-admin-campaigns-list-table';

wp_register_script(
$handleName,
GIVE_PLUGIN_URL . 'assets/dist/js/give-admin-campaigns-list-table.js',
[],
GIVE_VERSION,
true
);

wp_localize_script($handleName, 'GiveCampaignsListTable',
[
'apiRoot' => esc_url_raw(rest_url('give-api/v2/campaigns/list-table')),
'apiNonce' => wp_create_nonce('wp_rest'),
'table' => give(CampaignsListTable::class)->toArray(),
'adminUrl' => admin_url(),
'paymentMode' => give_is_test_mode(),
'pluginUrl' => GIVE_PLUGIN_URL,
]
);

wp_enqueue_script($handleName);
wp_enqueue_style('givewp-design-system-foundation');
}
}
18 changes: 17 additions & 1 deletion src/Campaigns/CampaignsAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Give\Campaigns;

use Give\Campaigns\Actions\LoadCampaignDetailsAssets;
use Give\Campaigns\Actions\LoadCampaignsListTableAssets;
use Give\Campaigns\Models\Campaign;

/**
* @unreleased
*/
Expand All @@ -28,6 +32,18 @@ public function addCampaignsSubmenuPage()
*/
public function renderCampaignsPage()
{
echo '<div id="give-admin-campaigns-root"><p style="padding: 200px 30px">The campaigns list table will be loaded here...</p></div>';
if (isset($_GET['id'])) {
$campaign = Campaign::find(absint($_GET['id']));

if ( ! $campaign) {
wp_die(__('Campaign not found', 'give'), 404);
}

give(LoadCampaignDetailsAssets::class)($campaign);
} else {
give(LoadCampaignsListTableAssets::class)();
}

echo '<div id="give-admin-campaigns-root"></div>';
}
}
63 changes: 63 additions & 0 deletions src/Campaigns/ListTable/CampaignsListTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Give\Campaigns\ListTable;

use Give\Campaigns\ListTable\Columns\DescriptionColumn;
use Give\Campaigns\ListTable\Columns\EndDateColumn;
use Give\Campaigns\ListTable\Columns\IdColumn;
use Give\Campaigns\ListTable\Columns\StartDateColumn;
use Give\Campaigns\ListTable\Columns\StatusColumn;
use Give\Campaigns\ListTable\Columns\TitleColumn;
use Give\Framework\ListTable\ListTable;
use Give\Framework\ListTable\ModelColumn;

/**
* @unreleased
*/
class CampaignsListTable extends ListTable
{
/**
* @unreleased
*/
public function id(): string
{
return 'campaigns';
}

/**
* @unreleased
*
* @return array|ModelColumn[]
*/
protected function getDefaultColumns(): array
{
// TODO We need to decide which columns should be displayed
return [
new IdColumn(),
new TitleColumn(),
new DescriptionColumn(),
//new DonationsCountColumn(),
new StartDateColumn(),
new EndDateColumn(),
new StatusColumn(),
];
}

/**
* @unreleased
*
* @return array|string[]
*/
protected function getDefaultVisibleColumns(): array
{
return [
IdColumn::getId(),
TitleColumn::getId(),
DescriptionColumn::getId(),
//DonationsCountColumn::getId(),
StartDateColumn::getId(),
EndDateColumn::getId(),
StatusColumn::getId(),
];
}
}
38 changes: 38 additions & 0 deletions src/Campaigns/ListTable/Columns/DescriptionColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Give\Campaigns\ListTable\Columns;

use Give\Campaigns\Models\Campaign;
use Give\Framework\ListTable\ModelColumn;

/**
* @unreleased
*/
class DescriptionColumn extends ModelColumn
{
/**
* @unreleased
*/
public static function getId(): string
{
return 'shortDescription';
}

/**
* @unreleased
*/
public function getLabel(): string
{
return __('Short Description', 'give');
}

/**
* @unreleased
*
* @param Campaign $model
*/
public function getCellValue($model): string
{
return wpautop($model->shortDescription);
}
}
38 changes: 38 additions & 0 deletions src/Campaigns/ListTable/Columns/DonationsCountColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Give\Campaigns\ListTable\Columns;

use Give\Campaigns\Models\Campaign;
use Give\Framework\ListTable\ModelColumn;

/**
* @unreleased
*/
class DonationsCountColumn extends ModelColumn
{
/**
* @unreleased
*/
public static function getId(): string
{
return 'donationsCount';
}

/**
* @unreleased
*/
public function getLabel(): string
{
return __('Donations Count', 'give');
}

/**
* @unreleased
*
* @param Campaign $model
*/
public function getCellValue($model): string
{
return (string)$model->query()->count(); //Temp count
}
}
42 changes: 42 additions & 0 deletions src/Campaigns/ListTable/Columns/EndDateColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Give\Campaigns\ListTable\Columns;

use Give\Campaigns\Models\Campaign;
use Give\Framework\ListTable\ModelColumn;

/**
* @unreleased
*/
class EndDateColumn extends ModelColumn
{
protected $sortColumn = 'endDate';

/**
* @unreleased
*/
public static function getId(): string
{
return 'endDate';
}

/**
* @unreleased
*/
public function getLabel(): string
{
return __('End Date', 'give');
}

/**
* @unreleased
*
* @param Campaign $model
*/
public function getCellValue($model, $locale = ''): string
{
$format = _x('m/d/Y \a\t g:ia', 'date format', 'give');

return $model->endDate->format($format);
}
}
40 changes: 40 additions & 0 deletions src/Campaigns/ListTable/Columns/IdColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Give\Campaigns\ListTable\Columns;

use Give\Campaigns\Models\Campaign;
use Give\Framework\ListTable\ModelColumn;

/**
* @unreleased
*/
class IdColumn extends ModelColumn
{
protected $sortColumn = 'id';

/**
* @unreleased
*/
public static function getId(): string
{
return 'id';
}

/**
* @unreleased
*/
public function getLabel(): string
{
return __('ID', 'give');
}

/**
* @unreleased
*
* @param Campaign $model
*/
public function getCellValue($model): int
{
return $model->id;
}
}
42 changes: 42 additions & 0 deletions src/Campaigns/ListTable/Columns/StartDateColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Give\Campaigns\ListTable\Columns;

use Give\Campaigns\Models\Campaign;
use Give\Framework\ListTable\ModelColumn;

/**
* @unreleased
*/
class StartDateColumn extends ModelColumn
{
protected $sortColumn = 'startDate';

/**
* @unreleased
*/
public static function getId(): string
{
return 'startDate';
}

/**
* @unreleased
*/
public function getLabel(): string
{
return __('Start Date', 'give');
}

/**
* @unreleased
*
* @param Campaign $model
*/
public function getCellValue($model, $locale = ''): string
{
$format = _x('m/d/Y \a\t g:ia', 'date format', 'give');

return $model->startDate->format($format);
}
}
Loading

0 comments on commit b8d25a2

Please sign in to comment.