PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
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
83 lines 1.6 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
11 /** @var SettingsRepository */
12 protected $settingsRepository;
13
14 /** @var DefaultFormFactory */
15 protected $defaultFormFactory;
16
17 /**
18 * @since 2.8.0
19 *
20 * @param SettingsRepository $settingsRepository
21 *
22 */
23 public function __construct(
24 SettingsRepositoryFactory $settingsRepositoryFactory,
25 DefaultFormFactory $defaultFormFactory
26 ) {
27 $this->settingsRepository = $settingsRepositoryFactory->make('give_onboarding');
28 $this->defaultFormFactory = $defaultFormFactory;
29 }
30
31 /**
32 * @since 2.8.0
33 * @return int Form ID
34 *
35 */
36 public function getOrMake()
37 {
38 return $this->getDefaultFormID() ?: $this->makeAndPersist();
39 }
40
41 /**
42 * @since 2.8.0
43 * @return int Form ID
44 *
45 */
46 public function getDefaultFormID()
47 {
48 $formID = $this->settingsRepository->get('form_id');
49
50 return $this->isFormAvailable($formID) ? $formID : 0;
51 }
52
53 /**
54 * @since 2.8.0
55 *
56 * @param int $formID
57 *
58 * @return bool
59 *
60 */
61 protected function isFormAvailable($formID)
62 {
63 $status = get_post_status($formID);
64
65 return ! (false === $status || 'trash' == $status);
66 }
67
68 /**
69 * @since 2.8.0
70 * @return int Form ID
71 *
72 */
73 protected function makeAndPersist()
74 {
75 $formID = $this->defaultFormFactory->make();
76
77 $this->settingsRepository->set('form_id', $formID);
78 $this->settingsRepository->save();
79
80 return $formID;
81 }
82 }
83