-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'epic/campaigns' into feature/campaigns-forms-relationship
- Loading branch information
Showing
12 changed files
with
569 additions
and
8 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
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,30 @@ | ||
<?php | ||
|
||
namespace Give\Campaigns\Actions; | ||
|
||
use Give\Campaigns\Models\Campaign; | ||
use Give\Campaigns\Models\CampaignPage; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class EditCampaignPageRedirect | ||
{ | ||
/** | ||
* @unreleased | ||
*/ | ||
public function __invoke() | ||
{ | ||
$campaign = Campaign::find( | ||
// @TODO (Maybe) refactor to request object. | ||
isset($_GET['campaign_id']) ? absint($_GET['campaign_id']) : 0 | ||
); | ||
|
||
$page = $campaign->page() ?: CampaignPage::create([ | ||
'campaignId' => $campaign->id, | ||
]); | ||
|
||
wp_safe_redirect($page->getEditLinkUrl(), 303); | ||
exit(); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Give\Campaigns\Actions; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class RegisterCampaignPagePostType | ||
{ | ||
/** | ||
* @unreleased | ||
*/ | ||
public function __invoke() | ||
{ | ||
register_post_type( 'give_campaign_page', [ | ||
'label' => __('Campaign Page', 'give'), | ||
'public' => true, | ||
'show_ui' => true, | ||
'show_in_menu' => false, | ||
'show_in_rest' => true, | ||
'supports' => [ | ||
'editor' | ||
], | ||
'rewrite' => [ | ||
'slug' => 'campaign' | ||
], | ||
'template' => [ | ||
// TODO: Add default blocks template. | ||
], | ||
] ); | ||
} | ||
} |
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
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
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
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,117 @@ | ||
<?php | ||
|
||
namespace Give\Campaigns\Models; | ||
|
||
use DateTime; | ||
use Give\Campaigns\Repositories\CampaignPageRepository; | ||
use Give\Framework\Models\Contracts\ModelCrud; | ||
use Give\Framework\Models\Model; | ||
use Give\Framework\Models\ModelQueryBuilder; | ||
use Give\Framework\Models\ValueObjects\Relationship; | ||
use Give\Framework\Support\Facades\DateTime\Temporal; | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @property int $id | ||
* @property int $campaignId | ||
* @property DateTime $createdAt | ||
* @property DateTime $updatedAt | ||
*/ | ||
class CampaignPage extends Model implements ModelCrud | ||
{ | ||
public $properties = [ | ||
'id' => 'int', | ||
'campaignId' => 'int', | ||
'createdAt' => DateTime::class, | ||
'updatedAt' => DateTime::class, | ||
]; | ||
|
||
public $relationships = [ | ||
'campaign' => Relationship::BELONGS_TO, | ||
]; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function getEditLinkUrl(): string | ||
{ | ||
// By default, the URL is encoded for display purposes. | ||
// Setting any other value prevents encoding the URL. | ||
return get_edit_post_link($this->id, 'redirect'); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function campaign() | ||
{ | ||
return Campaign::find($this->campaignId); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public static function find($id) | ||
{ | ||
return give(CampaignPageRepository::class) | ||
->prepareQuery() | ||
->where('ID', $id) | ||
->get(); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public static function create(array $attributes): CampaignPage | ||
{ | ||
$campaignPage = new static($attributes); | ||
|
||
give(CampaignPageRepository::class)->insert($campaignPage); | ||
|
||
return $campaignPage; | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function save(): void | ||
{ | ||
if (!$this->id) { | ||
give(CampaignPageRepository::class)->insert($this); | ||
} else { | ||
give(CampaignPageRepository::class)->update($this); | ||
} | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function delete(): bool | ||
{ | ||
return give(CampaignPageRepository::class)->delete($this); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @return ModelQueryBuilder<CampaignPage> | ||
*/ | ||
public static function query(): ModelQueryBuilder | ||
{ | ||
return give(CampaignPageRepository::class)->prepareQuery(); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public static function fromQueryBuilderObject($object): CampaignPage | ||
{ | ||
return new CampaignPage([ | ||
'id' => (int) $object->id, | ||
'campaignId' => (int) $object->campaignId, | ||
'createdAt' => Temporal::toDateTime($object->createdAt), | ||
'updatedAt' => Temporal::toDateTime($object->updatedAt), | ||
]); | ||
} | ||
} |
Oops, something went wrong.