@@ -20,55 +20,55 @@ |
||
20 | 20 | class EditorBlockCollection extends Collection |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Collection constructor |
|
25 | - * |
|
26 | - * @throws InvalidInterfaceException |
|
27 | - */ |
|
28 | - public function __construct() |
|
29 | - { |
|
30 | - parent::__construct('EventEspresso\core\domain\entities\editor\EditorBlockInterface'); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Collection constructor |
|
25 | + * |
|
26 | + * @throws InvalidInterfaceException |
|
27 | + */ |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + parent::__construct('EventEspresso\core\domain\entities\editor\EditorBlockInterface'); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * unRegisterBlock |
|
36 | - * finds block in the Collection based on the identifier that was set using addObject() |
|
37 | - * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found. |
|
38 | - * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
39 | - * |
|
40 | - * @param mixed $identifier |
|
41 | - * @return boolean |
|
42 | - */ |
|
43 | - public function unRegisterBlock($identifier) |
|
44 | - { |
|
45 | - $this->rewind(); |
|
46 | - while ($this->valid()) { |
|
47 | - if ($identifier === $this->getInfo()) { |
|
48 | - $object = $this->current(); |
|
49 | - $this->rewind(); |
|
50 | - return $object->unRegisterBlock(); |
|
51 | - } |
|
52 | - $this->next(); |
|
53 | - } |
|
54 | - return false; |
|
55 | - } |
|
34 | + /** |
|
35 | + * unRegisterBlock |
|
36 | + * finds block in the Collection based on the identifier that was set using addObject() |
|
37 | + * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found. |
|
38 | + * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
39 | + * |
|
40 | + * @param mixed $identifier |
|
41 | + * @return boolean |
|
42 | + */ |
|
43 | + public function unRegisterBlock($identifier) |
|
44 | + { |
|
45 | + $this->rewind(); |
|
46 | + while ($this->valid()) { |
|
47 | + if ($identifier === $this->getInfo()) { |
|
48 | + $object = $this->current(); |
|
49 | + $this->rewind(); |
|
50 | + return $object->unRegisterBlock(); |
|
51 | + } |
|
52 | + $this->next(); |
|
53 | + } |
|
54 | + return false; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * unRegisterAllBlocks |
|
60 | - * calls unRegisterBlock() on all blocks in Collection. |
|
61 | - * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function unRegisterAllBlocks() |
|
66 | - { |
|
67 | - $this->rewind(); |
|
68 | - while ($this->valid()) { |
|
69 | - $this->current()->unRegisterBlock(); |
|
70 | - $this->next(); |
|
71 | - } |
|
72 | - $this->rewind(); |
|
73 | - } |
|
58 | + /** |
|
59 | + * unRegisterAllBlocks |
|
60 | + * calls unRegisterBlock() on all blocks in Collection. |
|
61 | + * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function unRegisterAllBlocks() |
|
66 | + { |
|
67 | + $this->rewind(); |
|
68 | + while ($this->valid()) { |
|
69 | + $this->current()->unRegisterBlock(); |
|
70 | + $this->next(); |
|
71 | + } |
|
72 | + $this->rewind(); |
|
73 | + } |
|
74 | 74 | } |
@@ -25,72 +25,72 @@ |
||
25 | 25 | interface EditorBlockInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Perform any early setup required by the block |
|
30 | - * including setting the block type and supported post types |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function initialize(); |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function editorBlockType(); |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Registers the Editor Block with WP core; |
|
45 | - * Returns the registered block type on success, or false on failure. |
|
46 | - * |
|
47 | - * @return WP_Block_Type|false |
|
48 | - */ |
|
49 | - public function registerBlock(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Un-registers the Editor Block with WP core; |
|
54 | - * Returns the registered block type on success, or false on failure. |
|
55 | - * |
|
56 | - * @return WP_Block_Type|false |
|
57 | - */ |
|
58 | - public function unRegisterBlock(); |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * returns true if the block type applies for the supplied post type |
|
63 | - * and should be added to that post type's editor |
|
64 | - * |
|
65 | - * @param string $post_type |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public function appliesToPostType($post_type); |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function getEditorContainer(); |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - public function registerScripts(); |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function registerStyles(); |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * returns the rendered HTML for the block |
|
91 | - * |
|
92 | - * @param array $attributes |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function renderBlock(array $attributes = array()); |
|
28 | + /** |
|
29 | + * Perform any early setup required by the block |
|
30 | + * including setting the block type and supported post types |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function initialize(); |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function editorBlockType(); |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Registers the Editor Block with WP core; |
|
45 | + * Returns the registered block type on success, or false on failure. |
|
46 | + * |
|
47 | + * @return WP_Block_Type|false |
|
48 | + */ |
|
49 | + public function registerBlock(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Un-registers the Editor Block with WP core; |
|
54 | + * Returns the registered block type on success, or false on failure. |
|
55 | + * |
|
56 | + * @return WP_Block_Type|false |
|
57 | + */ |
|
58 | + public function unRegisterBlock(); |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * returns true if the block type applies for the supplied post type |
|
63 | + * and should be added to that post type's editor |
|
64 | + * |
|
65 | + * @param string $post_type |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public function appliesToPostType($post_type); |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function getEditorContainer(); |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + public function registerScripts(); |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function registerStyles(); |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * returns the rendered HTML for the block |
|
91 | + * |
|
92 | + * @param array $attributes |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function renderBlock(array $attributes = array()); |
|
96 | 96 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | foreach ($this->blocks as $block) { |
144 | 144 | // perform any setup required for the block |
145 | 145 | $block_type = $block->registerBlock(); |
146 | - if (! $block_type instanceof WP_Block_Type) { |
|
146 | + if ( ! $block_type instanceof WP_Block_Type) { |
|
147 | 147 | throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
148 | 148 | } |
149 | 149 | add_action('enqueue_block_assets', array($block, 'registerStyles')); |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | $this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS), |
179 | 179 | array( |
180 | 180 | 'eejs-core', |
181 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
182 | - 'wp-i18n', // Provides localization functions |
|
183 | - 'wp-element', // Provides React.Component |
|
181 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
182 | + 'wp-i18n', // Provides localization functions |
|
183 | + 'wp-element', // Provides React.Component |
|
184 | 184 | 'wp-components' // Provides many prebuilt components and controls |
185 | 185 | ), |
186 | 186 | null, |
@@ -34,153 +34,153 @@ |
||
34 | 34 | class EditorBlockRegistrationManager extends EditorBlockManager |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * Returns the name of a hookpoint to be used to call initialize() |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function initHook() |
|
43 | - { |
|
44 | - return 'AHEE__EE_System__set_hooks_for_core'; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Perform any early setup required for block editors to functions |
|
50 | - * |
|
51 | - * @return void |
|
52 | - * @throws Exception |
|
53 | - */ |
|
54 | - public function initialize() |
|
55 | - { |
|
56 | - $this->loadEditorBlocks(); |
|
57 | - add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks')); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @return CollectionInterface|EditorBlockInterface[] |
|
63 | - * @throws ReflectionException |
|
64 | - * @throws InvalidArgumentException |
|
65 | - * @throws EE_Error |
|
66 | - * @throws InvalidClassException |
|
67 | - * @throws InvalidDataTypeException |
|
68 | - * @throws InvalidEntityException |
|
69 | - * @throws InvalidFilePathException |
|
70 | - * @throws InvalidIdentifierException |
|
71 | - * @throws InvalidInterfaceException |
|
72 | - */ |
|
73 | - protected function populateEditorBlockCollection() |
|
74 | - { |
|
75 | - $loader = new CollectionLoader( |
|
76 | - new CollectionDetails( |
|
77 | - // collection name |
|
78 | - 'shortcodes', |
|
79 | - // collection interface |
|
80 | - 'EventEspresso\core\domain\entities\editor\EditorBlockInterface', |
|
81 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
82 | - apply_filters( |
|
83 | - 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs', |
|
84 | - array() |
|
85 | - // array( |
|
86 | - // 'EventEspresso\core\domain\entities\editor\blocks\common', |
|
87 | - // 'EventEspresso\core\domain\entities\editor\blocks\editor', |
|
88 | - // 'EventEspresso\core\domain\entities\editor\blocks\shortcodes', |
|
89 | - // 'EventEspresso\core\domain\entities\editor\blocks\widgets', |
|
90 | - // ) |
|
91 | - ), |
|
92 | - // filepaths to classes to add |
|
93 | - array(), |
|
94 | - // file mask to use if parsing folder for files to add |
|
95 | - '', |
|
96 | - // what to use as identifier for collection entities |
|
97 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
98 | - CollectionDetails::ID_CLASS_NAME |
|
99 | - ), |
|
100 | - $this->blocks |
|
101 | - ); |
|
102 | - return $loader->getCollection(); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * populates the EditorBlockCollection and calls initialize() on all installed blocks |
|
108 | - * |
|
109 | - * @return void |
|
110 | - * @throws Exception |
|
111 | - */ |
|
112 | - public function loadEditorBlocks() |
|
113 | - { |
|
114 | - try { |
|
115 | - $this->populateEditorBlockCollection(); |
|
116 | - // cycle thru block loaders and initialize each loader |
|
117 | - foreach ($this->blocks as $block) { |
|
118 | - $block->initialize(); |
|
119 | - } |
|
120 | - } catch (Exception $exception) { |
|
121 | - new ExceptionStackTraceDisplay($exception); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * calls registerBlock() and load assets for all installed blocks |
|
128 | - * |
|
129 | - * @return void |
|
130 | - * @throws Exception |
|
131 | - */ |
|
132 | - public function registerEditorBlocks() |
|
133 | - { |
|
134 | - try { |
|
135 | - // register primary assets |
|
136 | - add_action('enqueue_block_assets', array($this, 'registerStyles')); |
|
137 | - add_action('enqueue_block_assets', array($this, 'registerScripts')); |
|
138 | - // cycle thru block loader folders |
|
139 | - foreach ($this->blocks as $block) { |
|
140 | - // perform any setup required for the block |
|
141 | - $block_type = $block->registerBlock(); |
|
142 | - if (! $block_type instanceof WP_Block_Type) { |
|
143 | - throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
144 | - } |
|
145 | - add_action('enqueue_block_assets', array($block, 'registerStyles')); |
|
146 | - add_action('enqueue_block_assets', array($block, 'registerScripts')); |
|
147 | - do_action( |
|
148 | - 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered', |
|
149 | - $block, |
|
150 | - $block_type |
|
151 | - ); |
|
152 | - } |
|
153 | - } catch (Exception $exception) { |
|
154 | - new ExceptionStackTraceDisplay($exception); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - public function registerStyles() |
|
160 | - { |
|
161 | - // wp_register_style( |
|
162 | - // 'ee-block-styles', |
|
163 | - // $this->domain->distributionAssetsUrl() . 'style.css', |
|
164 | - // array(), |
|
165 | - // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
166 | - // ); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - public function registerScripts() |
|
171 | - { |
|
172 | - wp_register_script( |
|
173 | - 'ee-core-blocks', |
|
174 | - $this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS), |
|
175 | - array( |
|
176 | - 'eejs-core', |
|
177 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
178 | - 'wp-i18n', // Provides localization functions |
|
179 | - 'wp-element', // Provides React.Component |
|
180 | - 'wp-components' // Provides many prebuilt components and controls |
|
181 | - ), |
|
182 | - null, |
|
183 | - true |
|
184 | - ); |
|
185 | - } |
|
37 | + /** |
|
38 | + * Returns the name of a hookpoint to be used to call initialize() |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function initHook() |
|
43 | + { |
|
44 | + return 'AHEE__EE_System__set_hooks_for_core'; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Perform any early setup required for block editors to functions |
|
50 | + * |
|
51 | + * @return void |
|
52 | + * @throws Exception |
|
53 | + */ |
|
54 | + public function initialize() |
|
55 | + { |
|
56 | + $this->loadEditorBlocks(); |
|
57 | + add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks')); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @return CollectionInterface|EditorBlockInterface[] |
|
63 | + * @throws ReflectionException |
|
64 | + * @throws InvalidArgumentException |
|
65 | + * @throws EE_Error |
|
66 | + * @throws InvalidClassException |
|
67 | + * @throws InvalidDataTypeException |
|
68 | + * @throws InvalidEntityException |
|
69 | + * @throws InvalidFilePathException |
|
70 | + * @throws InvalidIdentifierException |
|
71 | + * @throws InvalidInterfaceException |
|
72 | + */ |
|
73 | + protected function populateEditorBlockCollection() |
|
74 | + { |
|
75 | + $loader = new CollectionLoader( |
|
76 | + new CollectionDetails( |
|
77 | + // collection name |
|
78 | + 'shortcodes', |
|
79 | + // collection interface |
|
80 | + 'EventEspresso\core\domain\entities\editor\EditorBlockInterface', |
|
81 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
82 | + apply_filters( |
|
83 | + 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs', |
|
84 | + array() |
|
85 | + // array( |
|
86 | + // 'EventEspresso\core\domain\entities\editor\blocks\common', |
|
87 | + // 'EventEspresso\core\domain\entities\editor\blocks\editor', |
|
88 | + // 'EventEspresso\core\domain\entities\editor\blocks\shortcodes', |
|
89 | + // 'EventEspresso\core\domain\entities\editor\blocks\widgets', |
|
90 | + // ) |
|
91 | + ), |
|
92 | + // filepaths to classes to add |
|
93 | + array(), |
|
94 | + // file mask to use if parsing folder for files to add |
|
95 | + '', |
|
96 | + // what to use as identifier for collection entities |
|
97 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
98 | + CollectionDetails::ID_CLASS_NAME |
|
99 | + ), |
|
100 | + $this->blocks |
|
101 | + ); |
|
102 | + return $loader->getCollection(); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * populates the EditorBlockCollection and calls initialize() on all installed blocks |
|
108 | + * |
|
109 | + * @return void |
|
110 | + * @throws Exception |
|
111 | + */ |
|
112 | + public function loadEditorBlocks() |
|
113 | + { |
|
114 | + try { |
|
115 | + $this->populateEditorBlockCollection(); |
|
116 | + // cycle thru block loaders and initialize each loader |
|
117 | + foreach ($this->blocks as $block) { |
|
118 | + $block->initialize(); |
|
119 | + } |
|
120 | + } catch (Exception $exception) { |
|
121 | + new ExceptionStackTraceDisplay($exception); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * calls registerBlock() and load assets for all installed blocks |
|
128 | + * |
|
129 | + * @return void |
|
130 | + * @throws Exception |
|
131 | + */ |
|
132 | + public function registerEditorBlocks() |
|
133 | + { |
|
134 | + try { |
|
135 | + // register primary assets |
|
136 | + add_action('enqueue_block_assets', array($this, 'registerStyles')); |
|
137 | + add_action('enqueue_block_assets', array($this, 'registerScripts')); |
|
138 | + // cycle thru block loader folders |
|
139 | + foreach ($this->blocks as $block) { |
|
140 | + // perform any setup required for the block |
|
141 | + $block_type = $block->registerBlock(); |
|
142 | + if (! $block_type instanceof WP_Block_Type) { |
|
143 | + throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
144 | + } |
|
145 | + add_action('enqueue_block_assets', array($block, 'registerStyles')); |
|
146 | + add_action('enqueue_block_assets', array($block, 'registerScripts')); |
|
147 | + do_action( |
|
148 | + 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered', |
|
149 | + $block, |
|
150 | + $block_type |
|
151 | + ); |
|
152 | + } |
|
153 | + } catch (Exception $exception) { |
|
154 | + new ExceptionStackTraceDisplay($exception); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + public function registerStyles() |
|
160 | + { |
|
161 | + // wp_register_style( |
|
162 | + // 'ee-block-styles', |
|
163 | + // $this->domain->distributionAssetsUrl() . 'style.css', |
|
164 | + // array(), |
|
165 | + // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
166 | + // ); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + public function registerScripts() |
|
171 | + { |
|
172 | + wp_register_script( |
|
173 | + 'ee-core-blocks', |
|
174 | + $this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS), |
|
175 | + array( |
|
176 | + 'eejs-core', |
|
177 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
178 | + 'wp-i18n', // Provides localization functions |
|
179 | + 'wp-element', // Provides React.Component |
|
180 | + 'wp-components' // Provides many prebuilt components and controls |
|
181 | + ), |
|
182 | + null, |
|
183 | + true |
|
184 | + ); |
|
185 | + } |
|
186 | 186 | } |
@@ -429,7 +429,7 @@ |
||
429 | 429 | * If $expired is set to true, then only line items for expired sessions will be returned. |
430 | 430 | * If $expired is set to false, then only line items for active sessions will be returned. |
431 | 431 | * |
432 | - * @param null $expired |
|
432 | + * @param boolean $expired |
|
433 | 433 | * @return EE_Base_Class[]|EE_Line_Item[] |
434 | 434 | * @throws InvalidInterfaceException |
435 | 435 | * @throws InvalidDataTypeException |
@@ -32,445 +32,445 @@ |
||
32 | 32 | class EEM_Line_Item extends EEM_Base |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Tax sub-total is just the total of all the taxes, which should be children |
|
37 | - * of this line item. There should only ever be one tax sub-total, and it should |
|
38 | - * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
39 | - */ |
|
40 | - const type_tax_sub_total = 'tax-sub-total'; |
|
41 | - |
|
42 | - /** |
|
43 | - * Tax line items indicate a tax applied to all the taxable line items. |
|
44 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
45 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
46 | - */ |
|
47 | - const type_tax = 'tax'; |
|
48 | - |
|
49 | - /** |
|
50 | - * Indicating individual items purchased, or discounts or surcharges. |
|
51 | - * The sum of all the regular line items plus the tax items should equal |
|
52 | - * the grand total. |
|
53 | - * Possible children are sub-line-items and cancellations. |
|
54 | - * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
55 | - * LIN_totals. Its LIN_percent = 0. |
|
56 | - * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
57 | - * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
58 | - */ |
|
59 | - const type_line_item = 'line-item'; |
|
60 | - |
|
61 | - /** |
|
62 | - * Line item indicating all the factors that make a single line item. |
|
63 | - * Sub-line items should have NO children line items. |
|
64 | - * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
65 | - * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
66 | - * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
67 | - * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
68 | - * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
69 | - */ |
|
70 | - const type_sub_line_item = 'sub-item'; |
|
71 | - |
|
72 | - /** |
|
73 | - * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
74 | - * Direct children should be event subtotals. |
|
75 | - * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
76 | - * |
|
77 | - */ |
|
78 | - const type_sub_total = 'sub-total'; |
|
79 | - |
|
80 | - /** |
|
81 | - * Line item for the grand total of an order. Its direct children |
|
82 | - * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item |
|
83 | - * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of |
|
84 | - * the entire order's mount. |
|
85 | - */ |
|
86 | - const type_total = 'total'; |
|
87 | - |
|
88 | - /** |
|
89 | - * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
90 | - * should be created, indicating the quantity that were cancelled |
|
91 | - * (because a line item could have a quantity of 1, and its cancellation item |
|
92 | - * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
93 | - * cancelled, and only one remains). |
|
94 | - * When items are refunded, a cancellation line item should be made, which points |
|
95 | - * to teh payment model object which actually refunded the payment. |
|
96 | - * Cancellations should NOT have any children line items; the should NOT affect |
|
97 | - * any calculations, and are only meant as a record that cancellations have occurred. |
|
98 | - * Their LIN_percent should be 0. |
|
99 | - */ |
|
100 | - const type_cancellation = 'cancellation'; |
|
101 | - |
|
102 | - // private instance of the EEM_Line_Item object |
|
103 | - protected static $_instance = null; |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * private constructor to prevent direct creation |
|
108 | - * @Constructor |
|
109 | - * @access protected |
|
110 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
111 | - * @return \EEM_Line_Item |
|
112 | - */ |
|
113 | - protected function __construct($timezone) |
|
114 | - { |
|
115 | - $this->singular_item = __('Line Item', 'event_espresso'); |
|
116 | - $this->plural_item = __('Line Items', 'event_espresso'); |
|
117 | - |
|
118 | - $this->_tables = array( |
|
119 | - 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
120 | - ); |
|
121 | - $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
122 | - $this->_fields = array( |
|
123 | - 'Line_Item' => array( |
|
124 | - 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
125 | - 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), true), |
|
126 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), true, null, 'Transaction'), |
|
127 | - 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), false, ''), |
|
128 | - 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), true), |
|
129 | - 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), false, 0), |
|
130 | - 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), false, 0), |
|
131 | - 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), false, false), |
|
132 | - 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), false, 1), |
|
133 | - 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), false, 0), |
|
134 | - 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), true, 1), |
|
135 | - 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), true, null), |
|
136 | - 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), false, 'line-item', array( |
|
137 | - self::type_line_item => __("Line Item", "event_espresso"), |
|
138 | - self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
|
139 | - self::type_sub_total => __("Subtotal", "event_espresso"), |
|
140 | - self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
|
141 | - self::type_tax => __("Tax", "event_espresso"), |
|
142 | - self::type_total => __("Total", "event_espresso"), |
|
143 | - self::type_cancellation => __('Cancellation', 'event_espresso') |
|
144 | - )), |
|
145 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), true, null, $line_items_can_be_for), |
|
146 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), true, null, $line_items_can_be_for), |
|
147 | - 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
148 | - ) |
|
149 | - ); |
|
150 | - $this->_model_relations = array( |
|
151 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
152 | - 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
153 | - 'Price' => new EE_Belongs_To_Any_Relation(), |
|
154 | - 'Event' => new EE_Belongs_To_Any_Relation() |
|
155 | - ); |
|
156 | - $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
157 | - $this->_caps_slug = 'transactions'; |
|
158 | - parent::__construct($timezone); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Gets all the line items for this transaction of the given type |
|
164 | - * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
165 | - * @param EE_Transaction|int $transaction |
|
166 | - * @return EE_Line_Item[] |
|
167 | - */ |
|
168 | - public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
169 | - { |
|
170 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
171 | - return $this->get_all(array(array( |
|
172 | - 'LIN_type' => $line_item_type, |
|
173 | - 'TXN_ID' => $transaction |
|
174 | - ))); |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Gets all line items unrelated to tickets that are normal line items |
|
180 | - * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
181 | - * @param EE_Transaction|int $transaction |
|
182 | - * @return EE_Line_Item[] |
|
183 | - */ |
|
184 | - public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
185 | - { |
|
186 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
187 | - return $this->get_all(array(array( |
|
188 | - 'LIN_type' => self::type_line_item, |
|
189 | - 'TXN_ID' => $transaction, |
|
190 | - 'OR' => array( |
|
191 | - 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
192 | - 'OBJ_type*null' => array('IS_NULL')) |
|
193 | - ))); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
198 | - * This needs to be very efficient |
|
199 | - * because if there are spam bots afoot there will be LOTS of line items |
|
200 | - * @return int count of how many deleted |
|
201 | - */ |
|
202 | - public function delete_line_items_with_no_transaction() |
|
203 | - { |
|
204 | - /** @type WPDB $wpdb */ |
|
205 | - global $wpdb; |
|
206 | - $time_to_leave_alone = apply_filters( |
|
207 | - 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
208 | - WEEK_IN_SECONDS |
|
209 | - ); |
|
210 | - $query = $wpdb->prepare( |
|
211 | - 'DELETE li |
|
35 | + /** |
|
36 | + * Tax sub-total is just the total of all the taxes, which should be children |
|
37 | + * of this line item. There should only ever be one tax sub-total, and it should |
|
38 | + * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
39 | + */ |
|
40 | + const type_tax_sub_total = 'tax-sub-total'; |
|
41 | + |
|
42 | + /** |
|
43 | + * Tax line items indicate a tax applied to all the taxable line items. |
|
44 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
45 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
46 | + */ |
|
47 | + const type_tax = 'tax'; |
|
48 | + |
|
49 | + /** |
|
50 | + * Indicating individual items purchased, or discounts or surcharges. |
|
51 | + * The sum of all the regular line items plus the tax items should equal |
|
52 | + * the grand total. |
|
53 | + * Possible children are sub-line-items and cancellations. |
|
54 | + * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
55 | + * LIN_totals. Its LIN_percent = 0. |
|
56 | + * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
57 | + * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
58 | + */ |
|
59 | + const type_line_item = 'line-item'; |
|
60 | + |
|
61 | + /** |
|
62 | + * Line item indicating all the factors that make a single line item. |
|
63 | + * Sub-line items should have NO children line items. |
|
64 | + * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
65 | + * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
66 | + * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
67 | + * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
68 | + * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
69 | + */ |
|
70 | + const type_sub_line_item = 'sub-item'; |
|
71 | + |
|
72 | + /** |
|
73 | + * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
74 | + * Direct children should be event subtotals. |
|
75 | + * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
76 | + * |
|
77 | + */ |
|
78 | + const type_sub_total = 'sub-total'; |
|
79 | + |
|
80 | + /** |
|
81 | + * Line item for the grand total of an order. Its direct children |
|
82 | + * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item |
|
83 | + * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of |
|
84 | + * the entire order's mount. |
|
85 | + */ |
|
86 | + const type_total = 'total'; |
|
87 | + |
|
88 | + /** |
|
89 | + * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
90 | + * should be created, indicating the quantity that were cancelled |
|
91 | + * (because a line item could have a quantity of 1, and its cancellation item |
|
92 | + * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
93 | + * cancelled, and only one remains). |
|
94 | + * When items are refunded, a cancellation line item should be made, which points |
|
95 | + * to teh payment model object which actually refunded the payment. |
|
96 | + * Cancellations should NOT have any children line items; the should NOT affect |
|
97 | + * any calculations, and are only meant as a record that cancellations have occurred. |
|
98 | + * Their LIN_percent should be 0. |
|
99 | + */ |
|
100 | + const type_cancellation = 'cancellation'; |
|
101 | + |
|
102 | + // private instance of the EEM_Line_Item object |
|
103 | + protected static $_instance = null; |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * private constructor to prevent direct creation |
|
108 | + * @Constructor |
|
109 | + * @access protected |
|
110 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
111 | + * @return \EEM_Line_Item |
|
112 | + */ |
|
113 | + protected function __construct($timezone) |
|
114 | + { |
|
115 | + $this->singular_item = __('Line Item', 'event_espresso'); |
|
116 | + $this->plural_item = __('Line Items', 'event_espresso'); |
|
117 | + |
|
118 | + $this->_tables = array( |
|
119 | + 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
120 | + ); |
|
121 | + $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
122 | + $this->_fields = array( |
|
123 | + 'Line_Item' => array( |
|
124 | + 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
125 | + 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), true), |
|
126 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), true, null, 'Transaction'), |
|
127 | + 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), false, ''), |
|
128 | + 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), true), |
|
129 | + 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), false, 0), |
|
130 | + 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), false, 0), |
|
131 | + 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), false, false), |
|
132 | + 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), false, 1), |
|
133 | + 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), false, 0), |
|
134 | + 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), true, 1), |
|
135 | + 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), true, null), |
|
136 | + 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), false, 'line-item', array( |
|
137 | + self::type_line_item => __("Line Item", "event_espresso"), |
|
138 | + self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
|
139 | + self::type_sub_total => __("Subtotal", "event_espresso"), |
|
140 | + self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
|
141 | + self::type_tax => __("Tax", "event_espresso"), |
|
142 | + self::type_total => __("Total", "event_espresso"), |
|
143 | + self::type_cancellation => __('Cancellation', 'event_espresso') |
|
144 | + )), |
|
145 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), true, null, $line_items_can_be_for), |
|
146 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), true, null, $line_items_can_be_for), |
|
147 | + 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
148 | + ) |
|
149 | + ); |
|
150 | + $this->_model_relations = array( |
|
151 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
152 | + 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
153 | + 'Price' => new EE_Belongs_To_Any_Relation(), |
|
154 | + 'Event' => new EE_Belongs_To_Any_Relation() |
|
155 | + ); |
|
156 | + $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
157 | + $this->_caps_slug = 'transactions'; |
|
158 | + parent::__construct($timezone); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Gets all the line items for this transaction of the given type |
|
164 | + * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
165 | + * @param EE_Transaction|int $transaction |
|
166 | + * @return EE_Line_Item[] |
|
167 | + */ |
|
168 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
169 | + { |
|
170 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
171 | + return $this->get_all(array(array( |
|
172 | + 'LIN_type' => $line_item_type, |
|
173 | + 'TXN_ID' => $transaction |
|
174 | + ))); |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Gets all line items unrelated to tickets that are normal line items |
|
180 | + * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
181 | + * @param EE_Transaction|int $transaction |
|
182 | + * @return EE_Line_Item[] |
|
183 | + */ |
|
184 | + public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
185 | + { |
|
186 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
187 | + return $this->get_all(array(array( |
|
188 | + 'LIN_type' => self::type_line_item, |
|
189 | + 'TXN_ID' => $transaction, |
|
190 | + 'OR' => array( |
|
191 | + 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
192 | + 'OBJ_type*null' => array('IS_NULL')) |
|
193 | + ))); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
198 | + * This needs to be very efficient |
|
199 | + * because if there are spam bots afoot there will be LOTS of line items |
|
200 | + * @return int count of how many deleted |
|
201 | + */ |
|
202 | + public function delete_line_items_with_no_transaction() |
|
203 | + { |
|
204 | + /** @type WPDB $wpdb */ |
|
205 | + global $wpdb; |
|
206 | + $time_to_leave_alone = apply_filters( |
|
207 | + 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
208 | + WEEK_IN_SECONDS |
|
209 | + ); |
|
210 | + $query = $wpdb->prepare( |
|
211 | + 'DELETE li |
|
212 | 212 | FROM ' . $this->table() . ' li |
213 | 213 | LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
214 | 214 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
215 | - // use GMT time because that's what TXN_timestamps are in |
|
216 | - date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
217 | - ); |
|
218 | - return $wpdb->query($query); |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * get_line_item_for_transaction_object |
|
224 | - * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
225 | - * |
|
226 | - * @param int $TXN_ID |
|
227 | - * @param \EE_Base_Class $object |
|
228 | - * @return EE_Line_Item[] |
|
229 | - */ |
|
230 | - public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
231 | - { |
|
232 | - return $this->get_all(array(array( |
|
233 | - 'TXN_ID' => $TXN_ID, |
|
234 | - 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
235 | - 'OBJ_ID' => $object->ID() |
|
236 | - ))); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * get_object_line_items_for_transaction |
|
242 | - * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
243 | - * |
|
244 | - * @param int $TXN_ID |
|
245 | - * @param string $OBJ_type |
|
246 | - * @param array $OBJ_IDs |
|
247 | - * @return EE_Line_Item[] |
|
248 | - */ |
|
249 | - public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) |
|
250 | - { |
|
251 | - $query_params = array( |
|
252 | - 'OBJ_type' => $OBJ_type, |
|
253 | - // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
254 | - 'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
255 | - ); |
|
256 | - if ($TXN_ID) { |
|
257 | - $query_params['TXN_ID'] = $TXN_ID; |
|
258 | - } |
|
259 | - return $this->get_all(array($query_params)); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * get_all_ticket_line_items_for_transaction |
|
265 | - * |
|
266 | - * @param EE_Transaction $transaction |
|
267 | - * @return EE_Line_Item[] |
|
268 | - */ |
|
269 | - public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
270 | - { |
|
271 | - return $this->get_all(array( |
|
272 | - array( |
|
273 | - 'TXN_ID' => $transaction->ID(), |
|
274 | - 'OBJ_type' => 'Ticket', |
|
275 | - ) |
|
276 | - )); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * get_ticket_line_item_for_transaction |
|
282 | - * |
|
283 | - * @param int $TXN_ID |
|
284 | - * @param int $TKT_ID |
|
285 | - * @return \EE_Line_Item |
|
286 | - */ |
|
287 | - public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
288 | - { |
|
289 | - return $this->get_one(array( |
|
290 | - array( |
|
291 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
292 | - 'OBJ_ID' => $TKT_ID, |
|
293 | - 'OBJ_type' => 'Ticket', |
|
294 | - ) |
|
295 | - )); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * get_existing_promotion_line_item |
|
301 | - * searches the cart for existing line items for the specified promotion |
|
302 | - * |
|
303 | - * @since 1.0.0 |
|
304 | - * |
|
305 | - * @param EE_Line_Item $parent_line_item |
|
306 | - * @param EE_Promotion $promotion |
|
307 | - * @return EE_Line_Item |
|
308 | - */ |
|
309 | - public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
310 | - { |
|
311 | - return $this->get_one(array( |
|
312 | - array( |
|
313 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
314 | - 'LIN_parent' => $parent_line_item->ID(), |
|
315 | - 'OBJ_type' => 'Promotion', |
|
316 | - 'OBJ_ID' => $promotion->ID() |
|
317 | - ) |
|
318 | - )); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * get_all_promotion_line_items |
|
324 | - * searches the cart for any and all existing promotion line items |
|
325 | - * |
|
326 | - * @since 1.0.0 |
|
327 | - * |
|
328 | - * @param EE_Line_Item $parent_line_item |
|
329 | - * @return EE_Line_Item[] |
|
330 | - */ |
|
331 | - public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
332 | - { |
|
333 | - return $this->get_all(array( |
|
334 | - array( |
|
335 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
336 | - 'LIN_parent' => $parent_line_item->ID(), |
|
337 | - 'OBJ_type' => 'Promotion' |
|
338 | - ) |
|
339 | - )); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Gets the registration's corresponding line item. |
|
344 | - * Note: basically does NOT support having multiple line items for a single ticket, |
|
345 | - * which would happen if some of the registrations had a price modifier while others didn't. |
|
346 | - * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
347 | - * @param EE_Registration $registration |
|
348 | - * @return EE_Line_ITem |
|
349 | - */ |
|
350 | - public function get_line_item_for_registration(EE_Registration $registration) |
|
351 | - { |
|
352 | - return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Gets the query params used to retrieve a specific line item for the given registration |
|
357 | - * @param EE_Registration $registration |
|
358 | - * @param array $original_query_params any extra query params you'd like to be merged with |
|
359 | - * @return array like EEM_Base::get_all()'s $query_params |
|
360 | - */ |
|
361 | - public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) |
|
362 | - { |
|
363 | - return array_replace_recursive($original_query_params, array( |
|
364 | - array( |
|
365 | - 'OBJ_ID' => $registration->ticket_ID(), |
|
366 | - 'OBJ_type' => 'Ticket', |
|
367 | - 'TXN_ID' => $registration->transaction_ID() |
|
368 | - ) |
|
369 | - )); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
375 | - * @throws InvalidInterfaceException |
|
376 | - * @throws InvalidDataTypeException |
|
377 | - * @throws EE_Error |
|
378 | - * @throws InvalidArgumentException |
|
379 | - */ |
|
380 | - public function get_total_line_items_with_no_transaction() |
|
381 | - { |
|
382 | - return $this->get_total_line_items_for_carts(); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
388 | - * @throws InvalidInterfaceException |
|
389 | - * @throws InvalidDataTypeException |
|
390 | - * @throws EE_Error |
|
391 | - * @throws InvalidArgumentException |
|
392 | - */ |
|
393 | - public function get_total_line_items_for_active_carts() |
|
394 | - { |
|
395 | - return $this->get_total_line_items_for_carts(false); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
401 | - * @throws InvalidInterfaceException |
|
402 | - * @throws InvalidDataTypeException |
|
403 | - * @throws EE_Error |
|
404 | - * @throws InvalidArgumentException |
|
405 | - */ |
|
406 | - public function get_total_line_items_for_expired_carts() |
|
407 | - { |
|
408 | - return $this->get_total_line_items_for_carts(true); |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
414 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
415 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
416 | - * |
|
417 | - * @param null $expired |
|
418 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
419 | - * @throws InvalidInterfaceException |
|
420 | - * @throws InvalidDataTypeException |
|
421 | - * @throws EE_Error |
|
422 | - * @throws InvalidArgumentException |
|
423 | - * @throws InvalidDataTypeException |
|
424 | - * @throws InvalidInterfaceException |
|
425 | - */ |
|
426 | - private function get_total_line_items_for_carts($expired = null) |
|
427 | - { |
|
428 | - $where_params = array( |
|
429 | - 'TXN_ID' => 0, |
|
430 | - 'LIN_type' => 'total', |
|
431 | - ); |
|
432 | - if ($expired !== null) { |
|
433 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
434 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
435 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
436 | - ); |
|
437 | - $where_params['LIN_timestamp'] = array( |
|
438 | - $expired ? '<=' : '>', |
|
439 | - $session_lifespan->expiration(), |
|
440 | - ); |
|
441 | - } |
|
442 | - return $this->get_all(array($where_params)); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * Returns an array of ticket total line items where the TXN_ID is 0 |
|
448 | - * AND the timestamp is older than the session lifespan. |
|
449 | - * |
|
450 | - * @param int $timestamp |
|
451 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
452 | - * @throws EE_Error |
|
453 | - * @throws InvalidArgumentException |
|
454 | - * @throws InvalidDataTypeException |
|
455 | - * @throws InvalidInterfaceException |
|
456 | - */ |
|
457 | - public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
458 | - { |
|
459 | - if (! absint($timestamp)) { |
|
460 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
461 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
462 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
463 | - ); |
|
464 | - $timestamp = $session_lifespan->expiration(); |
|
465 | - } |
|
466 | - return $this->get_all( |
|
467 | - array( |
|
468 | - array( |
|
469 | - 'TXN_ID' => 0, |
|
470 | - 'OBJ_type' => 'Ticket', |
|
471 | - 'LIN_timestamp' => array('<=', $timestamp), |
|
472 | - ) |
|
473 | - ) |
|
474 | - ); |
|
475 | - } |
|
215 | + // use GMT time because that's what TXN_timestamps are in |
|
216 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
217 | + ); |
|
218 | + return $wpdb->query($query); |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * get_line_item_for_transaction_object |
|
224 | + * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
225 | + * |
|
226 | + * @param int $TXN_ID |
|
227 | + * @param \EE_Base_Class $object |
|
228 | + * @return EE_Line_Item[] |
|
229 | + */ |
|
230 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
231 | + { |
|
232 | + return $this->get_all(array(array( |
|
233 | + 'TXN_ID' => $TXN_ID, |
|
234 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
235 | + 'OBJ_ID' => $object->ID() |
|
236 | + ))); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * get_object_line_items_for_transaction |
|
242 | + * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
243 | + * |
|
244 | + * @param int $TXN_ID |
|
245 | + * @param string $OBJ_type |
|
246 | + * @param array $OBJ_IDs |
|
247 | + * @return EE_Line_Item[] |
|
248 | + */ |
|
249 | + public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) |
|
250 | + { |
|
251 | + $query_params = array( |
|
252 | + 'OBJ_type' => $OBJ_type, |
|
253 | + // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
254 | + 'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
255 | + ); |
|
256 | + if ($TXN_ID) { |
|
257 | + $query_params['TXN_ID'] = $TXN_ID; |
|
258 | + } |
|
259 | + return $this->get_all(array($query_params)); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * get_all_ticket_line_items_for_transaction |
|
265 | + * |
|
266 | + * @param EE_Transaction $transaction |
|
267 | + * @return EE_Line_Item[] |
|
268 | + */ |
|
269 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
270 | + { |
|
271 | + return $this->get_all(array( |
|
272 | + array( |
|
273 | + 'TXN_ID' => $transaction->ID(), |
|
274 | + 'OBJ_type' => 'Ticket', |
|
275 | + ) |
|
276 | + )); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * get_ticket_line_item_for_transaction |
|
282 | + * |
|
283 | + * @param int $TXN_ID |
|
284 | + * @param int $TKT_ID |
|
285 | + * @return \EE_Line_Item |
|
286 | + */ |
|
287 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
288 | + { |
|
289 | + return $this->get_one(array( |
|
290 | + array( |
|
291 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
292 | + 'OBJ_ID' => $TKT_ID, |
|
293 | + 'OBJ_type' => 'Ticket', |
|
294 | + ) |
|
295 | + )); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * get_existing_promotion_line_item |
|
301 | + * searches the cart for existing line items for the specified promotion |
|
302 | + * |
|
303 | + * @since 1.0.0 |
|
304 | + * |
|
305 | + * @param EE_Line_Item $parent_line_item |
|
306 | + * @param EE_Promotion $promotion |
|
307 | + * @return EE_Line_Item |
|
308 | + */ |
|
309 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
310 | + { |
|
311 | + return $this->get_one(array( |
|
312 | + array( |
|
313 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
314 | + 'LIN_parent' => $parent_line_item->ID(), |
|
315 | + 'OBJ_type' => 'Promotion', |
|
316 | + 'OBJ_ID' => $promotion->ID() |
|
317 | + ) |
|
318 | + )); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * get_all_promotion_line_items |
|
324 | + * searches the cart for any and all existing promotion line items |
|
325 | + * |
|
326 | + * @since 1.0.0 |
|
327 | + * |
|
328 | + * @param EE_Line_Item $parent_line_item |
|
329 | + * @return EE_Line_Item[] |
|
330 | + */ |
|
331 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
332 | + { |
|
333 | + return $this->get_all(array( |
|
334 | + array( |
|
335 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
336 | + 'LIN_parent' => $parent_line_item->ID(), |
|
337 | + 'OBJ_type' => 'Promotion' |
|
338 | + ) |
|
339 | + )); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Gets the registration's corresponding line item. |
|
344 | + * Note: basically does NOT support having multiple line items for a single ticket, |
|
345 | + * which would happen if some of the registrations had a price modifier while others didn't. |
|
346 | + * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
347 | + * @param EE_Registration $registration |
|
348 | + * @return EE_Line_ITem |
|
349 | + */ |
|
350 | + public function get_line_item_for_registration(EE_Registration $registration) |
|
351 | + { |
|
352 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Gets the query params used to retrieve a specific line item for the given registration |
|
357 | + * @param EE_Registration $registration |
|
358 | + * @param array $original_query_params any extra query params you'd like to be merged with |
|
359 | + * @return array like EEM_Base::get_all()'s $query_params |
|
360 | + */ |
|
361 | + public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) |
|
362 | + { |
|
363 | + return array_replace_recursive($original_query_params, array( |
|
364 | + array( |
|
365 | + 'OBJ_ID' => $registration->ticket_ID(), |
|
366 | + 'OBJ_type' => 'Ticket', |
|
367 | + 'TXN_ID' => $registration->transaction_ID() |
|
368 | + ) |
|
369 | + )); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
375 | + * @throws InvalidInterfaceException |
|
376 | + * @throws InvalidDataTypeException |
|
377 | + * @throws EE_Error |
|
378 | + * @throws InvalidArgumentException |
|
379 | + */ |
|
380 | + public function get_total_line_items_with_no_transaction() |
|
381 | + { |
|
382 | + return $this->get_total_line_items_for_carts(); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
388 | + * @throws InvalidInterfaceException |
|
389 | + * @throws InvalidDataTypeException |
|
390 | + * @throws EE_Error |
|
391 | + * @throws InvalidArgumentException |
|
392 | + */ |
|
393 | + public function get_total_line_items_for_active_carts() |
|
394 | + { |
|
395 | + return $this->get_total_line_items_for_carts(false); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
401 | + * @throws InvalidInterfaceException |
|
402 | + * @throws InvalidDataTypeException |
|
403 | + * @throws EE_Error |
|
404 | + * @throws InvalidArgumentException |
|
405 | + */ |
|
406 | + public function get_total_line_items_for_expired_carts() |
|
407 | + { |
|
408 | + return $this->get_total_line_items_for_carts(true); |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
414 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
415 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
416 | + * |
|
417 | + * @param null $expired |
|
418 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
419 | + * @throws InvalidInterfaceException |
|
420 | + * @throws InvalidDataTypeException |
|
421 | + * @throws EE_Error |
|
422 | + * @throws InvalidArgumentException |
|
423 | + * @throws InvalidDataTypeException |
|
424 | + * @throws InvalidInterfaceException |
|
425 | + */ |
|
426 | + private function get_total_line_items_for_carts($expired = null) |
|
427 | + { |
|
428 | + $where_params = array( |
|
429 | + 'TXN_ID' => 0, |
|
430 | + 'LIN_type' => 'total', |
|
431 | + ); |
|
432 | + if ($expired !== null) { |
|
433 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
434 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
435 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
436 | + ); |
|
437 | + $where_params['LIN_timestamp'] = array( |
|
438 | + $expired ? '<=' : '>', |
|
439 | + $session_lifespan->expiration(), |
|
440 | + ); |
|
441 | + } |
|
442 | + return $this->get_all(array($where_params)); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * Returns an array of ticket total line items where the TXN_ID is 0 |
|
448 | + * AND the timestamp is older than the session lifespan. |
|
449 | + * |
|
450 | + * @param int $timestamp |
|
451 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
452 | + * @throws EE_Error |
|
453 | + * @throws InvalidArgumentException |
|
454 | + * @throws InvalidDataTypeException |
|
455 | + * @throws InvalidInterfaceException |
|
456 | + */ |
|
457 | + public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
458 | + { |
|
459 | + if (! absint($timestamp)) { |
|
460 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
461 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
462 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
463 | + ); |
|
464 | + $timestamp = $session_lifespan->expiration(); |
|
465 | + } |
|
466 | + return $this->get_all( |
|
467 | + array( |
|
468 | + array( |
|
469 | + 'TXN_ID' => 0, |
|
470 | + 'OBJ_type' => 'Ticket', |
|
471 | + 'LIN_timestamp' => array('<=', $timestamp), |
|
472 | + ) |
|
473 | + ) |
|
474 | + ); |
|
475 | + } |
|
476 | 476 | } |
@@ -19,94 +19,94 @@ |
||
19 | 19 | class ExitModal |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var Registry |
|
24 | - */ |
|
25 | - private $assets_registry; |
|
22 | + /** |
|
23 | + * @var Registry |
|
24 | + */ |
|
25 | + private $assets_registry; |
|
26 | 26 | |
27 | - /** |
|
28 | - * ExitModal constructor. |
|
29 | - * |
|
30 | - * @param Registry $assets_registry |
|
31 | - */ |
|
32 | - public function __construct(Registry $assets_registry) |
|
33 | - { |
|
34 | - $this->assets_registry = $assets_registry; |
|
35 | - add_action('in_admin_footer', array($this, 'modalContainer')); |
|
36 | - add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
37 | - } |
|
27 | + /** |
|
28 | + * ExitModal constructor. |
|
29 | + * |
|
30 | + * @param Registry $assets_registry |
|
31 | + */ |
|
32 | + public function __construct(Registry $assets_registry) |
|
33 | + { |
|
34 | + $this->assets_registry = $assets_registry; |
|
35 | + add_action('in_admin_footer', array($this, 'modalContainer')); |
|
36 | + add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Callback on in_admin_footer that is used to output the exit modal container. |
|
42 | - */ |
|
43 | - public function modalContainer() |
|
44 | - { |
|
45 | - echo '<div id="ee-exit-survey-modal"></div>'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * Callback on in_admin_footer that is used to output the exit modal container. |
|
42 | + */ |
|
43 | + public function modalContainer() |
|
44 | + { |
|
45 | + echo '<div id="ee-exit-survey-modal"></div>'; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
51 | - * |
|
52 | - * @throws InvalidArgumentException |
|
53 | - */ |
|
54 | - public function enqueues() |
|
55 | - { |
|
56 | - $current_user = new WP_User(get_current_user_id()); |
|
57 | - $this->assets_registry->addData( |
|
58 | - 'exitModali18n', |
|
59 | - array( |
|
60 | - 'introText' => htmlspecialchars( |
|
61 | - __( |
|
62 | - 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
63 | - 'event_espresso' |
|
64 | - ), |
|
65 | - ENT_NOQUOTES |
|
66 | - ), |
|
67 | - 'doSurveyButtonText' => htmlspecialchars( |
|
68 | - __( |
|
69 | - 'Sure I\'ll help', |
|
70 | - 'event_espresso' |
|
71 | - ), |
|
72 | - ENT_NOQUOTES |
|
73 | - ), |
|
74 | - 'skipButtonText' => htmlspecialchars( |
|
75 | - __( |
|
76 | - 'Skip', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - ENT_NOQUOTES |
|
80 | - ) |
|
81 | - ) |
|
82 | - ); |
|
83 | - $this->assets_registry->addData( |
|
84 | - 'exitModalInfo', |
|
85 | - array( |
|
86 | - 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
87 | - 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
88 | - 'website' => htmlspecialchars(site_url()), |
|
89 | - 'isModalActive' => $this->isModalActive() |
|
90 | - ) |
|
91 | - ); |
|
49 | + /** |
|
50 | + * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
51 | + * |
|
52 | + * @throws InvalidArgumentException |
|
53 | + */ |
|
54 | + public function enqueues() |
|
55 | + { |
|
56 | + $current_user = new WP_User(get_current_user_id()); |
|
57 | + $this->assets_registry->addData( |
|
58 | + 'exitModali18n', |
|
59 | + array( |
|
60 | + 'introText' => htmlspecialchars( |
|
61 | + __( |
|
62 | + 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
63 | + 'event_espresso' |
|
64 | + ), |
|
65 | + ENT_NOQUOTES |
|
66 | + ), |
|
67 | + 'doSurveyButtonText' => htmlspecialchars( |
|
68 | + __( |
|
69 | + 'Sure I\'ll help', |
|
70 | + 'event_espresso' |
|
71 | + ), |
|
72 | + ENT_NOQUOTES |
|
73 | + ), |
|
74 | + 'skipButtonText' => htmlspecialchars( |
|
75 | + __( |
|
76 | + 'Skip', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + ENT_NOQUOTES |
|
80 | + ) |
|
81 | + ) |
|
82 | + ); |
|
83 | + $this->assets_registry->addData( |
|
84 | + 'exitModalInfo', |
|
85 | + array( |
|
86 | + 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
87 | + 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
88 | + 'website' => htmlspecialchars(site_url()), |
|
89 | + 'isModalActive' => $this->isModalActive() |
|
90 | + ) |
|
91 | + ); |
|
92 | 92 | |
93 | - wp_enqueue_script('ee-wp-plugins-page'); |
|
94 | - wp_enqueue_style('ee-wp-plugins-page'); |
|
95 | - } |
|
93 | + wp_enqueue_script('ee-wp-plugins-page'); |
|
94 | + wp_enqueue_style('ee-wp-plugins-page'); |
|
95 | + } |
|
96 | 96 | |
97 | 97 | |
98 | - /** |
|
99 | - * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - private function isModalActive() |
|
103 | - { |
|
104 | - return filter_var( |
|
105 | - apply_filters( |
|
106 | - 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
107 | - true |
|
108 | - ), |
|
109 | - FILTER_VALIDATE_BOOLEAN |
|
110 | - ); |
|
111 | - } |
|
98 | + /** |
|
99 | + * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + private function isModalActive() |
|
103 | + { |
|
104 | + return filter_var( |
|
105 | + apply_filters( |
|
106 | + 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
107 | + true |
|
108 | + ), |
|
109 | + FILTER_VALIDATE_BOOLEAN |
|
110 | + ); |
|
111 | + } |
|
112 | 112 | } |
@@ -16,67 +16,67 @@ |
||
16 | 16 | interface DomainInterface extends InterminableInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @return string |
|
21 | - * @throws DomainException |
|
22 | - */ |
|
23 | - public function pluginFile(); |
|
19 | + /** |
|
20 | + * @return string |
|
21 | + * @throws DomainException |
|
22 | + */ |
|
23 | + public function pluginFile(); |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @return string |
|
28 | - * @throws DomainException |
|
29 | - */ |
|
30 | - public function pluginBasename(); |
|
26 | + /** |
|
27 | + * @return string |
|
28 | + * @throws DomainException |
|
29 | + */ |
|
30 | + public function pluginBasename(); |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function pluginPath(); |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function pluginPath(); |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - * @throws DomainException |
|
42 | - */ |
|
43 | - public function pluginUrl(); |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + * @throws DomainException |
|
42 | + */ |
|
43 | + public function pluginUrl(); |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @return string |
|
48 | - * @throws DomainException |
|
49 | - */ |
|
50 | - public function version(); |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + * @throws DomainException |
|
49 | + */ |
|
50 | + public function version(); |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function sourceAssetsPath(); |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function sourceAssetsPath(); |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function sourceAssetsUrl(); |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function sourceAssetsUrl(); |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function distributionAssetsPath(); |
|
65 | + /** |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function distributionAssetsPath(); |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function distributionAssetsUrl(); |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function distributionAssetsUrl(); |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function assetNamespace(); |
|
77 | + /** |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function assetNamespace(); |
|
81 | 81 | |
82 | 82 | } |
@@ -163,7 +163,7 @@ |
||
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @param $entity |
166 | - * @param mixed $identifier |
|
166 | + * @param string $identifier |
|
167 | 167 | * @return string |
168 | 168 | * @throws InvalidEntityException |
169 | 169 | */ |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | LocatorInterface $file_locator = null |
85 | 85 | ) { |
86 | 86 | $this->collection_details = $collection_details; |
87 | - if (! $collection instanceof CollectionInterface) { |
|
87 | + if ( ! $collection instanceof CollectionInterface) { |
|
88 | 88 | $collection = new Collection($this->collection_details->getCollectionInterface()); |
89 | 89 | } |
90 | 90 | $this->collection = $collection; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function loadAllFromFilepaths() |
113 | 113 | { |
114 | - if (! $this->file_locator instanceof FileLocator) { |
|
114 | + if ( ! $this->file_locator instanceof FileLocator) { |
|
115 | 115 | $this->file_locator = new FileLocator(); |
116 | 116 | } |
117 | 117 | $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function loadClassFromFilepath($filepath) |
145 | 145 | { |
146 | - if (! is_string($filepath)) { |
|
146 | + if ( ! is_string($filepath)) { |
|
147 | 147 | throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
148 | 148 | } |
149 | - if (! is_readable($filepath)) { |
|
149 | + if ( ! is_readable($filepath)) { |
|
150 | 150 | throw new InvalidFilePathException($filepath); |
151 | 151 | } |
152 | 152 | require_once $filepath; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $file_name = basename($filepath); |
155 | 155 | // now remove any file extensions |
156 | 156 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
157 | - if (! class_exists($class_name)) { |
|
157 | + if ( ! class_exists($class_name)) { |
|
158 | 158 | throw new InvalidClassException($class_name); |
159 | 159 | } |
160 | 160 | return $this->addEntityToCollection(new $class_name(), $file_name); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | // objects added to the collection based on entity callback, so the entity itself decides |
225 | 225 | case CollectionDetails::ID_CALLBACK_METHOD: |
226 | 226 | $identifier_callback = $this->collection_details->identifierCallback(); |
227 | - if (! method_exists($entity, $identifier_callback)) { |
|
227 | + if ( ! method_exists($entity, $identifier_callback)) { |
|
228 | 228 | throw new InvalidEntityException( |
229 | 229 | $entity, |
230 | 230 | $this->collection_details->getCollectionInterface(), |
@@ -288,10 +288,10 @@ discard block |
||
288 | 288 | */ |
289 | 289 | protected function loadClassFromFQCN($FQCN) |
290 | 290 | { |
291 | - if (! is_string($FQCN)) { |
|
291 | + if ( ! is_string($FQCN)) { |
|
292 | 292 | throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
293 | 293 | } |
294 | - if (! class_exists($FQCN)) { |
|
294 | + if ( ! class_exists($FQCN)) { |
|
295 | 295 | throw new InvalidClassException($FQCN); |
296 | 296 | } |
297 | 297 | return $this->addEntityToCollection( |
@@ -27,276 +27,276 @@ |
||
27 | 27 | class CollectionLoader |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * possible return value when adding entities to a collection. |
|
32 | - * denotes that the entity was NOT ADDED to the collection |
|
33 | - */ |
|
34 | - const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
30 | + /** |
|
31 | + * possible return value when adding entities to a collection. |
|
32 | + * denotes that the entity was NOT ADDED to the collection |
|
33 | + */ |
|
34 | + const ENTITY_NOT_ADDED = 'entity-not-added-to-collection'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * possible return value when adding entities to a collection. |
|
38 | - * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
39 | - */ |
|
40 | - const ENTITY_ADDED = 'entity-added-to-collection'; |
|
36 | + /** |
|
37 | + * possible return value when adding entities to a collection. |
|
38 | + * denotes that the entity was SUCCESSFULLY ADDED to the collection |
|
39 | + */ |
|
40 | + const ENTITY_ADDED = 'entity-added-to-collection'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * possible return value when adding entities to a collection. |
|
44 | - * denotes that the entity was ALREADY ADDED to the collection, |
|
45 | - * and therefore could not be added again. |
|
46 | - */ |
|
47 | - const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
42 | + /** |
|
43 | + * possible return value when adding entities to a collection. |
|
44 | + * denotes that the entity was ALREADY ADDED to the collection, |
|
45 | + * and therefore could not be added again. |
|
46 | + */ |
|
47 | + const ENTITY_EXISTS = 'entity-already-in-collection'; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @var CollectionDetailsInterface $collection_details |
|
52 | - */ |
|
53 | - protected $collection_details; |
|
50 | + /** |
|
51 | + * @var CollectionDetailsInterface $collection_details |
|
52 | + */ |
|
53 | + protected $collection_details; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var CollectionInterface $collection |
|
57 | - */ |
|
58 | - protected $collection; |
|
55 | + /** |
|
56 | + * @var CollectionInterface $collection |
|
57 | + */ |
|
58 | + protected $collection; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var FileLocator $file_locator |
|
62 | - */ |
|
63 | - protected $file_locator; |
|
60 | + /** |
|
61 | + * @var FileLocator $file_locator |
|
62 | + */ |
|
63 | + protected $file_locator; |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * CollectionLoader constructor. |
|
68 | - * |
|
69 | - * @param CollectionDetailsInterface $collection_details |
|
70 | - * @param CollectionInterface $collection |
|
71 | - * @param LocatorInterface $file_locator |
|
72 | - * @throws ReflectionException |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws EE_Error |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws InvalidClassException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidFilePathException |
|
79 | - * @throws InvalidEntityException |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - CollectionDetailsInterface $collection_details, |
|
83 | - CollectionInterface $collection = null, |
|
84 | - LocatorInterface $file_locator = null |
|
85 | - ) { |
|
86 | - $this->collection_details = $collection_details; |
|
87 | - if (! $collection instanceof CollectionInterface) { |
|
88 | - $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
89 | - } |
|
90 | - $this->collection = $collection; |
|
91 | - $this->file_locator = $file_locator; |
|
92 | - $this->loadAllFromFilepaths(); |
|
93 | - $this->loadFromFQCNs(); |
|
94 | - } |
|
66 | + /** |
|
67 | + * CollectionLoader constructor. |
|
68 | + * |
|
69 | + * @param CollectionDetailsInterface $collection_details |
|
70 | + * @param CollectionInterface $collection |
|
71 | + * @param LocatorInterface $file_locator |
|
72 | + * @throws ReflectionException |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws EE_Error |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws InvalidClassException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidFilePathException |
|
79 | + * @throws InvalidEntityException |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + CollectionDetailsInterface $collection_details, |
|
83 | + CollectionInterface $collection = null, |
|
84 | + LocatorInterface $file_locator = null |
|
85 | + ) { |
|
86 | + $this->collection_details = $collection_details; |
|
87 | + if (! $collection instanceof CollectionInterface) { |
|
88 | + $collection = new Collection($this->collection_details->getCollectionInterface()); |
|
89 | + } |
|
90 | + $this->collection = $collection; |
|
91 | + $this->file_locator = $file_locator; |
|
92 | + $this->loadAllFromFilepaths(); |
|
93 | + $this->loadFromFQCNs(); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * @return CollectionInterface |
|
99 | - */ |
|
100 | - public function getCollection() |
|
101 | - { |
|
102 | - return $this->collection; |
|
103 | - } |
|
97 | + /** |
|
98 | + * @return CollectionInterface |
|
99 | + */ |
|
100 | + public function getCollection() |
|
101 | + { |
|
102 | + return $this->collection; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * @throws InvalidClassException |
|
108 | - * @throws InvalidFilePathException |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidEntityException |
|
111 | - */ |
|
112 | - protected function loadAllFromFilepaths() |
|
113 | - { |
|
114 | - if (! $this->file_locator instanceof FileLocator) { |
|
115 | - $this->file_locator = new FileLocator(); |
|
116 | - } |
|
117 | - $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
118 | - // find all of the files that match the file mask in the specified folder |
|
119 | - $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
120 | - // filter the results |
|
121 | - $filepaths = (array) apply_filters( |
|
122 | - 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
123 | - $this->file_locator->getFilePaths(), |
|
124 | - $this->collection_details->collectionName(), |
|
125 | - $this->collection_details |
|
126 | - ); |
|
127 | - if (empty($filepaths)) { |
|
128 | - return; |
|
129 | - } |
|
130 | - foreach ($filepaths as $filepath) { |
|
131 | - $this->loadClassFromFilepath($filepath); |
|
132 | - } |
|
133 | - } |
|
106 | + /** |
|
107 | + * @throws InvalidClassException |
|
108 | + * @throws InvalidFilePathException |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidEntityException |
|
111 | + */ |
|
112 | + protected function loadAllFromFilepaths() |
|
113 | + { |
|
114 | + if (! $this->file_locator instanceof FileLocator) { |
|
115 | + $this->file_locator = new FileLocator(); |
|
116 | + } |
|
117 | + $this->file_locator->setFileMask($this->collection_details->getFileMask()); |
|
118 | + // find all of the files that match the file mask in the specified folder |
|
119 | + $this->file_locator->locate($this->collection_details->getCollectionPaths()); |
|
120 | + // filter the results |
|
121 | + $filepaths = (array) apply_filters( |
|
122 | + 'FHEE__CollectionLoader__loadAllFromFilepath__filepaths', |
|
123 | + $this->file_locator->getFilePaths(), |
|
124 | + $this->collection_details->collectionName(), |
|
125 | + $this->collection_details |
|
126 | + ); |
|
127 | + if (empty($filepaths)) { |
|
128 | + return; |
|
129 | + } |
|
130 | + foreach ($filepaths as $filepath) { |
|
131 | + $this->loadClassFromFilepath($filepath); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * @param string $filepath |
|
138 | - * @return string |
|
139 | - * @throws InvalidEntityException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidFilePathException |
|
142 | - * @throws InvalidClassException |
|
143 | - */ |
|
144 | - protected function loadClassFromFilepath($filepath) |
|
145 | - { |
|
146 | - if (! is_string($filepath)) { |
|
147 | - throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
148 | - } |
|
149 | - if (! is_readable($filepath)) { |
|
150 | - throw new InvalidFilePathException($filepath); |
|
151 | - } |
|
152 | - require_once $filepath; |
|
153 | - // extract filename from path |
|
154 | - $file_name = basename($filepath); |
|
155 | - // now remove any file extensions |
|
156 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
157 | - if (! class_exists($class_name)) { |
|
158 | - throw new InvalidClassException($class_name); |
|
159 | - } |
|
160 | - return $this->addEntityToCollection(new $class_name(), $file_name); |
|
161 | - } |
|
136 | + /** |
|
137 | + * @param string $filepath |
|
138 | + * @return string |
|
139 | + * @throws InvalidEntityException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidFilePathException |
|
142 | + * @throws InvalidClassException |
|
143 | + */ |
|
144 | + protected function loadClassFromFilepath($filepath) |
|
145 | + { |
|
146 | + if (! is_string($filepath)) { |
|
147 | + throw new InvalidDataTypeException('$filepath', $filepath, 'string'); |
|
148 | + } |
|
149 | + if (! is_readable($filepath)) { |
|
150 | + throw new InvalidFilePathException($filepath); |
|
151 | + } |
|
152 | + require_once $filepath; |
|
153 | + // extract filename from path |
|
154 | + $file_name = basename($filepath); |
|
155 | + // now remove any file extensions |
|
156 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($file_name); |
|
157 | + if (! class_exists($class_name)) { |
|
158 | + throw new InvalidClassException($class_name); |
|
159 | + } |
|
160 | + return $this->addEntityToCollection(new $class_name(), $file_name); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * @param $entity |
|
166 | - * @param mixed $identifier |
|
167 | - * @return string |
|
168 | - * @throws InvalidEntityException |
|
169 | - */ |
|
170 | - protected function addEntityToCollection($entity, $identifier) |
|
171 | - { |
|
172 | - do_action( |
|
173 | - 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
174 | - $entity, |
|
175 | - $this->collection_details->collectionName(), |
|
176 | - $this->collection_details |
|
177 | - ); |
|
178 | - $identifier = $this->setIdentifier($entity, $identifier); |
|
179 | - if ($this->collection->has($identifier)) { |
|
180 | - do_action( |
|
181 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
182 | - $this, |
|
183 | - $this->collection_details->collectionName(), |
|
184 | - $this->collection_details |
|
185 | - ); |
|
186 | - return CollectionLoader::ENTITY_EXISTS; |
|
187 | - } |
|
188 | - if ($this->collection->add($entity, $identifier)) { |
|
189 | - do_action( |
|
190 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
191 | - $this, |
|
192 | - $this->collection_details->collectionName(), |
|
193 | - $this->collection_details |
|
194 | - ); |
|
195 | - return CollectionLoader::ENTITY_ADDED; |
|
196 | - } |
|
197 | - do_action( |
|
198 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
199 | - $this, |
|
200 | - $this->collection_details->collectionName(), |
|
201 | - $this->collection_details |
|
202 | - ); |
|
203 | - return CollectionLoader::ENTITY_NOT_ADDED; |
|
204 | - } |
|
164 | + /** |
|
165 | + * @param $entity |
|
166 | + * @param mixed $identifier |
|
167 | + * @return string |
|
168 | + * @throws InvalidEntityException |
|
169 | + */ |
|
170 | + protected function addEntityToCollection($entity, $identifier) |
|
171 | + { |
|
172 | + do_action( |
|
173 | + 'FHEE__CollectionLoader__addEntityToCollection__entity', |
|
174 | + $entity, |
|
175 | + $this->collection_details->collectionName(), |
|
176 | + $this->collection_details |
|
177 | + ); |
|
178 | + $identifier = $this->setIdentifier($entity, $identifier); |
|
179 | + if ($this->collection->has($identifier)) { |
|
180 | + do_action( |
|
181 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_already_added', |
|
182 | + $this, |
|
183 | + $this->collection_details->collectionName(), |
|
184 | + $this->collection_details |
|
185 | + ); |
|
186 | + return CollectionLoader::ENTITY_EXISTS; |
|
187 | + } |
|
188 | + if ($this->collection->add($entity, $identifier)) { |
|
189 | + do_action( |
|
190 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_added', |
|
191 | + $this, |
|
192 | + $this->collection_details->collectionName(), |
|
193 | + $this->collection_details |
|
194 | + ); |
|
195 | + return CollectionLoader::ENTITY_ADDED; |
|
196 | + } |
|
197 | + do_action( |
|
198 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
199 | + $this, |
|
200 | + $this->collection_details->collectionName(), |
|
201 | + $this->collection_details |
|
202 | + ); |
|
203 | + return CollectionLoader::ENTITY_NOT_ADDED; |
|
204 | + } |
|
205 | 205 | |
206 | 206 | |
207 | - /** |
|
208 | - * @param $entity |
|
209 | - * @param mixed $identifier |
|
210 | - * @return string |
|
211 | - * @throws InvalidEntityException |
|
212 | - */ |
|
213 | - protected function setIdentifier($entity, $identifier) |
|
214 | - { |
|
215 | - switch ($this->collection_details->identifierType()) { |
|
216 | - // every unique object gets added to the collection, but not duplicates of the exact same object |
|
217 | - case CollectionDetails::ID_OBJECT_HASH: |
|
218 | - $identifier = spl_object_hash($entity); |
|
219 | - break; |
|
220 | - // only one entity per class can be added to collection, like a singleton |
|
221 | - case CollectionDetails::ID_CLASS_NAME: |
|
222 | - $identifier = get_class($entity); |
|
223 | - break; |
|
224 | - // objects added to the collection based on entity callback, so the entity itself decides |
|
225 | - case CollectionDetails::ID_CALLBACK_METHOD: |
|
226 | - $identifier_callback = $this->collection_details->identifierCallback(); |
|
227 | - if (! method_exists($entity, $identifier_callback)) { |
|
228 | - throw new InvalidEntityException( |
|
229 | - $entity, |
|
230 | - $this->collection_details->getCollectionInterface(), |
|
231 | - sprintf( |
|
232 | - __( |
|
233 | - 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
207 | + /** |
|
208 | + * @param $entity |
|
209 | + * @param mixed $identifier |
|
210 | + * @return string |
|
211 | + * @throws InvalidEntityException |
|
212 | + */ |
|
213 | + protected function setIdentifier($entity, $identifier) |
|
214 | + { |
|
215 | + switch ($this->collection_details->identifierType()) { |
|
216 | + // every unique object gets added to the collection, but not duplicates of the exact same object |
|
217 | + case CollectionDetails::ID_OBJECT_HASH: |
|
218 | + $identifier = spl_object_hash($entity); |
|
219 | + break; |
|
220 | + // only one entity per class can be added to collection, like a singleton |
|
221 | + case CollectionDetails::ID_CLASS_NAME: |
|
222 | + $identifier = get_class($entity); |
|
223 | + break; |
|
224 | + // objects added to the collection based on entity callback, so the entity itself decides |
|
225 | + case CollectionDetails::ID_CALLBACK_METHOD: |
|
226 | + $identifier_callback = $this->collection_details->identifierCallback(); |
|
227 | + if (! method_exists($entity, $identifier_callback)) { |
|
228 | + throw new InvalidEntityException( |
|
229 | + $entity, |
|
230 | + $this->collection_details->getCollectionInterface(), |
|
231 | + sprintf( |
|
232 | + __( |
|
233 | + 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
234 | 234 | of "%2$s", but does not contain this method.', |
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - $identifier_callback, |
|
238 | - get_class($entity) |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - $identifier = $entity->{$identifier_callback}(); |
|
243 | - break; |
|
244 | - } |
|
245 | - return apply_filters( |
|
246 | - 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
247 | - $identifier, |
|
248 | - $this->collection_details->collectionName(), |
|
249 | - $this->collection_details |
|
250 | - ); |
|
251 | - } |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + $identifier_callback, |
|
238 | + get_class($entity) |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + $identifier = $entity->{$identifier_callback}(); |
|
243 | + break; |
|
244 | + } |
|
245 | + return apply_filters( |
|
246 | + 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
|
247 | + $identifier, |
|
248 | + $this->collection_details->collectionName(), |
|
249 | + $this->collection_details |
|
250 | + ); |
|
251 | + } |
|
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * @throws ReflectionException |
|
256 | - * @throws InvalidArgumentException |
|
257 | - * @throws InvalidInterfaceException |
|
258 | - * @throws EE_Error |
|
259 | - * @throws InvalidClassException |
|
260 | - * @throws InvalidDataTypeException |
|
261 | - * @throws InvalidEntityException |
|
262 | - */ |
|
263 | - protected function loadFromFQCNs() |
|
264 | - { |
|
265 | - $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
266 | - $FQCNs = (array) apply_filters( |
|
267 | - 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
268 | - $FQCNs, |
|
269 | - $this->collection_details->collectionName(), |
|
270 | - $this->collection_details |
|
271 | - ); |
|
272 | - foreach ($FQCNs as $FQCN) { |
|
273 | - $this->loadClassFromFQCN($FQCN); |
|
274 | - } |
|
275 | - } |
|
254 | + /** |
|
255 | + * @throws ReflectionException |
|
256 | + * @throws InvalidArgumentException |
|
257 | + * @throws InvalidInterfaceException |
|
258 | + * @throws EE_Error |
|
259 | + * @throws InvalidClassException |
|
260 | + * @throws InvalidDataTypeException |
|
261 | + * @throws InvalidEntityException |
|
262 | + */ |
|
263 | + protected function loadFromFQCNs() |
|
264 | + { |
|
265 | + $FQCNs = $this->collection_details->getCollectionFQCNs(); |
|
266 | + $FQCNs = (array) apply_filters( |
|
267 | + 'FHEE__CollectionLoader__loadAllFromFQCNs__FQCNs', |
|
268 | + $FQCNs, |
|
269 | + $this->collection_details->collectionName(), |
|
270 | + $this->collection_details |
|
271 | + ); |
|
272 | + foreach ($FQCNs as $FQCN) { |
|
273 | + $this->loadClassFromFQCN($FQCN); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | 277 | |
278 | - /** |
|
279 | - * @param string $FQCN Fully Qualified Class Name |
|
280 | - * @return string |
|
281 | - * @throws InvalidArgumentException |
|
282 | - * @throws InvalidInterfaceException |
|
283 | - * @throws ReflectionException |
|
284 | - * @throws EE_Error |
|
285 | - * @throws InvalidEntityException |
|
286 | - * @throws InvalidDataTypeException |
|
287 | - * @throws InvalidClassException |
|
288 | - */ |
|
289 | - protected function loadClassFromFQCN($FQCN) |
|
290 | - { |
|
291 | - if (! is_string($FQCN)) { |
|
292 | - throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
293 | - } |
|
294 | - if (! class_exists($FQCN)) { |
|
295 | - throw new InvalidClassException($FQCN); |
|
296 | - } |
|
297 | - return $this->addEntityToCollection( |
|
298 | - EE_Registry::instance()->create($FQCN), |
|
299 | - $FQCN |
|
300 | - ); |
|
301 | - } |
|
278 | + /** |
|
279 | + * @param string $FQCN Fully Qualified Class Name |
|
280 | + * @return string |
|
281 | + * @throws InvalidArgumentException |
|
282 | + * @throws InvalidInterfaceException |
|
283 | + * @throws ReflectionException |
|
284 | + * @throws EE_Error |
|
285 | + * @throws InvalidEntityException |
|
286 | + * @throws InvalidDataTypeException |
|
287 | + * @throws InvalidClassException |
|
288 | + */ |
|
289 | + protected function loadClassFromFQCN($FQCN) |
|
290 | + { |
|
291 | + if (! is_string($FQCN)) { |
|
292 | + throw new InvalidDataTypeException('$FQCN', $FQCN, 'string'); |
|
293 | + } |
|
294 | + if (! class_exists($FQCN)) { |
|
295 | + throw new InvalidClassException($FQCN); |
|
296 | + } |
|
297 | + return $this->addEntityToCollection( |
|
298 | + EE_Registry::instance()->create($FQCN), |
|
299 | + $FQCN |
|
300 | + ); |
|
301 | + } |
|
302 | 302 | } |
@@ -16,30 +16,30 @@ |
||
16 | 16 | class InvalidEntityException extends InvalidArgumentException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidEntityException constructor. |
|
21 | - * |
|
22 | - * @param mixed $actual the actual object (or thing) we got |
|
23 | - * @param string $expected classname of the entity we wanted |
|
24 | - * @param string $message |
|
25 | - * @param int $code |
|
26 | - * @param Exception $previous |
|
27 | - */ |
|
28 | - public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | - { |
|
30 | - if (empty($message)) { |
|
31 | - $message = sprintf( |
|
32 | - __( |
|
33 | - 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - is_object($actual) |
|
37 | - ? get_class($actual) |
|
38 | - : gettype($actual), |
|
39 | - $expected, |
|
40 | - var_export($actual, true) |
|
41 | - ); |
|
42 | - } |
|
43 | - parent::__construct($message, $code, $previous); |
|
44 | - } |
|
19 | + /** |
|
20 | + * InvalidEntityException constructor. |
|
21 | + * |
|
22 | + * @param mixed $actual the actual object (or thing) we got |
|
23 | + * @param string $expected classname of the entity we wanted |
|
24 | + * @param string $message |
|
25 | + * @param int $code |
|
26 | + * @param Exception $previous |
|
27 | + */ |
|
28 | + public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | + { |
|
30 | + if (empty($message)) { |
|
31 | + $message = sprintf( |
|
32 | + __( |
|
33 | + 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + is_object($actual) |
|
37 | + ? get_class($actual) |
|
38 | + : gettype($actual), |
|
39 | + $expected, |
|
40 | + var_export($actual, true) |
|
41 | + ); |
|
42 | + } |
|
43 | + parent::__construct($message, $code, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -23,246 +23,246 @@ |
||
23 | 23 | abstract class EditorBlock implements EditorBlockInterface |
24 | 24 | { |
25 | 25 | |
26 | - const NS = 'event-espresso/'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var DomainInterface $domain |
|
30 | - */ |
|
31 | - protected $domain; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var LoaderInterface $loader |
|
35 | - */ |
|
36 | - protected $loader; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @var Registry |
|
41 | - */ |
|
42 | - protected $assets_registry; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string $editor_block_type |
|
46 | - */ |
|
47 | - private $editor_block_type; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var WP_Block_Type $wp_block_type |
|
51 | - */ |
|
52 | - private $wp_block_type; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $supported_post_types |
|
56 | - */ |
|
57 | - private $supported_post_types; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var array $attributes |
|
61 | - */ |
|
62 | - private $attributes; |
|
63 | - |
|
64 | - /** |
|
65 | - * If set to true, then the block will render its content client side |
|
66 | - * If false, then the block will render its content server side using the renderBlock() method |
|
67 | - * |
|
68 | - * @var bool $dynamic |
|
69 | - */ |
|
70 | - private $dynamic = false; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * EditorBlockLoader constructor. |
|
75 | - * |
|
76 | - * @param DomainInterface $domain |
|
77 | - * @param LoaderInterface $loader |
|
78 | - * @param Registry $assets_registry |
|
79 | - */ |
|
80 | - public function __construct( |
|
81 | - DomainInterface $domain, |
|
82 | - LoaderInterface $loader, |
|
83 | - Registry $assets_registry |
|
84 | - ) { |
|
85 | - $this->domain = $domain; |
|
86 | - $this->loader = $loader; |
|
87 | - $this->assets_registry = $assets_registry; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function editorBlockType() |
|
95 | - { |
|
96 | - return $this->editor_block_type; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function namespacedEditorBlockType() |
|
104 | - { |
|
105 | - return EditorBlock::NS . $this->editor_block_type; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param string $editor_block_type |
|
111 | - */ |
|
112 | - protected function setEditorBlockType($editor_block_type) |
|
113 | - { |
|
114 | - $this->editor_block_type = $editor_block_type; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @param WP_Block_Type $wp_block_type |
|
120 | - */ |
|
121 | - protected function setWpBlockType($wp_block_type) |
|
122 | - { |
|
123 | - $this->wp_block_type = $wp_block_type; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param array $supported_post_types |
|
129 | - */ |
|
130 | - protected function setSupportedPostTypes(array $supported_post_types) |
|
131 | - { |
|
132 | - $this->supported_post_types = $supported_post_types; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function attributes() |
|
140 | - { |
|
141 | - return $this->attributes; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param array $attributes |
|
147 | - */ |
|
148 | - public function setAttributes(array $attributes) |
|
149 | - { |
|
150 | - $this->attributes = $attributes; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function isDynamic() |
|
158 | - { |
|
159 | - return $this->dynamic; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param bool $dynamic |
|
165 | - */ |
|
166 | - public function setDynamic($dynamic = true) |
|
167 | - { |
|
168 | - $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Registers the Editor Block with WP core; |
|
174 | - * Returns the registered block type on success, or false on failure. |
|
175 | - * |
|
176 | - * @return WP_Block_Type|false |
|
177 | - */ |
|
178 | - public function registerBlock() |
|
179 | - { |
|
180 | - $context ='core'; |
|
181 | - // todo add route detection (ie inject route) and change context based on route |
|
182 | - $args = array( |
|
183 | - 'attributes' => $this->attributes(), |
|
184 | - 'editor_script' => "ee-{$context}-blocks", |
|
185 | - 'editor_style' => "ee-{$context}-blocks", |
|
186 | - 'script' => "ee-{$context}-blocks", |
|
187 | - 'style' => "ee-{$context}-blocks", |
|
188 | - ); |
|
189 | - if (! $this->isDynamic()) { |
|
190 | - $args['render_callback'] = $this->renderBlock(); |
|
191 | - } |
|
192 | - $wp_block_type = register_block_type( |
|
193 | - new WP_Block_Type( |
|
194 | - $this->namespacedEditorBlockType(), |
|
195 | - $args |
|
196 | - ) |
|
197 | - ); |
|
198 | - $this->setWpBlockType($wp_block_type); |
|
199 | - return $wp_block_type; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
205 | - */ |
|
206 | - public function unRegisterBlock() |
|
207 | - { |
|
208 | - return unregister_block_type($this->namespacedEditorBlockType()); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * returns true if the block type applies for the supplied post type |
|
214 | - * and should be added to that post type's editor |
|
215 | - * |
|
216 | - * @param string $post_type |
|
217 | - * @return boolean |
|
218 | - */ |
|
219 | - public function appliesToPostType($post_type) |
|
220 | - { |
|
221 | - return in_array($post_type, $this->supported_post_types, true); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - public function getEditorContainer() |
|
229 | - { |
|
230 | - return array( |
|
231 | - $this->namespacedEditorBlockType(), |
|
232 | - array() |
|
233 | - ); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function registerScripts() |
|
241 | - { |
|
242 | - // wp_register_script( |
|
243 | - // 'core-blocks', |
|
244 | - // $this->domain->distributionAssetsUrl() . 'ee-core-blocks.dist.js', |
|
245 | - // array( |
|
246 | - // 'wp-blocks', // Provides useful functions and components for extending the editor |
|
247 | - // 'wp-i18n', // Provides localization functions |
|
248 | - // 'wp-element', // Provides React.Component |
|
249 | - // 'wp-components' // Provides many prebuilt components and controls |
|
250 | - // ), |
|
251 | - // filemtime($this->domain->distributionAssetsPath() . 'ee-core-blocks.dist.js') |
|
252 | - // ); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - public function registerStyles() |
|
260 | - { |
|
261 | - // wp_register_style( |
|
262 | - // 'ee-block-styles', |
|
263 | - // $this->domain->distributionAssetsUrl() . 'style.css', |
|
264 | - // array(), |
|
265 | - // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
266 | - // ); |
|
267 | - } |
|
26 | + const NS = 'event-espresso/'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var DomainInterface $domain |
|
30 | + */ |
|
31 | + protected $domain; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var LoaderInterface $loader |
|
35 | + */ |
|
36 | + protected $loader; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @var Registry |
|
41 | + */ |
|
42 | + protected $assets_registry; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string $editor_block_type |
|
46 | + */ |
|
47 | + private $editor_block_type; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var WP_Block_Type $wp_block_type |
|
51 | + */ |
|
52 | + private $wp_block_type; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $supported_post_types |
|
56 | + */ |
|
57 | + private $supported_post_types; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var array $attributes |
|
61 | + */ |
|
62 | + private $attributes; |
|
63 | + |
|
64 | + /** |
|
65 | + * If set to true, then the block will render its content client side |
|
66 | + * If false, then the block will render its content server side using the renderBlock() method |
|
67 | + * |
|
68 | + * @var bool $dynamic |
|
69 | + */ |
|
70 | + private $dynamic = false; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * EditorBlockLoader constructor. |
|
75 | + * |
|
76 | + * @param DomainInterface $domain |
|
77 | + * @param LoaderInterface $loader |
|
78 | + * @param Registry $assets_registry |
|
79 | + */ |
|
80 | + public function __construct( |
|
81 | + DomainInterface $domain, |
|
82 | + LoaderInterface $loader, |
|
83 | + Registry $assets_registry |
|
84 | + ) { |
|
85 | + $this->domain = $domain; |
|
86 | + $this->loader = $loader; |
|
87 | + $this->assets_registry = $assets_registry; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function editorBlockType() |
|
95 | + { |
|
96 | + return $this->editor_block_type; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function namespacedEditorBlockType() |
|
104 | + { |
|
105 | + return EditorBlock::NS . $this->editor_block_type; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param string $editor_block_type |
|
111 | + */ |
|
112 | + protected function setEditorBlockType($editor_block_type) |
|
113 | + { |
|
114 | + $this->editor_block_type = $editor_block_type; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @param WP_Block_Type $wp_block_type |
|
120 | + */ |
|
121 | + protected function setWpBlockType($wp_block_type) |
|
122 | + { |
|
123 | + $this->wp_block_type = $wp_block_type; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param array $supported_post_types |
|
129 | + */ |
|
130 | + protected function setSupportedPostTypes(array $supported_post_types) |
|
131 | + { |
|
132 | + $this->supported_post_types = $supported_post_types; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function attributes() |
|
140 | + { |
|
141 | + return $this->attributes; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param array $attributes |
|
147 | + */ |
|
148 | + public function setAttributes(array $attributes) |
|
149 | + { |
|
150 | + $this->attributes = $attributes; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function isDynamic() |
|
158 | + { |
|
159 | + return $this->dynamic; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param bool $dynamic |
|
165 | + */ |
|
166 | + public function setDynamic($dynamic = true) |
|
167 | + { |
|
168 | + $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Registers the Editor Block with WP core; |
|
174 | + * Returns the registered block type on success, or false on failure. |
|
175 | + * |
|
176 | + * @return WP_Block_Type|false |
|
177 | + */ |
|
178 | + public function registerBlock() |
|
179 | + { |
|
180 | + $context ='core'; |
|
181 | + // todo add route detection (ie inject route) and change context based on route |
|
182 | + $args = array( |
|
183 | + 'attributes' => $this->attributes(), |
|
184 | + 'editor_script' => "ee-{$context}-blocks", |
|
185 | + 'editor_style' => "ee-{$context}-blocks", |
|
186 | + 'script' => "ee-{$context}-blocks", |
|
187 | + 'style' => "ee-{$context}-blocks", |
|
188 | + ); |
|
189 | + if (! $this->isDynamic()) { |
|
190 | + $args['render_callback'] = $this->renderBlock(); |
|
191 | + } |
|
192 | + $wp_block_type = register_block_type( |
|
193 | + new WP_Block_Type( |
|
194 | + $this->namespacedEditorBlockType(), |
|
195 | + $args |
|
196 | + ) |
|
197 | + ); |
|
198 | + $this->setWpBlockType($wp_block_type); |
|
199 | + return $wp_block_type; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
205 | + */ |
|
206 | + public function unRegisterBlock() |
|
207 | + { |
|
208 | + return unregister_block_type($this->namespacedEditorBlockType()); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * returns true if the block type applies for the supplied post type |
|
214 | + * and should be added to that post type's editor |
|
215 | + * |
|
216 | + * @param string $post_type |
|
217 | + * @return boolean |
|
218 | + */ |
|
219 | + public function appliesToPostType($post_type) |
|
220 | + { |
|
221 | + return in_array($post_type, $this->supported_post_types, true); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + public function getEditorContainer() |
|
229 | + { |
|
230 | + return array( |
|
231 | + $this->namespacedEditorBlockType(), |
|
232 | + array() |
|
233 | + ); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function registerScripts() |
|
241 | + { |
|
242 | + // wp_register_script( |
|
243 | + // 'core-blocks', |
|
244 | + // $this->domain->distributionAssetsUrl() . 'ee-core-blocks.dist.js', |
|
245 | + // array( |
|
246 | + // 'wp-blocks', // Provides useful functions and components for extending the editor |
|
247 | + // 'wp-i18n', // Provides localization functions |
|
248 | + // 'wp-element', // Provides React.Component |
|
249 | + // 'wp-components' // Provides many prebuilt components and controls |
|
250 | + // ), |
|
251 | + // filemtime($this->domain->distributionAssetsPath() . 'ee-core-blocks.dist.js') |
|
252 | + // ); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + public function registerStyles() |
|
260 | + { |
|
261 | + // wp_register_style( |
|
262 | + // 'ee-block-styles', |
|
263 | + // $this->domain->distributionAssetsUrl() . 'style.css', |
|
264 | + // array(), |
|
265 | + // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
266 | + // ); |
|
267 | + } |
|
268 | 268 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function namespacedEditorBlockType() |
104 | 104 | { |
105 | - return EditorBlock::NS . $this->editor_block_type; |
|
105 | + return EditorBlock::NS.$this->editor_block_type; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function registerBlock() |
179 | 179 | { |
180 | - $context ='core'; |
|
180 | + $context = 'core'; |
|
181 | 181 | // todo add route detection (ie inject route) and change context based on route |
182 | - $args = array( |
|
182 | + $args = array( |
|
183 | 183 | 'attributes' => $this->attributes(), |
184 | 184 | 'editor_script' => "ee-{$context}-blocks", |
185 | 185 | 'editor_style' => "ee-{$context}-blocks", |
186 | 186 | 'script' => "ee-{$context}-blocks", |
187 | 187 | 'style' => "ee-{$context}-blocks", |
188 | 188 | ); |
189 | - if (! $this->isDynamic()) { |
|
189 | + if ( ! $this->isDynamic()) { |
|
190 | 190 | $args['render_callback'] = $this->renderBlock(); |
191 | 191 | } |
192 | 192 | $wp_block_type = register_block_type( |