| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Campaigns\Actions; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
use Give\Campaigns\Models\Campaign; |
| 7 |
use Give\Campaigns\Repositories\CampaignRepository; |
| 8 |
use Give\DonationForms\FormDesigns\MultiStepFormDesign\MultiStepFormDesign; |
| 9 |
use Give\DonationForms\Models\DonationForm; |
| 10 |
use Give\DonationForms\Properties\FormSettings; |
| 11 |
use Give\DonationForms\ValueObjects\DonationFormStatus; |
| 12 |
use Give\DonationForms\ValueObjects\GoalSource; |
| 13 |
use Give\FormBuilder\Actions\GenerateDefaultDonationFormBlockCollection; |
| 14 |
|
| 15 |
/** |
| 16 |
* @since 4.0.0 |
| 17 |
*/ |
| 18 |
class CreateDefaultCampaignForm |
| 19 |
{ |
| 20 |
/** |
| 21 |
* @since 4.16.8 Set formStatus on FormSettings so it agrees with the form's own status. |
| 22 |
* @since 4.14.2 add formTitle to FormSettings |
| 23 |
* @since 4.2.0 return if campaign already has default form set |
| 24 |
* @since 4.1.0 Added inheritCampaignColors property to FormSettings |
| 25 |
* @since 4.0.0 |
| 26 |
* |
| 27 |
* @throws Exception |
| 28 |
*/ |
| 29 |
public function __invoke(Campaign $campaign) |
| 30 |
{ |
| 31 |
if ($campaign->defaultFormId) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$defaultCampaignForm = DonationForm::create([ |
| 36 |
'title' => $campaign->title, |
| 37 |
'status' => DonationFormStatus::PUBLISHED(), |
| 38 |
'settings' => FormSettings::fromArray([ |
| 39 |
'formTitle' => $campaign->title, |
| 40 |
'formStatus' => DonationFormStatus::PUBLISHED, |
| 41 |
'showHeader' => false, |
| 42 |
'enableDonationGoal' => false, |
| 43 |
'goalAmount' => $campaign->goal, |
| 44 |
'goalType' => $campaign->goalType->getValue(), |
| 45 |
'goalSource' => GoalSource::CAMPAIGN()->getValue(), |
| 46 |
'designId' => MultiStepFormDesign::id(), |
| 47 |
'inheritCampaignColors' => true, |
| 48 |
]), |
| 49 |
'blocks' => (new GenerateDefaultDonationFormBlockCollection())(), |
| 50 |
]); |
| 51 |
|
| 52 |
give(CampaignRepository::class)->addCampaignForm($campaign, $defaultCampaignForm->id, true); |
| 53 |
} |
| 54 |
} |
| 55 |
|