| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\FeatureFlags\OptionBasedFormEditor; |
| 4 |
|
| 5 |
use Give\DonationForms\V2\Repositories\DonationFormsRepository; |
| 6 |
use Give\FeatureFlags\FeatureFlags; |
| 7 |
use Give\Framework\Database\DB; |
| 8 |
use Give\Framework\QueryBuilder\QueryBuilder; |
| 9 |
|
| 10 |
/** |
| 11 |
* @since 3.18.0 |
| 12 |
*/ |
| 13 |
class OptionBasedFormEditor implements FeatureFlags |
| 14 |
{ |
| 15 |
/** |
| 16 |
* @since 3.18.0 |
| 17 |
*/ |
| 18 |
public static function isEnabled(): bool |
| 19 |
{ |
| 20 |
$option = give_get_option('option_based_form_editor', ''); |
| 21 |
|
| 22 |
if (empty($option)) { |
| 23 |
$option = self::existOptionBasedFormsOnDb(); |
| 24 |
give_update_option('option_based_form_editor', $option ? 'enabled' : 'disabled'); |
| 25 |
|
| 26 |
return $option; |
| 27 |
} |
| 28 |
|
| 29 |
return give_is_setting_enabled($option); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @since 3.18.0 |
| 34 |
*/ |
| 35 |
public static function helperText(): string |
| 36 |
{ |
| 37 |
|
| 38 |
return sprintf( |
| 39 |
'<div class="give-settings-section-group-helper"> |
| 40 |
<img src="%1$s" /> |
| 41 |
<div class="give-settings-section-group-helper__popout"> |
| 42 |
<img src="%2$s" /> |
| 43 |
<h5>%3$s</h5> |
| 44 |
<p>%4$s</p> |
| 45 |
</div> |
| 46 |
</div>', |
| 47 |
esc_url(GIVE_PLUGIN_URL . 'build/assets/dist/images/admin/help-circle.svg'), |
| 48 |
esc_url(GIVE_PLUGIN_URL . 'build/assets/dist/images/admin/give-settings-gateways-v2.jpg'), |
| 49 |
__('Only for Option-Based Form Editor', 'give'), |
| 50 |
__('Uses the traditional settings options for creating and customizing a donation form.', |
| 51 |
'give') |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @since 3.18.0 |
| 57 |
*/ |
| 58 |
public static function existOptionBasedFormsOnDb(): bool |
| 59 |
{ |
| 60 |
return (bool)give(DonationFormsRepository::class)->prepareQuery() |
| 61 |
->whereNotExists(function ( |
| 62 |
QueryBuilder $builder |
| 63 |
) { |
| 64 |
$builder |
| 65 |
->select(['meta_value', 'formBuilderSettings']) |
| 66 |
->from(DB::raw(DB::prefix('give_formmeta'))) |
| 67 |
->where('meta_key', 'formBuilderSettings') |
| 68 |
->whereRaw('AND form_id = ID'); |
| 69 |
})->count(); |
| 70 |
} |
| 71 |
} |
| 72 |
|