PluginProbe
Elementor Website Builder – more than just a page builder / 3.26.0-dev5
Elementor Website Builder – more than just a page builder v3.26.0-dev5
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / checklist / steps / step-base.php

step-base.php in Elementor Website Builder – more than just a page builder 3.26.0-dev5, at modules/checklist/steps/step-base.php

208 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Checklist\Steps;
4
5 use Elementor\Core\Isolation\Wordpress_Adapter;
6 use Elementor\Core\Isolation\Wordpress_Adapter_Interface;
7 use Elementor\Core\Isolation\Elementor_Adapter;
8 use Elementor\Core\Isolation\Elementor_Adapter_Interface;
9 use Elementor\Core\Utils\Isolation_Manager;
10 use Elementor\Modules\Checklist\Module as Checklist_Module;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 abstract class Step_Base {
17 /**
18 * @var string
19 * This is the key to be set to true if the step can be completed, and still be considered completed even if the user later did something to the should have it marked as not completed
20 */
21 const IS_COMPLETION_IMMUTABLE = 'is_completion_immutable';
22 const MARKED_AS_COMPLETED_KEY = 'is_marked_completed';
23 const IMMUTABLE_COMPLETION_KEY = 'is_immutable_completed';
24 const ABSOLUTE_COMPLETION_KEY = 'is_absolute_completed';
25
26 private array $user_progress;
27 protected Wordpress_Adapter_Interface $wordpress_adapter;
28 protected Elementor_Adapter_Interface $elementor_adapter;
29 protected ?array $promotion_data;
30 protected Checklist_Module $module;
31
32 /**
33 * Returns a steps current completion status
34 *
35 * @return bool
36 */
37 abstract protected function is_absolute_completed() : bool;
38
39 /**
40 * @return string
41 */
42 abstract public function get_id() : string;
43
44 /**
45 * @return string
46 */
47 abstract public function get_title() : string;
48
49 /**
50 * @return string
51 */
52 abstract public function get_description() : string;
53
54 /**
55 * For instance; 'Create 3 pages'
56 * @return string
57 */
58 abstract public function get_cta_text() : string;
59
60 /**
61 * @return string
62 */
63 abstract public function get_cta_url() : string;
64
65 /**
66 * @return bool
67 */
68 abstract public function get_is_completion_immutable() : bool;
69
70 /**
71 * @return string
72 */
73 abstract public function get_image_src() : string;
74
75 /**
76 * Step_Base constructor.
77 *
78 * @param Checklist_Module $module
79 * @param ?Wordpress_Adapter_Interface $wordpress_adapter
80 * @param ?Elementor_Adapter_Interface $elementor_adapter
81 * @return void
82 */
83 public function __construct( Checklist_Module $module, ?Wordpress_Adapter_Interface $wordpress_adapter = null, ?Elementor_Adapter_Interface $elementor_adapter = null, $promotion_data = null ) {
84 $this->module = $module;
85 $this->wordpress_adapter = $wordpress_adapter ?? Isolation_Manager::get_adapter( Wordpress_Adapter::class );
86 $this->elementor_adapter = $elementor_adapter ?? Isolation_Manager::get_adapter( Elementor_Adapter::class );
87 $this->promotion_data = $promotion_data;
88 $this->user_progress = $module->get_step_progress( $this->get_id() ) ?? $this->get_step_initial_progress();
89 }
90
91 /**
92 * Returns step visibility (by-default step is visible)
93 *
94 * @return bool
95 */
96 public function is_visible() : bool {
97 return true;
98 }
99
100 public function get_learn_more_text() : string {
101 return esc_html__( 'Learn more', 'elementor' );
102 }
103
104 public function get_learn_more_url() : string {
105 return 'https://go.elementor.com/getting-started-with-elementor/';
106 }
107
108 public function update_step( array $step_data ) : void {
109 $allowed_properties = [
110 self::MARKED_AS_COMPLETED_KEY => $step_data[ self::MARKED_AS_COMPLETED_KEY ] ?? null,
111 self::IMMUTABLE_COMPLETION_KEY => $step_data[ self::IMMUTABLE_COMPLETION_KEY ] ?? null,
112 self::ABSOLUTE_COMPLETION_KEY => $step_data[ self::ABSOLUTE_COMPLETION_KEY ] ?? null,
113 ];
114
115 foreach ( $allowed_properties as $key => $value ) {
116 if ( null !== $value ) {
117 $this->user_progress[ $key ] = $value;
118 }
119 }
120
121 $this->set_step_progress();
122 }
123
124 /**
125 * Marking a step as completed based on user's desire
126 *
127 * @return void
128 */
129 public function mark_as_completed() : void {
130 $this->update_step( [ self::MARKED_AS_COMPLETED_KEY => true ] );
131 }
132
133 /**
134 * Unmarking a step as completed based on user's desire
135 *
136 * @return void
137 */
138 public function unmark_as_completed() : void {
139 $this->update_step( [ self::MARKED_AS_COMPLETED_KEY => false ] );
140 }
141
142 /**
143 * Marking a step as completed if it was completed once, and it's suffice to marketing's requirements
144 *
145 * @return void
146 */
147 public function maybe_immutably_mark_as_completed() : void {
148 $is_immutable_completed = $this->user_progress[ self::IMMUTABLE_COMPLETION_KEY ] ?? false;
149
150 if ( ! $is_immutable_completed && $this->get_is_completion_immutable() && $this->is_absolute_completed() ) {
151 $this->update_step( [
152 self::MARKED_AS_COMPLETED_KEY => false,
153 self::IMMUTABLE_COMPLETION_KEY => true,
154 ] );
155 }
156 }
157
158 /**
159 * Returns the step marked as completed value
160 *
161 * @return bool
162 */
163 public function is_marked_as_completed() : bool {
164 return $this->user_progress[ self::MARKED_AS_COMPLETED_KEY ];
165 }
166
167 /**
168 * Returns the step completed value
169 *
170 * @return bool
171 */
172 public function is_immutable_completed() : bool {
173 return $this->get_is_completion_immutable() && $this->user_progress[ self::IMMUTABLE_COMPLETION_KEY ] ?? false;
174 }
175
176 /**
177 * Sets and returns the initial progress of the step
178 *
179 * @return array
180 */
181 public function get_step_initial_progress() : array {
182 $initial_progress = [
183 self::MARKED_AS_COMPLETED_KEY => false,
184 self::IMMUTABLE_COMPLETION_KEY => false,
185 ];
186
187 $this->module->set_step_progress( $this->get_id(), $initial_progress );
188
189 return $initial_progress;
190 }
191
192 /**
193 * @return ?array
194 */
195 public function get_promotion_data() : ?array {
196 return $this->promotion_data;
197 }
198
199 /**
200 * Sets the step progress
201 *
202 * @return void
203 */
204 private function set_step_progress() : void {
205 $this->module->set_step_progress( $this->get_id(), $this->user_progress );
206 }
207 }
208