PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Onboarding / FormRepository.php
FormRepository.php
71 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Onboarding;
4
5 /**
6 * @since 2.8.0
7 */
8 class FormRepository {
9
10 /** @var SettingsRepository */
11 protected $settingsRepository;
12
13 /** @var DefaultFormFactory */
14 protected $defaultFormFactory;
15
16 /**
17 * @param SettingsRepository $settingsRepository
18 *
19 * @since 2.8.0
20 */
21 public function __construct( SettingsRepositoryFactory $settingsRepositoryFactory, DefaultFormFactory $defaultFormFactory ) {
22 $this->settingsRepository = $settingsRepositoryFactory->make( 'give_onboarding' );
23 $this->defaultFormFactory = $defaultFormFactory;
24 }
25
26 /**
27 * @return int Form ID
28 *
29 * @since 2.8.0
30 */
31 public function getOrMake() {
32 return $this->getDefaultFormID() ?: $this->makeAndPersist();
33 }
34
35 /**
36 * @return int Form ID
37 *
38 * @since 2.8.0
39 */
40 public function getDefaultFormID() {
41 $formID = $this->settingsRepository->get( 'form_id' );
42 return $this->isFormAvailable( $formID ) ? $formID : 0;
43 }
44
45 /**
46 * @param int $formID
47 *
48 * @return bool
49 *
50 * @since 2.8.0
51 */
52 protected function isFormAvailable( $formID ) {
53 $status = get_post_status( $formID );
54 return ! ( false === $status || 'trash' == $status );
55 }
56
57 /**
58 * @return int Form ID
59 *
60 * @since 2.8.0
61 */
62 protected function makeAndPersist() {
63 $formID = $this->defaultFormFactory->make();
64
65 $this->settingsRepository->set( 'form_id', $formID );
66 $this->settingsRepository->save();
67
68 return $formID;
69 }
70 }
71