@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | /** @var Asset $asset */ |
76 | 76 | $asset = $this->current(); |
77 | 77 | if ($asset->type() === $type) { |
78 | - $files[ $asset->handle() ] = $asset; |
|
78 | + $files[$asset->handle()] = $asset; |
|
79 | 79 | } |
80 | 80 | $this->next(); |
81 | 81 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | /** @var JavascriptAsset $asset */ |
97 | 97 | $asset = $this->current(); |
98 | 98 | if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
99 | - $files[ $asset->handle() ] = $asset; |
|
99 | + $files[$asset->handle()] = $asset; |
|
100 | 100 | } |
101 | 101 | $this->next(); |
102 | 102 | } |
@@ -21,192 +21,192 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * AssetCollection constructor |
|
26 | - * |
|
27 | - * @throws InvalidInterfaceException |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @return StylesheetAsset[] |
|
37 | - * @since 4.9.62.p |
|
38 | - */ |
|
39 | - public function getStylesheetAssets() |
|
40 | - { |
|
41 | - return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return JavascriptAsset[] |
|
47 | - * @since 4.9.62.p |
|
48 | - */ |
|
49 | - public function getJavascriptAssets() |
|
50 | - { |
|
51 | - return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return ManifestFile[] |
|
57 | - * @since 4.9.62.p |
|
58 | - */ |
|
59 | - public function getManifestFiles() |
|
60 | - { |
|
61 | - return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param $type |
|
67 | - * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[] |
|
68 | - * @since 4.9.62.p |
|
69 | - */ |
|
70 | - protected function getAssetsOfType($type) |
|
71 | - { |
|
72 | - $files = array(); |
|
73 | - $this->rewind(); |
|
74 | - while ($this->valid()) { |
|
75 | - /** @var Asset $asset */ |
|
76 | - $asset = $this->current(); |
|
77 | - if ($asset->type() === $type) { |
|
78 | - $files[ $asset->handle() ] = $asset; |
|
79 | - } |
|
80 | - $this->next(); |
|
81 | - } |
|
82 | - $this->rewind(); |
|
83 | - return $files; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @return JavascriptAsset[] |
|
89 | - * @since 4.9.62.p |
|
90 | - */ |
|
91 | - public function getJavascriptAssetsWithData() |
|
92 | - { |
|
93 | - $files = array(); |
|
94 | - $this->rewind(); |
|
95 | - while ($this->valid()) { |
|
96 | - /** @var JavascriptAsset $asset */ |
|
97 | - $asset = $this->current(); |
|
98 | - if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
|
99 | - $files[ $asset->handle() ] = $asset; |
|
100 | - } |
|
101 | - $this->next(); |
|
102 | - } |
|
103 | - $this->rewind(); |
|
104 | - return $files; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * returns TRUE or FALSE |
|
110 | - * depending on whether the object is within the Collection |
|
111 | - * based on the supplied $identifier and type |
|
112 | - * |
|
113 | - * @param mixed $identifier |
|
114 | - * @param string $type |
|
115 | - * @return bool |
|
116 | - * @since 4.9.63.p |
|
117 | - */ |
|
118 | - public function hasAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
119 | - { |
|
120 | - $this->rewind(); |
|
121 | - while ($this->valid()) { |
|
122 | - if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
123 | - $this->rewind(); |
|
124 | - return true; |
|
125 | - } |
|
126 | - $this->next(); |
|
127 | - } |
|
128 | - return false; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * returns TRUE or FALSE |
|
134 | - * depending on whether the Javascript Asset is within the Collection |
|
135 | - * based on the supplied $identifier |
|
136 | - * |
|
137 | - * @param mixed $identifier |
|
138 | - * @return bool |
|
139 | - * @since 4.9.63.p |
|
140 | - */ |
|
141 | - public function hasJavascriptAsset($identifier) |
|
142 | - { |
|
143 | - return $this->hasAssetOfType($identifier, Asset::TYPE_JS); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * returns TRUE or FALSE |
|
149 | - * depending on whether the Stylesheet Asset is within the Collection |
|
150 | - * based on the supplied $identifier |
|
151 | - * |
|
152 | - * @param mixed $identifier |
|
153 | - * @return bool |
|
154 | - * @since 4.9.63.p |
|
155 | - */ |
|
156 | - public function hasStylesheetAsset($identifier) |
|
157 | - { |
|
158 | - return $this->hasAssetOfType($identifier, Asset::TYPE_CSS); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * returns the object from the Collection |
|
163 | - * based on the supplied $identifier and type |
|
164 | - * |
|
165 | - * @param mixed $identifier |
|
166 | - * @param string $type |
|
167 | - * @return JavascriptAsset|StylesheetAsset |
|
168 | - * @since 4.9.63.p |
|
169 | - */ |
|
170 | - public function getAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
171 | - { |
|
172 | - $this->rewind(); |
|
173 | - while ($this->valid()) { |
|
174 | - if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
175 | - /** @var JavascriptAsset|StylesheetAsset $object */ |
|
176 | - $object = $this->current(); |
|
177 | - $this->rewind(); |
|
178 | - return $object; |
|
179 | - } |
|
180 | - $this->next(); |
|
181 | - } |
|
182 | - return null; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * returns the Stylesheet Asset from the Collection |
|
188 | - * based on the supplied $identifier |
|
189 | - * |
|
190 | - * @param mixed $identifier |
|
191 | - * @return StylesheetAsset |
|
192 | - * @since 4.9.63.p |
|
193 | - */ |
|
194 | - public function getStylesheetAsset($identifier) |
|
195 | - { |
|
196 | - return $this->getAssetOfType($identifier, Asset::TYPE_CSS); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * returns the Javascript Asset from the Collection |
|
202 | - * based on the supplied $identifier |
|
203 | - * |
|
204 | - * @param mixed $identifier |
|
205 | - * @return JavascriptAsset |
|
206 | - * @since 4.9.63.p |
|
207 | - */ |
|
208 | - public function getJavascriptAsset($identifier) |
|
209 | - { |
|
210 | - return $this->getAssetOfType($identifier, Asset::TYPE_JS); |
|
211 | - } |
|
24 | + /** |
|
25 | + * AssetCollection constructor |
|
26 | + * |
|
27 | + * @throws InvalidInterfaceException |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @return StylesheetAsset[] |
|
37 | + * @since 4.9.62.p |
|
38 | + */ |
|
39 | + public function getStylesheetAssets() |
|
40 | + { |
|
41 | + return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return JavascriptAsset[] |
|
47 | + * @since 4.9.62.p |
|
48 | + */ |
|
49 | + public function getJavascriptAssets() |
|
50 | + { |
|
51 | + return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return ManifestFile[] |
|
57 | + * @since 4.9.62.p |
|
58 | + */ |
|
59 | + public function getManifestFiles() |
|
60 | + { |
|
61 | + return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param $type |
|
67 | + * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[] |
|
68 | + * @since 4.9.62.p |
|
69 | + */ |
|
70 | + protected function getAssetsOfType($type) |
|
71 | + { |
|
72 | + $files = array(); |
|
73 | + $this->rewind(); |
|
74 | + while ($this->valid()) { |
|
75 | + /** @var Asset $asset */ |
|
76 | + $asset = $this->current(); |
|
77 | + if ($asset->type() === $type) { |
|
78 | + $files[ $asset->handle() ] = $asset; |
|
79 | + } |
|
80 | + $this->next(); |
|
81 | + } |
|
82 | + $this->rewind(); |
|
83 | + return $files; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @return JavascriptAsset[] |
|
89 | + * @since 4.9.62.p |
|
90 | + */ |
|
91 | + public function getJavascriptAssetsWithData() |
|
92 | + { |
|
93 | + $files = array(); |
|
94 | + $this->rewind(); |
|
95 | + while ($this->valid()) { |
|
96 | + /** @var JavascriptAsset $asset */ |
|
97 | + $asset = $this->current(); |
|
98 | + if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
|
99 | + $files[ $asset->handle() ] = $asset; |
|
100 | + } |
|
101 | + $this->next(); |
|
102 | + } |
|
103 | + $this->rewind(); |
|
104 | + return $files; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * returns TRUE or FALSE |
|
110 | + * depending on whether the object is within the Collection |
|
111 | + * based on the supplied $identifier and type |
|
112 | + * |
|
113 | + * @param mixed $identifier |
|
114 | + * @param string $type |
|
115 | + * @return bool |
|
116 | + * @since 4.9.63.p |
|
117 | + */ |
|
118 | + public function hasAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
119 | + { |
|
120 | + $this->rewind(); |
|
121 | + while ($this->valid()) { |
|
122 | + if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
123 | + $this->rewind(); |
|
124 | + return true; |
|
125 | + } |
|
126 | + $this->next(); |
|
127 | + } |
|
128 | + return false; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * returns TRUE or FALSE |
|
134 | + * depending on whether the Javascript Asset is within the Collection |
|
135 | + * based on the supplied $identifier |
|
136 | + * |
|
137 | + * @param mixed $identifier |
|
138 | + * @return bool |
|
139 | + * @since 4.9.63.p |
|
140 | + */ |
|
141 | + public function hasJavascriptAsset($identifier) |
|
142 | + { |
|
143 | + return $this->hasAssetOfType($identifier, Asset::TYPE_JS); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * returns TRUE or FALSE |
|
149 | + * depending on whether the Stylesheet Asset is within the Collection |
|
150 | + * based on the supplied $identifier |
|
151 | + * |
|
152 | + * @param mixed $identifier |
|
153 | + * @return bool |
|
154 | + * @since 4.9.63.p |
|
155 | + */ |
|
156 | + public function hasStylesheetAsset($identifier) |
|
157 | + { |
|
158 | + return $this->hasAssetOfType($identifier, Asset::TYPE_CSS); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * returns the object from the Collection |
|
163 | + * based on the supplied $identifier and type |
|
164 | + * |
|
165 | + * @param mixed $identifier |
|
166 | + * @param string $type |
|
167 | + * @return JavascriptAsset|StylesheetAsset |
|
168 | + * @since 4.9.63.p |
|
169 | + */ |
|
170 | + public function getAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
171 | + { |
|
172 | + $this->rewind(); |
|
173 | + while ($this->valid()) { |
|
174 | + if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
175 | + /** @var JavascriptAsset|StylesheetAsset $object */ |
|
176 | + $object = $this->current(); |
|
177 | + $this->rewind(); |
|
178 | + return $object; |
|
179 | + } |
|
180 | + $this->next(); |
|
181 | + } |
|
182 | + return null; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * returns the Stylesheet Asset from the Collection |
|
188 | + * based on the supplied $identifier |
|
189 | + * |
|
190 | + * @param mixed $identifier |
|
191 | + * @return StylesheetAsset |
|
192 | + * @since 4.9.63.p |
|
193 | + */ |
|
194 | + public function getStylesheetAsset($identifier) |
|
195 | + { |
|
196 | + return $this->getAssetOfType($identifier, Asset::TYPE_CSS); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * returns the Javascript Asset from the Collection |
|
202 | + * based on the supplied $identifier |
|
203 | + * |
|
204 | + * @param mixed $identifier |
|
205 | + * @return JavascriptAsset |
|
206 | + * @since 4.9.63.p |
|
207 | + */ |
|
208 | + public function getJavascriptAsset($identifier) |
|
209 | + { |
|
210 | + return $this->getAssetOfType($identifier, Asset::TYPE_JS); |
|
211 | + } |
|
212 | 212 | } |
@@ -81,7 +81,7 @@ |
||
81 | 81 | */ |
82 | 82 | public function namespacedBlockType() |
83 | 83 | { |
84 | - return self::NAME_SPACE . '/' . $this->block_type; |
|
84 | + return self::NAME_SPACE.'/'.$this->block_type; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 |
@@ -20,211 +20,211 @@ |
||
20 | 20 | */ |
21 | 21 | abstract class Block implements BlockInterface |
22 | 22 | { |
23 | - /** |
|
24 | - * BlockAssetManager that this editor block uses for asset registration |
|
25 | - * |
|
26 | - * @var BlockAssetManagerInterface $block_asset_manager |
|
27 | - */ |
|
28 | - protected $block_asset_manager; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var RequestInterface $request |
|
32 | - */ |
|
33 | - protected $request; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array $attributes |
|
37 | - */ |
|
38 | - private $attributes; |
|
39 | - |
|
40 | - /** |
|
41 | - * If set to true, then the block will render its content client side |
|
42 | - * If false, then the block will render its content server side using the renderBlock() method |
|
43 | - * |
|
44 | - * @var bool $dynamic |
|
45 | - */ |
|
46 | - private $dynamic = false; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string $block_type |
|
50 | - */ |
|
51 | - private $block_type; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var array $supported_routes |
|
55 | - */ |
|
56 | - private $supported_routes; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var WP_Block_Type $wp_block_type |
|
60 | - */ |
|
61 | - private $wp_block_type; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * BlockLoader constructor. |
|
66 | - * |
|
67 | - * @param BlockAssetManagerInterface $block_asset_manager |
|
68 | - * @param RequestInterface $request |
|
69 | - */ |
|
70 | - public function __construct(BlockAssetManagerInterface $block_asset_manager, RequestInterface $request) |
|
71 | - { |
|
72 | - $this->block_asset_manager = $block_asset_manager; |
|
73 | - $this->request = $request; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function blockType() |
|
81 | - { |
|
82 | - return $this->block_type; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function namespacedBlockType() |
|
90 | - { |
|
91 | - return self::NAME_SPACE . '/' . $this->block_type; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param string $block_type |
|
97 | - */ |
|
98 | - protected function setBlockType($block_type) |
|
99 | - { |
|
100 | - $this->block_type = $block_type; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * BlockAssetManager that this editor block uses for asset registration |
|
106 | - * |
|
107 | - * @return BlockAssetManagerInterface |
|
108 | - */ |
|
109 | - public function assetManager() |
|
110 | - { |
|
111 | - return $this->block_asset_manager; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param WP_Block_Type $wp_block_type |
|
117 | - */ |
|
118 | - protected function setWpBlockType($wp_block_type) |
|
119 | - { |
|
120 | - $this->wp_block_type = $wp_block_type; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * returns an array of fully qualified class names |
|
125 | - * for RouteMatchSpecificationInterface objects |
|
126 | - * that specify routes that the block should be loaded for. |
|
127 | - * |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function supportedRoutes() |
|
131 | - { |
|
132 | - return $this->supported_routes; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param array $supported_routes |
|
138 | - */ |
|
139 | - protected function setSupportedRoutes(array $supported_routes) |
|
140 | - { |
|
141 | - $this->supported_routes = $supported_routes; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - public function attributes() |
|
149 | - { |
|
150 | - return $this->attributes; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param array $attributes |
|
156 | - */ |
|
157 | - public function setAttributes(array $attributes) |
|
158 | - { |
|
159 | - $this->attributes = $attributes; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @return bool |
|
165 | - */ |
|
166 | - public function isDynamic() |
|
167 | - { |
|
168 | - return $this->dynamic; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * @param bool $dynamic |
|
174 | - */ |
|
175 | - public function setDynamic($dynamic = true) |
|
176 | - { |
|
177 | - $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Registers the Editor Block with WP core; |
|
183 | - * Returns the registered block type on success, or false on failure. |
|
184 | - * |
|
185 | - * @return WP_Block_Type|false |
|
186 | - */ |
|
187 | - public function registerBlock() |
|
188 | - { |
|
189 | - $args = array( |
|
190 | - 'attributes' => $this->attributes(), |
|
191 | - 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
192 | - 'editor_style' => $this->block_asset_manager->getEditorStyleHandle(), |
|
193 | - 'script' => $this->block_asset_manager->getScriptHandle(), |
|
194 | - 'style' => $this->block_asset_manager->getStyleHandle(), |
|
195 | - ); |
|
196 | - if ($this->isDynamic()) { |
|
197 | - $args['render_callback'] = array($this, 'renderBlock'); |
|
198 | - } |
|
199 | - $wp_block_type = register_block_type( |
|
200 | - new WP_Block_Type( |
|
201 | - $this->namespacedBlockType(), |
|
202 | - $args |
|
203 | - ) |
|
204 | - ); |
|
205 | - $this->setWpBlockType($wp_block_type); |
|
206 | - return $wp_block_type; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
212 | - */ |
|
213 | - public function unRegisterBlock() |
|
214 | - { |
|
215 | - return unregister_block_type($this->namespacedBlockType()); |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @return array |
|
222 | - */ |
|
223 | - public function getEditorContainer() |
|
224 | - { |
|
225 | - return array( |
|
226 | - $this->namespacedBlockType(), |
|
227 | - array(), |
|
228 | - ); |
|
229 | - } |
|
23 | + /** |
|
24 | + * BlockAssetManager that this editor block uses for asset registration |
|
25 | + * |
|
26 | + * @var BlockAssetManagerInterface $block_asset_manager |
|
27 | + */ |
|
28 | + protected $block_asset_manager; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var RequestInterface $request |
|
32 | + */ |
|
33 | + protected $request; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array $attributes |
|
37 | + */ |
|
38 | + private $attributes; |
|
39 | + |
|
40 | + /** |
|
41 | + * If set to true, then the block will render its content client side |
|
42 | + * If false, then the block will render its content server side using the renderBlock() method |
|
43 | + * |
|
44 | + * @var bool $dynamic |
|
45 | + */ |
|
46 | + private $dynamic = false; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string $block_type |
|
50 | + */ |
|
51 | + private $block_type; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var array $supported_routes |
|
55 | + */ |
|
56 | + private $supported_routes; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var WP_Block_Type $wp_block_type |
|
60 | + */ |
|
61 | + private $wp_block_type; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * BlockLoader constructor. |
|
66 | + * |
|
67 | + * @param BlockAssetManagerInterface $block_asset_manager |
|
68 | + * @param RequestInterface $request |
|
69 | + */ |
|
70 | + public function __construct(BlockAssetManagerInterface $block_asset_manager, RequestInterface $request) |
|
71 | + { |
|
72 | + $this->block_asset_manager = $block_asset_manager; |
|
73 | + $this->request = $request; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function blockType() |
|
81 | + { |
|
82 | + return $this->block_type; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function namespacedBlockType() |
|
90 | + { |
|
91 | + return self::NAME_SPACE . '/' . $this->block_type; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param string $block_type |
|
97 | + */ |
|
98 | + protected function setBlockType($block_type) |
|
99 | + { |
|
100 | + $this->block_type = $block_type; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * BlockAssetManager that this editor block uses for asset registration |
|
106 | + * |
|
107 | + * @return BlockAssetManagerInterface |
|
108 | + */ |
|
109 | + public function assetManager() |
|
110 | + { |
|
111 | + return $this->block_asset_manager; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param WP_Block_Type $wp_block_type |
|
117 | + */ |
|
118 | + protected function setWpBlockType($wp_block_type) |
|
119 | + { |
|
120 | + $this->wp_block_type = $wp_block_type; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * returns an array of fully qualified class names |
|
125 | + * for RouteMatchSpecificationInterface objects |
|
126 | + * that specify routes that the block should be loaded for. |
|
127 | + * |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function supportedRoutes() |
|
131 | + { |
|
132 | + return $this->supported_routes; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param array $supported_routes |
|
138 | + */ |
|
139 | + protected function setSupportedRoutes(array $supported_routes) |
|
140 | + { |
|
141 | + $this->supported_routes = $supported_routes; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + public function attributes() |
|
149 | + { |
|
150 | + return $this->attributes; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param array $attributes |
|
156 | + */ |
|
157 | + public function setAttributes(array $attributes) |
|
158 | + { |
|
159 | + $this->attributes = $attributes; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @return bool |
|
165 | + */ |
|
166 | + public function isDynamic() |
|
167 | + { |
|
168 | + return $this->dynamic; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * @param bool $dynamic |
|
174 | + */ |
|
175 | + public function setDynamic($dynamic = true) |
|
176 | + { |
|
177 | + $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Registers the Editor Block with WP core; |
|
183 | + * Returns the registered block type on success, or false on failure. |
|
184 | + * |
|
185 | + * @return WP_Block_Type|false |
|
186 | + */ |
|
187 | + public function registerBlock() |
|
188 | + { |
|
189 | + $args = array( |
|
190 | + 'attributes' => $this->attributes(), |
|
191 | + 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
192 | + 'editor_style' => $this->block_asset_manager->getEditorStyleHandle(), |
|
193 | + 'script' => $this->block_asset_manager->getScriptHandle(), |
|
194 | + 'style' => $this->block_asset_manager->getStyleHandle(), |
|
195 | + ); |
|
196 | + if ($this->isDynamic()) { |
|
197 | + $args['render_callback'] = array($this, 'renderBlock'); |
|
198 | + } |
|
199 | + $wp_block_type = register_block_type( |
|
200 | + new WP_Block_Type( |
|
201 | + $this->namespacedBlockType(), |
|
202 | + $args |
|
203 | + ) |
|
204 | + ); |
|
205 | + $this->setWpBlockType($wp_block_type); |
|
206 | + return $wp_block_type; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
212 | + */ |
|
213 | + public function unRegisterBlock() |
|
214 | + { |
|
215 | + return unregister_block_type($this->namespacedBlockType()); |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @return array |
|
222 | + */ |
|
223 | + public function getEditorContainer() |
|
224 | + { |
|
225 | + return array( |
|
226 | + $this->namespacedBlockType(), |
|
227 | + array(), |
|
228 | + ); |
|
229 | + } |
|
230 | 230 | } |
@@ -447,8 +447,8 @@ discard block |
||
447 | 447 | $this->organization_config->instagram = isset($form_data['organization_instagram']) |
448 | 448 | ? esc_url_raw($form_data['organization_instagram']) |
449 | 449 | : $this->organization_config->instagram; |
450 | - $this->core_config->ee_ueip_optin = isset($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0]) |
|
451 | - ? filter_var($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0], FILTER_VALIDATE_BOOLEAN) |
|
450 | + $this->core_config->ee_ueip_optin = isset($form_data[EE_Core_Config::OPTION_NAME_UXIP][0]) |
|
451 | + ? filter_var($form_data[EE_Core_Config::OPTION_NAME_UXIP][0], FILTER_VALIDATE_BOOLEAN) |
|
452 | 452 | : false; |
453 | 453 | $this->core_config->ee_ueip_has_notified = true; |
454 | 454 | |
@@ -479,10 +479,10 @@ discard block |
||
479 | 479 | if (empty($this->network_core_config->site_license_key)) { |
480 | 480 | return false; |
481 | 481 | } |
482 | - $ver_option_key = 'puvererr_' . basename(EE_PLUGIN_BASENAME); |
|
482 | + $ver_option_key = 'puvererr_'.basename(EE_PLUGIN_BASENAME); |
|
483 | 483 | $verify_fail = get_option($ver_option_key, false); |
484 | 484 | return $verify_fail === false |
485 | - || (! empty($this->network_core_config->site_license_key) |
|
485 | + || ( ! empty($this->network_core_config->site_license_key) |
|
486 | 486 | && $verify_fail === false |
487 | 487 | ); |
488 | 488 | } |
@@ -528,6 +528,6 @@ discard block |
||
528 | 528 | private function getValidationIndicator() |
529 | 529 | { |
530 | 530 | $verified_class = $this->licenseKeyVerified() ? 'ee-icon-color-ee-green' : 'ee-icon-color-ee-red'; |
531 | - return '<span class="dashicons dashicons-admin-network ' . $verified_class . ' ee-icon-size-20"></span>'; |
|
531 | + return '<span class="dashicons dashicons-admin-network '.$verified_class.' ee-icon-size-20"></span>'; |
|
532 | 532 | } |
533 | 533 | } |
@@ -43,530 +43,530 @@ |
||
43 | 43 | */ |
44 | 44 | class OrganizationSettings extends FormHandler |
45 | 45 | { |
46 | - /** |
|
47 | - * @var EE_Organization_Config |
|
48 | - */ |
|
49 | - protected $organization_config; |
|
46 | + /** |
|
47 | + * @var EE_Organization_Config |
|
48 | + */ |
|
49 | + protected $organization_config; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var EE_Core_Config |
|
53 | - */ |
|
54 | - protected $core_config; |
|
51 | + /** |
|
52 | + * @var EE_Core_Config |
|
53 | + */ |
|
54 | + protected $core_config; |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @var EE_Network_Core_Config |
|
59 | - */ |
|
60 | - protected $network_core_config; |
|
57 | + /** |
|
58 | + * @var EE_Network_Core_Config |
|
59 | + */ |
|
60 | + protected $network_core_config; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @var CountrySubRegionDao $countrySubRegionDao |
|
64 | - */ |
|
65 | - protected $countrySubRegionDao; |
|
62 | + /** |
|
63 | + * @var CountrySubRegionDao $countrySubRegionDao |
|
64 | + */ |
|
65 | + protected $countrySubRegionDao; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Form constructor. |
|
69 | - * |
|
70 | - * @param EE_Registry $registry |
|
71 | - * @param EE_Organization_Config $organization_config |
|
72 | - * @param EE_Core_Config $core_config |
|
73 | - * @param EE_Network_Core_Config $network_core_config |
|
74 | - * @param CountrySubRegionDao $countrySubRegionDao |
|
75 | - * @throws InvalidArgumentException |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws DomainException |
|
78 | - */ |
|
79 | - public function __construct( |
|
80 | - EE_Registry $registry, |
|
81 | - EE_Organization_Config $organization_config, |
|
82 | - EE_Core_Config $core_config, |
|
83 | - EE_Network_Core_Config $network_core_config, |
|
84 | - CountrySubRegionDao $countrySubRegionDao |
|
85 | - ) { |
|
86 | - $this->organization_config = $organization_config; |
|
87 | - $this->core_config = $core_config; |
|
88 | - $this->network_core_config = $network_core_config; |
|
89 | - $this->countrySubRegionDao = $countrySubRegionDao; |
|
90 | - parent::__construct( |
|
91 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
92 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
93 | - 'organization_settings', |
|
94 | - '', |
|
95 | - FormHandler::DO_NOT_SETUP_FORM, |
|
96 | - $registry |
|
97 | - ); |
|
98 | - } |
|
67 | + /** |
|
68 | + * Form constructor. |
|
69 | + * |
|
70 | + * @param EE_Registry $registry |
|
71 | + * @param EE_Organization_Config $organization_config |
|
72 | + * @param EE_Core_Config $core_config |
|
73 | + * @param EE_Network_Core_Config $network_core_config |
|
74 | + * @param CountrySubRegionDao $countrySubRegionDao |
|
75 | + * @throws InvalidArgumentException |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws DomainException |
|
78 | + */ |
|
79 | + public function __construct( |
|
80 | + EE_Registry $registry, |
|
81 | + EE_Organization_Config $organization_config, |
|
82 | + EE_Core_Config $core_config, |
|
83 | + EE_Network_Core_Config $network_core_config, |
|
84 | + CountrySubRegionDao $countrySubRegionDao |
|
85 | + ) { |
|
86 | + $this->organization_config = $organization_config; |
|
87 | + $this->core_config = $core_config; |
|
88 | + $this->network_core_config = $network_core_config; |
|
89 | + $this->countrySubRegionDao = $countrySubRegionDao; |
|
90 | + parent::__construct( |
|
91 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
92 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
93 | + 'organization_settings', |
|
94 | + '', |
|
95 | + FormHandler::DO_NOT_SETUP_FORM, |
|
96 | + $registry |
|
97 | + ); |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | - /** |
|
102 | - * creates and returns the actual form |
|
103 | - * |
|
104 | - * @return EE_Form_Section_Proper |
|
105 | - * @throws EE_Error |
|
106 | - * @throws InvalidArgumentException |
|
107 | - * @throws InvalidDataTypeException |
|
108 | - * @throws InvalidInterfaceException |
|
109 | - * @throws ReflectionException |
|
110 | - */ |
|
111 | - public function generate() |
|
112 | - { |
|
113 | - $has_sub_regions = EEM_State::instance()->count( |
|
114 | - array(array('Country.CNT_ISO' => $this->organization_config->CNT_ISO)) |
|
115 | - ); |
|
116 | - $form = new EE_Form_Section_Proper( |
|
117 | - array( |
|
118 | - 'name' => 'organization_settings', |
|
119 | - 'html_id' => 'organization_settings', |
|
120 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
121 | - 'subsections' => array( |
|
122 | - 'contact_information_hdr' => new EE_Form_Section_HTML( |
|
123 | - EEH_HTML::h2( |
|
124 | - esc_html__('Contact Information', 'event_espresso') |
|
125 | - . ' ' |
|
126 | - . EEH_HTML::span(EEH_Template::get_help_tab_link('contact_info_info')), |
|
127 | - '', |
|
128 | - 'contact-information-hdr' |
|
129 | - ) |
|
130 | - ), |
|
131 | - 'organization_name' => new EE_Text_Input( |
|
132 | - array( |
|
133 | - 'html_name' => 'organization_name', |
|
134 | - 'html_label_text' => esc_html__('Organization Name', 'event_espresso'), |
|
135 | - 'html_help_text' => esc_html__( |
|
136 | - 'Displayed on all emails and invoices.', |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - 'default' => $this->organization_config->get_pretty('name'), |
|
140 | - 'required' => false, |
|
141 | - ) |
|
142 | - ), |
|
143 | - 'organization_address_1' => new EE_Text_Input( |
|
144 | - array( |
|
145 | - 'html_name' => 'organization_address_1', |
|
146 | - 'html_label_text' => esc_html__('Street Address', 'event_espresso'), |
|
147 | - 'default' => $this->organization_config->get_pretty('address_1'), |
|
148 | - 'required' => false, |
|
149 | - ) |
|
150 | - ), |
|
151 | - 'organization_address_2' => new EE_Text_Input( |
|
152 | - array( |
|
153 | - 'html_name' => 'organization_address_2', |
|
154 | - 'html_label_text' => esc_html__('Street Address 2', 'event_espresso'), |
|
155 | - 'default' => $this->organization_config->get_pretty('address_2'), |
|
156 | - 'required' => false, |
|
157 | - ) |
|
158 | - ), |
|
159 | - 'organization_city' => new EE_Text_Input( |
|
160 | - array( |
|
161 | - 'html_name' => 'organization_city', |
|
162 | - 'html_label_text' => esc_html__('City', 'event_espresso'), |
|
163 | - 'default' => $this->organization_config->get_pretty('city'), |
|
164 | - 'required' => false, |
|
165 | - ) |
|
166 | - ), |
|
167 | - 'organization_country' => new EE_Country_Select_Input( |
|
168 | - null, |
|
169 | - array( |
|
170 | - EE_Country_Select_Input::OPTION_GET_KEY => EE_Country_Select_Input::OPTION_GET_ALL, |
|
171 | - 'html_name' => 'organization_country', |
|
172 | - 'html_label_text' => esc_html__('Country', 'event_espresso'), |
|
173 | - 'default' => $this->organization_config->CNT_ISO, |
|
174 | - 'required' => false, |
|
175 | - 'html_help_text' => sprintf( |
|
176 | - esc_html__( |
|
177 | - '%1$sThe Country set here will have the effect of setting the currency used for all ticket prices.%2$s', |
|
178 | - 'event_espresso' |
|
179 | - ), |
|
180 | - '<span class="reminder-spn">', |
|
181 | - '</span>' |
|
182 | - ), |
|
183 | - ) |
|
184 | - ), |
|
185 | - 'organization_state' => new EE_State_Select_Input( |
|
186 | - null, |
|
187 | - array( |
|
188 | - 'html_name' => 'organization_state', |
|
189 | - 'html_label_text' => esc_html__('State/Province', 'event_espresso'), |
|
190 | - 'default' => $this->organization_config->STA_ID, |
|
191 | - 'required' => false, |
|
192 | - 'html_help_text' => empty($this->organization_config->STA_ID) || ! $has_sub_regions |
|
193 | - ? sprintf( |
|
194 | - esc_html__( |
|
195 | - 'If the States/Provinces for the selected Country do not appear in this list, then click "Save".%3$sIf data exists, then the list will be populated when the page reloads and you will be able to make a selection at that time.%3$s%1$sMake sure you click "Save" again after selecting a State/Province that has just been loaded in order to keep that selection.%2$s', |
|
196 | - 'event_espresso' |
|
197 | - ), |
|
198 | - '<span class="reminder-spn">', |
|
199 | - '</span>', |
|
200 | - '<br />' |
|
201 | - ) |
|
202 | - : '', |
|
203 | - ) |
|
204 | - ), |
|
205 | - 'organization_zip' => new EE_Text_Input( |
|
206 | - array( |
|
207 | - 'html_name' => 'organization_zip', |
|
208 | - 'html_label_text' => esc_html__('Zip/Postal Code', 'event_espresso'), |
|
209 | - 'default' => $this->organization_config->get_pretty('zip'), |
|
210 | - 'required' => false, |
|
211 | - ) |
|
212 | - ), |
|
213 | - 'organization_email' => new EE_Text_Input( |
|
214 | - array( |
|
215 | - 'html_name' => 'organization_email', |
|
216 | - 'html_label_text' => esc_html__('Primary Contact Email', 'event_espresso'), |
|
217 | - 'html_help_text' => sprintf( |
|
218 | - esc_html__( |
|
219 | - 'This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', |
|
220 | - 'event_espresso' |
|
221 | - ), |
|
222 | - '<code>[CO_FORMATTED_EMAIL]</code>', |
|
223 | - '<code>[CO_EMAIL]</code>' |
|
224 | - ), |
|
225 | - 'default' => $this->organization_config->get_pretty('email'), |
|
226 | - 'required' => false, |
|
227 | - ) |
|
228 | - ), |
|
229 | - 'organization_phone' => new EE_Text_Input( |
|
230 | - array( |
|
231 | - 'html_name' => 'organization_phone', |
|
232 | - 'html_label_text' => esc_html__('Phone Number', 'event_espresso'), |
|
233 | - 'html_help_text' => esc_html__( |
|
234 | - 'The phone number for your organization.', |
|
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - 'default' => $this->organization_config->get_pretty('phone'), |
|
238 | - 'required' => false, |
|
239 | - ) |
|
240 | - ), |
|
241 | - 'organization_vat' => new EE_Text_Input( |
|
242 | - array( |
|
243 | - 'html_name' => 'organization_vat', |
|
244 | - 'html_label_text' => esc_html__('VAT/Tax Number', 'event_espresso'), |
|
245 | - 'html_help_text' => esc_html__( |
|
246 | - 'The VAT/Tax Number may be displayed on invoices and receipts.', |
|
247 | - 'event_espresso' |
|
248 | - ), |
|
249 | - 'default' => $this->organization_config->get_pretty('vat'), |
|
250 | - 'required' => false, |
|
251 | - ) |
|
252 | - ), |
|
253 | - 'company_logo_hdr' => new EE_Form_Section_HTML( |
|
254 | - EEH_HTML::h2( |
|
255 | - esc_html__('Company Logo', 'event_espresso') |
|
256 | - . ' ' |
|
257 | - . EEH_HTML::span(EEH_Template::get_help_tab_link('organization_logo_info')), |
|
258 | - '', |
|
259 | - 'company-logo-hdr' |
|
260 | - ) |
|
261 | - ), |
|
262 | - 'organization_logo_url' => new EE_Admin_File_Uploader_Input( |
|
263 | - array( |
|
264 | - 'html_name' => 'organization_logo_url', |
|
265 | - 'html_label_text' => esc_html__('Upload New Logo', 'event_espresso'), |
|
266 | - 'html_help_text' => esc_html__( |
|
267 | - 'Your logo will be used on custom invoices, tickets, certificates, and payment templates.', |
|
268 | - 'event_espresso' |
|
269 | - ), |
|
270 | - 'default' => $this->organization_config->get_pretty('logo_url'), |
|
271 | - 'required' => false, |
|
272 | - ) |
|
273 | - ), |
|
274 | - 'social_links_hdr' => new EE_Form_Section_HTML( |
|
275 | - EEH_HTML::h2( |
|
276 | - esc_html__('Social Links', 'event_espresso') |
|
277 | - . ' ' |
|
278 | - . EEH_HTML::span(EEH_Template::get_help_tab_link('social_links_info')) |
|
279 | - . EEH_HTML::br() |
|
280 | - . EEH_HTML::p( |
|
281 | - esc_html__( |
|
282 | - 'Enter any links to social accounts for your organization here', |
|
283 | - 'event_espresso' |
|
284 | - ), |
|
285 | - '', |
|
286 | - 'description' |
|
287 | - ), |
|
288 | - '', |
|
289 | - 'social-links-hdr' |
|
290 | - ) |
|
291 | - ), |
|
292 | - 'organization_facebook' => new EE_Text_Input( |
|
293 | - array( |
|
294 | - 'html_name' => 'organization_facebook', |
|
295 | - 'html_label_text' => esc_html__('Facebook', 'event_espresso'), |
|
296 | - 'other_html_attributes' => ' placeholder="facebook.com/profile.name"', |
|
297 | - 'default' => $this->organization_config->get_pretty('facebook'), |
|
298 | - 'required' => false, |
|
299 | - ) |
|
300 | - ), |
|
301 | - 'organization_twitter' => new EE_Text_Input( |
|
302 | - array( |
|
303 | - 'html_name' => 'organization_twitter', |
|
304 | - 'html_label_text' => esc_html__('Twitter', 'event_espresso'), |
|
305 | - 'other_html_attributes' => ' placeholder="twitter.com/twitterhandle"', |
|
306 | - 'default' => $this->organization_config->get_pretty('twitter'), |
|
307 | - 'required' => false, |
|
308 | - ) |
|
309 | - ), |
|
310 | - 'organization_linkedin' => new EE_Text_Input( |
|
311 | - array( |
|
312 | - 'html_name' => 'organization_linkedin', |
|
313 | - 'html_label_text' => esc_html__('LinkedIn', 'event_espresso'), |
|
314 | - 'other_html_attributes' => ' placeholder="linkedin.com/in/profilename"', |
|
315 | - 'default' => $this->organization_config->get_pretty('linkedin'), |
|
316 | - 'required' => false, |
|
317 | - ) |
|
318 | - ), |
|
319 | - 'organization_pinterest' => new EE_Text_Input( |
|
320 | - array( |
|
321 | - 'html_name' => 'organization_pinterest', |
|
322 | - 'html_label_text' => esc_html__('Pinterest', 'event_espresso'), |
|
323 | - 'other_html_attributes' => ' placeholder="pinterest.com/profilename"', |
|
324 | - 'default' => $this->organization_config->get_pretty('pinterest'), |
|
325 | - 'required' => false, |
|
326 | - ) |
|
327 | - ), |
|
328 | - 'organization_instagram' => new EE_Text_Input( |
|
329 | - array( |
|
330 | - 'html_name' => 'organization_instagram', |
|
331 | - 'html_label_text' => esc_html__('Instagram', 'event_espresso'), |
|
332 | - 'other_html_attributes' => ' placeholder="instagram.com/handle"', |
|
333 | - 'default' => $this->organization_config->get_pretty('instagram'), |
|
334 | - 'required' => false, |
|
335 | - ) |
|
336 | - ), |
|
337 | - ), |
|
338 | - ) |
|
339 | - ); |
|
340 | - if (is_main_site()) { |
|
341 | - $form->add_subsections( |
|
342 | - array( |
|
343 | - 'site_license_key_hdr' => new EE_Form_Section_HTML( |
|
344 | - EEH_HTML::h2( |
|
345 | - esc_html__('Your Event Espresso License Key', 'event_espresso') |
|
346 | - . ' ' |
|
347 | - . EEH_HTML::span( |
|
348 | - EEH_Template::get_help_tab_link('site_license_key_info') |
|
349 | - ), |
|
350 | - '', |
|
351 | - 'site-license-key-hdr' |
|
352 | - ) |
|
353 | - ), |
|
354 | - 'site_license_key' => $this->getSiteLicenseKeyField() |
|
355 | - ) |
|
356 | - ); |
|
357 | - $form->add_subsections( |
|
358 | - array( |
|
359 | - 'uxip_optin_hdr' => new EE_Form_Section_HTML( |
|
360 | - $this->uxipOptinText() |
|
361 | - ), |
|
362 | - 'ueip_optin' => new EE_Checkbox_Multi_Input( |
|
363 | - array( |
|
364 | - true => esc_html__('Yes! I want to help improve Event Espresso!', 'event_espresso') |
|
365 | - ), |
|
366 | - array( |
|
367 | - 'html_name' => EE_Core_Config::OPTION_NAME_UXIP, |
|
368 | - 'html_label_text' => esc_html__( |
|
369 | - 'UXIP Opt In?', |
|
370 | - 'event_espresso' |
|
371 | - ), |
|
372 | - 'default' => isset($this->core_config->ee_ueip_optin) |
|
373 | - ? filter_var($this->core_config->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN) |
|
374 | - : false, |
|
375 | - 'required' => false, |
|
376 | - ) |
|
377 | - ), |
|
378 | - ), |
|
379 | - 'organization_instagram', |
|
380 | - false |
|
381 | - ); |
|
382 | - } |
|
383 | - return $form; |
|
384 | - } |
|
101 | + /** |
|
102 | + * creates and returns the actual form |
|
103 | + * |
|
104 | + * @return EE_Form_Section_Proper |
|
105 | + * @throws EE_Error |
|
106 | + * @throws InvalidArgumentException |
|
107 | + * @throws InvalidDataTypeException |
|
108 | + * @throws InvalidInterfaceException |
|
109 | + * @throws ReflectionException |
|
110 | + */ |
|
111 | + public function generate() |
|
112 | + { |
|
113 | + $has_sub_regions = EEM_State::instance()->count( |
|
114 | + array(array('Country.CNT_ISO' => $this->organization_config->CNT_ISO)) |
|
115 | + ); |
|
116 | + $form = new EE_Form_Section_Proper( |
|
117 | + array( |
|
118 | + 'name' => 'organization_settings', |
|
119 | + 'html_id' => 'organization_settings', |
|
120 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
121 | + 'subsections' => array( |
|
122 | + 'contact_information_hdr' => new EE_Form_Section_HTML( |
|
123 | + EEH_HTML::h2( |
|
124 | + esc_html__('Contact Information', 'event_espresso') |
|
125 | + . ' ' |
|
126 | + . EEH_HTML::span(EEH_Template::get_help_tab_link('contact_info_info')), |
|
127 | + '', |
|
128 | + 'contact-information-hdr' |
|
129 | + ) |
|
130 | + ), |
|
131 | + 'organization_name' => new EE_Text_Input( |
|
132 | + array( |
|
133 | + 'html_name' => 'organization_name', |
|
134 | + 'html_label_text' => esc_html__('Organization Name', 'event_espresso'), |
|
135 | + 'html_help_text' => esc_html__( |
|
136 | + 'Displayed on all emails and invoices.', |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + 'default' => $this->organization_config->get_pretty('name'), |
|
140 | + 'required' => false, |
|
141 | + ) |
|
142 | + ), |
|
143 | + 'organization_address_1' => new EE_Text_Input( |
|
144 | + array( |
|
145 | + 'html_name' => 'organization_address_1', |
|
146 | + 'html_label_text' => esc_html__('Street Address', 'event_espresso'), |
|
147 | + 'default' => $this->organization_config->get_pretty('address_1'), |
|
148 | + 'required' => false, |
|
149 | + ) |
|
150 | + ), |
|
151 | + 'organization_address_2' => new EE_Text_Input( |
|
152 | + array( |
|
153 | + 'html_name' => 'organization_address_2', |
|
154 | + 'html_label_text' => esc_html__('Street Address 2', 'event_espresso'), |
|
155 | + 'default' => $this->organization_config->get_pretty('address_2'), |
|
156 | + 'required' => false, |
|
157 | + ) |
|
158 | + ), |
|
159 | + 'organization_city' => new EE_Text_Input( |
|
160 | + array( |
|
161 | + 'html_name' => 'organization_city', |
|
162 | + 'html_label_text' => esc_html__('City', 'event_espresso'), |
|
163 | + 'default' => $this->organization_config->get_pretty('city'), |
|
164 | + 'required' => false, |
|
165 | + ) |
|
166 | + ), |
|
167 | + 'organization_country' => new EE_Country_Select_Input( |
|
168 | + null, |
|
169 | + array( |
|
170 | + EE_Country_Select_Input::OPTION_GET_KEY => EE_Country_Select_Input::OPTION_GET_ALL, |
|
171 | + 'html_name' => 'organization_country', |
|
172 | + 'html_label_text' => esc_html__('Country', 'event_espresso'), |
|
173 | + 'default' => $this->organization_config->CNT_ISO, |
|
174 | + 'required' => false, |
|
175 | + 'html_help_text' => sprintf( |
|
176 | + esc_html__( |
|
177 | + '%1$sThe Country set here will have the effect of setting the currency used for all ticket prices.%2$s', |
|
178 | + 'event_espresso' |
|
179 | + ), |
|
180 | + '<span class="reminder-spn">', |
|
181 | + '</span>' |
|
182 | + ), |
|
183 | + ) |
|
184 | + ), |
|
185 | + 'organization_state' => new EE_State_Select_Input( |
|
186 | + null, |
|
187 | + array( |
|
188 | + 'html_name' => 'organization_state', |
|
189 | + 'html_label_text' => esc_html__('State/Province', 'event_espresso'), |
|
190 | + 'default' => $this->organization_config->STA_ID, |
|
191 | + 'required' => false, |
|
192 | + 'html_help_text' => empty($this->organization_config->STA_ID) || ! $has_sub_regions |
|
193 | + ? sprintf( |
|
194 | + esc_html__( |
|
195 | + 'If the States/Provinces for the selected Country do not appear in this list, then click "Save".%3$sIf data exists, then the list will be populated when the page reloads and you will be able to make a selection at that time.%3$s%1$sMake sure you click "Save" again after selecting a State/Province that has just been loaded in order to keep that selection.%2$s', |
|
196 | + 'event_espresso' |
|
197 | + ), |
|
198 | + '<span class="reminder-spn">', |
|
199 | + '</span>', |
|
200 | + '<br />' |
|
201 | + ) |
|
202 | + : '', |
|
203 | + ) |
|
204 | + ), |
|
205 | + 'organization_zip' => new EE_Text_Input( |
|
206 | + array( |
|
207 | + 'html_name' => 'organization_zip', |
|
208 | + 'html_label_text' => esc_html__('Zip/Postal Code', 'event_espresso'), |
|
209 | + 'default' => $this->organization_config->get_pretty('zip'), |
|
210 | + 'required' => false, |
|
211 | + ) |
|
212 | + ), |
|
213 | + 'organization_email' => new EE_Text_Input( |
|
214 | + array( |
|
215 | + 'html_name' => 'organization_email', |
|
216 | + 'html_label_text' => esc_html__('Primary Contact Email', 'event_espresso'), |
|
217 | + 'html_help_text' => sprintf( |
|
218 | + esc_html__( |
|
219 | + 'This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', |
|
220 | + 'event_espresso' |
|
221 | + ), |
|
222 | + '<code>[CO_FORMATTED_EMAIL]</code>', |
|
223 | + '<code>[CO_EMAIL]</code>' |
|
224 | + ), |
|
225 | + 'default' => $this->organization_config->get_pretty('email'), |
|
226 | + 'required' => false, |
|
227 | + ) |
|
228 | + ), |
|
229 | + 'organization_phone' => new EE_Text_Input( |
|
230 | + array( |
|
231 | + 'html_name' => 'organization_phone', |
|
232 | + 'html_label_text' => esc_html__('Phone Number', 'event_espresso'), |
|
233 | + 'html_help_text' => esc_html__( |
|
234 | + 'The phone number for your organization.', |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + 'default' => $this->organization_config->get_pretty('phone'), |
|
238 | + 'required' => false, |
|
239 | + ) |
|
240 | + ), |
|
241 | + 'organization_vat' => new EE_Text_Input( |
|
242 | + array( |
|
243 | + 'html_name' => 'organization_vat', |
|
244 | + 'html_label_text' => esc_html__('VAT/Tax Number', 'event_espresso'), |
|
245 | + 'html_help_text' => esc_html__( |
|
246 | + 'The VAT/Tax Number may be displayed on invoices and receipts.', |
|
247 | + 'event_espresso' |
|
248 | + ), |
|
249 | + 'default' => $this->organization_config->get_pretty('vat'), |
|
250 | + 'required' => false, |
|
251 | + ) |
|
252 | + ), |
|
253 | + 'company_logo_hdr' => new EE_Form_Section_HTML( |
|
254 | + EEH_HTML::h2( |
|
255 | + esc_html__('Company Logo', 'event_espresso') |
|
256 | + . ' ' |
|
257 | + . EEH_HTML::span(EEH_Template::get_help_tab_link('organization_logo_info')), |
|
258 | + '', |
|
259 | + 'company-logo-hdr' |
|
260 | + ) |
|
261 | + ), |
|
262 | + 'organization_logo_url' => new EE_Admin_File_Uploader_Input( |
|
263 | + array( |
|
264 | + 'html_name' => 'organization_logo_url', |
|
265 | + 'html_label_text' => esc_html__('Upload New Logo', 'event_espresso'), |
|
266 | + 'html_help_text' => esc_html__( |
|
267 | + 'Your logo will be used on custom invoices, tickets, certificates, and payment templates.', |
|
268 | + 'event_espresso' |
|
269 | + ), |
|
270 | + 'default' => $this->organization_config->get_pretty('logo_url'), |
|
271 | + 'required' => false, |
|
272 | + ) |
|
273 | + ), |
|
274 | + 'social_links_hdr' => new EE_Form_Section_HTML( |
|
275 | + EEH_HTML::h2( |
|
276 | + esc_html__('Social Links', 'event_espresso') |
|
277 | + . ' ' |
|
278 | + . EEH_HTML::span(EEH_Template::get_help_tab_link('social_links_info')) |
|
279 | + . EEH_HTML::br() |
|
280 | + . EEH_HTML::p( |
|
281 | + esc_html__( |
|
282 | + 'Enter any links to social accounts for your organization here', |
|
283 | + 'event_espresso' |
|
284 | + ), |
|
285 | + '', |
|
286 | + 'description' |
|
287 | + ), |
|
288 | + '', |
|
289 | + 'social-links-hdr' |
|
290 | + ) |
|
291 | + ), |
|
292 | + 'organization_facebook' => new EE_Text_Input( |
|
293 | + array( |
|
294 | + 'html_name' => 'organization_facebook', |
|
295 | + 'html_label_text' => esc_html__('Facebook', 'event_espresso'), |
|
296 | + 'other_html_attributes' => ' placeholder="facebook.com/profile.name"', |
|
297 | + 'default' => $this->organization_config->get_pretty('facebook'), |
|
298 | + 'required' => false, |
|
299 | + ) |
|
300 | + ), |
|
301 | + 'organization_twitter' => new EE_Text_Input( |
|
302 | + array( |
|
303 | + 'html_name' => 'organization_twitter', |
|
304 | + 'html_label_text' => esc_html__('Twitter', 'event_espresso'), |
|
305 | + 'other_html_attributes' => ' placeholder="twitter.com/twitterhandle"', |
|
306 | + 'default' => $this->organization_config->get_pretty('twitter'), |
|
307 | + 'required' => false, |
|
308 | + ) |
|
309 | + ), |
|
310 | + 'organization_linkedin' => new EE_Text_Input( |
|
311 | + array( |
|
312 | + 'html_name' => 'organization_linkedin', |
|
313 | + 'html_label_text' => esc_html__('LinkedIn', 'event_espresso'), |
|
314 | + 'other_html_attributes' => ' placeholder="linkedin.com/in/profilename"', |
|
315 | + 'default' => $this->organization_config->get_pretty('linkedin'), |
|
316 | + 'required' => false, |
|
317 | + ) |
|
318 | + ), |
|
319 | + 'organization_pinterest' => new EE_Text_Input( |
|
320 | + array( |
|
321 | + 'html_name' => 'organization_pinterest', |
|
322 | + 'html_label_text' => esc_html__('Pinterest', 'event_espresso'), |
|
323 | + 'other_html_attributes' => ' placeholder="pinterest.com/profilename"', |
|
324 | + 'default' => $this->organization_config->get_pretty('pinterest'), |
|
325 | + 'required' => false, |
|
326 | + ) |
|
327 | + ), |
|
328 | + 'organization_instagram' => new EE_Text_Input( |
|
329 | + array( |
|
330 | + 'html_name' => 'organization_instagram', |
|
331 | + 'html_label_text' => esc_html__('Instagram', 'event_espresso'), |
|
332 | + 'other_html_attributes' => ' placeholder="instagram.com/handle"', |
|
333 | + 'default' => $this->organization_config->get_pretty('instagram'), |
|
334 | + 'required' => false, |
|
335 | + ) |
|
336 | + ), |
|
337 | + ), |
|
338 | + ) |
|
339 | + ); |
|
340 | + if (is_main_site()) { |
|
341 | + $form->add_subsections( |
|
342 | + array( |
|
343 | + 'site_license_key_hdr' => new EE_Form_Section_HTML( |
|
344 | + EEH_HTML::h2( |
|
345 | + esc_html__('Your Event Espresso License Key', 'event_espresso') |
|
346 | + . ' ' |
|
347 | + . EEH_HTML::span( |
|
348 | + EEH_Template::get_help_tab_link('site_license_key_info') |
|
349 | + ), |
|
350 | + '', |
|
351 | + 'site-license-key-hdr' |
|
352 | + ) |
|
353 | + ), |
|
354 | + 'site_license_key' => $this->getSiteLicenseKeyField() |
|
355 | + ) |
|
356 | + ); |
|
357 | + $form->add_subsections( |
|
358 | + array( |
|
359 | + 'uxip_optin_hdr' => new EE_Form_Section_HTML( |
|
360 | + $this->uxipOptinText() |
|
361 | + ), |
|
362 | + 'ueip_optin' => new EE_Checkbox_Multi_Input( |
|
363 | + array( |
|
364 | + true => esc_html__('Yes! I want to help improve Event Espresso!', 'event_espresso') |
|
365 | + ), |
|
366 | + array( |
|
367 | + 'html_name' => EE_Core_Config::OPTION_NAME_UXIP, |
|
368 | + 'html_label_text' => esc_html__( |
|
369 | + 'UXIP Opt In?', |
|
370 | + 'event_espresso' |
|
371 | + ), |
|
372 | + 'default' => isset($this->core_config->ee_ueip_optin) |
|
373 | + ? filter_var($this->core_config->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN) |
|
374 | + : false, |
|
375 | + 'required' => false, |
|
376 | + ) |
|
377 | + ), |
|
378 | + ), |
|
379 | + 'organization_instagram', |
|
380 | + false |
|
381 | + ); |
|
382 | + } |
|
383 | + return $form; |
|
384 | + } |
|
385 | 385 | |
386 | 386 | |
387 | - /** |
|
388 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
389 | - * returns a string of HTML that can be directly echoed in a template |
|
390 | - * |
|
391 | - * @return string |
|
392 | - * @throws EE_Error |
|
393 | - * @throws InvalidArgumentException |
|
394 | - * @throws InvalidDataTypeException |
|
395 | - * @throws InvalidInterfaceException |
|
396 | - * @throws LogicException |
|
397 | - */ |
|
398 | - public function display() |
|
399 | - { |
|
400 | - $this->form()->enqueue_js(); |
|
401 | - return parent::display(); |
|
402 | - } |
|
387 | + /** |
|
388 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
389 | + * returns a string of HTML that can be directly echoed in a template |
|
390 | + * |
|
391 | + * @return string |
|
392 | + * @throws EE_Error |
|
393 | + * @throws InvalidArgumentException |
|
394 | + * @throws InvalidDataTypeException |
|
395 | + * @throws InvalidInterfaceException |
|
396 | + * @throws LogicException |
|
397 | + */ |
|
398 | + public function display() |
|
399 | + { |
|
400 | + $this->form()->enqueue_js(); |
|
401 | + return parent::display(); |
|
402 | + } |
|
403 | 403 | |
404 | 404 | |
405 | - /** |
|
406 | - * handles processing the form submission |
|
407 | - * returns true or false depending on whether the form was processed successfully or not |
|
408 | - * |
|
409 | - * @param array $form_data |
|
410 | - * @return bool |
|
411 | - * @throws InvalidFormSubmissionException |
|
412 | - * @throws EE_Error |
|
413 | - * @throws LogicException |
|
414 | - * @throws InvalidArgumentException |
|
415 | - * @throws InvalidDataTypeException |
|
416 | - * @throws ReflectionException |
|
417 | - */ |
|
418 | - public function process($form_data = array()) |
|
419 | - { |
|
420 | - // process form |
|
421 | - $valid_data = (array) parent::process($form_data); |
|
422 | - if (empty($valid_data)) { |
|
423 | - return false; |
|
424 | - } |
|
405 | + /** |
|
406 | + * handles processing the form submission |
|
407 | + * returns true or false depending on whether the form was processed successfully or not |
|
408 | + * |
|
409 | + * @param array $form_data |
|
410 | + * @return bool |
|
411 | + * @throws InvalidFormSubmissionException |
|
412 | + * @throws EE_Error |
|
413 | + * @throws LogicException |
|
414 | + * @throws InvalidArgumentException |
|
415 | + * @throws InvalidDataTypeException |
|
416 | + * @throws ReflectionException |
|
417 | + */ |
|
418 | + public function process($form_data = array()) |
|
419 | + { |
|
420 | + // process form |
|
421 | + $valid_data = (array) parent::process($form_data); |
|
422 | + if (empty($valid_data)) { |
|
423 | + return false; |
|
424 | + } |
|
425 | 425 | |
426 | - if (is_main_site()) { |
|
427 | - $this->network_core_config->site_license_key = isset($form_data['ee_site_license_key']) |
|
428 | - ? sanitize_text_field($form_data['ee_site_license_key']) |
|
429 | - : $this->network_core_config->site_license_key; |
|
430 | - } |
|
431 | - $this->organization_config->name = isset($form_data['organization_name']) |
|
432 | - ? sanitize_text_field($form_data['organization_name']) |
|
433 | - : $this->organization_config->name; |
|
434 | - $this->organization_config->address_1 = isset($form_data['organization_address_1']) |
|
435 | - ? sanitize_text_field($form_data['organization_address_1']) |
|
436 | - : $this->organization_config->address_1; |
|
437 | - $this->organization_config->address_2 = isset($form_data['organization_address_2']) |
|
438 | - ? sanitize_text_field($form_data['organization_address_2']) |
|
439 | - : $this->organization_config->address_2; |
|
440 | - $this->organization_config->city = isset($form_data['organization_city']) |
|
441 | - ? sanitize_text_field($form_data['organization_city']) |
|
442 | - : $this->organization_config->city; |
|
443 | - $this->organization_config->STA_ID = isset($form_data['organization_state']) |
|
444 | - ? absint($form_data['organization_state']) |
|
445 | - : $this->organization_config->STA_ID; |
|
446 | - $this->organization_config->CNT_ISO = isset($form_data['organization_country']) |
|
447 | - ? sanitize_text_field($form_data['organization_country']) |
|
448 | - : $this->organization_config->CNT_ISO; |
|
449 | - $this->organization_config->zip = isset($form_data['organization_zip']) |
|
450 | - ? sanitize_text_field($form_data['organization_zip']) |
|
451 | - : $this->organization_config->zip; |
|
452 | - $this->organization_config->email = isset($form_data['organization_email']) |
|
453 | - ? sanitize_email($form_data['organization_email']) |
|
454 | - : $this->organization_config->email; |
|
455 | - $this->organization_config->vat = isset($form_data['organization_vat']) |
|
456 | - ? sanitize_text_field($form_data['organization_vat']) |
|
457 | - : $this->organization_config->vat; |
|
458 | - $this->organization_config->phone = isset($form_data['organization_phone']) |
|
459 | - ? sanitize_text_field($form_data['organization_phone']) |
|
460 | - : $this->organization_config->phone; |
|
461 | - $this->organization_config->logo_url = isset($form_data['organization_logo_url']) |
|
462 | - ? esc_url_raw($form_data['organization_logo_url']) |
|
463 | - : $this->organization_config->logo_url; |
|
464 | - $this->organization_config->facebook = isset($form_data['organization_facebook']) |
|
465 | - ? esc_url_raw($form_data['organization_facebook']) |
|
466 | - : $this->organization_config->facebook; |
|
467 | - $this->organization_config->twitter = isset($form_data['organization_twitter']) |
|
468 | - ? esc_url_raw($form_data['organization_twitter']) |
|
469 | - : $this->organization_config->twitter; |
|
470 | - $this->organization_config->linkedin = isset($form_data['organization_linkedin']) |
|
471 | - ? esc_url_raw($form_data['organization_linkedin']) |
|
472 | - : $this->organization_config->linkedin; |
|
473 | - $this->organization_config->pinterest = isset($form_data['organization_pinterest']) |
|
474 | - ? esc_url_raw($form_data['organization_pinterest']) |
|
475 | - : $this->organization_config->pinterest; |
|
476 | - $this->organization_config->google = isset($form_data['organization_google']) |
|
477 | - ? esc_url_raw($form_data['organization_google']) |
|
478 | - : $this->organization_config->google; |
|
479 | - $this->organization_config->instagram = isset($form_data['organization_instagram']) |
|
480 | - ? esc_url_raw($form_data['organization_instagram']) |
|
481 | - : $this->organization_config->instagram; |
|
482 | - $this->core_config->ee_ueip_optin = isset($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0]) |
|
483 | - ? filter_var($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0], FILTER_VALIDATE_BOOLEAN) |
|
484 | - : false; |
|
485 | - $this->core_config->ee_ueip_has_notified = true; |
|
426 | + if (is_main_site()) { |
|
427 | + $this->network_core_config->site_license_key = isset($form_data['ee_site_license_key']) |
|
428 | + ? sanitize_text_field($form_data['ee_site_license_key']) |
|
429 | + : $this->network_core_config->site_license_key; |
|
430 | + } |
|
431 | + $this->organization_config->name = isset($form_data['organization_name']) |
|
432 | + ? sanitize_text_field($form_data['organization_name']) |
|
433 | + : $this->organization_config->name; |
|
434 | + $this->organization_config->address_1 = isset($form_data['organization_address_1']) |
|
435 | + ? sanitize_text_field($form_data['organization_address_1']) |
|
436 | + : $this->organization_config->address_1; |
|
437 | + $this->organization_config->address_2 = isset($form_data['organization_address_2']) |
|
438 | + ? sanitize_text_field($form_data['organization_address_2']) |
|
439 | + : $this->organization_config->address_2; |
|
440 | + $this->organization_config->city = isset($form_data['organization_city']) |
|
441 | + ? sanitize_text_field($form_data['organization_city']) |
|
442 | + : $this->organization_config->city; |
|
443 | + $this->organization_config->STA_ID = isset($form_data['organization_state']) |
|
444 | + ? absint($form_data['organization_state']) |
|
445 | + : $this->organization_config->STA_ID; |
|
446 | + $this->organization_config->CNT_ISO = isset($form_data['organization_country']) |
|
447 | + ? sanitize_text_field($form_data['organization_country']) |
|
448 | + : $this->organization_config->CNT_ISO; |
|
449 | + $this->organization_config->zip = isset($form_data['organization_zip']) |
|
450 | + ? sanitize_text_field($form_data['organization_zip']) |
|
451 | + : $this->organization_config->zip; |
|
452 | + $this->organization_config->email = isset($form_data['organization_email']) |
|
453 | + ? sanitize_email($form_data['organization_email']) |
|
454 | + : $this->organization_config->email; |
|
455 | + $this->organization_config->vat = isset($form_data['organization_vat']) |
|
456 | + ? sanitize_text_field($form_data['organization_vat']) |
|
457 | + : $this->organization_config->vat; |
|
458 | + $this->organization_config->phone = isset($form_data['organization_phone']) |
|
459 | + ? sanitize_text_field($form_data['organization_phone']) |
|
460 | + : $this->organization_config->phone; |
|
461 | + $this->organization_config->logo_url = isset($form_data['organization_logo_url']) |
|
462 | + ? esc_url_raw($form_data['organization_logo_url']) |
|
463 | + : $this->organization_config->logo_url; |
|
464 | + $this->organization_config->facebook = isset($form_data['organization_facebook']) |
|
465 | + ? esc_url_raw($form_data['organization_facebook']) |
|
466 | + : $this->organization_config->facebook; |
|
467 | + $this->organization_config->twitter = isset($form_data['organization_twitter']) |
|
468 | + ? esc_url_raw($form_data['organization_twitter']) |
|
469 | + : $this->organization_config->twitter; |
|
470 | + $this->organization_config->linkedin = isset($form_data['organization_linkedin']) |
|
471 | + ? esc_url_raw($form_data['organization_linkedin']) |
|
472 | + : $this->organization_config->linkedin; |
|
473 | + $this->organization_config->pinterest = isset($form_data['organization_pinterest']) |
|
474 | + ? esc_url_raw($form_data['organization_pinterest']) |
|
475 | + : $this->organization_config->pinterest; |
|
476 | + $this->organization_config->google = isset($form_data['organization_google']) |
|
477 | + ? esc_url_raw($form_data['organization_google']) |
|
478 | + : $this->organization_config->google; |
|
479 | + $this->organization_config->instagram = isset($form_data['organization_instagram']) |
|
480 | + ? esc_url_raw($form_data['organization_instagram']) |
|
481 | + : $this->organization_config->instagram; |
|
482 | + $this->core_config->ee_ueip_optin = isset($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0]) |
|
483 | + ? filter_var($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0], FILTER_VALIDATE_BOOLEAN) |
|
484 | + : false; |
|
485 | + $this->core_config->ee_ueip_has_notified = true; |
|
486 | 486 | |
487 | - $this->registry->CFG->currency = new EE_Currency_Config( |
|
488 | - $this->organization_config->CNT_ISO |
|
489 | - ); |
|
490 | - /** @var EE_Country $country */ |
|
491 | - $country = EEM_Country::instance()->get_one_by_ID($this->organization_config->CNT_ISO); |
|
492 | - if ($country instanceof EE_Country) { |
|
493 | - $country->set('CNT_active', 1); |
|
494 | - $country->save(); |
|
495 | - $this->countrySubRegionDao->saveCountrySubRegions($country); |
|
496 | - } |
|
497 | - return true; |
|
498 | - } |
|
487 | + $this->registry->CFG->currency = new EE_Currency_Config( |
|
488 | + $this->organization_config->CNT_ISO |
|
489 | + ); |
|
490 | + /** @var EE_Country $country */ |
|
491 | + $country = EEM_Country::instance()->get_one_by_ID($this->organization_config->CNT_ISO); |
|
492 | + if ($country instanceof EE_Country) { |
|
493 | + $country->set('CNT_active', 1); |
|
494 | + $country->save(); |
|
495 | + $this->countrySubRegionDao->saveCountrySubRegions($country); |
|
496 | + } |
|
497 | + return true; |
|
498 | + } |
|
499 | 499 | |
500 | 500 | |
501 | - /** |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - private function uxipOptinText() |
|
505 | - { |
|
506 | - ob_start(); |
|
507 | - Stats::optinText(false); |
|
508 | - return ob_get_clean(); |
|
509 | - } |
|
501 | + /** |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + private function uxipOptinText() |
|
505 | + { |
|
506 | + ob_start(); |
|
507 | + Stats::optinText(false); |
|
508 | + return ob_get_clean(); |
|
509 | + } |
|
510 | 510 | |
511 | 511 | |
512 | - /** |
|
513 | - * Return whether the site license key has been verified or not. |
|
514 | - * @return bool |
|
515 | - */ |
|
516 | - private function licenseKeyVerified() |
|
517 | - { |
|
518 | - if (empty($this->network_core_config->site_license_key)) { |
|
519 | - return false; |
|
520 | - } |
|
521 | - $ver_option_key = 'puvererr_' . basename(EE_PLUGIN_BASENAME); |
|
522 | - $verify_fail = get_option($ver_option_key, false); |
|
523 | - return $verify_fail === false |
|
524 | - || (! empty($this->network_core_config->site_license_key) |
|
525 | - && $verify_fail === false |
|
526 | - ); |
|
527 | - } |
|
512 | + /** |
|
513 | + * Return whether the site license key has been verified or not. |
|
514 | + * @return bool |
|
515 | + */ |
|
516 | + private function licenseKeyVerified() |
|
517 | + { |
|
518 | + if (empty($this->network_core_config->site_license_key)) { |
|
519 | + return false; |
|
520 | + } |
|
521 | + $ver_option_key = 'puvererr_' . basename(EE_PLUGIN_BASENAME); |
|
522 | + $verify_fail = get_option($ver_option_key, false); |
|
523 | + return $verify_fail === false |
|
524 | + || (! empty($this->network_core_config->site_license_key) |
|
525 | + && $verify_fail === false |
|
526 | + ); |
|
527 | + } |
|
528 | 528 | |
529 | 529 | |
530 | - /** |
|
531 | - * @return EE_Text_Input |
|
532 | - */ |
|
533 | - private function getSiteLicenseKeyField() |
|
534 | - { |
|
535 | - $text_input = new EE_Text_Input( |
|
536 | - array( |
|
537 | - 'html_name' => 'ee_site_license_key', |
|
538 | - 'html_id' => 'site_license_key', |
|
539 | - 'html_label_text' => esc_html__('Support License Key', 'event_espresso'), |
|
540 | - /** phpcs:disable WordPress.WP.I18n.UnorderedPlaceholdersText */ |
|
541 | - 'html_help_text' => sprintf( |
|
542 | - esc_html__( |
|
543 | - 'Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', |
|
544 | - 'event_espresso' |
|
545 | - ), |
|
546 | - '<strong>', |
|
547 | - '</strong>' |
|
548 | - ), |
|
549 | - /** phpcs:enable */ |
|
550 | - 'default' => isset($this->network_core_config->site_license_key) |
|
551 | - ? $this->network_core_config->site_license_key |
|
552 | - : '', |
|
553 | - 'required' => false, |
|
554 | - 'form_html_filter' => new VsprintfFilter( |
|
555 | - '%2$s %1$s', |
|
556 | - array($this->getValidationIndicator()) |
|
557 | - ) |
|
558 | - ) |
|
559 | - ); |
|
560 | - return $text_input; |
|
561 | - } |
|
530 | + /** |
|
531 | + * @return EE_Text_Input |
|
532 | + */ |
|
533 | + private function getSiteLicenseKeyField() |
|
534 | + { |
|
535 | + $text_input = new EE_Text_Input( |
|
536 | + array( |
|
537 | + 'html_name' => 'ee_site_license_key', |
|
538 | + 'html_id' => 'site_license_key', |
|
539 | + 'html_label_text' => esc_html__('Support License Key', 'event_espresso'), |
|
540 | + /** phpcs:disable WordPress.WP.I18n.UnorderedPlaceholdersText */ |
|
541 | + 'html_help_text' => sprintf( |
|
542 | + esc_html__( |
|
543 | + 'Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', |
|
544 | + 'event_espresso' |
|
545 | + ), |
|
546 | + '<strong>', |
|
547 | + '</strong>' |
|
548 | + ), |
|
549 | + /** phpcs:enable */ |
|
550 | + 'default' => isset($this->network_core_config->site_license_key) |
|
551 | + ? $this->network_core_config->site_license_key |
|
552 | + : '', |
|
553 | + 'required' => false, |
|
554 | + 'form_html_filter' => new VsprintfFilter( |
|
555 | + '%2$s %1$s', |
|
556 | + array($this->getValidationIndicator()) |
|
557 | + ) |
|
558 | + ) |
|
559 | + ); |
|
560 | + return $text_input; |
|
561 | + } |
|
562 | 562 | |
563 | 563 | |
564 | - /** |
|
565 | - * @return string |
|
566 | - */ |
|
567 | - private function getValidationIndicator() |
|
568 | - { |
|
569 | - $verified_class = $this->licenseKeyVerified() ? 'ee-icon-color-ee-green' : 'ee-icon-color-ee-red'; |
|
570 | - return '<span class="dashicons dashicons-admin-network ' . $verified_class . ' ee-icon-size-20"></span>'; |
|
571 | - } |
|
564 | + /** |
|
565 | + * @return string |
|
566 | + */ |
|
567 | + private function getValidationIndicator() |
|
568 | + { |
|
569 | + $verified_class = $this->licenseKeyVerified() ? 'ee-icon-color-ee-green' : 'ee-icon-color-ee-red'; |
|
570 | + return '<span class="dashicons dashicons-admin-network ' . $verified_class . ' ee-icon-size-20"></span>'; |
|
571 | + } |
|
572 | 572 | } |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | $html .= $this->_attributes_string( |
33 | 33 | array( |
34 | 34 | 'for' => $html_id, |
35 | - 'id' => $html_id . '-lbl', |
|
35 | + 'id' => $html_id.'-lbl', |
|
36 | 36 | 'class' => apply_filters( |
37 | 37 | 'FHEE__EE_Radio_Button_Display_Strategy__display__option_label_class', |
38 | - 'ee-radio-label-after' . $label_size_class, |
|
38 | + 'ee-radio-label-after'.$label_size_class, |
|
39 | 39 | $this, |
40 | 40 | $input, |
41 | 41 | $value |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | $html .= '> '; |
64 | 64 | $html .= $display_text; |
65 | - $html .= EEH_HTML::nl(-1, 'radio') . '</label>'; |
|
65 | + $html .= EEH_HTML::nl(-1, 'radio').'</label>'; |
|
66 | 66 | } |
67 | 67 | $html .= EEH_HTML::div('', '', 'clear-float'); |
68 | 68 | $html .= EEH_HTML::divx(); |
@@ -11,61 +11,61 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Radio_Button_Display_Strategy extends EE_Compound_Input_Display_Strategy |
13 | 13 | { |
14 | - /** |
|
15 | - * |
|
16 | - * @throws EE_Error |
|
17 | - * @return string of html to display the field |
|
18 | - */ |
|
19 | - public function display() |
|
20 | - { |
|
21 | - $input = $this->get_input(); |
|
22 | - $input->set_label_sizes(); |
|
23 | - $label_size_class = $input->get_label_size_class(); |
|
24 | - $html = ''; |
|
25 | - foreach ($input->options() as $value => $display_text) { |
|
26 | - $value = $input->get_normalization_strategy()->unnormalize($value); |
|
14 | + /** |
|
15 | + * |
|
16 | + * @throws EE_Error |
|
17 | + * @return string of html to display the field |
|
18 | + */ |
|
19 | + public function display() |
|
20 | + { |
|
21 | + $input = $this->get_input(); |
|
22 | + $input->set_label_sizes(); |
|
23 | + $label_size_class = $input->get_label_size_class(); |
|
24 | + $html = ''; |
|
25 | + foreach ($input->options() as $value => $display_text) { |
|
26 | + $value = $input->get_normalization_strategy()->unnormalize($value); |
|
27 | 27 | |
28 | - $html_id = $this->get_sub_input_id($value); |
|
29 | - $html .= EEH_HTML::nl(0, 'radio'); |
|
28 | + $html_id = $this->get_sub_input_id($value); |
|
29 | + $html .= EEH_HTML::nl(0, 'radio'); |
|
30 | 30 | |
31 | - $html .= $this->_opening_tag('label'); |
|
32 | - $html .= $this->_attributes_string( |
|
33 | - array( |
|
34 | - 'for' => $html_id, |
|
35 | - 'id' => $html_id . '-lbl', |
|
36 | - 'class' => apply_filters( |
|
37 | - 'FHEE__EE_Radio_Button_Display_Strategy__display__option_label_class', |
|
38 | - 'ee-radio-label-after' . $label_size_class, |
|
39 | - $this, |
|
40 | - $input, |
|
41 | - $value |
|
42 | - ) |
|
43 | - ) |
|
44 | - ); |
|
45 | - $html .= '>'; |
|
46 | - $html .= EEH_HTML::nl(1, 'radio'); |
|
47 | - $html .= $this->_opening_tag('input'); |
|
48 | - $attributes = array( |
|
49 | - 'id' => $html_id, |
|
50 | - 'name' => $input->html_name(), |
|
51 | - 'class' => $input->html_class(), |
|
52 | - 'style' => $input->html_style(), |
|
53 | - 'type' => 'radio', |
|
54 | - 'value' => $value, |
|
55 | - 0 => $input->other_html_attributes(), |
|
56 | - 'data-question_label' => $input->html_label_id() |
|
57 | - ); |
|
58 | - if ($input->raw_value() === $value) { |
|
59 | - $attributes['checked'] = 'checked'; |
|
60 | - } |
|
61 | - $html .= $this->_attributes_string($attributes); |
|
31 | + $html .= $this->_opening_tag('label'); |
|
32 | + $html .= $this->_attributes_string( |
|
33 | + array( |
|
34 | + 'for' => $html_id, |
|
35 | + 'id' => $html_id . '-lbl', |
|
36 | + 'class' => apply_filters( |
|
37 | + 'FHEE__EE_Radio_Button_Display_Strategy__display__option_label_class', |
|
38 | + 'ee-radio-label-after' . $label_size_class, |
|
39 | + $this, |
|
40 | + $input, |
|
41 | + $value |
|
42 | + ) |
|
43 | + ) |
|
44 | + ); |
|
45 | + $html .= '>'; |
|
46 | + $html .= EEH_HTML::nl(1, 'radio'); |
|
47 | + $html .= $this->_opening_tag('input'); |
|
48 | + $attributes = array( |
|
49 | + 'id' => $html_id, |
|
50 | + 'name' => $input->html_name(), |
|
51 | + 'class' => $input->html_class(), |
|
52 | + 'style' => $input->html_style(), |
|
53 | + 'type' => 'radio', |
|
54 | + 'value' => $value, |
|
55 | + 0 => $input->other_html_attributes(), |
|
56 | + 'data-question_label' => $input->html_label_id() |
|
57 | + ); |
|
58 | + if ($input->raw_value() === $value) { |
|
59 | + $attributes['checked'] = 'checked'; |
|
60 | + } |
|
61 | + $html .= $this->_attributes_string($attributes); |
|
62 | 62 | |
63 | - $html .= '> '; |
|
64 | - $html .= $display_text; |
|
65 | - $html .= EEH_HTML::nl(-1, 'radio') . '</label>'; |
|
66 | - } |
|
67 | - $html .= EEH_HTML::div('', '', 'clear-float'); |
|
68 | - $html .= EEH_HTML::divx(); |
|
69 | - return apply_filters('FHEE__EE_Radio_Button_Display_Strategy__display', $html, $this, $this->_input); |
|
70 | - } |
|
63 | + $html .= '> '; |
|
64 | + $html .= $display_text; |
|
65 | + $html .= EEH_HTML::nl(-1, 'radio') . '</label>'; |
|
66 | + } |
|
67 | + $html .= EEH_HTML::div('', '', 'clear-float'); |
|
68 | + $html .= EEH_HTML::divx(); |
|
69 | + return apply_filters('FHEE__EE_Radio_Button_Display_Strategy__display', $html, $this, $this->_input); |
|
70 | + } |
|
71 | 71 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | { |
74 | 74 | // if there are no standard caps for this model, then for now all we know |
75 | 75 | // if they need the default cap to access this |
76 | - if (! $this->model()->cap_slug()) { |
|
76 | + if ( ! $this->model()->cap_slug()) { |
|
77 | 77 | return array( |
78 | 78 | self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
79 | 79 | ); |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | // if they don't have the basic event cap, they can't access ANY non-default items |
86 | 86 | EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event()) => new EE_Return_None_Where_Conditions(), |
87 | 87 | // if they don't have the others event cap, they can't access others' non-default items |
88 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event() . '_others') => new EE_Default_Where_Conditions( |
|
89 | - array( $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder ) |
|
88 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event().'_others') => new EE_Default_Where_Conditions( |
|
89 | + array($this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder) |
|
90 | 90 | ), |
91 | 91 | // if they have basic and others, but not private, they can't access others' private non-default items |
92 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event() . '_private') => new EE_Default_Where_Conditions( |
|
92 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event().'_private') => new EE_Default_Where_Conditions( |
|
93 | 93 | array( |
94 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event() . '_private') => $this->addPublishedPostConditions( |
|
94 | + 'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event().'_private') => $this->addPublishedPostConditions( |
|
95 | 95 | array( |
96 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
96 | + $this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
97 | 97 | ), |
98 | 98 | false, |
99 | 99 | $this->_path_to_event_model |
@@ -16,89 +16,89 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Restriction_Generator_Event_Related_Protected extends EE_Restriction_Generator_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * Path to the event model from the model this restriction generator will be applied to; |
|
21 | - * including the event model itself. Eg "Ticket.Datetime.Event" |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_path_to_event_model = null; |
|
19 | + /** |
|
20 | + * Path to the event model from the model this restriction generator will be applied to; |
|
21 | + * including the event model itself. Eg "Ticket.Datetime.Event" |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_path_to_event_model = null; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Capability context on event model when creating restrictions. |
|
28 | - * Eg, although we may want capability restrictions relating to deleting datetimes, |
|
29 | - * they don't need to be able to DELETE EVENTS, they just need to be able to |
|
30 | - * EDIT EVENTS in order to DELETE DATETIMES. |
|
31 | - * @var string one of EEM_Base::valid_cap_contexts() |
|
32 | - */ |
|
33 | - protected $_cap_context_on_event_model = null; |
|
34 | - /** |
|
35 | - * |
|
36 | - * @param string $path_to_event_model |
|
37 | - * @param string $cap_context_on_event_model capability context on event model when creating restrictions. |
|
38 | - * Eg, although we may want capability restrictions relating to deleting datetimes, |
|
39 | - * they don't need to be able to DELETE EVENTS, they just need to be able to |
|
40 | - * EDIT EVENTS in order to DELETE DATETIMES. If none if provided, assumed to be the same |
|
41 | - * as on the primary model. |
|
42 | - */ |
|
43 | - public function __construct($path_to_event_model, $cap_context_on_event_model = null) |
|
44 | - { |
|
45 | - if (substr($path_to_event_model, -1, 1) != '.') { |
|
46 | - $path_to_event_model .= '.'; |
|
47 | - } |
|
48 | - $this->_path_to_event_model = $path_to_event_model; |
|
49 | - $this->_cap_context_on_event_model = $cap_context_on_event_model; |
|
50 | - } |
|
26 | + /** |
|
27 | + * Capability context on event model when creating restrictions. |
|
28 | + * Eg, although we may want capability restrictions relating to deleting datetimes, |
|
29 | + * they don't need to be able to DELETE EVENTS, they just need to be able to |
|
30 | + * EDIT EVENTS in order to DELETE DATETIMES. |
|
31 | + * @var string one of EEM_Base::valid_cap_contexts() |
|
32 | + */ |
|
33 | + protected $_cap_context_on_event_model = null; |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param string $path_to_event_model |
|
37 | + * @param string $cap_context_on_event_model capability context on event model when creating restrictions. |
|
38 | + * Eg, although we may want capability restrictions relating to deleting datetimes, |
|
39 | + * they don't need to be able to DELETE EVENTS, they just need to be able to |
|
40 | + * EDIT EVENTS in order to DELETE DATETIMES. If none if provided, assumed to be the same |
|
41 | + * as on the primary model. |
|
42 | + */ |
|
43 | + public function __construct($path_to_event_model, $cap_context_on_event_model = null) |
|
44 | + { |
|
45 | + if (substr($path_to_event_model, -1, 1) != '.') { |
|
46 | + $path_to_event_model .= '.'; |
|
47 | + } |
|
48 | + $this->_path_to_event_model = $path_to_event_model; |
|
49 | + $this->_cap_context_on_event_model = $cap_context_on_event_model; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Returns `$this->_cap_context_on_event_model`, the relevant action ("read", |
|
54 | - * "read_admin", "edit" or "delete") for the EVENT related to this model. |
|
55 | - * @see EE_Restriction_Generator_Event_Related_Protected::__construct() |
|
56 | - * @return string one of EEM_Base::valid_cap_contexts() |
|
57 | - */ |
|
58 | - protected function action_for_event() |
|
59 | - { |
|
60 | - if ($this->_cap_context_on_event_model) { |
|
61 | - return $this->_cap_context_on_event_model; |
|
62 | - } else { |
|
63 | - return $this->action(); |
|
64 | - } |
|
65 | - } |
|
52 | + /** |
|
53 | + * Returns `$this->_cap_context_on_event_model`, the relevant action ("read", |
|
54 | + * "read_admin", "edit" or "delete") for the EVENT related to this model. |
|
55 | + * @see EE_Restriction_Generator_Event_Related_Protected::__construct() |
|
56 | + * @return string one of EEM_Base::valid_cap_contexts() |
|
57 | + */ |
|
58 | + protected function action_for_event() |
|
59 | + { |
|
60 | + if ($this->_cap_context_on_event_model) { |
|
61 | + return $this->_cap_context_on_event_model; |
|
62 | + } else { |
|
63 | + return $this->action(); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * |
|
69 | - * @return \EE_Default_Where_Conditions |
|
70 | - */ |
|
71 | - protected function _generate_restrictions() |
|
72 | - { |
|
73 | - // if there are no standard caps for this model, then for now all we know |
|
74 | - // if they need the default cap to access this |
|
75 | - if (! $this->model()->cap_slug()) { |
|
76 | - return array( |
|
77 | - self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
|
78 | - ); |
|
79 | - } |
|
67 | + /** |
|
68 | + * |
|
69 | + * @return \EE_Default_Where_Conditions |
|
70 | + */ |
|
71 | + protected function _generate_restrictions() |
|
72 | + { |
|
73 | + // if there are no standard caps for this model, then for now all we know |
|
74 | + // if they need the default cap to access this |
|
75 | + if (! $this->model()->cap_slug()) { |
|
76 | + return array( |
|
77 | + self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | |
81 | - $event_model = EEM_Event::instance(); |
|
82 | - return array( |
|
83 | - // first: basically access to non-defaults is essentially controlled by which events are accessible |
|
84 | - // if they don't have the basic event cap, they can't access ANY non-default items |
|
85 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event()) => new EE_Return_None_Where_Conditions(), |
|
86 | - // if they don't have the others event cap, they can't access others' non-default items |
|
87 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event() . '_others') => new EE_Default_Where_Conditions( |
|
88 | - array( $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder ) |
|
89 | - ), |
|
90 | - // if they have basic and others, but not private, they can't access others' private non-default items |
|
91 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event() . '_private') => new EE_Default_Where_Conditions( |
|
92 | - array( |
|
93 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event() . '_private') => $this->addPublishedPostConditions( |
|
94 | - array( |
|
95 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
96 | - ), |
|
97 | - false, |
|
98 | - $this->_path_to_event_model |
|
99 | - ) |
|
100 | - ) |
|
101 | - ), |
|
102 | - ); |
|
103 | - } |
|
81 | + $event_model = EEM_Event::instance(); |
|
82 | + return array( |
|
83 | + // first: basically access to non-defaults is essentially controlled by which events are accessible |
|
84 | + // if they don't have the basic event cap, they can't access ANY non-default items |
|
85 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event()) => new EE_Return_None_Where_Conditions(), |
|
86 | + // if they don't have the others event cap, they can't access others' non-default items |
|
87 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event() . '_others') => new EE_Default_Where_Conditions( |
|
88 | + array( $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder ) |
|
89 | + ), |
|
90 | + // if they have basic and others, but not private, they can't access others' private non-default items |
|
91 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event() . '_private') => new EE_Default_Where_Conditions( |
|
92 | + array( |
|
93 | + 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action_for_event() . '_private') => $this->addPublishedPostConditions( |
|
94 | + array( |
|
95 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
96 | + ), |
|
97 | + false, |
|
98 | + $this->_path_to_event_model |
|
99 | + ) |
|
100 | + ) |
|
101 | + ), |
|
102 | + ); |
|
103 | + } |
|
104 | 104 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | { |
43 | 43 | // if there are no standard caps for this model, then for now all we know |
44 | 44 | // if they need the default cap to access this |
45 | - if (! $this->model()->cap_slug()) { |
|
45 | + if ( ! $this->model()->cap_slug()) { |
|
46 | 46 | return array( |
47 | 47 | self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
48 | 48 | ); |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | ) |
61 | 61 | ), |
62 | 62 | // if they don't have the others event cap, they can't access others' non-default items |
63 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions( |
|
63 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_others') => new EE_Default_Where_Conditions( |
|
64 | 64 | array( |
65 | - 'OR*' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions( |
|
65 | + 'OR*'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_others') => $this->addPublishedPostConditions( |
|
66 | 66 | array( |
67 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
67 | + $this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
68 | 68 | ), |
69 | 69 | true, |
70 | 70 | $this->_path_to_event_model |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | ) |
73 | 73 | ), |
74 | 74 | // if they have basic and others, but not private, they can't access others' private non-default items |
75 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions( |
|
75 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_private') => new EE_Default_Where_Conditions( |
|
76 | 76 | array( |
77 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions( |
|
77 | + 'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_private') => $this->addPublishedPostConditions( |
|
78 | 78 | array( |
79 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
79 | + $this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
80 | 80 | ), |
81 | 81 | false, |
82 | 82 | $this->_path_to_event_model |
@@ -16,72 +16,72 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Restriction_Generator_Event_Related_Public extends EE_Restriction_Generator_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * Path to the event model from the model this restriction generator will be applied to; |
|
21 | - * including the event model itself. Eg "Ticket.Datetime.Event" |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_path_to_event_model; |
|
25 | - /** |
|
26 | - * |
|
27 | - * @param string $path_to_event_model |
|
28 | - */ |
|
29 | - public function __construct($path_to_event_model) |
|
30 | - { |
|
31 | - if (substr($path_to_event_model, -1, 1) != '.') { |
|
32 | - $path_to_event_model .= '.'; |
|
33 | - } |
|
34 | - $this->_path_to_event_model = $path_to_event_model; |
|
35 | - } |
|
36 | - /** |
|
37 | - * |
|
38 | - * @return \EE_Default_Where_Conditions |
|
39 | - */ |
|
40 | - protected function _generate_restrictions() |
|
41 | - { |
|
42 | - // if there are no standard caps for this model, then for now all we know |
|
43 | - // if they need the default cap to access this |
|
44 | - if (! $this->model()->cap_slug()) { |
|
45 | - return array( |
|
46 | - self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
|
47 | - ); |
|
48 | - } |
|
19 | + /** |
|
20 | + * Path to the event model from the model this restriction generator will be applied to; |
|
21 | + * including the event model itself. Eg "Ticket.Datetime.Event" |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_path_to_event_model; |
|
25 | + /** |
|
26 | + * |
|
27 | + * @param string $path_to_event_model |
|
28 | + */ |
|
29 | + public function __construct($path_to_event_model) |
|
30 | + { |
|
31 | + if (substr($path_to_event_model, -1, 1) != '.') { |
|
32 | + $path_to_event_model .= '.'; |
|
33 | + } |
|
34 | + $this->_path_to_event_model = $path_to_event_model; |
|
35 | + } |
|
36 | + /** |
|
37 | + * |
|
38 | + * @return \EE_Default_Where_Conditions |
|
39 | + */ |
|
40 | + protected function _generate_restrictions() |
|
41 | + { |
|
42 | + // if there are no standard caps for this model, then for now all we know |
|
43 | + // if they need the default cap to access this |
|
44 | + if (! $this->model()->cap_slug()) { |
|
45 | + return array( |
|
46 | + self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | - $event_model = EEM_Event::instance(); |
|
51 | - return array( |
|
52 | - // first: basically access to non-defaults is essentially controlled by which events are accessible |
|
53 | - // if they don't have the basic event cap, they can only read things for published events |
|
54 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions( |
|
55 | - $this->addPublishedPostConditions( |
|
56 | - array(), |
|
57 | - true, |
|
58 | - $this->_path_to_event_model |
|
59 | - ) |
|
60 | - ), |
|
61 | - // if they don't have the others event cap, they can't access others' non-default items |
|
62 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions( |
|
63 | - array( |
|
64 | - 'OR*' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions( |
|
65 | - array( |
|
66 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
67 | - ), |
|
68 | - true, |
|
69 | - $this->_path_to_event_model |
|
70 | - ) |
|
71 | - ) |
|
72 | - ), |
|
73 | - // if they have basic and others, but not private, they can't access others' private non-default items |
|
74 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions( |
|
75 | - array( |
|
76 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions( |
|
77 | - array( |
|
78 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
79 | - ), |
|
80 | - false, |
|
81 | - $this->_path_to_event_model |
|
82 | - ) |
|
83 | - ) |
|
84 | - ), |
|
85 | - ); |
|
86 | - } |
|
50 | + $event_model = EEM_Event::instance(); |
|
51 | + return array( |
|
52 | + // first: basically access to non-defaults is essentially controlled by which events are accessible |
|
53 | + // if they don't have the basic event cap, they can only read things for published events |
|
54 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions( |
|
55 | + $this->addPublishedPostConditions( |
|
56 | + array(), |
|
57 | + true, |
|
58 | + $this->_path_to_event_model |
|
59 | + ) |
|
60 | + ), |
|
61 | + // if they don't have the others event cap, they can't access others' non-default items |
|
62 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions( |
|
63 | + array( |
|
64 | + 'OR*' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions( |
|
65 | + array( |
|
66 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
67 | + ), |
|
68 | + true, |
|
69 | + $this->_path_to_event_model |
|
70 | + ) |
|
71 | + ) |
|
72 | + ), |
|
73 | + // if they have basic and others, but not private, they can't access others' private non-default items |
|
74 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions( |
|
75 | + array( |
|
76 | + 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions( |
|
77 | + array( |
|
78 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
79 | + ), |
|
80 | + false, |
|
81 | + $this->_path_to_event_model |
|
82 | + ) |
|
83 | + ) |
|
84 | + ), |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | } |
@@ -12,74 +12,74 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Restriction_Generator_Public extends EE_Restriction_Generator_Base |
14 | 14 | { |
15 | - protected function _generate_restrictions() |
|
16 | - { |
|
17 | - // if there are no standard caps for this model, then for allow full access |
|
18 | - if (! $this->model()->cap_slug()) { |
|
19 | - return array( |
|
20 | - ); |
|
21 | - } |
|
15 | + protected function _generate_restrictions() |
|
16 | + { |
|
17 | + // if there are no standard caps for this model, then for allow full access |
|
18 | + if (! $this->model()->cap_slug()) { |
|
19 | + return array( |
|
20 | + ); |
|
21 | + } |
|
22 | 22 | |
23 | - $restrictions = array(); |
|
24 | - // does the basic cap exist? (eg 'ee_read_registrations') |
|
25 | - if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action())) { |
|
26 | - if ($this->model() instanceof EEM_CPT_Base) { |
|
27 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions( |
|
28 | - $this->addPublishedPostConditions() |
|
29 | - ); |
|
30 | - } elseif ($this->model() instanceof EEM_Soft_Delete_Base) { |
|
31 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions( |
|
32 | - array( $this->model()->deleted_field_name() => false ) |
|
33 | - ); |
|
34 | - } else { |
|
35 | - // don't impose any restrictions if they don't have the basic reading cap |
|
36 | - } |
|
37 | - // does the others cap exist? (eg 'ee_read_others_registrations') |
|
38 | - if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others')) {// both caps exist |
|
39 | - if ($this->model() instanceof EEM_CPT_Base) { |
|
40 | - // then if they don't have the others cap, AT MOST show them their own and other published ones |
|
41 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions( |
|
42 | - array( |
|
43 | - 'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => $this->addPublishedPostConditions( |
|
44 | - array( |
|
45 | - EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
|
46 | - ) |
|
47 | - ) |
|
48 | - ) |
|
49 | - ); |
|
50 | - } elseif ($this->model() instanceof EEM_Soft_Delete_Base) { |
|
51 | - // then if they don't have the other cap, AT MOST show them their own or non deleted ones |
|
52 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions( |
|
53 | - array( |
|
54 | - 'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => array( |
|
55 | - EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
|
56 | - $this->model()->deleted_field_name() => false |
|
57 | - ) |
|
58 | - ) |
|
59 | - ); |
|
60 | - } else { |
|
61 | - // again, if they don't have the others cap, continue showing all because there are no inherently hidden ones |
|
62 | - } |
|
63 | - // does the private cap exist (eg 'ee_read_others_private_events') |
|
64 | - if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_private') && $this->model() instanceof EEM_CPT_Base) { |
|
65 | - // if they have basic and others, but not private, restrict them to see theirs and others' that aren't private |
|
66 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') ] = new EE_Default_Where_Conditions( |
|
67 | - array( |
|
68 | - 'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') => $this->addPublishedPostConditions( |
|
69 | - array( |
|
70 | - EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
|
71 | - ), |
|
72 | - false, |
|
73 | - '' |
|
74 | - ) |
|
75 | - ) |
|
76 | - ); |
|
77 | - } |
|
78 | - } |
|
79 | - } else { |
|
80 | - // there is no basic cap. So allow full access |
|
81 | - $restrictions = array(); |
|
82 | - } |
|
83 | - return $restrictions; |
|
84 | - } |
|
23 | + $restrictions = array(); |
|
24 | + // does the basic cap exist? (eg 'ee_read_registrations') |
|
25 | + if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action())) { |
|
26 | + if ($this->model() instanceof EEM_CPT_Base) { |
|
27 | + $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions( |
|
28 | + $this->addPublishedPostConditions() |
|
29 | + ); |
|
30 | + } elseif ($this->model() instanceof EEM_Soft_Delete_Base) { |
|
31 | + $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions( |
|
32 | + array( $this->model()->deleted_field_name() => false ) |
|
33 | + ); |
|
34 | + } else { |
|
35 | + // don't impose any restrictions if they don't have the basic reading cap |
|
36 | + } |
|
37 | + // does the others cap exist? (eg 'ee_read_others_registrations') |
|
38 | + if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others')) {// both caps exist |
|
39 | + if ($this->model() instanceof EEM_CPT_Base) { |
|
40 | + // then if they don't have the others cap, AT MOST show them their own and other published ones |
|
41 | + $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions( |
|
42 | + array( |
|
43 | + 'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => $this->addPublishedPostConditions( |
|
44 | + array( |
|
45 | + EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
|
46 | + ) |
|
47 | + ) |
|
48 | + ) |
|
49 | + ); |
|
50 | + } elseif ($this->model() instanceof EEM_Soft_Delete_Base) { |
|
51 | + // then if they don't have the other cap, AT MOST show them their own or non deleted ones |
|
52 | + $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions( |
|
53 | + array( |
|
54 | + 'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => array( |
|
55 | + EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
|
56 | + $this->model()->deleted_field_name() => false |
|
57 | + ) |
|
58 | + ) |
|
59 | + ); |
|
60 | + } else { |
|
61 | + // again, if they don't have the others cap, continue showing all because there are no inherently hidden ones |
|
62 | + } |
|
63 | + // does the private cap exist (eg 'ee_read_others_private_events') |
|
64 | + if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_private') && $this->model() instanceof EEM_CPT_Base) { |
|
65 | + // if they have basic and others, but not private, restrict them to see theirs and others' that aren't private |
|
66 | + $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') ] = new EE_Default_Where_Conditions( |
|
67 | + array( |
|
68 | + 'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') => $this->addPublishedPostConditions( |
|
69 | + array( |
|
70 | + EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
|
71 | + ), |
|
72 | + false, |
|
73 | + '' |
|
74 | + ) |
|
75 | + ) |
|
76 | + ); |
|
77 | + } |
|
78 | + } |
|
79 | + } else { |
|
80 | + // there is no basic cap. So allow full access |
|
81 | + $restrictions = array(); |
|
82 | + } |
|
83 | + return $restrictions; |
|
84 | + } |
|
85 | 85 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | protected function _generate_restrictions() |
16 | 16 | { |
17 | 17 | // if there are no standard caps for this model, then for allow full access |
18 | - if (! $this->model()->cap_slug()) { |
|
18 | + if ( ! $this->model()->cap_slug()) { |
|
19 | 19 | return array( |
20 | 20 | ); |
21 | 21 | } |
@@ -24,23 +24,23 @@ discard block |
||
24 | 24 | // does the basic cap exist? (eg 'ee_read_registrations') |
25 | 25 | if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action())) { |
26 | 26 | if ($this->model() instanceof EEM_CPT_Base) { |
27 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions( |
|
27 | + $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action())] = new EE_Default_Where_Conditions( |
|
28 | 28 | $this->addPublishedPostConditions() |
29 | 29 | ); |
30 | 30 | } elseif ($this->model() instanceof EEM_Soft_Delete_Base) { |
31 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) ] = new EE_Default_Where_Conditions( |
|
32 | - array( $this->model()->deleted_field_name() => false ) |
|
31 | + $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action())] = new EE_Default_Where_Conditions( |
|
32 | + array($this->model()->deleted_field_name() => false) |
|
33 | 33 | ); |
34 | 34 | } else { |
35 | 35 | // don't impose any restrictions if they don't have the basic reading cap |
36 | 36 | } |
37 | 37 | // does the others cap exist? (eg 'ee_read_others_registrations') |
38 | - if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others')) {// both caps exist |
|
38 | + if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action().'_others')) {// both caps exist |
|
39 | 39 | if ($this->model() instanceof EEM_CPT_Base) { |
40 | 40 | // then if they don't have the others cap, AT MOST show them their own and other published ones |
41 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions( |
|
41 | + $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others')] = new EE_Default_Where_Conditions( |
|
42 | 42 | array( |
43 | - 'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => $this->addPublishedPostConditions( |
|
43 | + 'OR*'.EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others') => $this->addPublishedPostConditions( |
|
44 | 44 | array( |
45 | 45 | EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
46 | 46 | ) |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | ); |
50 | 50 | } elseif ($this->model() instanceof EEM_Soft_Delete_Base) { |
51 | 51 | // then if they don't have the other cap, AT MOST show them their own or non deleted ones |
52 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') ] = new EE_Default_Where_Conditions( |
|
52 | + $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others')] = new EE_Default_Where_Conditions( |
|
53 | 53 | array( |
54 | - 'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others') => array( |
|
54 | + 'OR*'.EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others') => array( |
|
55 | 55 | EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
56 | 56 | $this->model()->deleted_field_name() => false |
57 | 57 | ) |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | // again, if they don't have the others cap, continue showing all because there are no inherently hidden ones |
62 | 62 | } |
63 | 63 | // does the private cap exist (eg 'ee_read_others_private_events') |
64 | - if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_private') && $this->model() instanceof EEM_CPT_Base) { |
|
64 | + if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action().'_private') && $this->model() instanceof EEM_CPT_Base) { |
|
65 | 65 | // if they have basic and others, but not private, restrict them to see theirs and others' that aren't private |
66 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') ] = new EE_Default_Where_Conditions( |
|
66 | + $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_private')] = new EE_Default_Where_Conditions( |
|
67 | 67 | array( |
68 | - 'OR*' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_private') => $this->addPublishedPostConditions( |
|
68 | + 'OR*'.EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_private') => $this->addPublishedPostConditions( |
|
69 | 69 | array( |
70 | 70 | EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
71 | 71 | ), |
@@ -18,110 +18,110 @@ |
||
18 | 18 | class EE_Restriction_Generator_Default_Public extends EE_Restriction_Generator_Base |
19 | 19 | { |
20 | 20 | /** |
21 | - * Name of the field on this model (or a related model, including the model chain to it) |
|
22 | - * that is a boolean indicating whether or not a model object is considered "Default" or not |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $_default_field_name; |
|
21 | + * Name of the field on this model (or a related model, including the model chain to it) |
|
22 | + * that is a boolean indicating whether or not a model object is considered "Default" or not |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $_default_field_name; |
|
26 | 26 | |
27 | - /** |
|
28 | - * The model chain to follow to get to the event model, including the event model itself. |
|
29 | - * Eg 'Ticket.Datetime.Event' |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $_path_to_event_model; |
|
33 | - /** |
|
34 | - * |
|
35 | - * @param string $default_field_name the name of the field Name of the field on this model (or a related model, including the model chain to it) |
|
36 | - * that is a boolean indicating whether or not a model object is considered "Default" or not |
|
37 | - * @param string $path_to_event_model The model chain to follow to get to the event model, including the event model itself. |
|
38 | - * Eg 'Ticket.Datetime.Event' |
|
39 | - */ |
|
40 | - public function __construct($default_field_name, $path_to_event_model) |
|
41 | - { |
|
42 | - $this->_default_field_name = $default_field_name; |
|
43 | - if (substr($path_to_event_model, -1, 1) != '.') { |
|
44 | - $path_to_event_model .= '.'; |
|
45 | - } |
|
46 | - $this->_path_to_event_model = $path_to_event_model; |
|
47 | - } |
|
27 | + /** |
|
28 | + * The model chain to follow to get to the event model, including the event model itself. |
|
29 | + * Eg 'Ticket.Datetime.Event' |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $_path_to_event_model; |
|
33 | + /** |
|
34 | + * |
|
35 | + * @param string $default_field_name the name of the field Name of the field on this model (or a related model, including the model chain to it) |
|
36 | + * that is a boolean indicating whether or not a model object is considered "Default" or not |
|
37 | + * @param string $path_to_event_model The model chain to follow to get to the event model, including the event model itself. |
|
38 | + * Eg 'Ticket.Datetime.Event' |
|
39 | + */ |
|
40 | + public function __construct($default_field_name, $path_to_event_model) |
|
41 | + { |
|
42 | + $this->_default_field_name = $default_field_name; |
|
43 | + if (substr($path_to_event_model, -1, 1) != '.') { |
|
44 | + $path_to_event_model .= '.'; |
|
45 | + } |
|
46 | + $this->_path_to_event_model = $path_to_event_model; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return EE_Default_Where_Conditions |
|
51 | - * @throws EE_Error |
|
52 | - */ |
|
53 | - protected function _generate_restrictions() |
|
54 | - { |
|
55 | - // if there are no standard caps for this model, then for now all we know |
|
56 | - // if they need the default cap to access this |
|
57 | - if (!$this->model()->cap_slug()) { |
|
58 | - return array( |
|
59 | - self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
|
60 | - ); |
|
61 | - } |
|
49 | + /** |
|
50 | + * @return EE_Default_Where_Conditions |
|
51 | + * @throws EE_Error |
|
52 | + */ |
|
53 | + protected function _generate_restrictions() |
|
54 | + { |
|
55 | + // if there are no standard caps for this model, then for now all we know |
|
56 | + // if they need the default cap to access this |
|
57 | + if (!$this->model()->cap_slug()) { |
|
58 | + return array( |
|
59 | + self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - $event_model = EEM_Event::instance(); |
|
63 | + $event_model = EEM_Event::instance(); |
|
64 | 64 | |
65 | - $restrictions = array( |
|
66 | - // first: basically access to non-defaults is essentially controlled by which events are accessible |
|
67 | - // if they don't have the basic event cap, they can't access ANY non-default items |
|
68 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(array( |
|
69 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => $this->addPublishedPostConditions( |
|
70 | - array( |
|
71 | - $this->_default_field_name => true, |
|
72 | - ), |
|
73 | - true, |
|
74 | - $this->_path_to_event_model |
|
75 | - ) |
|
76 | - )), |
|
77 | - // if they don't have the others event cap, they can only access their own, others' that are for published events, or defaults |
|
78 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions( |
|
79 | - array( |
|
80 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions( |
|
81 | - array( |
|
82 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
83 | - $this->_default_field_name => true, |
|
84 | - ), |
|
85 | - true, |
|
86 | - $this->_path_to_event_model |
|
87 | - ) |
|
88 | - ) |
|
89 | - ), |
|
90 | - // if they have basic and others, but not private, they can access default, their own, and others' that aren't private |
|
91 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions( |
|
92 | - array( |
|
93 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions( |
|
94 | - array( |
|
95 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
96 | - $this->_default_field_name => true |
|
97 | - ), |
|
98 | - false, |
|
99 | - $this->_path_to_event_model |
|
100 | - ) |
|
101 | - ) |
|
102 | - ), |
|
103 | - // second: access to defaults is controlled by the default capabilities |
|
104 | - // if they don't have the basic default capability, restrict access to only non-default items |
|
105 | - EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_default') => new EE_Default_Where_Conditions( |
|
106 | - array( $this->_default_field_name => false ) |
|
107 | - ), |
|
108 | - ); |
|
109 | - if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others_default')) { |
|
110 | - // if they don't have the "others" default capability, restrict access to only their default ones, and non-default ones |
|
111 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') ] = new EE_Default_Where_Conditions( |
|
112 | - array( |
|
113 | - // if they don't have the others default cap, they can't access others default items (but they can access |
|
114 | - // their own default items, and non-default items) |
|
115 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') => array( |
|
116 | - 'AND' => array( |
|
117 | - EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
|
118 | - $this->_default_field_name => true |
|
119 | - ), |
|
120 | - $this->_default_field_name => false |
|
121 | - ) |
|
122 | - ) |
|
123 | - ); |
|
124 | - } |
|
125 | - return $restrictions; |
|
126 | - } |
|
65 | + $restrictions = array( |
|
66 | + // first: basically access to non-defaults is essentially controlled by which events are accessible |
|
67 | + // if they don't have the basic event cap, they can't access ANY non-default items |
|
68 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(array( |
|
69 | + 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => $this->addPublishedPostConditions( |
|
70 | + array( |
|
71 | + $this->_default_field_name => true, |
|
72 | + ), |
|
73 | + true, |
|
74 | + $this->_path_to_event_model |
|
75 | + ) |
|
76 | + )), |
|
77 | + // if they don't have the others event cap, they can only access their own, others' that are for published events, or defaults |
|
78 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions( |
|
79 | + array( |
|
80 | + 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions( |
|
81 | + array( |
|
82 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
83 | + $this->_default_field_name => true, |
|
84 | + ), |
|
85 | + true, |
|
86 | + $this->_path_to_event_model |
|
87 | + ) |
|
88 | + ) |
|
89 | + ), |
|
90 | + // if they have basic and others, but not private, they can access default, their own, and others' that aren't private |
|
91 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions( |
|
92 | + array( |
|
93 | + 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions( |
|
94 | + array( |
|
95 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
96 | + $this->_default_field_name => true |
|
97 | + ), |
|
98 | + false, |
|
99 | + $this->_path_to_event_model |
|
100 | + ) |
|
101 | + ) |
|
102 | + ), |
|
103 | + // second: access to defaults is controlled by the default capabilities |
|
104 | + // if they don't have the basic default capability, restrict access to only non-default items |
|
105 | + EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_default') => new EE_Default_Where_Conditions( |
|
106 | + array( $this->_default_field_name => false ) |
|
107 | + ), |
|
108 | + ); |
|
109 | + if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others_default')) { |
|
110 | + // if they don't have the "others" default capability, restrict access to only their default ones, and non-default ones |
|
111 | + $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') ] = new EE_Default_Where_Conditions( |
|
112 | + array( |
|
113 | + // if they don't have the others default cap, they can't access others default items (but they can access |
|
114 | + // their own default items, and non-default items) |
|
115 | + 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') => array( |
|
116 | + 'AND' => array( |
|
117 | + EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
|
118 | + $this->_default_field_name => true |
|
119 | + ), |
|
120 | + $this->_default_field_name => false |
|
121 | + ) |
|
122 | + ) |
|
123 | + ); |
|
124 | + } |
|
125 | + return $restrictions; |
|
126 | + } |
|
127 | 127 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | // if there are no standard caps for this model, then for now all we know |
56 | 56 | // if they need the default cap to access this |
57 | - if (!$this->model()->cap_slug()) { |
|
57 | + if ( ! $this->model()->cap_slug()) { |
|
58 | 58 | return array( |
59 | 59 | self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
60 | 60 | ); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | // first: basically access to non-defaults is essentially controlled by which events are accessible |
67 | 67 | // if they don't have the basic event cap, they can't access ANY non-default items |
68 | 68 | EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions(array( |
69 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => $this->addPublishedPostConditions( |
|
69 | + 'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action()) => $this->addPublishedPostConditions( |
|
70 | 70 | array( |
71 | 71 | $this->_default_field_name => true, |
72 | 72 | ), |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | ) |
76 | 76 | )), |
77 | 77 | // if they don't have the others event cap, they can only access their own, others' that are for published events, or defaults |
78 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => new EE_Default_Where_Conditions( |
|
78 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_others') => new EE_Default_Where_Conditions( |
|
79 | 79 | array( |
80 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_others') => $this->addPublishedPostConditions( |
|
80 | + 'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_others') => $this->addPublishedPostConditions( |
|
81 | 81 | array( |
82 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
82 | + $this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
83 | 83 | $this->_default_field_name => true, |
84 | 84 | ), |
85 | 85 | true, |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | ) |
89 | 89 | ), |
90 | 90 | // if they have basic and others, but not private, they can access default, their own, and others' that aren't private |
91 | - EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions( |
|
91 | + EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_private') => new EE_Default_Where_Conditions( |
|
92 | 92 | array( |
93 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action() . '_private') => $this->addPublishedPostConditions( |
|
93 | + 'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($event_model, $this->action().'_private') => $this->addPublishedPostConditions( |
|
94 | 94 | array( |
95 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
95 | + $this->_path_to_event_model.'EVT_wp_user' => EE_Default_Where_Conditions::current_user_placeholder, |
|
96 | 96 | $this->_default_field_name => true |
97 | 97 | ), |
98 | 98 | false, |
@@ -102,17 +102,17 @@ discard block |
||
102 | 102 | ), |
103 | 103 | // second: access to defaults is controlled by the default capabilities |
104 | 104 | // if they don't have the basic default capability, restrict access to only non-default items |
105 | - EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_default') => new EE_Default_Where_Conditions( |
|
106 | - array( $this->_default_field_name => false ) |
|
105 | + EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_default') => new EE_Default_Where_Conditions( |
|
106 | + array($this->_default_field_name => false) |
|
107 | 107 | ), |
108 | 108 | ); |
109 | - if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action() . '_others_default')) { |
|
109 | + if (EE_Restriction_Generator_Base::is_cap($this->model(), $this->action().'_others_default')) { |
|
110 | 110 | // if they don't have the "others" default capability, restrict access to only their default ones, and non-default ones |
111 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') ] = new EE_Default_Where_Conditions( |
|
111 | + $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others_default')] = new EE_Default_Where_Conditions( |
|
112 | 112 | array( |
113 | 113 | // if they don't have the others default cap, they can't access others default items (but they can access |
114 | 114 | // their own default items, and non-default items) |
115 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_others_default') => array( |
|
115 | + 'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_others_default') => array( |
|
116 | 116 | 'AND' => array( |
117 | 117 | EE_Default_Where_Conditions::user_field_name_placeholder => EE_Default_Where_Conditions::current_user_placeholder, |
118 | 118 | $this->_default_field_name => true |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | protected function setCollectionInterface($collection_interface) |
68 | 68 | { |
69 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
69 | + if ( ! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
70 | 70 | throw new InvalidInterfaceException($collection_interface); |
71 | 71 | } |
72 | 72 | $this->collection_interface = $collection_interface; |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | protected function setCollectionIdentifier() |
112 | 112 | { |
113 | 113 | // hash a few collection details |
114 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
114 | + $identifier = md5(spl_object_hash($this).$this->collection_interface.time()); |
|
115 | 115 | // grab a few characters from the start, middle, and end of the hash |
116 | 116 | $id = array(); |
117 | 117 | for ($x = 0; $x < 19; $x += 9) { |
118 | 118 | $id[] = substr($identifier, $x, 3); |
119 | 119 | } |
120 | - $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id)); |
|
120 | + $this->collection_identifier = $this->collection_name.'-'.strtoupper(implode('-', $id)); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function add($object, $identifier = null) |
137 | 137 | { |
138 | - if (! $object instanceof $this->collection_interface) { |
|
138 | + if ( ! $object instanceof $this->collection_interface) { |
|
139 | 139 | throw new InvalidEntityException($object, $this->collection_interface); |
140 | 140 | } |
141 | 141 | if ($this->contains($object)) { |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | */ |
352 | 352 | public function indexOf($object) |
353 | 353 | { |
354 | - if (! $this->contains($object)) { |
|
354 | + if ( ! $this->contains($object)) { |
|
355 | 355 | return false; |
356 | 356 | } |
357 | 357 | foreach ($this as $index => $obj) { |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | $remaining_objects = $this->slice($index, $this->count() - $index); |
421 | 421 | foreach ($remaining_objects as $key => $remaining_object) { |
422 | 422 | // we need to grab the identifiers for each object and use them as keys |
423 | - $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
423 | + $remaining_objects[$remaining_object->getInfo()] = $remaining_object; |
|
424 | 424 | // and then remove the object from the current tracking array |
425 | - unset($remaining_objects[ $key ]); |
|
425 | + unset($remaining_objects[$key]); |
|
426 | 426 | // and then remove it from the Collection |
427 | 427 | $this->detach($remaining_object); |
428 | 428 | } |
@@ -446,17 +446,17 @@ discard block |
||
446 | 446 | */ |
447 | 447 | public function insertAt($objects, $index) |
448 | 448 | { |
449 | - if (! is_array($objects)) { |
|
449 | + if ( ! is_array($objects)) { |
|
450 | 450 | $objects = array($objects); |
451 | 451 | } |
452 | 452 | // check to ensure that objects don't already exist in the collection |
453 | 453 | foreach ($objects as $key => $object) { |
454 | 454 | if ($this->contains($object)) { |
455 | - unset($objects[ $key ]); |
|
455 | + unset($objects[$key]); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | // do we have any objects left? |
459 | - if (! $objects) { |
|
459 | + if ( ! $objects) { |
|
460 | 460 | return; |
461 | 461 | } |
462 | 462 | // detach any objects at or past this index |
@@ -18,514 +18,514 @@ |
||
18 | 18 | */ |
19 | 19 | class Collection extends SplObjectStorage implements CollectionInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * a unique string for identifying this collection |
|
23 | - * |
|
24 | - * @type string $collection_identifier |
|
25 | - */ |
|
26 | - protected $collection_identifier; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
31 | - * this should be set from within the child class constructor |
|
32 | - * |
|
33 | - * @type string $interface |
|
34 | - */ |
|
35 | - protected $collection_interface; |
|
36 | - |
|
37 | - /** |
|
38 | - * a short dash separated string describing the contents of this collection |
|
39 | - * used as the base for the $collection_identifier |
|
40 | - * defaults to the class short name if not set |
|
41 | - * |
|
42 | - * @type string $collection_identifier |
|
43 | - */ |
|
44 | - protected $collection_name; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Collection constructor |
|
49 | - * |
|
50 | - * @param string $collection_interface |
|
51 | - * @param string $collection_name |
|
52 | - * @throws InvalidInterfaceException |
|
53 | - */ |
|
54 | - public function __construct($collection_interface, $collection_name = '') |
|
55 | - { |
|
56 | - $this->setCollectionInterface($collection_interface); |
|
57 | - $this->setCollectionName($collection_name); |
|
58 | - $this->setCollectionIdentifier(); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return string |
|
64 | - * @since 4.10.33.p |
|
65 | - */ |
|
66 | - public function collectionInterface(): string |
|
67 | - { |
|
68 | - return $this->collection_interface; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * setCollectionInterface |
|
74 | - * |
|
75 | - * @param string $collection_interface |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - */ |
|
78 | - protected function setCollectionInterface($collection_interface) |
|
79 | - { |
|
80 | - if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
81 | - throw new InvalidInterfaceException($collection_interface); |
|
82 | - } |
|
83 | - $this->collection_interface = $collection_interface; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function collectionName() |
|
91 | - { |
|
92 | - return $this->collection_name; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @param string $collection_name |
|
98 | - */ |
|
99 | - protected function setCollectionName($collection_name) |
|
100 | - { |
|
101 | - $this->collection_name = ! empty($collection_name) |
|
102 | - ? sanitize_key($collection_name) |
|
103 | - : basename(str_replace('\\', '/', get_class($this))); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function collectionIdentifier() |
|
111 | - { |
|
112 | - return $this->collection_identifier; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
118 | - * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
119 | - * |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - protected function setCollectionIdentifier() |
|
123 | - { |
|
124 | - // hash a few collection details |
|
125 | - $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
126 | - // grab a few characters from the start, middle, and end of the hash |
|
127 | - $id = array(); |
|
128 | - for ($x = 0; $x < 19; $x += 9) { |
|
129 | - $id[] = substr($identifier, $x, 3); |
|
130 | - } |
|
131 | - $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id)); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * add |
|
137 | - * attaches an object to the Collection |
|
138 | - * and sets any supplied data associated with the current iterator entry |
|
139 | - * by calling EE_Object_Collection::set_identifier() |
|
140 | - * |
|
141 | - * @param $object |
|
142 | - * @param mixed $identifier |
|
143 | - * @return bool |
|
144 | - * @throws InvalidEntityException |
|
145 | - * @throws DuplicateCollectionIdentifierException |
|
146 | - */ |
|
147 | - public function add($object, $identifier = null) |
|
148 | - { |
|
149 | - if (! $object instanceof $this->collection_interface) { |
|
150 | - throw new InvalidEntityException($object, $this->collection_interface); |
|
151 | - } |
|
152 | - if ($this->contains($object)) { |
|
153 | - throw new DuplicateCollectionIdentifierException($identifier); |
|
154 | - } |
|
155 | - $this->attach($object); |
|
156 | - $this->setIdentifier($object, $identifier); |
|
157 | - return $this->contains($object); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * getIdentifier |
|
163 | - * if no $identifier is supplied, then the spl_object_hash() is used |
|
164 | - * |
|
165 | - * @param $object |
|
166 | - * @param mixed $identifier |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - public function getIdentifier($object, $identifier = null) |
|
170 | - { |
|
171 | - return ! empty($identifier) |
|
172 | - ? $identifier |
|
173 | - : spl_object_hash($object); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * setIdentifier |
|
179 | - * Sets the data associated with an object in the Collection |
|
180 | - * if no $identifier is supplied, then the spl_object_hash() is used |
|
181 | - * |
|
182 | - * @param $object |
|
183 | - * @param mixed $identifier |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function setIdentifier($object, $identifier = null) |
|
187 | - { |
|
188 | - $identifier = $this->getIdentifier($object, $identifier); |
|
189 | - $this->rewind(); |
|
190 | - while ($this->valid()) { |
|
191 | - if ($object === $this->current()) { |
|
192 | - $this->setInfo($identifier); |
|
193 | - $this->rewind(); |
|
194 | - return true; |
|
195 | - } |
|
196 | - $this->next(); |
|
197 | - } |
|
198 | - return false; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * get |
|
204 | - * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
205 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
206 | - * |
|
207 | - * @param mixed $identifier |
|
208 | - * @return mixed |
|
209 | - */ |
|
210 | - public function get($identifier) |
|
211 | - { |
|
212 | - $this->rewind(); |
|
213 | - while ($this->valid()) { |
|
214 | - if ($identifier === $this->getInfo()) { |
|
215 | - $object = $this->current(); |
|
216 | - $this->rewind(); |
|
217 | - return $object; |
|
218 | - } |
|
219 | - $this->next(); |
|
220 | - } |
|
221 | - return null; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * has |
|
227 | - * returns TRUE or FALSE |
|
228 | - * depending on whether the object is within the Collection |
|
229 | - * based on the supplied $identifier |
|
230 | - * |
|
231 | - * @param mixed $identifier |
|
232 | - * @return bool |
|
233 | - */ |
|
234 | - public function has($identifier) |
|
235 | - { |
|
236 | - $this->rewind(); |
|
237 | - while ($this->valid()) { |
|
238 | - if ($identifier === $this->getInfo()) { |
|
239 | - $this->rewind(); |
|
240 | - return true; |
|
241 | - } |
|
242 | - $this->next(); |
|
243 | - } |
|
244 | - return false; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * hasObject |
|
250 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
251 | - * |
|
252 | - * @param $object |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - public function hasObject($object) |
|
256 | - { |
|
257 | - return $this->contains($object); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * hasObjects |
|
263 | - * returns true if there are objects within the Collection, and false if it is empty |
|
264 | - * |
|
265 | - * @return bool |
|
266 | - */ |
|
267 | - public function hasObjects() |
|
268 | - { |
|
269 | - return $this->count() !== 0; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * isEmpty |
|
275 | - * returns true if there are no objects within the Collection, and false if there are |
|
276 | - * |
|
277 | - * @return bool |
|
278 | - */ |
|
279 | - public function isEmpty() |
|
280 | - { |
|
281 | - return $this->count() === 0; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * remove |
|
287 | - * detaches an object from the Collection |
|
288 | - * |
|
289 | - * @param $object |
|
290 | - * @return bool |
|
291 | - */ |
|
292 | - public function remove($object) |
|
293 | - { |
|
294 | - $this->detach($object); |
|
295 | - return true; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * setCurrent |
|
301 | - * advances pointer to the object whose identifier matches that which was provided |
|
302 | - * |
|
303 | - * @param mixed $identifier |
|
304 | - * @return boolean |
|
305 | - */ |
|
306 | - public function setCurrent($identifier) |
|
307 | - { |
|
308 | - $this->rewind(); |
|
309 | - while ($this->valid()) { |
|
310 | - if ($identifier === $this->getInfo()) { |
|
311 | - return true; |
|
312 | - } |
|
313 | - $this->next(); |
|
314 | - } |
|
315 | - return false; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * setCurrentUsingObject |
|
321 | - * advances pointer to the provided object |
|
322 | - * |
|
323 | - * @param $object |
|
324 | - * @return boolean |
|
325 | - */ |
|
326 | - public function setCurrentUsingObject($object) |
|
327 | - { |
|
328 | - $this->rewind(); |
|
329 | - while ($this->valid()) { |
|
330 | - if ($this->current() === $object) { |
|
331 | - return true; |
|
332 | - } |
|
333 | - $this->next(); |
|
334 | - } |
|
335 | - return false; |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * Returns the object occupying the index before the current object, |
|
341 | - * unless this is already the first object, in which case it just returns the first object |
|
342 | - * |
|
343 | - * @return mixed |
|
344 | - */ |
|
345 | - public function previous() |
|
346 | - { |
|
347 | - $index = $this->indexOf($this->current()); |
|
348 | - if ($index === 0) { |
|
349 | - return $this->current(); |
|
350 | - } |
|
351 | - $index--; |
|
352 | - return $this->objectAtIndex($index); |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * Returns the index of a given object, or false if not found |
|
358 | - * |
|
359 | - * @see http://stackoverflow.com/a/8736013 |
|
360 | - * @param $object |
|
361 | - * @return boolean|int|string |
|
362 | - */ |
|
363 | - public function indexOf($object) |
|
364 | - { |
|
365 | - if (! $this->contains($object)) { |
|
366 | - return false; |
|
367 | - } |
|
368 | - foreach ($this as $index => $obj) { |
|
369 | - if ($obj === $object) { |
|
370 | - return $index; |
|
371 | - } |
|
372 | - } |
|
373 | - return false; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Returns the object at the given index |
|
379 | - * |
|
380 | - * @see http://stackoverflow.com/a/8736013 |
|
381 | - * @param int $index |
|
382 | - * @return mixed |
|
383 | - */ |
|
384 | - public function objectAtIndex($index) |
|
385 | - { |
|
386 | - $iterator = new LimitIterator($this, $index, 1); |
|
387 | - $iterator->rewind(); |
|
388 | - return $iterator->current(); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Returns the sequence of objects as specified by the offset and length |
|
394 | - * |
|
395 | - * @see http://stackoverflow.com/a/8736013 |
|
396 | - * @param int $offset |
|
397 | - * @param int $length |
|
398 | - * @return array |
|
399 | - */ |
|
400 | - public function slice($offset, $length) |
|
401 | - { |
|
402 | - $slice = array(); |
|
403 | - $iterator = new LimitIterator($this, $offset, $length); |
|
404 | - foreach ($iterator as $object) { |
|
405 | - $slice[] = $object; |
|
406 | - } |
|
407 | - return $slice; |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * Inserts an object at a certain point |
|
413 | - * |
|
414 | - * @see http://stackoverflow.com/a/8736013 |
|
415 | - * @param mixed $object A single object |
|
416 | - * @param int $index |
|
417 | - * @param mixed $identifier |
|
418 | - * @return bool |
|
419 | - * @throws DuplicateCollectionIdentifierException |
|
420 | - * @throws InvalidEntityException |
|
421 | - */ |
|
422 | - public function insertObjectAt($object, $index, $identifier = null) |
|
423 | - { |
|
424 | - // check to ensure that objects don't already exist in the collection |
|
425 | - if ($this->has($identifier)) { |
|
426 | - throw new DuplicateCollectionIdentifierException($identifier); |
|
427 | - } |
|
428 | - // detach any objects at or past this index |
|
429 | - $remaining_objects = array(); |
|
430 | - if ($index < $this->count()) { |
|
431 | - $remaining_objects = $this->slice($index, $this->count() - $index); |
|
432 | - foreach ($remaining_objects as $key => $remaining_object) { |
|
433 | - // we need to grab the identifiers for each object and use them as keys |
|
434 | - $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
435 | - // and then remove the object from the current tracking array |
|
436 | - unset($remaining_objects[ $key ]); |
|
437 | - // and then remove it from the Collection |
|
438 | - $this->detach($remaining_object); |
|
439 | - } |
|
440 | - } |
|
441 | - // add the new object we're splicing in |
|
442 | - $this->add($object, $identifier); |
|
443 | - // attach the objects we previously detached |
|
444 | - foreach ($remaining_objects as $key => $remaining_object) { |
|
445 | - $this->add($remaining_object, $key); |
|
446 | - } |
|
447 | - return $this->contains($object); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * Inserts an object (or an array of objects) at a certain point |
|
453 | - * |
|
454 | - * @see http://stackoverflow.com/a/8736013 |
|
455 | - * @param mixed $objects A single object or an array of objects |
|
456 | - * @param int $index |
|
457 | - */ |
|
458 | - public function insertAt($objects, $index) |
|
459 | - { |
|
460 | - if (! is_array($objects)) { |
|
461 | - $objects = array($objects); |
|
462 | - } |
|
463 | - // check to ensure that objects don't already exist in the collection |
|
464 | - foreach ($objects as $key => $object) { |
|
465 | - if ($this->contains($object)) { |
|
466 | - unset($objects[ $key ]); |
|
467 | - } |
|
468 | - } |
|
469 | - // do we have any objects left? |
|
470 | - if (! $objects) { |
|
471 | - return; |
|
472 | - } |
|
473 | - // detach any objects at or past this index |
|
474 | - $remaining = array(); |
|
475 | - if ($index < $this->count()) { |
|
476 | - $remaining = $this->slice($index, $this->count() - $index); |
|
477 | - foreach ($remaining as $object) { |
|
478 | - $this->detach($object); |
|
479 | - } |
|
480 | - } |
|
481 | - // add the new objects we're splicing in |
|
482 | - foreach ($objects as $object) { |
|
483 | - $this->attach($object); |
|
484 | - } |
|
485 | - // attach the objects we previously detached |
|
486 | - foreach ($remaining as $object) { |
|
487 | - $this->attach($object); |
|
488 | - } |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * Removes the object at the given index |
|
494 | - * |
|
495 | - * @see http://stackoverflow.com/a/8736013 |
|
496 | - * @param int $index |
|
497 | - */ |
|
498 | - public function removeAt($index) |
|
499 | - { |
|
500 | - $this->detach($this->objectAtIndex($index)); |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * detaches ALL objects from the Collection |
|
506 | - */ |
|
507 | - public function detachAll() |
|
508 | - { |
|
509 | - $this->rewind(); |
|
510 | - while ($this->valid()) { |
|
511 | - $object = $this->current(); |
|
512 | - $this->next(); |
|
513 | - $this->detach($object); |
|
514 | - } |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * unsets and detaches ALL objects from the Collection |
|
520 | - */ |
|
521 | - public function trashAndDetachAll() |
|
522 | - { |
|
523 | - $this->rewind(); |
|
524 | - while ($this->valid()) { |
|
525 | - $object = $this->current(); |
|
526 | - $this->next(); |
|
527 | - $this->detach($object); |
|
528 | - unset($object); |
|
529 | - } |
|
530 | - } |
|
21 | + /** |
|
22 | + * a unique string for identifying this collection |
|
23 | + * |
|
24 | + * @type string $collection_identifier |
|
25 | + */ |
|
26 | + protected $collection_identifier; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * an interface (or class) name to be used for restricting the type of objects added to the storage |
|
31 | + * this should be set from within the child class constructor |
|
32 | + * |
|
33 | + * @type string $interface |
|
34 | + */ |
|
35 | + protected $collection_interface; |
|
36 | + |
|
37 | + /** |
|
38 | + * a short dash separated string describing the contents of this collection |
|
39 | + * used as the base for the $collection_identifier |
|
40 | + * defaults to the class short name if not set |
|
41 | + * |
|
42 | + * @type string $collection_identifier |
|
43 | + */ |
|
44 | + protected $collection_name; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Collection constructor |
|
49 | + * |
|
50 | + * @param string $collection_interface |
|
51 | + * @param string $collection_name |
|
52 | + * @throws InvalidInterfaceException |
|
53 | + */ |
|
54 | + public function __construct($collection_interface, $collection_name = '') |
|
55 | + { |
|
56 | + $this->setCollectionInterface($collection_interface); |
|
57 | + $this->setCollectionName($collection_name); |
|
58 | + $this->setCollectionIdentifier(); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + * @since 4.10.33.p |
|
65 | + */ |
|
66 | + public function collectionInterface(): string |
|
67 | + { |
|
68 | + return $this->collection_interface; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * setCollectionInterface |
|
74 | + * |
|
75 | + * @param string $collection_interface |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + */ |
|
78 | + protected function setCollectionInterface($collection_interface) |
|
79 | + { |
|
80 | + if (! (interface_exists($collection_interface) || class_exists($collection_interface))) { |
|
81 | + throw new InvalidInterfaceException($collection_interface); |
|
82 | + } |
|
83 | + $this->collection_interface = $collection_interface; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function collectionName() |
|
91 | + { |
|
92 | + return $this->collection_name; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @param string $collection_name |
|
98 | + */ |
|
99 | + protected function setCollectionName($collection_name) |
|
100 | + { |
|
101 | + $this->collection_name = ! empty($collection_name) |
|
102 | + ? sanitize_key($collection_name) |
|
103 | + : basename(str_replace('\\', '/', get_class($this))); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function collectionIdentifier() |
|
111 | + { |
|
112 | + return $this->collection_identifier; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * creates a very readable unique 9 character identifier like: CF2-532-DAC |
|
118 | + * and appends it to the non-qualified class name, ex: ThingCollection-CF2-532-DAC |
|
119 | + * |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + protected function setCollectionIdentifier() |
|
123 | + { |
|
124 | + // hash a few collection details |
|
125 | + $identifier = md5(spl_object_hash($this) . $this->collection_interface . time()); |
|
126 | + // grab a few characters from the start, middle, and end of the hash |
|
127 | + $id = array(); |
|
128 | + for ($x = 0; $x < 19; $x += 9) { |
|
129 | + $id[] = substr($identifier, $x, 3); |
|
130 | + } |
|
131 | + $this->collection_identifier = $this->collection_name . '-' . strtoupper(implode('-', $id)); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * add |
|
137 | + * attaches an object to the Collection |
|
138 | + * and sets any supplied data associated with the current iterator entry |
|
139 | + * by calling EE_Object_Collection::set_identifier() |
|
140 | + * |
|
141 | + * @param $object |
|
142 | + * @param mixed $identifier |
|
143 | + * @return bool |
|
144 | + * @throws InvalidEntityException |
|
145 | + * @throws DuplicateCollectionIdentifierException |
|
146 | + */ |
|
147 | + public function add($object, $identifier = null) |
|
148 | + { |
|
149 | + if (! $object instanceof $this->collection_interface) { |
|
150 | + throw new InvalidEntityException($object, $this->collection_interface); |
|
151 | + } |
|
152 | + if ($this->contains($object)) { |
|
153 | + throw new DuplicateCollectionIdentifierException($identifier); |
|
154 | + } |
|
155 | + $this->attach($object); |
|
156 | + $this->setIdentifier($object, $identifier); |
|
157 | + return $this->contains($object); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * getIdentifier |
|
163 | + * if no $identifier is supplied, then the spl_object_hash() is used |
|
164 | + * |
|
165 | + * @param $object |
|
166 | + * @param mixed $identifier |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + public function getIdentifier($object, $identifier = null) |
|
170 | + { |
|
171 | + return ! empty($identifier) |
|
172 | + ? $identifier |
|
173 | + : spl_object_hash($object); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * setIdentifier |
|
179 | + * Sets the data associated with an object in the Collection |
|
180 | + * if no $identifier is supplied, then the spl_object_hash() is used |
|
181 | + * |
|
182 | + * @param $object |
|
183 | + * @param mixed $identifier |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function setIdentifier($object, $identifier = null) |
|
187 | + { |
|
188 | + $identifier = $this->getIdentifier($object, $identifier); |
|
189 | + $this->rewind(); |
|
190 | + while ($this->valid()) { |
|
191 | + if ($object === $this->current()) { |
|
192 | + $this->setInfo($identifier); |
|
193 | + $this->rewind(); |
|
194 | + return true; |
|
195 | + } |
|
196 | + $this->next(); |
|
197 | + } |
|
198 | + return false; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * get |
|
204 | + * finds and returns an object in the Collection based on the identifier that was set using addObject() |
|
205 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
206 | + * |
|
207 | + * @param mixed $identifier |
|
208 | + * @return mixed |
|
209 | + */ |
|
210 | + public function get($identifier) |
|
211 | + { |
|
212 | + $this->rewind(); |
|
213 | + while ($this->valid()) { |
|
214 | + if ($identifier === $this->getInfo()) { |
|
215 | + $object = $this->current(); |
|
216 | + $this->rewind(); |
|
217 | + return $object; |
|
218 | + } |
|
219 | + $this->next(); |
|
220 | + } |
|
221 | + return null; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * has |
|
227 | + * returns TRUE or FALSE |
|
228 | + * depending on whether the object is within the Collection |
|
229 | + * based on the supplied $identifier |
|
230 | + * |
|
231 | + * @param mixed $identifier |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | + public function has($identifier) |
|
235 | + { |
|
236 | + $this->rewind(); |
|
237 | + while ($this->valid()) { |
|
238 | + if ($identifier === $this->getInfo()) { |
|
239 | + $this->rewind(); |
|
240 | + return true; |
|
241 | + } |
|
242 | + $this->next(); |
|
243 | + } |
|
244 | + return false; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * hasObject |
|
250 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
251 | + * |
|
252 | + * @param $object |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + public function hasObject($object) |
|
256 | + { |
|
257 | + return $this->contains($object); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * hasObjects |
|
263 | + * returns true if there are objects within the Collection, and false if it is empty |
|
264 | + * |
|
265 | + * @return bool |
|
266 | + */ |
|
267 | + public function hasObjects() |
|
268 | + { |
|
269 | + return $this->count() !== 0; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * isEmpty |
|
275 | + * returns true if there are no objects within the Collection, and false if there are |
|
276 | + * |
|
277 | + * @return bool |
|
278 | + */ |
|
279 | + public function isEmpty() |
|
280 | + { |
|
281 | + return $this->count() === 0; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * remove |
|
287 | + * detaches an object from the Collection |
|
288 | + * |
|
289 | + * @param $object |
|
290 | + * @return bool |
|
291 | + */ |
|
292 | + public function remove($object) |
|
293 | + { |
|
294 | + $this->detach($object); |
|
295 | + return true; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * setCurrent |
|
301 | + * advances pointer to the object whose identifier matches that which was provided |
|
302 | + * |
|
303 | + * @param mixed $identifier |
|
304 | + * @return boolean |
|
305 | + */ |
|
306 | + public function setCurrent($identifier) |
|
307 | + { |
|
308 | + $this->rewind(); |
|
309 | + while ($this->valid()) { |
|
310 | + if ($identifier === $this->getInfo()) { |
|
311 | + return true; |
|
312 | + } |
|
313 | + $this->next(); |
|
314 | + } |
|
315 | + return false; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * setCurrentUsingObject |
|
321 | + * advances pointer to the provided object |
|
322 | + * |
|
323 | + * @param $object |
|
324 | + * @return boolean |
|
325 | + */ |
|
326 | + public function setCurrentUsingObject($object) |
|
327 | + { |
|
328 | + $this->rewind(); |
|
329 | + while ($this->valid()) { |
|
330 | + if ($this->current() === $object) { |
|
331 | + return true; |
|
332 | + } |
|
333 | + $this->next(); |
|
334 | + } |
|
335 | + return false; |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * Returns the object occupying the index before the current object, |
|
341 | + * unless this is already the first object, in which case it just returns the first object |
|
342 | + * |
|
343 | + * @return mixed |
|
344 | + */ |
|
345 | + public function previous() |
|
346 | + { |
|
347 | + $index = $this->indexOf($this->current()); |
|
348 | + if ($index === 0) { |
|
349 | + return $this->current(); |
|
350 | + } |
|
351 | + $index--; |
|
352 | + return $this->objectAtIndex($index); |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * Returns the index of a given object, or false if not found |
|
358 | + * |
|
359 | + * @see http://stackoverflow.com/a/8736013 |
|
360 | + * @param $object |
|
361 | + * @return boolean|int|string |
|
362 | + */ |
|
363 | + public function indexOf($object) |
|
364 | + { |
|
365 | + if (! $this->contains($object)) { |
|
366 | + return false; |
|
367 | + } |
|
368 | + foreach ($this as $index => $obj) { |
|
369 | + if ($obj === $object) { |
|
370 | + return $index; |
|
371 | + } |
|
372 | + } |
|
373 | + return false; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Returns the object at the given index |
|
379 | + * |
|
380 | + * @see http://stackoverflow.com/a/8736013 |
|
381 | + * @param int $index |
|
382 | + * @return mixed |
|
383 | + */ |
|
384 | + public function objectAtIndex($index) |
|
385 | + { |
|
386 | + $iterator = new LimitIterator($this, $index, 1); |
|
387 | + $iterator->rewind(); |
|
388 | + return $iterator->current(); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Returns the sequence of objects as specified by the offset and length |
|
394 | + * |
|
395 | + * @see http://stackoverflow.com/a/8736013 |
|
396 | + * @param int $offset |
|
397 | + * @param int $length |
|
398 | + * @return array |
|
399 | + */ |
|
400 | + public function slice($offset, $length) |
|
401 | + { |
|
402 | + $slice = array(); |
|
403 | + $iterator = new LimitIterator($this, $offset, $length); |
|
404 | + foreach ($iterator as $object) { |
|
405 | + $slice[] = $object; |
|
406 | + } |
|
407 | + return $slice; |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * Inserts an object at a certain point |
|
413 | + * |
|
414 | + * @see http://stackoverflow.com/a/8736013 |
|
415 | + * @param mixed $object A single object |
|
416 | + * @param int $index |
|
417 | + * @param mixed $identifier |
|
418 | + * @return bool |
|
419 | + * @throws DuplicateCollectionIdentifierException |
|
420 | + * @throws InvalidEntityException |
|
421 | + */ |
|
422 | + public function insertObjectAt($object, $index, $identifier = null) |
|
423 | + { |
|
424 | + // check to ensure that objects don't already exist in the collection |
|
425 | + if ($this->has($identifier)) { |
|
426 | + throw new DuplicateCollectionIdentifierException($identifier); |
|
427 | + } |
|
428 | + // detach any objects at or past this index |
|
429 | + $remaining_objects = array(); |
|
430 | + if ($index < $this->count()) { |
|
431 | + $remaining_objects = $this->slice($index, $this->count() - $index); |
|
432 | + foreach ($remaining_objects as $key => $remaining_object) { |
|
433 | + // we need to grab the identifiers for each object and use them as keys |
|
434 | + $remaining_objects[ $remaining_object->getInfo() ] = $remaining_object; |
|
435 | + // and then remove the object from the current tracking array |
|
436 | + unset($remaining_objects[ $key ]); |
|
437 | + // and then remove it from the Collection |
|
438 | + $this->detach($remaining_object); |
|
439 | + } |
|
440 | + } |
|
441 | + // add the new object we're splicing in |
|
442 | + $this->add($object, $identifier); |
|
443 | + // attach the objects we previously detached |
|
444 | + foreach ($remaining_objects as $key => $remaining_object) { |
|
445 | + $this->add($remaining_object, $key); |
|
446 | + } |
|
447 | + return $this->contains($object); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * Inserts an object (or an array of objects) at a certain point |
|
453 | + * |
|
454 | + * @see http://stackoverflow.com/a/8736013 |
|
455 | + * @param mixed $objects A single object or an array of objects |
|
456 | + * @param int $index |
|
457 | + */ |
|
458 | + public function insertAt($objects, $index) |
|
459 | + { |
|
460 | + if (! is_array($objects)) { |
|
461 | + $objects = array($objects); |
|
462 | + } |
|
463 | + // check to ensure that objects don't already exist in the collection |
|
464 | + foreach ($objects as $key => $object) { |
|
465 | + if ($this->contains($object)) { |
|
466 | + unset($objects[ $key ]); |
|
467 | + } |
|
468 | + } |
|
469 | + // do we have any objects left? |
|
470 | + if (! $objects) { |
|
471 | + return; |
|
472 | + } |
|
473 | + // detach any objects at or past this index |
|
474 | + $remaining = array(); |
|
475 | + if ($index < $this->count()) { |
|
476 | + $remaining = $this->slice($index, $this->count() - $index); |
|
477 | + foreach ($remaining as $object) { |
|
478 | + $this->detach($object); |
|
479 | + } |
|
480 | + } |
|
481 | + // add the new objects we're splicing in |
|
482 | + foreach ($objects as $object) { |
|
483 | + $this->attach($object); |
|
484 | + } |
|
485 | + // attach the objects we previously detached |
|
486 | + foreach ($remaining as $object) { |
|
487 | + $this->attach($object); |
|
488 | + } |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * Removes the object at the given index |
|
494 | + * |
|
495 | + * @see http://stackoverflow.com/a/8736013 |
|
496 | + * @param int $index |
|
497 | + */ |
|
498 | + public function removeAt($index) |
|
499 | + { |
|
500 | + $this->detach($this->objectAtIndex($index)); |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * detaches ALL objects from the Collection |
|
506 | + */ |
|
507 | + public function detachAll() |
|
508 | + { |
|
509 | + $this->rewind(); |
|
510 | + while ($this->valid()) { |
|
511 | + $object = $this->current(); |
|
512 | + $this->next(); |
|
513 | + $this->detach($object); |
|
514 | + } |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * unsets and detaches ALL objects from the Collection |
|
520 | + */ |
|
521 | + public function trashAndDetachAll() |
|
522 | + { |
|
523 | + $this->rewind(); |
|
524 | + while ($this->valid()) { |
|
525 | + $object = $this->current(); |
|
526 | + $this->next(); |
|
527 | + $this->detach($object); |
|
528 | + unset($object); |
|
529 | + } |
|
530 | + } |
|
531 | 531 | } |