@@ -5,9 +5,9 @@ |
||
5 | 5 | interface SessionIdentifierInterface |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @return string |
|
10 | - */ |
|
11 | - public function id(); |
|
8 | + /** |
|
9 | + * @return string |
|
10 | + */ |
|
11 | + public function id(); |
|
12 | 12 | |
13 | 13 | } |
14 | 14 | \ No newline at end of file |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | // with these parameters |
141 | 141 | $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
142 | 142 | // then md5 the above to control it's length, add all of our prefixes, and truncate |
143 | - return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
143 | + return substr($this->cachePrefix().$id_prefix.'-'.md5($cache_id), 0, 182); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | return ' |
171 | 171 | <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;"> |
172 | 172 | <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px"> |
173 | - <b>' . $type . '</b><span style="color:#999"> : </span> |
|
174 | - <span>' . $cache_id . '</span> |
|
175 | - <span style="margin-left:2em;">' . __FILE__ . '</span> |
|
173 | + <b>' . $type.'</b><span style="color:#999"> : </span> |
|
174 | + <span>' . $cache_id.'</span> |
|
175 | + <span style="margin-left:2em;">' . __FILE__.'</span> |
|
176 | 176 | </p> |
177 | 177 | </div>'; |
178 | 178 | } |
@@ -19,140 +19,140 @@ discard block |
||
19 | 19 | class BasicCacheManager implements CacheManagerInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @type string |
|
24 | - */ |
|
25 | - const CACHE_PREFIX = 'ee_cache_'; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @var CacheStorageInterface $cache_storage |
|
30 | - */ |
|
31 | - private $cache_storage; |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * BasicCacheManager constructor. |
|
37 | - * |
|
38 | - * @param CacheStorageInterface $cache_storage [required] |
|
39 | - */ |
|
40 | - public function __construct(CacheStorageInterface $cache_storage) |
|
41 | - { |
|
42 | - $this->cache_storage = $cache_storage; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * returns a string that will be prepended to all cache identifiers |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function cachePrefix() |
|
53 | - { |
|
54 | - return BasicCacheManager::CACHE_PREFIX; |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
61 | - * May also be helpful to include an additional specific identifier, |
|
62 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
63 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
64 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
65 | - * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
66 | - * It is advisable to use some of the actual data |
|
67 | - * that is used to generate the content being cached, |
|
68 | - * in order to guarantee that the cache id is unique for that content. |
|
69 | - * The cache id will be md5'd before usage to make it more db friendly, |
|
70 | - * and the entire cache id string will be truncated to 190 characters. |
|
71 | - * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
72 | - * necessary, |
|
73 | - * we wrap our content creation in a Closure so that it is not executed until needed. |
|
74 | - * @param int $expiration |
|
75 | - * @return Closure|mixed |
|
76 | - */ |
|
77 | - public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
78 | - { |
|
79 | - $content = ''; |
|
80 | - $expiration = absint( |
|
81 | - apply_filters( |
|
82 | - 'FHEE__CacheManager__get__cache_expiration', |
|
83 | - $expiration, |
|
84 | - $id_prefix, |
|
85 | - $cache_id |
|
86 | - ) |
|
87 | - ); |
|
88 | - $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id); |
|
89 | - // is caching enabled for this content ? |
|
90 | - if ($expiration) { |
|
91 | - $content = $this->cache_storage->get($cache_id); |
|
92 | - } |
|
93 | - // any existing content ? |
|
94 | - if (empty($content)) { |
|
95 | - // nope! let's generate some new stuff |
|
96 | - $content = $callback(); |
|
97 | - // save the new content if caching is enabled |
|
98 | - if ($expiration) { |
|
99 | - $this->cache_storage->add($cache_id, $content, $expiration); |
|
100 | - if (EE_DEBUG) { |
|
101 | - $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE'); |
|
102 | - } |
|
103 | - } |
|
104 | - } else { |
|
105 | - if (EE_DEBUG) { |
|
106 | - $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT'); |
|
107 | - } |
|
108 | - } |
|
109 | - return $content; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Generates a unique identifier string for the cache |
|
116 | - * |
|
117 | - * @param string $id_prefix [required] see BasicCacheManager::get() |
|
118 | - * @param string $cache_id [required] see BasicCacheManager::get() |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - private function generateCacheIdentifier($id_prefix, $cache_id) |
|
122 | - { |
|
123 | - // let's make the cached content unique for this "page" |
|
124 | - $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL); |
|
125 | - // with these parameters |
|
126 | - $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
|
127 | - // then md5 the above to control it's length, add all of our prefixes, and truncate |
|
128 | - return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
135 | - * or a specific ID targeting a single cache item |
|
136 | - * @return void |
|
137 | - */ |
|
138 | - public function clear($cache_id) |
|
139 | - { |
|
140 | - // ensure incoming arg is in an array |
|
141 | - $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
142 | - // delete corresponding transients for the supplied id prefix |
|
143 | - $this->cache_storage->deleteMany($cache_id); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
150 | - * or a specific ID targeting a single cache item |
|
151 | - * @param string $type |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - private function displayCacheNotice($cache_id, $type) { |
|
155 | - return ' |
|
22 | + /** |
|
23 | + * @type string |
|
24 | + */ |
|
25 | + const CACHE_PREFIX = 'ee_cache_'; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @var CacheStorageInterface $cache_storage |
|
30 | + */ |
|
31 | + private $cache_storage; |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * BasicCacheManager constructor. |
|
37 | + * |
|
38 | + * @param CacheStorageInterface $cache_storage [required] |
|
39 | + */ |
|
40 | + public function __construct(CacheStorageInterface $cache_storage) |
|
41 | + { |
|
42 | + $this->cache_storage = $cache_storage; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * returns a string that will be prepended to all cache identifiers |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function cachePrefix() |
|
53 | + { |
|
54 | + return BasicCacheManager::CACHE_PREFIX; |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
61 | + * May also be helpful to include an additional specific identifier, |
|
62 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
63 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
64 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
65 | + * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
66 | + * It is advisable to use some of the actual data |
|
67 | + * that is used to generate the content being cached, |
|
68 | + * in order to guarantee that the cache id is unique for that content. |
|
69 | + * The cache id will be md5'd before usage to make it more db friendly, |
|
70 | + * and the entire cache id string will be truncated to 190 characters. |
|
71 | + * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
72 | + * necessary, |
|
73 | + * we wrap our content creation in a Closure so that it is not executed until needed. |
|
74 | + * @param int $expiration |
|
75 | + * @return Closure|mixed |
|
76 | + */ |
|
77 | + public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
78 | + { |
|
79 | + $content = ''; |
|
80 | + $expiration = absint( |
|
81 | + apply_filters( |
|
82 | + 'FHEE__CacheManager__get__cache_expiration', |
|
83 | + $expiration, |
|
84 | + $id_prefix, |
|
85 | + $cache_id |
|
86 | + ) |
|
87 | + ); |
|
88 | + $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id); |
|
89 | + // is caching enabled for this content ? |
|
90 | + if ($expiration) { |
|
91 | + $content = $this->cache_storage->get($cache_id); |
|
92 | + } |
|
93 | + // any existing content ? |
|
94 | + if (empty($content)) { |
|
95 | + // nope! let's generate some new stuff |
|
96 | + $content = $callback(); |
|
97 | + // save the new content if caching is enabled |
|
98 | + if ($expiration) { |
|
99 | + $this->cache_storage->add($cache_id, $content, $expiration); |
|
100 | + if (EE_DEBUG) { |
|
101 | + $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE'); |
|
102 | + } |
|
103 | + } |
|
104 | + } else { |
|
105 | + if (EE_DEBUG) { |
|
106 | + $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT'); |
|
107 | + } |
|
108 | + } |
|
109 | + return $content; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Generates a unique identifier string for the cache |
|
116 | + * |
|
117 | + * @param string $id_prefix [required] see BasicCacheManager::get() |
|
118 | + * @param string $cache_id [required] see BasicCacheManager::get() |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + private function generateCacheIdentifier($id_prefix, $cache_id) |
|
122 | + { |
|
123 | + // let's make the cached content unique for this "page" |
|
124 | + $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL); |
|
125 | + // with these parameters |
|
126 | + $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
|
127 | + // then md5 the above to control it's length, add all of our prefixes, and truncate |
|
128 | + return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
135 | + * or a specific ID targeting a single cache item |
|
136 | + * @return void |
|
137 | + */ |
|
138 | + public function clear($cache_id) |
|
139 | + { |
|
140 | + // ensure incoming arg is in an array |
|
141 | + $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
142 | + // delete corresponding transients for the supplied id prefix |
|
143 | + $this->cache_storage->deleteMany($cache_id); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
150 | + * or a specific ID targeting a single cache item |
|
151 | + * @param string $type |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + private function displayCacheNotice($cache_id, $type) { |
|
155 | + return ' |
|
156 | 156 | <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;"> |
157 | 157 | <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px"> |
158 | 158 | <b>' . $type . '</b><span style="color:#999"> : </span> |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | <span style="margin-left:2em;">' . __FILE__ . '</span> |
161 | 161 | </p> |
162 | 162 | </div>'; |
163 | - } |
|
163 | + } |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | // End of file BasicCacheManager.php |
@@ -120,7 +120,7 @@ |
||
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
123 | - * @param $field_name |
|
123 | + * @param string $field_name |
|
124 | 124 | * @param int $row_number |
125 | 125 | * @return string |
126 | 126 | */ |
@@ -14,225 +14,225 @@ |
||
14 | 14 | class EventsAdmin extends CoreAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Selector for the Add new Event button in the admin. |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * Selector for the Event Title field in the event editor |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
29 | - |
|
30 | - /** |
|
31 | - * Selector for the publish submit button in the event editor. |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
41 | - |
|
42 | - /** |
|
43 | - * Selector for the view link after publishing an event. |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
17 | + /** |
|
18 | + * Selector for the Add new Event button in the admin. |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * Selector for the Event Title field in the event editor |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
29 | + |
|
30 | + /** |
|
31 | + * Selector for the publish submit button in the event editor. |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
41 | + |
|
42 | + /** |
|
43 | + * Selector for the view link after publishing an event. |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
47 | 47 | |
48 | - |
|
49 | - /** |
|
50 | - * Selector for the ID of the event in the event editor |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
48 | + |
|
49 | + /** |
|
50 | + * Selector for the ID of the event in the event editor |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Selector for the search input on the event list table page. |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $additional_params |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public static function defaultEventsListTableUrl($additional_params = '') |
|
70 | - { |
|
71 | - return self::adminUrl('espresso_events', 'default', $additional_params); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * The selector for the DTTname field for the given row in the event editor. |
|
77 | - * @param int $row_number |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
81 | - { |
|
82 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
88 | - * @param int $row_number |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
92 | - { |
|
93 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
99 | - * |
|
100 | - * @param string $field_name |
|
101 | - * @param int $row_number |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
105 | - { |
|
106 | - return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * The selector for the TKT_name field for the given display row in the event editor. |
|
112 | - * @param int $row_number |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
116 | - { |
|
117 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - public static function eventEditorTicketPriceFieldSelector($row_number = 1) |
|
122 | - { |
|
123 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1) |
|
128 | - { |
|
129 | - return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]"; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1) |
|
134 | - { |
|
135 | - return "//span[@id='price-total-amount-$row_number']"; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1) |
|
140 | - { |
|
141 | - return "//span[@id='price-total-amount-$row_number']"; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1) |
|
146 | - { |
|
147 | - return "//input[@id='edit-ticket-TKT_taxable-$row_number']"; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * This returns the xpath locater for the Tax amount display container within the advanced settings view for the |
|
153 | - * given ticket (row) and the given tax id (PRC_ID). |
|
154 | - * |
|
155 | - * @param int $tax_id The PRC_ID for the tax you want the locater for. Note, this defaults to the default tax |
|
156 | - * setup on a fresh install. |
|
157 | - * @param int $row_number What row representing the ticket you want the locator for. |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1) |
|
161 | - { |
|
162 | - return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']"; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
168 | - * @param $field_name |
|
169 | - * @param int $row_number |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
173 | - { |
|
174 | - return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]"; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
180 | - * @param string $event_title |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
184 | - { |
|
185 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Locator for for the ID column in the event list table for a given event title. |
|
191 | - * @param string $event_title |
|
192 | - * @return string |
|
193 | - */ |
|
194 | - public static function eventListTableEventIdSelectorForTitle($event_title) |
|
195 | - { |
|
196 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
197 | - . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Locator for the view link in the row of an event list table for the given event title. |
|
203 | - * @param string $event_title |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
207 | - { |
|
208 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
209 | - . "//ancestor::td//span[@class='view']/a"; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
215 | - * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
219 | - { |
|
220 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
221 | - . "//a[@rel='ee-tab-$messenger_slug']"; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * Locator for the select input within the notifications metabox. |
|
227 | - * Note, this assumes the tab content for the related messenger is already visible. |
|
228 | - * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
229 | - * @return string |
|
230 | - */ |
|
231 | - public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
232 | - { |
|
233 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
234 | - . "//table[@class='messages-custom-template-switcher']" |
|
235 | - . "//tr/td[contains(.,'Registration Approved')]" |
|
236 | - . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
237 | - } |
|
56 | + /** |
|
57 | + * Selector for the search input on the event list table page. |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $additional_params |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public static function defaultEventsListTableUrl($additional_params = '') |
|
70 | + { |
|
71 | + return self::adminUrl('espresso_events', 'default', $additional_params); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * The selector for the DTTname field for the given row in the event editor. |
|
77 | + * @param int $row_number |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
81 | + { |
|
82 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
88 | + * @param int $row_number |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
92 | + { |
|
93 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
99 | + * |
|
100 | + * @param string $field_name |
|
101 | + * @param int $row_number |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
105 | + { |
|
106 | + return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * The selector for the TKT_name field for the given display row in the event editor. |
|
112 | + * @param int $row_number |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
116 | + { |
|
117 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + public static function eventEditorTicketPriceFieldSelector($row_number = 1) |
|
122 | + { |
|
123 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1) |
|
128 | + { |
|
129 | + return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]"; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1) |
|
134 | + { |
|
135 | + return "//span[@id='price-total-amount-$row_number']"; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1) |
|
140 | + { |
|
141 | + return "//span[@id='price-total-amount-$row_number']"; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1) |
|
146 | + { |
|
147 | + return "//input[@id='edit-ticket-TKT_taxable-$row_number']"; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * This returns the xpath locater for the Tax amount display container within the advanced settings view for the |
|
153 | + * given ticket (row) and the given tax id (PRC_ID). |
|
154 | + * |
|
155 | + * @param int $tax_id The PRC_ID for the tax you want the locater for. Note, this defaults to the default tax |
|
156 | + * setup on a fresh install. |
|
157 | + * @param int $row_number What row representing the ticket you want the locator for. |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1) |
|
161 | + { |
|
162 | + return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']"; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
168 | + * @param $field_name |
|
169 | + * @param int $row_number |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
173 | + { |
|
174 | + return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]"; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
180 | + * @param string $event_title |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
184 | + { |
|
185 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Locator for for the ID column in the event list table for a given event title. |
|
191 | + * @param string $event_title |
|
192 | + * @return string |
|
193 | + */ |
|
194 | + public static function eventListTableEventIdSelectorForTitle($event_title) |
|
195 | + { |
|
196 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
197 | + . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Locator for the view link in the row of an event list table for the given event title. |
|
203 | + * @param string $event_title |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
207 | + { |
|
208 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
209 | + . "//ancestor::td//span[@class='view']/a"; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
215 | + * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
219 | + { |
|
220 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
221 | + . "//a[@rel='ee-tab-$messenger_slug']"; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * Locator for the select input within the notifications metabox. |
|
227 | + * Note, this assumes the tab content for the related messenger is already visible. |
|
228 | + * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
229 | + * @return string |
|
230 | + */ |
|
231 | + public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
232 | + { |
|
233 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
234 | + . "//table[@class='messages-custom-template-switcher']" |
|
235 | + . "//tr/td[contains(.,'Registration Approved')]" |
|
236 | + . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
237 | + } |
|
238 | 238 | } |
@@ -13,58 +13,58 @@ |
||
13 | 13 | trait BaseCoreAdmin |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Core method for going to an Event Espresso Admin page. |
|
18 | - * @param string $page |
|
19 | - * @param string $action |
|
20 | - * @param string $additional_params |
|
21 | - */ |
|
22 | - public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
23 | - { |
|
24 | - $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
25 | - } |
|
16 | + /** |
|
17 | + * Core method for going to an Event Espresso Admin page. |
|
18 | + * @param string $page |
|
19 | + * @param string $action |
|
20 | + * @param string $additional_params |
|
21 | + */ |
|
22 | + public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
23 | + { |
|
24 | + $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
30 | - * @return \EventEspressoAcceptanceTester; |
|
31 | - */ |
|
32 | - protected function actor() |
|
33 | - { |
|
34 | - /** @var \EventEspressoAcceptanceTester $this */ |
|
35 | - return $this; |
|
36 | - } |
|
28 | + /** |
|
29 | + * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
30 | + * @return \EventEspressoAcceptanceTester; |
|
31 | + */ |
|
32 | + protected function actor() |
|
33 | + { |
|
34 | + /** @var \EventEspressoAcceptanceTester $this */ |
|
35 | + return $this; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * Use this to set the per page option for a list table page. |
|
41 | - * Assumes you are on a page that has this field exposed. |
|
42 | - * |
|
43 | - * @param int|string $per_page_value |
|
44 | - * @throws \Codeception\Exception\TestRuntimeException |
|
45 | - */ |
|
46 | - public function setPerPageOptionForScreen($per_page_value) |
|
47 | - { |
|
48 | - $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
49 | - $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
50 | - $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
51 | - $this->actor()->wait(8); |
|
52 | - } |
|
39 | + /** |
|
40 | + * Use this to set the per page option for a list table page. |
|
41 | + * Assumes you are on a page that has this field exposed. |
|
42 | + * |
|
43 | + * @param int|string $per_page_value |
|
44 | + * @throws \Codeception\Exception\TestRuntimeException |
|
45 | + */ |
|
46 | + public function setPerPageOptionForScreen($per_page_value) |
|
47 | + { |
|
48 | + $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
49 | + $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
50 | + $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
51 | + $this->actor()->wait(8); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Use this to append a given value to a wpEditor instance. |
|
58 | - * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
59 | - * the value is added to the text area. |
|
60 | - * |
|
61 | - * @param $field_reference |
|
62 | - * @param $value |
|
63 | - * @throws \Codeception\Exception\ElementNotFound |
|
64 | - */ |
|
65 | - public function appendToWPEditorField($field_reference, $value) |
|
66 | - { |
|
67 | - $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
68 | - $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
69 | - } |
|
56 | + /** |
|
57 | + * Use this to append a given value to a wpEditor instance. |
|
58 | + * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
59 | + * the value is added to the text area. |
|
60 | + * |
|
61 | + * @param $field_reference |
|
62 | + * @param $value |
|
63 | + * @throws \Codeception\Exception\ElementNotFound |
|
64 | + */ |
|
65 | + public function appendToWPEditorField($field_reference, $value) |
|
66 | + { |
|
67 | + $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
68 | + $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
69 | + } |
|
70 | 70 | } |
@@ -13,84 +13,84 @@ |
||
13 | 13 | class CoreAdmin |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - const URL_PREFIX = 'admin.php?page='; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * This is the selector for the next page button on list tables. |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * The selector for the search input submit button on list table pages |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit'; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * Selector for the screen options dropdown. |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link'; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Selector for the per page field setting selector (found within screen options dropdown) |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page'; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Selector for apply screen options settings. |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply'; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Get the EE admin url for the given properties. |
|
59 | - * Note, this is JUST the endpoint for the admin route. It is expected that the actor/test would be calling this |
|
60 | - * with `amOnAdminPage` action. |
|
61 | - * |
|
62 | - * @param string $page |
|
63 | - * @param string $action |
|
64 | - * @param string $additional_params |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
|
68 | - { |
|
69 | - $url = self::URL_PREFIX . $page; |
|
70 | - $url .= $action ? '&action=' . $action : ''; |
|
71 | - $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
72 | - return $url; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns the selector for the text tab switcher for a wp-editor instance. |
|
78 | - * @param $field_reference |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public static function wpEditorTextTabSelector($field_reference) |
|
82 | - { |
|
83 | - return '#content-' . $field_reference . '-content-html'; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Returns the selector for the textarea exposed when clicing the text tab switcher for a wp-editor instance. |
|
89 | - * @param $field_reference |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public static function wpEditorTextAreaSelector($field_reference) |
|
93 | - { |
|
94 | - return '#content-' . $field_reference . '-content'; |
|
95 | - } |
|
16 | + /** |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + const URL_PREFIX = 'admin.php?page='; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * This is the selector for the next page button on list tables. |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * The selector for the search input submit button on list table pages |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit'; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * Selector for the screen options dropdown. |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link'; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Selector for the per page field setting selector (found within screen options dropdown) |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page'; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Selector for apply screen options settings. |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply'; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Get the EE admin url for the given properties. |
|
59 | + * Note, this is JUST the endpoint for the admin route. It is expected that the actor/test would be calling this |
|
60 | + * with `amOnAdminPage` action. |
|
61 | + * |
|
62 | + * @param string $page |
|
63 | + * @param string $action |
|
64 | + * @param string $additional_params |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
|
68 | + { |
|
69 | + $url = self::URL_PREFIX . $page; |
|
70 | + $url .= $action ? '&action=' . $action : ''; |
|
71 | + $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
72 | + return $url; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns the selector for the text tab switcher for a wp-editor instance. |
|
78 | + * @param $field_reference |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public static function wpEditorTextTabSelector($field_reference) |
|
82 | + { |
|
83 | + return '#content-' . $field_reference . '-content-html'; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Returns the selector for the textarea exposed when clicing the text tab switcher for a wp-editor instance. |
|
89 | + * @param $field_reference |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public static function wpEditorTextAreaSelector($field_reference) |
|
93 | + { |
|
94 | + return '#content-' . $field_reference . '-content'; |
|
95 | + } |
|
96 | 96 | } |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
68 | 68 | { |
69 | - $url = self::URL_PREFIX . $page; |
|
70 | - $url .= $action ? '&action=' . $action : ''; |
|
71 | - $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
69 | + $url = self::URL_PREFIX.$page; |
|
70 | + $url .= $action ? '&action='.$action : ''; |
|
71 | + $url .= $additional_params ? '&'.ltrim('&', ltrim('?', $additional_params)) : ''; |
|
72 | 72 | return $url; |
73 | 73 | } |
74 | 74 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public static function wpEditorTextTabSelector($field_reference) |
82 | 82 | { |
83 | - return '#content-' . $field_reference . '-content-html'; |
|
83 | + return '#content-'.$field_reference.'-content-html'; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -91,6 +91,6 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public static function wpEditorTextAreaSelector($field_reference) |
93 | 93 | { |
94 | - return '#content-' . $field_reference . '-content'; |
|
94 | + return '#content-'.$field_reference.'-content'; |
|
95 | 95 | } |
96 | 96 | } |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | * there's a single shared message template group among all the events. Otherwise it returns null. |
444 | 444 | * |
445 | 445 | * @param array $event_ids |
446 | - * @return EE_Message_Template_Group|null |
|
446 | + * @return null|EE_Base_Class |
|
447 | 447 | * @throws EE_Error |
448 | 448 | */ |
449 | 449 | protected function _get_shared_message_template_for_events(array $event_ids) |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | /** |
477 | 477 | * Retrieves the global message template group for the current messenger and message type. |
478 | 478 | * |
479 | - * @return EE_Message_Template_Group|null |
|
479 | + * @return null|EE_Base_Class |
|
480 | 480 | * @throws EE_Error |
481 | 481 | */ |
482 | 482 | protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | * @param EE_Messages_Addressee $recipient |
618 | 618 | * @param array $templates formatted array of templates used for parsing data. |
619 | 619 | * @param EE_Message_Template_Group $message_template_group |
620 | - * @return bool|EE_Message |
|
620 | + * @return EE_Message |
|
621 | 621 | * @throws EE_Error |
622 | 622 | */ |
623 | 623 | protected function _setup_message_object( |
@@ -13,935 +13,935 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @type EE_Messages_Data_Handler_Collection |
|
18 | - */ |
|
19 | - protected $_data_handler_collection; |
|
20 | - |
|
21 | - /** |
|
22 | - * @type EE_Message_Template_Group_Collection |
|
23 | - */ |
|
24 | - protected $_template_collection; |
|
25 | - |
|
26 | - /** |
|
27 | - * This will hold the data handler for the current EE_Message being generated. |
|
28 | - * |
|
29 | - * @type EE_Messages_incoming_data |
|
30 | - */ |
|
31 | - protected $_current_data_handler; |
|
32 | - |
|
33 | - /** |
|
34 | - * This holds the EE_Messages_Queue that contains the messages to generate. |
|
35 | - * |
|
36 | - * @type EE_Messages_Queue |
|
37 | - */ |
|
38 | - protected $_generation_queue; |
|
39 | - |
|
40 | - /** |
|
41 | - * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
42 | - * |
|
43 | - * @type EE_Messages_Queue |
|
44 | - */ |
|
45 | - protected $_ready_queue; |
|
46 | - |
|
47 | - /** |
|
48 | - * This is a container for any error messages that get created through the generation |
|
49 | - * process. |
|
50 | - * |
|
51 | - * @type array |
|
52 | - */ |
|
53 | - protected $_error_msg = array(); |
|
54 | - |
|
55 | - /** |
|
56 | - * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
57 | - * |
|
58 | - * @type bool |
|
59 | - */ |
|
60 | - protected $_verified = false; |
|
61 | - |
|
62 | - /** |
|
63 | - * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
64 | - * |
|
65 | - * @type EE_messenger |
|
66 | - */ |
|
67 | - protected $_current_messenger; |
|
68 | - |
|
69 | - /** |
|
70 | - * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
71 | - * |
|
72 | - * @type EE_message_type |
|
73 | - */ |
|
74 | - protected $_current_message_type; |
|
75 | - |
|
76 | - /** |
|
77 | - * @type EEH_Parse_Shortcodes |
|
78 | - */ |
|
79 | - protected $_shortcode_parser; |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param EE_Messages_Queue $generation_queue |
|
84 | - * @param \EE_Messages_Queue $ready_queue |
|
85 | - * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
86 | - * @param \EE_Message_Template_Group_Collection $template_collection |
|
87 | - * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
88 | - */ |
|
89 | - public function __construct( |
|
90 | - EE_Messages_Queue $generation_queue, |
|
91 | - EE_Messages_Queue $ready_queue, |
|
92 | - EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
93 | - EE_Message_Template_Group_Collection $template_collection, |
|
94 | - EEH_Parse_Shortcodes $shortcode_parser |
|
95 | - ) { |
|
96 | - $this->_generation_queue = $generation_queue; |
|
97 | - $this->_ready_queue = $ready_queue; |
|
98 | - $this->_data_handler_collection = $data_handler_collection; |
|
99 | - $this->_template_collection = $template_collection; |
|
100 | - $this->_shortcode_parser = $shortcode_parser; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return EE_Messages_Queue |
|
106 | - */ |
|
107 | - public function generation_queue() |
|
108 | - { |
|
109 | - return $this->_generation_queue; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * This iterates through the provided queue and generates the EE_Message objects. |
|
115 | - * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
116 | - * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
117 | - * for the caller to decide what to do with it. |
|
118 | - * |
|
119 | - * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
120 | - * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
121 | - */ |
|
122 | - public function generate($save = true) |
|
123 | - { |
|
124 | - //iterate through the messages in the queue, generate, and add to new queue. |
|
125 | - $this->_generation_queue->get_message_repository()->rewind(); |
|
126 | - while ($this->_generation_queue->get_message_repository()->valid()) { |
|
127 | - //reset "current" properties |
|
128 | - $this->_reset_current_properties(); |
|
129 | - |
|
130 | - /** @type EE_Message $msg */ |
|
131 | - $msg = $this->_generation_queue->get_message_repository()->current(); |
|
132 | - |
|
133 | - /** |
|
134 | - * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
135 | - * an object is removed from the repo then valid for the next object will fail. |
|
136 | - */ |
|
137 | - $this->_generation_queue->get_message_repository()->next(); |
|
138 | - $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
139 | - //restore pointer to current item |
|
140 | - $this->_generation_queue->get_message_repository()->set_current($msg); |
|
141 | - |
|
142 | - //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
143 | - if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
144 | - //we keep this item in the db just remove from the repo. |
|
145 | - $this->_generation_queue->get_message_repository()->remove($msg); |
|
146 | - //next item |
|
147 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
148 | - continue; |
|
149 | - } |
|
150 | - |
|
151 | - if ($this->_verify()) { |
|
152 | - //let's get generating! |
|
153 | - $this->_generate(); |
|
154 | - } |
|
155 | - |
|
156 | - //don't persist debug_only messages if the messages system is not in debug mode. |
|
157 | - if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
158 | - && ! EEM_Message::debug() |
|
159 | - ) { |
|
160 | - do_action( |
|
161 | - 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
162 | - $msg, |
|
163 | - $this->_error_msg, |
|
164 | - $this->_current_messenger, |
|
165 | - $this->_current_message_type, |
|
166 | - $this->_current_data_handler |
|
167 | - ); |
|
168 | - $this->_generation_queue->get_message_repository()->delete(); |
|
169 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
170 | - continue; |
|
171 | - } |
|
172 | - |
|
173 | - //if there are error messages then let's set the status and the error message. |
|
174 | - if ($this->_error_msg) { |
|
175 | - //if the status is already debug only, then let's leave it at that. |
|
176 | - if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
177 | - $msg->set_STS_ID(EEM_Message::status_failed); |
|
178 | - } |
|
179 | - do_action( |
|
180 | - 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
181 | - $msg, |
|
182 | - $this->_error_msg, |
|
183 | - $this->_current_messenger, |
|
184 | - $this->_current_message_type, |
|
185 | - $this->_current_data_handler |
|
186 | - ); |
|
187 | - $msg->set_error_message( |
|
188 | - esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
189 | - . "\n" |
|
190 | - . implode("\n", $this->_error_msg) |
|
191 | - ); |
|
192 | - $msg->set_modified(time()); |
|
193 | - } else { |
|
194 | - do_action( |
|
195 | - 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
196 | - $msg, |
|
197 | - $this->_error_msg, |
|
198 | - $this->_current_messenger, |
|
199 | - $this->_current_message_type, |
|
200 | - $this->_current_data_handler |
|
201 | - ); |
|
202 | - //remove from db |
|
203 | - $this->_generation_queue->get_message_repository()->delete(); |
|
204 | - } |
|
205 | - //next item |
|
206 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
207 | - } |
|
208 | - |
|
209 | - //generation queue is ALWAYS saved to record any errors in the generation process. |
|
210 | - $this->_generation_queue->save(); |
|
211 | - |
|
212 | - /** |
|
213 | - * save _ready_queue if flag set. |
|
214 | - * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
215 | - * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
216 | - * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
217 | - * irrelevant. |
|
218 | - */ |
|
219 | - if ($save) { |
|
220 | - $this->_ready_queue->save(); |
|
221 | - } |
|
222 | - |
|
223 | - //final reset of properties |
|
224 | - $this->_reset_current_properties(); |
|
225 | - |
|
226 | - return $this->_ready_queue; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
232 | - * in the generation queue. |
|
233 | - */ |
|
234 | - protected function _reset_current_properties() |
|
235 | - { |
|
236 | - $this->_verified = false; |
|
237 | - //make sure any _data value in the current message type is reset |
|
238 | - if ($this->_current_message_type instanceof EE_message_type) { |
|
239 | - $this->_current_message_type->reset_data(); |
|
240 | - } |
|
241 | - $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
247 | - * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
248 | - * _generating_queue. |
|
249 | - * |
|
250 | - * @return bool Whether the message was successfully generated or not. |
|
251 | - * @throws EE_Error |
|
252 | - */ |
|
253 | - protected function _generate() |
|
254 | - { |
|
255 | - //double check verification has run and that everything is ready to work with (saves us having to validate |
|
256 | - // everything again). |
|
257 | - if (! $this->_verified) { |
|
258 | - return false; //get out because we don't have a valid setup to work with. |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - try { |
|
263 | - $addressees = $this->_current_message_type->get_addressees( |
|
264 | - $this->_current_data_handler, |
|
265 | - $this->_generation_queue->get_message_repository()->current()->context() |
|
266 | - ); |
|
267 | - } catch (EE_Error $e) { |
|
268 | - $this->_error_msg[] = $e->getMessage(); |
|
269 | - return false; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - //if no addressees then get out because there is nothing to generation (possible bad data). |
|
274 | - if (! $this->_valid_addressees($addressees)) { |
|
275 | - do_action( |
|
276 | - 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
277 | - $this->_generation_queue->get_message_repository()->current(), |
|
278 | - $addressees, |
|
279 | - $this->_current_messenger, |
|
280 | - $this->_current_message_type, |
|
281 | - $this->_current_data_handler |
|
282 | - ); |
|
283 | - $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
284 | - EEM_Message::status_debug_only |
|
285 | - ); |
|
286 | - $this->_error_msg[] = esc_html__( |
|
287 | - 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
288 | - 'event_espresso' |
|
289 | - ); |
|
290 | - return false; |
|
291 | - } |
|
292 | - |
|
293 | - $message_template_group = $this->_get_message_template_group(); |
|
294 | - |
|
295 | - //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
296 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
297 | - $this->_error_msg[] = esc_html__( |
|
298 | - 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
299 | - 'event_espresso' |
|
300 | - ); |
|
301 | - return false; |
|
302 | - } |
|
303 | - |
|
304 | - //get formatted templates for using to parse and setup EE_Message objects. |
|
305 | - $templates = $this->_get_templates($message_template_group); |
|
306 | - |
|
307 | - |
|
308 | - //setup new EE_Message objects (and add to _ready_queue) |
|
309 | - return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Retrieves the message template group being used for generating messages. |
|
315 | - * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
316 | - * |
|
317 | - * @return EE_Message_Template_Group|null |
|
318 | - * @throws EE_Error |
|
319 | - */ |
|
320 | - protected function _get_message_template_group() |
|
321 | - { |
|
322 | - //first see if there is a specific message template group requested (current message in the queue has a specific |
|
323 | - //GRP_ID |
|
324 | - $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
325 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
326 | - return $message_template_group; |
|
327 | - } |
|
328 | - |
|
329 | - //get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
330 | - //in the collection. |
|
331 | - $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
332 | - $message_template_group = $this->_template_collection->get_by_key( |
|
333 | - $this->_template_collection->getKey( |
|
334 | - $this->_current_messenger->name, |
|
335 | - $this->_current_message_type->name, |
|
336 | - $event_ids |
|
337 | - ) |
|
338 | - ); |
|
339 | - |
|
340 | - //if we have a message template group then no need to hit the database, just return it. |
|
341 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
342 | - return $message_template_group; |
|
343 | - } |
|
344 | - |
|
345 | - //okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
346 | - //there is no override set. |
|
347 | - $global_message_template_group = $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
348 | - |
|
349 | - if ($global_message_template_group instanceof EE_Message_Template_Group |
|
350 | - && $global_message_template_group->get('MTP_is_override') |
|
351 | - ) { |
|
352 | - return $global_message_template_group; |
|
353 | - } |
|
354 | - |
|
355 | - //if we're still here, that means there was no message template group for the events in the collection and |
|
356 | - //the global message template group for the messenger and message type is not set for override. So next step is |
|
357 | - //to see if there is a common shared custom message template group for this set of events. |
|
358 | - $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
359 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
360 | - return $message_template_group; |
|
361 | - } |
|
362 | - |
|
363 | - //STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
364 | - //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
365 | - //and return it. |
|
366 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
367 | - $this->_template_collection->add( |
|
368 | - $global_message_template_group, |
|
369 | - $event_ids |
|
370 | - ); |
|
371 | - return $global_message_template_group; |
|
372 | - } |
|
373 | - |
|
374 | - //if we land here that means there's NO active message template group for this set. |
|
375 | - //TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
376 | - //template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
377 | - //this should likely bit hit rarely enough that it's not a significant issue. |
|
378 | - return null; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
384 | - * requested for that message. |
|
385 | - * |
|
386 | - * @return EE_Message_Template_Group|null |
|
387 | - */ |
|
388 | - protected function _specific_message_template_group_from_queue() |
|
389 | - { |
|
390 | - //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
391 | - //so let's use that. |
|
392 | - $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
393 | - |
|
394 | - if ($GRP_ID) { |
|
395 | - //attempt to retrieve from repo first |
|
396 | - $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
397 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
398 | - return $message_template_group; //got it! |
|
399 | - } |
|
400 | - |
|
401 | - //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
402 | - //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
403 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
404 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
405 | - $this->_template_collection->add($message_template_group); |
|
406 | - return $message_template_group; |
|
407 | - } |
|
408 | - } |
|
409 | - return null; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Returns whether the event ids passed in all share the same message template group for the current message type |
|
415 | - * and messenger. |
|
416 | - * |
|
417 | - * @param array $event_ids |
|
418 | - * @return bool true means they DO share the same message template group, false means they don't. |
|
419 | - * @throws EE_Error |
|
420 | - */ |
|
421 | - protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
422 | - { |
|
423 | - foreach ($this->_current_data_handler->events as $event) { |
|
424 | - $event_ids[$event['ID']] = $event['ID']; |
|
425 | - } |
|
426 | - $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
427 | - array( |
|
428 | - array( |
|
429 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
430 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
431 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
432 | - ), |
|
433 | - ), |
|
434 | - 'GRP_ID', |
|
435 | - true |
|
436 | - ); |
|
437 | - return $count_of_message_template_groups === 1; |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
443 | - * there's a single shared message template group among all the events. Otherwise it returns null. |
|
444 | - * |
|
445 | - * @param array $event_ids |
|
446 | - * @return EE_Message_Template_Group|null |
|
447 | - * @throws EE_Error |
|
448 | - */ |
|
449 | - protected function _get_shared_message_template_for_events(array $event_ids) |
|
450 | - { |
|
451 | - $message_template_group = null; |
|
452 | - if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
453 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
454 | - array( |
|
455 | - array( |
|
456 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
457 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
458 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
459 | - 'MTP_is_active' => true, |
|
460 | - ), |
|
461 | - 'group_by' => 'GRP_ID', |
|
462 | - ) |
|
463 | - ); |
|
464 | - //store this in the collection if its valid |
|
465 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
466 | - $this->_template_collection->add( |
|
467 | - $message_template_group, |
|
468 | - $event_ids |
|
469 | - ); |
|
470 | - } |
|
471 | - } |
|
472 | - return $message_template_group; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Retrieves the global message template group for the current messenger and message type. |
|
478 | - * |
|
479 | - * @return EE_Message_Template_Group|null |
|
480 | - * @throws EE_Error |
|
481 | - */ |
|
482 | - protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
483 | - { |
|
484 | - //first check the collection (we use an array with 0 in it to represent global groups). |
|
485 | - $global_message_template_group = $this->_template_collection->get_by_key( |
|
486 | - $this->_template_collection->getKey( |
|
487 | - $this->_current_messenger->name, |
|
488 | - $this->_current_message_type->name, |
|
489 | - array(0) |
|
490 | - ) |
|
491 | - ); |
|
492 | - |
|
493 | - //if we don't have a group lets hit the db. |
|
494 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
495 | - $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
496 | - array( |
|
497 | - array( |
|
498 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
499 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
500 | - 'MTP_is_active' => true, |
|
501 | - 'MTP_is_global' => true, |
|
502 | - ), |
|
503 | - ) |
|
504 | - ); |
|
505 | - //if we have a group, add it to the collection. |
|
506 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
507 | - $this->_template_collection->add( |
|
508 | - $global_message_template_group, |
|
509 | - array(0) |
|
510 | - ); |
|
511 | - } |
|
512 | - } |
|
513 | - return $global_message_template_group; |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * Returns an array of event ids for all the events within the current data handler. |
|
519 | - * |
|
520 | - * @return array |
|
521 | - */ |
|
522 | - protected function _get_event_ids_from_current_data_handler() |
|
523 | - { |
|
524 | - $event_ids = array(); |
|
525 | - foreach ($this->_current_data_handler->events as $event) { |
|
526 | - $event_ids[$event['ID']] = $event['ID']; |
|
527 | - } |
|
528 | - return $event_ids; |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * Retrieves formatted array of template information for each context specific to the given |
|
534 | - * EE_Message_Template_Group |
|
535 | - * |
|
536 | - * @param EE_Message_Template_Group $message_template_group |
|
537 | - * @return array The returned array is in this structure: |
|
538 | - * array( |
|
539 | - * 'field_name' => array( |
|
540 | - * 'context' => 'content' |
|
541 | - * ) |
|
542 | - * ) |
|
543 | - * @throws EE_Error |
|
544 | - */ |
|
545 | - protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
546 | - { |
|
547 | - $templates = array(); |
|
548 | - $context_templates = $message_template_group->context_templates(); |
|
549 | - foreach ($context_templates as $context => $template_fields) { |
|
550 | - foreach ($template_fields as $template_field => $template_obj) { |
|
551 | - if (! $template_obj instanceof EE_Message_Template) { |
|
552 | - continue; |
|
553 | - } |
|
554 | - $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
555 | - } |
|
556 | - } |
|
557 | - return $templates; |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
563 | - * |
|
564 | - * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
565 | - * context. |
|
566 | - * @param array $templates formatted array of templates used for parsing data. |
|
567 | - * @param EE_Message_Template_Group $message_template_group |
|
568 | - * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
569 | - * method will attempt to generate ALL EE_Message objects and add to |
|
570 | - * the _ready_queue. Successfully generated messages get added to the |
|
571 | - * queue with EEM_Message::status_idle, unsuccessfully generated |
|
572 | - * messages will get added to the queue as EEM_Message::status_failed. |
|
573 | - * Very rarely should "false" be returned from this method. |
|
574 | - */ |
|
575 | - protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
576 | - { |
|
577 | - |
|
578 | - //if templates are empty then get out because we can't generate anything. |
|
579 | - if (! $templates) { |
|
580 | - $this->_error_msg[] = esc_html__( |
|
581 | - 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
582 | - 'event_espresso' |
|
583 | - ); |
|
584 | - return false; |
|
585 | - } |
|
586 | - |
|
587 | - //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
588 | - //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
589 | - $generated_count = 0; |
|
590 | - foreach ($addressees as $context => $recipients) { |
|
591 | - foreach ($recipients as $recipient) { |
|
592 | - $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
593 | - if ($message instanceof EE_Message) { |
|
594 | - $this->_ready_queue->add( |
|
595 | - $message, |
|
596 | - array(), |
|
597 | - $this->_generation_queue->get_message_repository()->is_preview(), |
|
598 | - $this->_generation_queue->get_message_repository()->is_test_send() |
|
599 | - ); |
|
600 | - $generated_count++; |
|
601 | - } |
|
602 | - |
|
603 | - //if the current MSG being generated is for a test send then we'll only use ONE message in the generation. |
|
604 | - if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
605 | - break 2; |
|
606 | - } |
|
607 | - } |
|
608 | - } |
|
609 | - |
|
610 | - //if there are no generated messages then something else fatal went wrong. |
|
611 | - return $generated_count > 0; |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * @param string $context The context for the generated message. |
|
617 | - * @param EE_Messages_Addressee $recipient |
|
618 | - * @param array $templates formatted array of templates used for parsing data. |
|
619 | - * @param EE_Message_Template_Group $message_template_group |
|
620 | - * @return bool|EE_Message |
|
621 | - * @throws EE_Error |
|
622 | - */ |
|
623 | - protected function _setup_message_object( |
|
624 | - $context, |
|
625 | - EE_Messages_Addressee $recipient, |
|
626 | - $templates, |
|
627 | - EE_Message_Template_Group $message_template_group |
|
628 | - ) { |
|
629 | - //stuff we already know |
|
630 | - $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
631 | - $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
632 | - ? $this->_current_data_handler->txn->ID() |
|
633 | - : $transaction_id; |
|
634 | - $message_fields = array( |
|
635 | - 'GRP_ID' => $message_template_group->ID(), |
|
636 | - 'TXN_ID' => $transaction_id, |
|
637 | - 'MSG_messenger' => $this->_current_messenger->name, |
|
638 | - 'MSG_message_type' => $this->_current_message_type->name, |
|
639 | - 'MSG_context' => $context, |
|
640 | - ); |
|
641 | - |
|
642 | - //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
643 | - // the info from the att_obj found in the EE_Messages_Addressee object. |
|
644 | - if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
645 | - $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
646 | - ? $recipient->att_obj->ID() |
|
647 | - : 0; |
|
648 | - $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
649 | - } else { |
|
650 | - $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
651 | - $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
652 | - } |
|
653 | - $message = EE_Message_Factory::create($message_fields); |
|
654 | - |
|
655 | - //grab valid shortcodes for shortcode parser |
|
656 | - $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
657 | - $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
658 | - |
|
659 | - //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
|
660 | - //context is turned off) EXCEPT if we're previewing |
|
661 | - if (empty($templates['to'][$context]) |
|
662 | - && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
663 | - && ! $this->_current_messenger->allow_empty_to_field() |
|
664 | - ) { |
|
665 | - //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
666 | - //field. |
|
667 | - return false; |
|
668 | - } |
|
669 | - $error_msg = array(); |
|
670 | - foreach ($templates as $field => $field_context) { |
|
671 | - $error_msg = array(); |
|
672 | - //let's setup the valid shortcodes for the incoming context. |
|
673 | - $valid_shortcodes = $mt_shortcodes[$context]; |
|
674 | - //merge in valid shortcodes for the field. |
|
675 | - $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
676 | - if (isset($templates[$field][$context])) { |
|
677 | - //prefix field. |
|
678 | - $column_name = 'MSG_' . $field; |
|
679 | - try { |
|
680 | - $content = $this->_shortcode_parser->parse_message_template( |
|
681 | - $templates[$field][$context], |
|
682 | - $recipient, |
|
683 | - $shortcodes, |
|
684 | - $this->_current_message_type, |
|
685 | - $this->_current_messenger, |
|
686 | - $message |
|
687 | - ); |
|
688 | - $message->set_field_or_extra_meta($column_name, $content); |
|
689 | - } catch (EE_Error $e) { |
|
690 | - $error_msg[] = sprintf( |
|
691 | - esc_html__( |
|
692 | - 'There was a problem generating the content for the field %s: %s', |
|
693 | - 'event_espresso' |
|
694 | - ), |
|
695 | - $field, |
|
696 | - $e->getMessage() |
|
697 | - ); |
|
698 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
699 | - } |
|
700 | - } |
|
701 | - } |
|
702 | - |
|
703 | - if ($message->STS_ID() === EEM_Message::status_failed) { |
|
704 | - $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
705 | - . "\n" |
|
706 | - . implode("\n", $error_msg); |
|
707 | - $message->set_error_message($error_msg); |
|
708 | - } else { |
|
709 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
710 | - } |
|
711 | - return $message; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
717 | - * error message if either is missing. |
|
718 | - * |
|
719 | - * @return bool true means there were no errors, false means there were errors. |
|
720 | - */ |
|
721 | - protected function _verify() |
|
722 | - { |
|
723 | - //reset error message to an empty array. |
|
724 | - $this->_error_msg = array(); |
|
725 | - $valid = true; |
|
726 | - $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
727 | - $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
728 | - |
|
729 | - //set the verified flag so we know everything has been validated. |
|
730 | - $this->_verified = $valid; |
|
731 | - |
|
732 | - return $valid; |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
738 | - * EE_Messages_Addressee objects. |
|
739 | - * |
|
740 | - * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
741 | - * @return bool |
|
742 | - */ |
|
743 | - protected function _valid_addressees($addressees) |
|
744 | - { |
|
745 | - if (! $addressees || ! is_array($addressees)) { |
|
746 | - return false; |
|
747 | - } |
|
748 | - |
|
749 | - foreach ($addressees as $addressee_array) { |
|
750 | - foreach ($addressee_array as $addressee) { |
|
751 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
752 | - return false; |
|
753 | - } |
|
754 | - } |
|
755 | - } |
|
756 | - return true; |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - /** |
|
761 | - * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
762 | - * queue. This process sets error messages if something is wrong. |
|
763 | - * |
|
764 | - * @return bool true is if there are no errors. false is if there is. |
|
765 | - */ |
|
766 | - protected function _validate_messenger_and_message_type() |
|
767 | - { |
|
768 | - |
|
769 | - //first are there any existing error messages? If so then return. |
|
770 | - if ($this->_error_msg) { |
|
771 | - return false; |
|
772 | - } |
|
773 | - /** @type EE_Message $message */ |
|
774 | - $message = $this->_generation_queue->get_message_repository()->current(); |
|
775 | - try { |
|
776 | - $this->_current_messenger = $message->valid_messenger(true) |
|
777 | - ? $message->messenger_object() |
|
778 | - : null; |
|
779 | - } catch (Exception $e) { |
|
780 | - $this->_error_msg[] = $e->getMessage(); |
|
781 | - } |
|
782 | - try { |
|
783 | - $this->_current_message_type = $message->valid_message_type(true) |
|
784 | - ? $message->message_type_object() |
|
785 | - : null; |
|
786 | - } catch (Exception $e) { |
|
787 | - $this->_error_msg[] = $e->getMessage(); |
|
788 | - } |
|
789 | - |
|
790 | - /** |
|
791 | - * Check if there is any generation data, but only if this is not for a preview. |
|
792 | - */ |
|
793 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
794 | - && ( |
|
795 | - ! $this->_generation_queue->get_message_repository()->is_preview() |
|
796 | - && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
797 | - !== 'EE_Messages_Preview_incoming_data' |
|
798 | - ) |
|
799 | - ) { |
|
800 | - $this->_error_msg[] = esc_html__( |
|
801 | - 'There is no generation data for this message. Unable to generate.', |
|
802 | - 'event_espresso' |
|
803 | - ); |
|
804 | - } |
|
805 | - |
|
806 | - return empty($this->_error_msg); |
|
807 | - } |
|
808 | - |
|
809 | - |
|
810 | - /** |
|
811 | - * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
812 | - * data handler. |
|
813 | - * |
|
814 | - * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
815 | - */ |
|
816 | - protected function _validate_and_setup_data() |
|
817 | - { |
|
818 | - |
|
819 | - //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
820 | - //be used anyways. |
|
821 | - if ($this->_error_msg) { |
|
822 | - return false; |
|
823 | - } |
|
824 | - |
|
825 | - $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
826 | - |
|
827 | - /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
|
828 | - $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
829 | - ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
830 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
831 | - |
|
832 | - //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
833 | - if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
834 | - $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
835 | - } |
|
836 | - |
|
837 | - //First get the class name for the data handler (and also verifies it exists. |
|
838 | - if (! class_exists($data_handler_class_name)) { |
|
839 | - $this->_error_msg[] = sprintf( |
|
840 | - esc_html__( |
|
841 | - 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
842 | - 'event_espresso' |
|
843 | - ), |
|
844 | - 'EE_Messages_incoming_data', |
|
845 | - $data_handler_class_name |
|
846 | - ); |
|
847 | - return false; |
|
848 | - } |
|
849 | - |
|
850 | - //convert generation_data for data_handler_instantiation. |
|
851 | - $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
852 | - |
|
853 | - //note, this may set error messages as well. |
|
854 | - $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
855 | - |
|
856 | - return empty($this->_error_msg); |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - /** |
|
861 | - * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
862 | - * adds it to the _data repository. |
|
863 | - * |
|
864 | - * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
865 | - * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
866 | - * instantiated. |
|
867 | - * @return void . |
|
868 | - * @throws EE_Error |
|
869 | - * @throws ReflectionException |
|
870 | - */ |
|
871 | - protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
872 | - { |
|
873 | - //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
874 | - //is already a ready data handler in the repository. |
|
875 | - $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
876 | - $this->_data_handler_collection->get_key( |
|
877 | - $data_handler_class_name, |
|
878 | - $generating_data |
|
879 | - ) |
|
880 | - ); |
|
881 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
882 | - //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
883 | - try { |
|
884 | - $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
885 | - $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
886 | - } catch (EE_Error $e) { |
|
887 | - $this->_error_msg[] = $e->get_error(); |
|
888 | - } |
|
889 | - } |
|
890 | - } |
|
891 | - |
|
892 | - |
|
893 | - /** |
|
894 | - * The queued EE_Message for generation does not save the data used for generation as objects |
|
895 | - * because serialization of those objects could be problematic if the data is saved to the db. |
|
896 | - * So this method calls the static method on the associated data_handler for the given message_type |
|
897 | - * and that preps the data for later instantiation when generating. |
|
898 | - * |
|
899 | - * @param EE_Message_To_Generate $message_to_generate |
|
900 | - * @param bool $preview Indicate whether this is being used for a preview or not. |
|
901 | - * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
902 | - */ |
|
903 | - protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
904 | - { |
|
905 | - /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
906 | - $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
907 | - if (! $message_to_generate->valid()) { |
|
908 | - return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
909 | - } |
|
910 | - return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
911 | - } |
|
912 | - |
|
913 | - |
|
914 | - /** |
|
915 | - * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
916 | - * |
|
917 | - * @param EE_Message_To_Generate $message_to_generate |
|
918 | - * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
919 | - */ |
|
920 | - public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
921 | - { |
|
922 | - //prep data |
|
923 | - $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
924 | - |
|
925 | - $message = $message_to_generate->get_EE_Message(); |
|
926 | - |
|
927 | - //is there a GRP_ID in the request? |
|
928 | - if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
929 | - $message->set_GRP_ID($GRP_ID); |
|
930 | - } |
|
931 | - |
|
932 | - if ($data === false) { |
|
933 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
934 | - $message->set_error_message( |
|
935 | - esc_html__( |
|
936 | - 'Unable to prepare data for persistence to the database.', |
|
937 | - 'event_espresso' |
|
938 | - ) |
|
939 | - ); |
|
940 | - } else { |
|
941 | - //make sure that the data handler is cached on the message as well |
|
942 | - $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
943 | - } |
|
944 | - |
|
945 | - $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
946 | - } |
|
16 | + /** |
|
17 | + * @type EE_Messages_Data_Handler_Collection |
|
18 | + */ |
|
19 | + protected $_data_handler_collection; |
|
20 | + |
|
21 | + /** |
|
22 | + * @type EE_Message_Template_Group_Collection |
|
23 | + */ |
|
24 | + protected $_template_collection; |
|
25 | + |
|
26 | + /** |
|
27 | + * This will hold the data handler for the current EE_Message being generated. |
|
28 | + * |
|
29 | + * @type EE_Messages_incoming_data |
|
30 | + */ |
|
31 | + protected $_current_data_handler; |
|
32 | + |
|
33 | + /** |
|
34 | + * This holds the EE_Messages_Queue that contains the messages to generate. |
|
35 | + * |
|
36 | + * @type EE_Messages_Queue |
|
37 | + */ |
|
38 | + protected $_generation_queue; |
|
39 | + |
|
40 | + /** |
|
41 | + * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
42 | + * |
|
43 | + * @type EE_Messages_Queue |
|
44 | + */ |
|
45 | + protected $_ready_queue; |
|
46 | + |
|
47 | + /** |
|
48 | + * This is a container for any error messages that get created through the generation |
|
49 | + * process. |
|
50 | + * |
|
51 | + * @type array |
|
52 | + */ |
|
53 | + protected $_error_msg = array(); |
|
54 | + |
|
55 | + /** |
|
56 | + * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
57 | + * |
|
58 | + * @type bool |
|
59 | + */ |
|
60 | + protected $_verified = false; |
|
61 | + |
|
62 | + /** |
|
63 | + * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
64 | + * |
|
65 | + * @type EE_messenger |
|
66 | + */ |
|
67 | + protected $_current_messenger; |
|
68 | + |
|
69 | + /** |
|
70 | + * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
71 | + * |
|
72 | + * @type EE_message_type |
|
73 | + */ |
|
74 | + protected $_current_message_type; |
|
75 | + |
|
76 | + /** |
|
77 | + * @type EEH_Parse_Shortcodes |
|
78 | + */ |
|
79 | + protected $_shortcode_parser; |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param EE_Messages_Queue $generation_queue |
|
84 | + * @param \EE_Messages_Queue $ready_queue |
|
85 | + * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
86 | + * @param \EE_Message_Template_Group_Collection $template_collection |
|
87 | + * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
88 | + */ |
|
89 | + public function __construct( |
|
90 | + EE_Messages_Queue $generation_queue, |
|
91 | + EE_Messages_Queue $ready_queue, |
|
92 | + EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
93 | + EE_Message_Template_Group_Collection $template_collection, |
|
94 | + EEH_Parse_Shortcodes $shortcode_parser |
|
95 | + ) { |
|
96 | + $this->_generation_queue = $generation_queue; |
|
97 | + $this->_ready_queue = $ready_queue; |
|
98 | + $this->_data_handler_collection = $data_handler_collection; |
|
99 | + $this->_template_collection = $template_collection; |
|
100 | + $this->_shortcode_parser = $shortcode_parser; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return EE_Messages_Queue |
|
106 | + */ |
|
107 | + public function generation_queue() |
|
108 | + { |
|
109 | + return $this->_generation_queue; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * This iterates through the provided queue and generates the EE_Message objects. |
|
115 | + * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
116 | + * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
117 | + * for the caller to decide what to do with it. |
|
118 | + * |
|
119 | + * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
120 | + * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
121 | + */ |
|
122 | + public function generate($save = true) |
|
123 | + { |
|
124 | + //iterate through the messages in the queue, generate, and add to new queue. |
|
125 | + $this->_generation_queue->get_message_repository()->rewind(); |
|
126 | + while ($this->_generation_queue->get_message_repository()->valid()) { |
|
127 | + //reset "current" properties |
|
128 | + $this->_reset_current_properties(); |
|
129 | + |
|
130 | + /** @type EE_Message $msg */ |
|
131 | + $msg = $this->_generation_queue->get_message_repository()->current(); |
|
132 | + |
|
133 | + /** |
|
134 | + * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
135 | + * an object is removed from the repo then valid for the next object will fail. |
|
136 | + */ |
|
137 | + $this->_generation_queue->get_message_repository()->next(); |
|
138 | + $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
139 | + //restore pointer to current item |
|
140 | + $this->_generation_queue->get_message_repository()->set_current($msg); |
|
141 | + |
|
142 | + //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
143 | + if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
144 | + //we keep this item in the db just remove from the repo. |
|
145 | + $this->_generation_queue->get_message_repository()->remove($msg); |
|
146 | + //next item |
|
147 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
148 | + continue; |
|
149 | + } |
|
150 | + |
|
151 | + if ($this->_verify()) { |
|
152 | + //let's get generating! |
|
153 | + $this->_generate(); |
|
154 | + } |
|
155 | + |
|
156 | + //don't persist debug_only messages if the messages system is not in debug mode. |
|
157 | + if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
158 | + && ! EEM_Message::debug() |
|
159 | + ) { |
|
160 | + do_action( |
|
161 | + 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
162 | + $msg, |
|
163 | + $this->_error_msg, |
|
164 | + $this->_current_messenger, |
|
165 | + $this->_current_message_type, |
|
166 | + $this->_current_data_handler |
|
167 | + ); |
|
168 | + $this->_generation_queue->get_message_repository()->delete(); |
|
169 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
170 | + continue; |
|
171 | + } |
|
172 | + |
|
173 | + //if there are error messages then let's set the status and the error message. |
|
174 | + if ($this->_error_msg) { |
|
175 | + //if the status is already debug only, then let's leave it at that. |
|
176 | + if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
177 | + $msg->set_STS_ID(EEM_Message::status_failed); |
|
178 | + } |
|
179 | + do_action( |
|
180 | + 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
181 | + $msg, |
|
182 | + $this->_error_msg, |
|
183 | + $this->_current_messenger, |
|
184 | + $this->_current_message_type, |
|
185 | + $this->_current_data_handler |
|
186 | + ); |
|
187 | + $msg->set_error_message( |
|
188 | + esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
189 | + . "\n" |
|
190 | + . implode("\n", $this->_error_msg) |
|
191 | + ); |
|
192 | + $msg->set_modified(time()); |
|
193 | + } else { |
|
194 | + do_action( |
|
195 | + 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
196 | + $msg, |
|
197 | + $this->_error_msg, |
|
198 | + $this->_current_messenger, |
|
199 | + $this->_current_message_type, |
|
200 | + $this->_current_data_handler |
|
201 | + ); |
|
202 | + //remove from db |
|
203 | + $this->_generation_queue->get_message_repository()->delete(); |
|
204 | + } |
|
205 | + //next item |
|
206 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
207 | + } |
|
208 | + |
|
209 | + //generation queue is ALWAYS saved to record any errors in the generation process. |
|
210 | + $this->_generation_queue->save(); |
|
211 | + |
|
212 | + /** |
|
213 | + * save _ready_queue if flag set. |
|
214 | + * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
215 | + * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
216 | + * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
217 | + * irrelevant. |
|
218 | + */ |
|
219 | + if ($save) { |
|
220 | + $this->_ready_queue->save(); |
|
221 | + } |
|
222 | + |
|
223 | + //final reset of properties |
|
224 | + $this->_reset_current_properties(); |
|
225 | + |
|
226 | + return $this->_ready_queue; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
232 | + * in the generation queue. |
|
233 | + */ |
|
234 | + protected function _reset_current_properties() |
|
235 | + { |
|
236 | + $this->_verified = false; |
|
237 | + //make sure any _data value in the current message type is reset |
|
238 | + if ($this->_current_message_type instanceof EE_message_type) { |
|
239 | + $this->_current_message_type->reset_data(); |
|
240 | + } |
|
241 | + $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
247 | + * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
248 | + * _generating_queue. |
|
249 | + * |
|
250 | + * @return bool Whether the message was successfully generated or not. |
|
251 | + * @throws EE_Error |
|
252 | + */ |
|
253 | + protected function _generate() |
|
254 | + { |
|
255 | + //double check verification has run and that everything is ready to work with (saves us having to validate |
|
256 | + // everything again). |
|
257 | + if (! $this->_verified) { |
|
258 | + return false; //get out because we don't have a valid setup to work with. |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + try { |
|
263 | + $addressees = $this->_current_message_type->get_addressees( |
|
264 | + $this->_current_data_handler, |
|
265 | + $this->_generation_queue->get_message_repository()->current()->context() |
|
266 | + ); |
|
267 | + } catch (EE_Error $e) { |
|
268 | + $this->_error_msg[] = $e->getMessage(); |
|
269 | + return false; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + //if no addressees then get out because there is nothing to generation (possible bad data). |
|
274 | + if (! $this->_valid_addressees($addressees)) { |
|
275 | + do_action( |
|
276 | + 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
277 | + $this->_generation_queue->get_message_repository()->current(), |
|
278 | + $addressees, |
|
279 | + $this->_current_messenger, |
|
280 | + $this->_current_message_type, |
|
281 | + $this->_current_data_handler |
|
282 | + ); |
|
283 | + $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
284 | + EEM_Message::status_debug_only |
|
285 | + ); |
|
286 | + $this->_error_msg[] = esc_html__( |
|
287 | + 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
288 | + 'event_espresso' |
|
289 | + ); |
|
290 | + return false; |
|
291 | + } |
|
292 | + |
|
293 | + $message_template_group = $this->_get_message_template_group(); |
|
294 | + |
|
295 | + //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
296 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
297 | + $this->_error_msg[] = esc_html__( |
|
298 | + 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
299 | + 'event_espresso' |
|
300 | + ); |
|
301 | + return false; |
|
302 | + } |
|
303 | + |
|
304 | + //get formatted templates for using to parse and setup EE_Message objects. |
|
305 | + $templates = $this->_get_templates($message_template_group); |
|
306 | + |
|
307 | + |
|
308 | + //setup new EE_Message objects (and add to _ready_queue) |
|
309 | + return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Retrieves the message template group being used for generating messages. |
|
315 | + * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
316 | + * |
|
317 | + * @return EE_Message_Template_Group|null |
|
318 | + * @throws EE_Error |
|
319 | + */ |
|
320 | + protected function _get_message_template_group() |
|
321 | + { |
|
322 | + //first see if there is a specific message template group requested (current message in the queue has a specific |
|
323 | + //GRP_ID |
|
324 | + $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
325 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
326 | + return $message_template_group; |
|
327 | + } |
|
328 | + |
|
329 | + //get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
330 | + //in the collection. |
|
331 | + $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
332 | + $message_template_group = $this->_template_collection->get_by_key( |
|
333 | + $this->_template_collection->getKey( |
|
334 | + $this->_current_messenger->name, |
|
335 | + $this->_current_message_type->name, |
|
336 | + $event_ids |
|
337 | + ) |
|
338 | + ); |
|
339 | + |
|
340 | + //if we have a message template group then no need to hit the database, just return it. |
|
341 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
342 | + return $message_template_group; |
|
343 | + } |
|
344 | + |
|
345 | + //okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
346 | + //there is no override set. |
|
347 | + $global_message_template_group = $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
348 | + |
|
349 | + if ($global_message_template_group instanceof EE_Message_Template_Group |
|
350 | + && $global_message_template_group->get('MTP_is_override') |
|
351 | + ) { |
|
352 | + return $global_message_template_group; |
|
353 | + } |
|
354 | + |
|
355 | + //if we're still here, that means there was no message template group for the events in the collection and |
|
356 | + //the global message template group for the messenger and message type is not set for override. So next step is |
|
357 | + //to see if there is a common shared custom message template group for this set of events. |
|
358 | + $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
359 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
360 | + return $message_template_group; |
|
361 | + } |
|
362 | + |
|
363 | + //STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
364 | + //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
365 | + //and return it. |
|
366 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
367 | + $this->_template_collection->add( |
|
368 | + $global_message_template_group, |
|
369 | + $event_ids |
|
370 | + ); |
|
371 | + return $global_message_template_group; |
|
372 | + } |
|
373 | + |
|
374 | + //if we land here that means there's NO active message template group for this set. |
|
375 | + //TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
376 | + //template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
377 | + //this should likely bit hit rarely enough that it's not a significant issue. |
|
378 | + return null; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
384 | + * requested for that message. |
|
385 | + * |
|
386 | + * @return EE_Message_Template_Group|null |
|
387 | + */ |
|
388 | + protected function _specific_message_template_group_from_queue() |
|
389 | + { |
|
390 | + //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
391 | + //so let's use that. |
|
392 | + $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
393 | + |
|
394 | + if ($GRP_ID) { |
|
395 | + //attempt to retrieve from repo first |
|
396 | + $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
397 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
398 | + return $message_template_group; //got it! |
|
399 | + } |
|
400 | + |
|
401 | + //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
402 | + //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
403 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
404 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
405 | + $this->_template_collection->add($message_template_group); |
|
406 | + return $message_template_group; |
|
407 | + } |
|
408 | + } |
|
409 | + return null; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Returns whether the event ids passed in all share the same message template group for the current message type |
|
415 | + * and messenger. |
|
416 | + * |
|
417 | + * @param array $event_ids |
|
418 | + * @return bool true means they DO share the same message template group, false means they don't. |
|
419 | + * @throws EE_Error |
|
420 | + */ |
|
421 | + protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
422 | + { |
|
423 | + foreach ($this->_current_data_handler->events as $event) { |
|
424 | + $event_ids[$event['ID']] = $event['ID']; |
|
425 | + } |
|
426 | + $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
427 | + array( |
|
428 | + array( |
|
429 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
430 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
431 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
432 | + ), |
|
433 | + ), |
|
434 | + 'GRP_ID', |
|
435 | + true |
|
436 | + ); |
|
437 | + return $count_of_message_template_groups === 1; |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
443 | + * there's a single shared message template group among all the events. Otherwise it returns null. |
|
444 | + * |
|
445 | + * @param array $event_ids |
|
446 | + * @return EE_Message_Template_Group|null |
|
447 | + * @throws EE_Error |
|
448 | + */ |
|
449 | + protected function _get_shared_message_template_for_events(array $event_ids) |
|
450 | + { |
|
451 | + $message_template_group = null; |
|
452 | + if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
453 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
454 | + array( |
|
455 | + array( |
|
456 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
457 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
458 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
459 | + 'MTP_is_active' => true, |
|
460 | + ), |
|
461 | + 'group_by' => 'GRP_ID', |
|
462 | + ) |
|
463 | + ); |
|
464 | + //store this in the collection if its valid |
|
465 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
466 | + $this->_template_collection->add( |
|
467 | + $message_template_group, |
|
468 | + $event_ids |
|
469 | + ); |
|
470 | + } |
|
471 | + } |
|
472 | + return $message_template_group; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Retrieves the global message template group for the current messenger and message type. |
|
478 | + * |
|
479 | + * @return EE_Message_Template_Group|null |
|
480 | + * @throws EE_Error |
|
481 | + */ |
|
482 | + protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
483 | + { |
|
484 | + //first check the collection (we use an array with 0 in it to represent global groups). |
|
485 | + $global_message_template_group = $this->_template_collection->get_by_key( |
|
486 | + $this->_template_collection->getKey( |
|
487 | + $this->_current_messenger->name, |
|
488 | + $this->_current_message_type->name, |
|
489 | + array(0) |
|
490 | + ) |
|
491 | + ); |
|
492 | + |
|
493 | + //if we don't have a group lets hit the db. |
|
494 | + if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
495 | + $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
496 | + array( |
|
497 | + array( |
|
498 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
499 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
500 | + 'MTP_is_active' => true, |
|
501 | + 'MTP_is_global' => true, |
|
502 | + ), |
|
503 | + ) |
|
504 | + ); |
|
505 | + //if we have a group, add it to the collection. |
|
506 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
507 | + $this->_template_collection->add( |
|
508 | + $global_message_template_group, |
|
509 | + array(0) |
|
510 | + ); |
|
511 | + } |
|
512 | + } |
|
513 | + return $global_message_template_group; |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * Returns an array of event ids for all the events within the current data handler. |
|
519 | + * |
|
520 | + * @return array |
|
521 | + */ |
|
522 | + protected function _get_event_ids_from_current_data_handler() |
|
523 | + { |
|
524 | + $event_ids = array(); |
|
525 | + foreach ($this->_current_data_handler->events as $event) { |
|
526 | + $event_ids[$event['ID']] = $event['ID']; |
|
527 | + } |
|
528 | + return $event_ids; |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * Retrieves formatted array of template information for each context specific to the given |
|
534 | + * EE_Message_Template_Group |
|
535 | + * |
|
536 | + * @param EE_Message_Template_Group $message_template_group |
|
537 | + * @return array The returned array is in this structure: |
|
538 | + * array( |
|
539 | + * 'field_name' => array( |
|
540 | + * 'context' => 'content' |
|
541 | + * ) |
|
542 | + * ) |
|
543 | + * @throws EE_Error |
|
544 | + */ |
|
545 | + protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
546 | + { |
|
547 | + $templates = array(); |
|
548 | + $context_templates = $message_template_group->context_templates(); |
|
549 | + foreach ($context_templates as $context => $template_fields) { |
|
550 | + foreach ($template_fields as $template_field => $template_obj) { |
|
551 | + if (! $template_obj instanceof EE_Message_Template) { |
|
552 | + continue; |
|
553 | + } |
|
554 | + $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
555 | + } |
|
556 | + } |
|
557 | + return $templates; |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
563 | + * |
|
564 | + * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
565 | + * context. |
|
566 | + * @param array $templates formatted array of templates used for parsing data. |
|
567 | + * @param EE_Message_Template_Group $message_template_group |
|
568 | + * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
569 | + * method will attempt to generate ALL EE_Message objects and add to |
|
570 | + * the _ready_queue. Successfully generated messages get added to the |
|
571 | + * queue with EEM_Message::status_idle, unsuccessfully generated |
|
572 | + * messages will get added to the queue as EEM_Message::status_failed. |
|
573 | + * Very rarely should "false" be returned from this method. |
|
574 | + */ |
|
575 | + protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
576 | + { |
|
577 | + |
|
578 | + //if templates are empty then get out because we can't generate anything. |
|
579 | + if (! $templates) { |
|
580 | + $this->_error_msg[] = esc_html__( |
|
581 | + 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
582 | + 'event_espresso' |
|
583 | + ); |
|
584 | + return false; |
|
585 | + } |
|
586 | + |
|
587 | + //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
588 | + //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
589 | + $generated_count = 0; |
|
590 | + foreach ($addressees as $context => $recipients) { |
|
591 | + foreach ($recipients as $recipient) { |
|
592 | + $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
593 | + if ($message instanceof EE_Message) { |
|
594 | + $this->_ready_queue->add( |
|
595 | + $message, |
|
596 | + array(), |
|
597 | + $this->_generation_queue->get_message_repository()->is_preview(), |
|
598 | + $this->_generation_queue->get_message_repository()->is_test_send() |
|
599 | + ); |
|
600 | + $generated_count++; |
|
601 | + } |
|
602 | + |
|
603 | + //if the current MSG being generated is for a test send then we'll only use ONE message in the generation. |
|
604 | + if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
605 | + break 2; |
|
606 | + } |
|
607 | + } |
|
608 | + } |
|
609 | + |
|
610 | + //if there are no generated messages then something else fatal went wrong. |
|
611 | + return $generated_count > 0; |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * @param string $context The context for the generated message. |
|
617 | + * @param EE_Messages_Addressee $recipient |
|
618 | + * @param array $templates formatted array of templates used for parsing data. |
|
619 | + * @param EE_Message_Template_Group $message_template_group |
|
620 | + * @return bool|EE_Message |
|
621 | + * @throws EE_Error |
|
622 | + */ |
|
623 | + protected function _setup_message_object( |
|
624 | + $context, |
|
625 | + EE_Messages_Addressee $recipient, |
|
626 | + $templates, |
|
627 | + EE_Message_Template_Group $message_template_group |
|
628 | + ) { |
|
629 | + //stuff we already know |
|
630 | + $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
631 | + $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
632 | + ? $this->_current_data_handler->txn->ID() |
|
633 | + : $transaction_id; |
|
634 | + $message_fields = array( |
|
635 | + 'GRP_ID' => $message_template_group->ID(), |
|
636 | + 'TXN_ID' => $transaction_id, |
|
637 | + 'MSG_messenger' => $this->_current_messenger->name, |
|
638 | + 'MSG_message_type' => $this->_current_message_type->name, |
|
639 | + 'MSG_context' => $context, |
|
640 | + ); |
|
641 | + |
|
642 | + //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
643 | + // the info from the att_obj found in the EE_Messages_Addressee object. |
|
644 | + if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
645 | + $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
646 | + ? $recipient->att_obj->ID() |
|
647 | + : 0; |
|
648 | + $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
649 | + } else { |
|
650 | + $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
651 | + $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
652 | + } |
|
653 | + $message = EE_Message_Factory::create($message_fields); |
|
654 | + |
|
655 | + //grab valid shortcodes for shortcode parser |
|
656 | + $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
657 | + $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
658 | + |
|
659 | + //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
|
660 | + //context is turned off) EXCEPT if we're previewing |
|
661 | + if (empty($templates['to'][$context]) |
|
662 | + && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
663 | + && ! $this->_current_messenger->allow_empty_to_field() |
|
664 | + ) { |
|
665 | + //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
666 | + //field. |
|
667 | + return false; |
|
668 | + } |
|
669 | + $error_msg = array(); |
|
670 | + foreach ($templates as $field => $field_context) { |
|
671 | + $error_msg = array(); |
|
672 | + //let's setup the valid shortcodes for the incoming context. |
|
673 | + $valid_shortcodes = $mt_shortcodes[$context]; |
|
674 | + //merge in valid shortcodes for the field. |
|
675 | + $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
676 | + if (isset($templates[$field][$context])) { |
|
677 | + //prefix field. |
|
678 | + $column_name = 'MSG_' . $field; |
|
679 | + try { |
|
680 | + $content = $this->_shortcode_parser->parse_message_template( |
|
681 | + $templates[$field][$context], |
|
682 | + $recipient, |
|
683 | + $shortcodes, |
|
684 | + $this->_current_message_type, |
|
685 | + $this->_current_messenger, |
|
686 | + $message |
|
687 | + ); |
|
688 | + $message->set_field_or_extra_meta($column_name, $content); |
|
689 | + } catch (EE_Error $e) { |
|
690 | + $error_msg[] = sprintf( |
|
691 | + esc_html__( |
|
692 | + 'There was a problem generating the content for the field %s: %s', |
|
693 | + 'event_espresso' |
|
694 | + ), |
|
695 | + $field, |
|
696 | + $e->getMessage() |
|
697 | + ); |
|
698 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
699 | + } |
|
700 | + } |
|
701 | + } |
|
702 | + |
|
703 | + if ($message->STS_ID() === EEM_Message::status_failed) { |
|
704 | + $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
705 | + . "\n" |
|
706 | + . implode("\n", $error_msg); |
|
707 | + $message->set_error_message($error_msg); |
|
708 | + } else { |
|
709 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
710 | + } |
|
711 | + return $message; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
717 | + * error message if either is missing. |
|
718 | + * |
|
719 | + * @return bool true means there were no errors, false means there were errors. |
|
720 | + */ |
|
721 | + protected function _verify() |
|
722 | + { |
|
723 | + //reset error message to an empty array. |
|
724 | + $this->_error_msg = array(); |
|
725 | + $valid = true; |
|
726 | + $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
727 | + $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
728 | + |
|
729 | + //set the verified flag so we know everything has been validated. |
|
730 | + $this->_verified = $valid; |
|
731 | + |
|
732 | + return $valid; |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
738 | + * EE_Messages_Addressee objects. |
|
739 | + * |
|
740 | + * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
741 | + * @return bool |
|
742 | + */ |
|
743 | + protected function _valid_addressees($addressees) |
|
744 | + { |
|
745 | + if (! $addressees || ! is_array($addressees)) { |
|
746 | + return false; |
|
747 | + } |
|
748 | + |
|
749 | + foreach ($addressees as $addressee_array) { |
|
750 | + foreach ($addressee_array as $addressee) { |
|
751 | + if (! $addressee instanceof EE_Messages_Addressee) { |
|
752 | + return false; |
|
753 | + } |
|
754 | + } |
|
755 | + } |
|
756 | + return true; |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + /** |
|
761 | + * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
762 | + * queue. This process sets error messages if something is wrong. |
|
763 | + * |
|
764 | + * @return bool true is if there are no errors. false is if there is. |
|
765 | + */ |
|
766 | + protected function _validate_messenger_and_message_type() |
|
767 | + { |
|
768 | + |
|
769 | + //first are there any existing error messages? If so then return. |
|
770 | + if ($this->_error_msg) { |
|
771 | + return false; |
|
772 | + } |
|
773 | + /** @type EE_Message $message */ |
|
774 | + $message = $this->_generation_queue->get_message_repository()->current(); |
|
775 | + try { |
|
776 | + $this->_current_messenger = $message->valid_messenger(true) |
|
777 | + ? $message->messenger_object() |
|
778 | + : null; |
|
779 | + } catch (Exception $e) { |
|
780 | + $this->_error_msg[] = $e->getMessage(); |
|
781 | + } |
|
782 | + try { |
|
783 | + $this->_current_message_type = $message->valid_message_type(true) |
|
784 | + ? $message->message_type_object() |
|
785 | + : null; |
|
786 | + } catch (Exception $e) { |
|
787 | + $this->_error_msg[] = $e->getMessage(); |
|
788 | + } |
|
789 | + |
|
790 | + /** |
|
791 | + * Check if there is any generation data, but only if this is not for a preview. |
|
792 | + */ |
|
793 | + if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
794 | + && ( |
|
795 | + ! $this->_generation_queue->get_message_repository()->is_preview() |
|
796 | + && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
797 | + !== 'EE_Messages_Preview_incoming_data' |
|
798 | + ) |
|
799 | + ) { |
|
800 | + $this->_error_msg[] = esc_html__( |
|
801 | + 'There is no generation data for this message. Unable to generate.', |
|
802 | + 'event_espresso' |
|
803 | + ); |
|
804 | + } |
|
805 | + |
|
806 | + return empty($this->_error_msg); |
|
807 | + } |
|
808 | + |
|
809 | + |
|
810 | + /** |
|
811 | + * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
812 | + * data handler. |
|
813 | + * |
|
814 | + * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
815 | + */ |
|
816 | + protected function _validate_and_setup_data() |
|
817 | + { |
|
818 | + |
|
819 | + //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
820 | + //be used anyways. |
|
821 | + if ($this->_error_msg) { |
|
822 | + return false; |
|
823 | + } |
|
824 | + |
|
825 | + $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
826 | + |
|
827 | + /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
|
828 | + $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
829 | + ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
830 | + : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
831 | + |
|
832 | + //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
833 | + if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
834 | + $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
835 | + } |
|
836 | + |
|
837 | + //First get the class name for the data handler (and also verifies it exists. |
|
838 | + if (! class_exists($data_handler_class_name)) { |
|
839 | + $this->_error_msg[] = sprintf( |
|
840 | + esc_html__( |
|
841 | + 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
842 | + 'event_espresso' |
|
843 | + ), |
|
844 | + 'EE_Messages_incoming_data', |
|
845 | + $data_handler_class_name |
|
846 | + ); |
|
847 | + return false; |
|
848 | + } |
|
849 | + |
|
850 | + //convert generation_data for data_handler_instantiation. |
|
851 | + $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
852 | + |
|
853 | + //note, this may set error messages as well. |
|
854 | + $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
855 | + |
|
856 | + return empty($this->_error_msg); |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + /** |
|
861 | + * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
862 | + * adds it to the _data repository. |
|
863 | + * |
|
864 | + * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
865 | + * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
866 | + * instantiated. |
|
867 | + * @return void . |
|
868 | + * @throws EE_Error |
|
869 | + * @throws ReflectionException |
|
870 | + */ |
|
871 | + protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
872 | + { |
|
873 | + //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
874 | + //is already a ready data handler in the repository. |
|
875 | + $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
876 | + $this->_data_handler_collection->get_key( |
|
877 | + $data_handler_class_name, |
|
878 | + $generating_data |
|
879 | + ) |
|
880 | + ); |
|
881 | + if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
882 | + //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
883 | + try { |
|
884 | + $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
885 | + $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
886 | + } catch (EE_Error $e) { |
|
887 | + $this->_error_msg[] = $e->get_error(); |
|
888 | + } |
|
889 | + } |
|
890 | + } |
|
891 | + |
|
892 | + |
|
893 | + /** |
|
894 | + * The queued EE_Message for generation does not save the data used for generation as objects |
|
895 | + * because serialization of those objects could be problematic if the data is saved to the db. |
|
896 | + * So this method calls the static method on the associated data_handler for the given message_type |
|
897 | + * and that preps the data for later instantiation when generating. |
|
898 | + * |
|
899 | + * @param EE_Message_To_Generate $message_to_generate |
|
900 | + * @param bool $preview Indicate whether this is being used for a preview or not. |
|
901 | + * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
902 | + */ |
|
903 | + protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
904 | + { |
|
905 | + /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
906 | + $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
907 | + if (! $message_to_generate->valid()) { |
|
908 | + return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
909 | + } |
|
910 | + return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
911 | + } |
|
912 | + |
|
913 | + |
|
914 | + /** |
|
915 | + * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
916 | + * |
|
917 | + * @param EE_Message_To_Generate $message_to_generate |
|
918 | + * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
919 | + */ |
|
920 | + public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
921 | + { |
|
922 | + //prep data |
|
923 | + $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
924 | + |
|
925 | + $message = $message_to_generate->get_EE_Message(); |
|
926 | + |
|
927 | + //is there a GRP_ID in the request? |
|
928 | + if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
929 | + $message->set_GRP_ID($GRP_ID); |
|
930 | + } |
|
931 | + |
|
932 | + if ($data === false) { |
|
933 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
934 | + $message->set_error_message( |
|
935 | + esc_html__( |
|
936 | + 'Unable to prepare data for persistence to the database.', |
|
937 | + 'event_espresso' |
|
938 | + ) |
|
939 | + ); |
|
940 | + } else { |
|
941 | + //make sure that the data handler is cached on the message as well |
|
942 | + $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
943 | + } |
|
944 | + |
|
945 | + $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
946 | + } |
|
947 | 947 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | { |
255 | 255 | //double check verification has run and that everything is ready to work with (saves us having to validate |
256 | 256 | // everything again). |
257 | - if (! $this->_verified) { |
|
257 | + if ( ! $this->_verified) { |
|
258 | 258 | return false; //get out because we don't have a valid setup to work with. |
259 | 259 | } |
260 | 260 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | |
272 | 272 | |
273 | 273 | //if no addressees then get out because there is nothing to generation (possible bad data). |
274 | - if (! $this->_valid_addressees($addressees)) { |
|
274 | + if ( ! $this->_valid_addressees($addressees)) { |
|
275 | 275 | do_action( |
276 | 276 | 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
277 | 277 | $this->_generation_queue->get_message_repository()->current(), |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | $message_template_group = $this->_get_message_template_group(); |
294 | 294 | |
295 | 295 | //in the unlikely event there is no EE_Message_Template_Group available, get out! |
296 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
296 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
297 | 297 | $this->_error_msg[] = esc_html__( |
298 | 298 | 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
299 | 299 | 'event_espresso' |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | //attempt to retrieve from repo first |
396 | 396 | $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
397 | 397 | if ($message_template_group instanceof EE_Message_Template_Group) { |
398 | - return $message_template_group; //got it! |
|
398 | + return $message_template_group; //got it! |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | ); |
492 | 492 | |
493 | 493 | //if we don't have a group lets hit the db. |
494 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
494 | + if ( ! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
495 | 495 | $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
496 | 496 | array( |
497 | 497 | array( |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | $context_templates = $message_template_group->context_templates(); |
549 | 549 | foreach ($context_templates as $context => $template_fields) { |
550 | 550 | foreach ($template_fields as $template_field => $template_obj) { |
551 | - if (! $template_obj instanceof EE_Message_Template) { |
|
551 | + if ( ! $template_obj instanceof EE_Message_Template) { |
|
552 | 552 | continue; |
553 | 553 | } |
554 | 554 | $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | { |
577 | 577 | |
578 | 578 | //if templates are empty then get out because we can't generate anything. |
579 | - if (! $templates) { |
|
579 | + if ( ! $templates) { |
|
580 | 580 | $this->_error_msg[] = esc_html__( |
581 | 581 | 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
582 | 582 | 'event_espresso' |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
676 | 676 | if (isset($templates[$field][$context])) { |
677 | 677 | //prefix field. |
678 | - $column_name = 'MSG_' . $field; |
|
678 | + $column_name = 'MSG_'.$field; |
|
679 | 679 | try { |
680 | 680 | $content = $this->_shortcode_parser->parse_message_template( |
681 | 681 | $templates[$field][$context], |
@@ -742,13 +742,13 @@ discard block |
||
742 | 742 | */ |
743 | 743 | protected function _valid_addressees($addressees) |
744 | 744 | { |
745 | - if (! $addressees || ! is_array($addressees)) { |
|
745 | + if ( ! $addressees || ! is_array($addressees)) { |
|
746 | 746 | return false; |
747 | 747 | } |
748 | 748 | |
749 | 749 | foreach ($addressees as $addressee_array) { |
750 | 750 | foreach ($addressee_array as $addressee) { |
751 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
751 | + if ( ! $addressee instanceof EE_Messages_Addressee) { |
|
752 | 752 | return false; |
753 | 753 | } |
754 | 754 | } |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | /** |
791 | 791 | * Check if there is any generation data, but only if this is not for a preview. |
792 | 792 | */ |
793 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
793 | + if ( ! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
794 | 794 | && ( |
795 | 795 | ! $this->_generation_queue->get_message_repository()->is_preview() |
796 | 796 | && $this->_generation_queue->get_message_repository()->get_data_handler() |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
828 | 828 | $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
829 | 829 | ? $this->_generation_queue->get_message_repository()->get_data_handler() |
830 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
830 | + : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data'; |
|
831 | 831 | |
832 | 832 | //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
833 | 833 | if ($this->_generation_queue->get_message_repository()->is_preview()) { |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | } |
836 | 836 | |
837 | 837 | //First get the class name for the data handler (and also verifies it exists. |
838 | - if (! class_exists($data_handler_class_name)) { |
|
838 | + if ( ! class_exists($data_handler_class_name)) { |
|
839 | 839 | $this->_error_msg[] = sprintf( |
840 | 840 | esc_html__( |
841 | 841 | 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | $generating_data |
879 | 879 | ) |
880 | 880 | ); |
881 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
881 | + if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
882 | 882 | //no saved data_handler in the repo so let's set one up and add it to the repo. |
883 | 883 | try { |
884 | 884 | $this->_current_data_handler = new $data_handler_class_name($generating_data); |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | { |
905 | 905 | /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
906 | 906 | $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
907 | - if (! $message_to_generate->valid()) { |
|
907 | + if ( ! $message_to_generate->valid()) { |
|
908 | 908 | return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
909 | 909 | } |
910 | 910 | return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | $event_one_link = $event_two_link = $event_three_link = ''; |
19 | 19 | |
20 | 20 | $I->wantTo( |
21 | - 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
22 | - . 'template, that that custom template will be used.' |
|
21 | + 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
22 | + . 'template, that that custom template will be used.' |
|
23 | 23 | ); |
24 | 24 | |
25 | 25 | //need the MER plugin active for this test (we'll deactivate it after). |
26 | 26 | $I->ensurePluginActive( |
27 | - 'event-espresso-mer-multi-event-registration', |
|
28 | - 'activated' |
|
27 | + 'event-espresso-mer-multi-event-registration', |
|
28 | + 'activated' |
|
29 | 29 | ); |
30 | 30 | |
31 | 31 | $I->loginAsAdmin(); |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | |
84 | 84 | |
85 | 85 | $test_registration_details = array( |
86 | - 'fname' => 'CTGuy', |
|
87 | - 'lname' => 'Dude', |
|
88 | - 'email' => '[email protected]' |
|
86 | + 'fname' => 'CTGuy', |
|
87 | + 'lname' => 'Dude', |
|
88 | + 'email' => '[email protected]' |
|
89 | 89 | ); |
90 | 90 | |
91 | 91 | $I->amGoingTo('Register for Event One and Event Two and verify Custom Template A was used.'); |
@@ -111,24 +111,24 @@ discard block |
||
111 | 111 | $I->loginAsAdmin(); |
112 | 112 | $I->amOnMessagesActivityListTablePage(); |
113 | 113 | $I->viewMessageInMessagesListTableFor( |
114 | - 'Registration Approved', |
|
115 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
116 | - 'Email', |
|
117 | - 'Registrant' |
|
114 | + 'Registration Approved', |
|
115 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
116 | + 'Email', |
|
117 | + 'Registrant' |
|
118 | 118 | ); |
119 | 119 | $I->seeTextInViewMessageModal($custom_template_a_label); |
120 | 120 | //closes view window |
121 | 121 | $I->click('#espresso-admin-page-overlay-dv'); |
122 | 122 | $I->deleteMessageInMessagesListTableFor( |
123 | - 'Registration Approved', |
|
124 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
125 | - 'Email', |
|
126 | - 'Registrant' |
|
123 | + 'Registration Approved', |
|
124 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
125 | + 'Email', |
|
126 | + 'Registrant' |
|
127 | 127 | ); |
128 | 128 | |
129 | 129 | //verify admin context |
130 | 130 | $I->viewMessageInMessagesListTableFor( |
131 | - 'Registration Approved' |
|
131 | + 'Registration Approved' |
|
132 | 132 | ); |
133 | 133 | $I->seeTextInViewMessageModal($custom_template_a_label); |
134 | 134 | $I->click('#espresso-admin-page-overlay-dv'); |
@@ -157,10 +157,10 @@ discard block |
||
157 | 157 | $I->loginAsAdmin(); |
158 | 158 | $I->amOnMessagesActivityListTablePage(); |
159 | 159 | $I->viewMessageInMessagesListTableFor( |
160 | - 'Registration Approved', |
|
161 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
162 | - 'Email', |
|
163 | - 'Registrant' |
|
160 | + 'Registration Approved', |
|
161 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
162 | + 'Email', |
|
163 | + 'Registrant' |
|
164 | 164 | ); |
165 | 165 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
166 | 166 | $I->dontSeeTextInViewMessageModal($custom_template_a_label); |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | //closes view window |
169 | 169 | $I->click('#espresso-admin-page-overlay-dv'); |
170 | 170 | $I->deleteMessageInMessagesListTableFor( |
171 | - 'Registration Approved', |
|
172 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
173 | - 'Email', |
|
174 | - 'Registrant' |
|
171 | + 'Registration Approved', |
|
172 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
173 | + 'Email', |
|
174 | + 'Registrant' |
|
175 | 175 | ); |
176 | 176 | |
177 | 177 | //verify admin context |
178 | 178 | $I->viewMessageInMessagesListTableFor( |
179 | - 'Registration Approved' |
|
179 | + 'Registration Approved' |
|
180 | 180 | ); |
181 | 181 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
182 | 182 | $I->dontSee($custom_template_a_label); |
@@ -188,6 +188,6 @@ discard block |
||
188 | 188 | |
189 | 189 | //deactivate MER plugin so its not active for future tests |
190 | 190 | $I->ensurePluginDeactivated( |
191 | - 'event-espresso-mer-multi-event-registration', |
|
192 | - 'Plugin deactivated' |
|
191 | + 'event-espresso-mer-multi-event-registration', |
|
192 | + 'Plugin deactivated' |
|
193 | 193 | ); |
194 | 194 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | <ul class="wp-people-group" id="ee-people-group-owners"> |
4 | 4 | <li class="wp-person" id="ee-person-sshoultes"> |
5 | 5 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
6 | - <?php echo esp_gravatar_image( '[email protected]', 'Seth Shoultes' ); ?> |
|
6 | + <?php echo esp_gravatar_image('[email protected]', 'Seth Shoultes'); ?> |
|
7 | 7 | </a> |
8 | 8 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
9 | 9 | Seth Shoultes |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | </li> |
13 | 13 | <li class="wp-person" id="ee-person-gkoyle"> |
14 | 14 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
15 | - <?php echo esp_gravatar_image( '[email protected]', 'Garth Koyle' ); ?> |
|
15 | + <?php echo esp_gravatar_image('[email protected]', 'Garth Koyle'); ?> |
|
16 | 16 | </a> |
17 | 17 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
18 | 18 | Garth Koyle |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | <ul class="wp-people-group" id="ee-people-group-core-developers"> |
25 | 25 | <li class="wp-person" id="ee-person-bchristensen"> |
26 | 26 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
27 | - <?php echo esp_gravatar_image( '[email protected]', 'Brent Christensen' ); ?> |
|
27 | + <?php echo esp_gravatar_image('[email protected]', 'Brent Christensen'); ?> |
|
28 | 28 | </a> |
29 | 29 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
30 | 30 | Brent Christensen |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | </li> |
34 | 34 | <li class="wp-person" id="ee-person-dethier"> |
35 | 35 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
36 | - <?php echo esp_gravatar_image( '[email protected]', 'Darren Ethier' ); ?> |
|
36 | + <?php echo esp_gravatar_image('[email protected]', 'Darren Ethier'); ?> |
|
37 | 37 | </a> |
38 | 38 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
39 | 39 | Darren Ethier |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | </li> |
43 | 43 | <li class="wp-person" id="ee-person-mnelson"> |
44 | 44 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
45 | - <?php echo esp_gravatar_image( '[email protected]', 'Michael Nelson' ); ?> |
|
45 | + <?php echo esp_gravatar_image('[email protected]', 'Michael Nelson'); ?> |
|
46 | 46 | </a> |
47 | 47 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
48 | 48 | Michael Nelson |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | </li> |
52 | 52 | <li class="wp-person" id="ee-person-nkolivoshka"> |
53 | 53 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
54 | - <?php echo esp_gravatar_image( '[email protected]', 'Nazar Kolivoshka' ); ?> |
|
54 | + <?php echo esp_gravatar_image('[email protected]', 'Nazar Kolivoshka'); ?> |
|
55 | 55 | </a> |
56 | 56 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
57 | 57 | Nazar Kolivoshka |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | <ul class="wp-people-group" id="ee-people-group-support-staff"> |
64 | 64 | <li class="wp-person" id="ee-person-jfeck"> |
65 | 65 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
66 | - <?php echo esp_gravatar_image( '[email protected]', 'Josh Feck' ); ?> |
|
66 | + <?php echo esp_gravatar_image('[email protected]', 'Josh Feck'); ?> |
|
67 | 67 | </a> |
68 | 68 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
69 | 69 | Josh Feck |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | </li> |
72 | 72 | <li class="wp-person" id="ee-person-twarwick"> |
73 | 73 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
74 | - <?php echo esp_gravatar_image( '[email protected]', 'Tony Warwick' ); ?> |
|
74 | + <?php echo esp_gravatar_image('[email protected]', 'Tony Warwick'); ?> |
|
75 | 75 | </a> |
76 | 76 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
77 | 77 | Tony Warwick |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | </li> |
80 | 80 | <li class="wp-person" id="ee-person-lcaum"> |
81 | 81 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
82 | - <?php echo esp_gravatar_image( '[email protected]', 'Lorenzo Caum' ); ?> |
|
82 | + <?php echo esp_gravatar_image('[email protected]', 'Lorenzo Caum'); ?> |
|
83 | 83 | </a> |
84 | 84 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
85 | 85 | Lorenzo Caum |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | </li> |
88 | 88 | <li class="wp-person" id="ee-logan-lenz"> |
89 | 89 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
90 | - <?php echo esp_gravatar_image( '[email protected]', 'Logan Lenz' ); ?> |
|
90 | + <?php echo esp_gravatar_image('[email protected]', 'Logan Lenz'); ?> |
|
91 | 91 | </a> |
92 | 92 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
93 | 93 | Logan Lenz |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | </ul> |
98 | 98 | <h3 class="wp-people-group"><?php _e('Contributor Recognition', 'event_espresso'); ?></h3> |
99 | 99 | <p class="description"> |
100 | - <?php printf( __('For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', '</a>' ); ?> |
|
100 | + <?php printf(__('For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', '</a>'); ?> |
|
101 | 101 | </p> |
102 | 102 | <p class="wp-credits-list"> |
103 | 103 | <ul> |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | </p> |
112 | 112 | <h3 class="wp-people-group"><?php _e('External Libraries', 'event_espresso'); ?></h3> |
113 | 113 | <p class="description"> |
114 | - <?php printf( __('Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', 'event_espresso'), '<a href="credits.php">', '</a>' ); ?> |
|
114 | + <?php printf(__('Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', 'event_espresso'), '<a href="credits.php">', '</a>'); ?> |
|
115 | 115 | </p> |
116 | 116 | <p class="wp-credits-list"> |
117 | 117 | <a href="http://josscrowcroft.github.io/accounting.js/"><?php _e('accounting.js', 'event_espresso'); ?></a>, |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | |
128 | 128 | <?php |
129 | 129 | function esp_gravatar_profile($email) { |
130 | - echo 'http://www.gravatar.com/' . md5($email); |
|
130 | + echo 'http://www.gravatar.com/'.md5($email); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | function esp_gravatar_image($email, $name) { |
134 | - echo '<img src="http://0.gravatar.com/avatar/' . md5($email) . '?s=60" class="gravatar" alt="' . $name . '"/>'; |
|
134 | + echo '<img src="http://0.gravatar.com/avatar/'.md5($email).'?s=60" class="gravatar" alt="'.$name.'"/>'; |
|
135 | 135 | } |
136 | 136 | ?> |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @since 4.5.0 |
8 | 8 | */ |
9 | 9 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
10 | - exit('No direct script access allowed'); |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -21,166 +21,166 @@ discard block |
||
21 | 21 | class EE_Register_Capabilities implements EEI_Plugin_API |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Holds the settings for a specific registration. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected static $_registry = array(); |
|
24 | + /** |
|
25 | + * Holds the settings for a specific registration. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected static $_registry = array(); |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Used to register capability items with EE core. |
|
34 | - * |
|
35 | - * @since 4.5.0 |
|
36 | - * @param string $cap_reference usually will be a class name |
|
37 | - * that references capability |
|
38 | - * related items setup for |
|
39 | - * something. |
|
40 | - * @param array $setup_args { |
|
41 | - * An array of items related to |
|
42 | - * registering capabilities. |
|
43 | - * @type array $capabilities An array mapping capability |
|
44 | - * strings to core WP Role. Something like: array( |
|
45 | - * 'administrator' => array( |
|
46 | - * 'read_cap', 'edit_cap', |
|
47 | - * 'delete_cap'), |
|
48 | - * 'author' => |
|
49 | - * array( 'read_cap' ) |
|
50 | - * ). |
|
51 | - * @type array $capability_maps EE_Meta_Capability_Map[] |
|
52 | - * @see EE_Capabilities.php for php docs on these objects. |
|
53 | - * Should be indexed by the |
|
54 | - * classname for the capability |
|
55 | - * map and values representing |
|
56 | - * the arguments for the map. |
|
57 | - * } |
|
58 | - * @throws EE_Error |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - public static function register($cap_reference = null, $setup_args = array()) |
|
62 | - { |
|
63 | - //required fields MUST be present, so let's make sure they are. |
|
64 | - if (! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
65 | - throw new EE_Error( |
|
66 | - __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
67 | - 'event_espresso') |
|
68 | - ); |
|
69 | - } |
|
70 | - //make sure we don't register twice |
|
71 | - if (isset(self::$_registry[$cap_reference])) { |
|
72 | - return; |
|
73 | - } |
|
74 | - //make sure this is not registered too late or too early. |
|
75 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
76 | - EE_Error::doing_it_wrong(__METHOD__, |
|
77 | - sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
78 | - 'event_espresso'), $cap_reference), '4.5.0'); |
|
79 | - } |
|
80 | - //some preliminary sanitization and setting to the $_registry property |
|
81 | - self::$_registry[$cap_reference] = array( |
|
82 | - 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) ? $setup_args['capabilities'] : array(), |
|
83 | - 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array(), |
|
84 | - ); |
|
85 | - //set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
86 | - add_filter('FHEE__EE_Capabilities__init_caps_map__caps', |
|
87 | - array('EE_Register_Capabilities', 'register_capabilities'), 10); |
|
88 | - //add filter for cap maps |
|
89 | - add_filter('FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
90 | - array('EE_Register_Capabilities', 'register_cap_maps'), 10); |
|
91 | - //init_role_caps to register new capabilities |
|
92 | - if (is_admin()) { |
|
93 | - EE_Registry::instance()->load_core('Capabilities'); |
|
94 | - EE_Capabilities::instance()->init_caps(); |
|
95 | - } |
|
96 | - } |
|
32 | + /** |
|
33 | + * Used to register capability items with EE core. |
|
34 | + * |
|
35 | + * @since 4.5.0 |
|
36 | + * @param string $cap_reference usually will be a class name |
|
37 | + * that references capability |
|
38 | + * related items setup for |
|
39 | + * something. |
|
40 | + * @param array $setup_args { |
|
41 | + * An array of items related to |
|
42 | + * registering capabilities. |
|
43 | + * @type array $capabilities An array mapping capability |
|
44 | + * strings to core WP Role. Something like: array( |
|
45 | + * 'administrator' => array( |
|
46 | + * 'read_cap', 'edit_cap', |
|
47 | + * 'delete_cap'), |
|
48 | + * 'author' => |
|
49 | + * array( 'read_cap' ) |
|
50 | + * ). |
|
51 | + * @type array $capability_maps EE_Meta_Capability_Map[] |
|
52 | + * @see EE_Capabilities.php for php docs on these objects. |
|
53 | + * Should be indexed by the |
|
54 | + * classname for the capability |
|
55 | + * map and values representing |
|
56 | + * the arguments for the map. |
|
57 | + * } |
|
58 | + * @throws EE_Error |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + public static function register($cap_reference = null, $setup_args = array()) |
|
62 | + { |
|
63 | + //required fields MUST be present, so let's make sure they are. |
|
64 | + if (! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
65 | + throw new EE_Error( |
|
66 | + __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
67 | + 'event_espresso') |
|
68 | + ); |
|
69 | + } |
|
70 | + //make sure we don't register twice |
|
71 | + if (isset(self::$_registry[$cap_reference])) { |
|
72 | + return; |
|
73 | + } |
|
74 | + //make sure this is not registered too late or too early. |
|
75 | + if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
76 | + EE_Error::doing_it_wrong(__METHOD__, |
|
77 | + sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
78 | + 'event_espresso'), $cap_reference), '4.5.0'); |
|
79 | + } |
|
80 | + //some preliminary sanitization and setting to the $_registry property |
|
81 | + self::$_registry[$cap_reference] = array( |
|
82 | + 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) ? $setup_args['capabilities'] : array(), |
|
83 | + 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array(), |
|
84 | + ); |
|
85 | + //set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
86 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', |
|
87 | + array('EE_Register_Capabilities', 'register_capabilities'), 10); |
|
88 | + //add filter for cap maps |
|
89 | + add_filter('FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
90 | + array('EE_Register_Capabilities', 'register_cap_maps'), 10); |
|
91 | + //init_role_caps to register new capabilities |
|
92 | + if (is_admin()) { |
|
93 | + EE_Registry::instance()->load_core('Capabilities'); |
|
94 | + EE_Capabilities::instance()->init_caps(); |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
101 | - * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
102 | - * registration ensures that new capabilities are added to existing roles. |
|
103 | - * |
|
104 | - * @param array $incoming_caps The original caps map. |
|
105 | - * @return array merged in new caps. |
|
106 | - */ |
|
107 | - public static function register_capabilities($incoming_caps) |
|
108 | - { |
|
109 | - foreach (self::$_registry as $ref => $caps_and_cap_map) { |
|
110 | - $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
111 | - } |
|
112 | - return $incoming_caps; |
|
113 | - } |
|
99 | + /** |
|
100 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
101 | + * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
102 | + * registration ensures that new capabilities are added to existing roles. |
|
103 | + * |
|
104 | + * @param array $incoming_caps The original caps map. |
|
105 | + * @return array merged in new caps. |
|
106 | + */ |
|
107 | + public static function register_capabilities($incoming_caps) |
|
108 | + { |
|
109 | + foreach (self::$_registry as $ref => $caps_and_cap_map) { |
|
110 | + $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
111 | + } |
|
112 | + return $incoming_caps; |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
118 | - * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
119 | - * |
|
120 | - * @since 4.5.0 |
|
121 | - * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
122 | - * @return EE_Meta_Capability_Map[] |
|
123 | - * @throws EE_Error |
|
124 | - */ |
|
125 | - public static function register_cap_maps($cap_maps) |
|
126 | - { |
|
127 | - //loop through and instantiate cap maps. |
|
128 | - foreach (self::$_registry as $cap_reference => $setup) { |
|
129 | - if (! isset($setup['cap_maps'])) { |
|
130 | - continue; |
|
131 | - } |
|
132 | - foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
116 | + /** |
|
117 | + * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
118 | + * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
119 | + * |
|
120 | + * @since 4.5.0 |
|
121 | + * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
122 | + * @return EE_Meta_Capability_Map[] |
|
123 | + * @throws EE_Error |
|
124 | + */ |
|
125 | + public static function register_cap_maps($cap_maps) |
|
126 | + { |
|
127 | + //loop through and instantiate cap maps. |
|
128 | + foreach (self::$_registry as $cap_reference => $setup) { |
|
129 | + if (! isset($setup['cap_maps'])) { |
|
130 | + continue; |
|
131 | + } |
|
132 | + foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
133 | 133 | |
134 | - /** |
|
135 | - * account for cases where capability maps may be indexed |
|
136 | - * numerically to allow for the same map class to be utilized |
|
137 | - * In those cases, maps will be setup in an array like: |
|
138 | - * array( |
|
139 | - * 0 => array( 'EE_Meta_Capability' => array( |
|
140 | - * 'ee_edit_cap', array( 'Object_Name', |
|
141 | - * 'ee_edit_published_cap', |
|
142 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
143 | - * ) ) |
|
144 | - * 1 => ... |
|
145 | - * ) |
|
146 | - * instead of: |
|
147 | - * array( |
|
148 | - * 'EE_Meta_Capability' => array( |
|
149 | - * 'ee_edit_cap', array( 'Object_Name', |
|
150 | - * 'ee_edit_published_cap', |
|
151 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
152 | - * ), |
|
153 | - * ... |
|
154 | - * ) |
|
155 | - */ |
|
156 | - if (is_numeric($cap_class)) { |
|
157 | - $cap_class = key($args); |
|
158 | - $args = $args[$cap_class]; |
|
159 | - } |
|
134 | + /** |
|
135 | + * account for cases where capability maps may be indexed |
|
136 | + * numerically to allow for the same map class to be utilized |
|
137 | + * In those cases, maps will be setup in an array like: |
|
138 | + * array( |
|
139 | + * 0 => array( 'EE_Meta_Capability' => array( |
|
140 | + * 'ee_edit_cap', array( 'Object_Name', |
|
141 | + * 'ee_edit_published_cap', |
|
142 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
143 | + * ) ) |
|
144 | + * 1 => ... |
|
145 | + * ) |
|
146 | + * instead of: |
|
147 | + * array( |
|
148 | + * 'EE_Meta_Capability' => array( |
|
149 | + * 'ee_edit_cap', array( 'Object_Name', |
|
150 | + * 'ee_edit_published_cap', |
|
151 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
152 | + * ), |
|
153 | + * ... |
|
154 | + * ) |
|
155 | + */ |
|
156 | + if (is_numeric($cap_class)) { |
|
157 | + $cap_class = key($args); |
|
158 | + $args = $args[$cap_class]; |
|
159 | + } |
|
160 | 160 | |
161 | - if (! class_exists($cap_class)) { |
|
162 | - throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
163 | - 'event_espresso'), $cap_reference)); |
|
164 | - } |
|
161 | + if (! class_exists($cap_class)) { |
|
162 | + throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
163 | + 'event_espresso'), $cap_reference)); |
|
164 | + } |
|
165 | 165 | |
166 | - if (count($args) !== 2) { |
|
167 | - throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
168 | - 'event_espresso'), $cap_reference)); |
|
169 | - } |
|
170 | - $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
171 | - } |
|
172 | - } |
|
173 | - return $cap_maps; |
|
174 | - } |
|
166 | + if (count($args) !== 2) { |
|
167 | + throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
168 | + 'event_espresso'), $cap_reference)); |
|
169 | + } |
|
170 | + $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
171 | + } |
|
172 | + } |
|
173 | + return $cap_maps; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | - public static function deregister($cap_reference = null) |
|
178 | - { |
|
179 | - if (! empty(self::$_registry[$cap_reference])) { |
|
180 | - unset(self::$_registry[$cap_reference]); |
|
181 | - } |
|
177 | + public static function deregister($cap_reference = null) |
|
178 | + { |
|
179 | + if (! empty(self::$_registry[$cap_reference])) { |
|
180 | + unset(self::$_registry[$cap_reference]); |
|
181 | + } |
|
182 | 182 | |
183 | - //re init caps to grab the changes due to removed caps. |
|
184 | - EE_Capabilities::instance()->init_caps(); |
|
185 | - } |
|
183 | + //re init caps to grab the changes due to removed caps. |
|
184 | + EE_Capabilities::instance()->init_caps(); |
|
185 | + } |
|
186 | 186 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @subpackage plugin api, capabilities |
7 | 7 | * @since 4.5.0 |
8 | 8 | */ |
9 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | 10 | exit('No direct script access allowed'); |
11 | 11 | } |
12 | 12 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | public static function register($cap_reference = null, $setup_args = array()) |
62 | 62 | { |
63 | 63 | //required fields MUST be present, so let's make sure they are. |
64 | - if (! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
64 | + if ( ! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
65 | 65 | throw new EE_Error( |
66 | 66 | __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
67 | 67 | 'event_espresso') |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | return; |
73 | 73 | } |
74 | 74 | //make sure this is not registered too late or too early. |
75 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
75 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
76 | 76 | EE_Error::doing_it_wrong(__METHOD__, |
77 | 77 | sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
78 | 78 | 'event_espresso'), $cap_reference), '4.5.0'); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | //loop through and instantiate cap maps. |
128 | 128 | foreach (self::$_registry as $cap_reference => $setup) { |
129 | - if (! isset($setup['cap_maps'])) { |
|
129 | + if ( ! isset($setup['cap_maps'])) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | 132 | foreach ($setup['cap_maps'] as $cap_class => $args) { |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $args = $args[$cap_class]; |
159 | 159 | } |
160 | 160 | |
161 | - if (! class_exists($cap_class)) { |
|
161 | + if ( ! class_exists($cap_class)) { |
|
162 | 162 | throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
163 | 163 | 'event_espresso'), $cap_reference)); |
164 | 164 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | public static function deregister($cap_reference = null) |
178 | 178 | { |
179 | - if (! empty(self::$_registry[$cap_reference])) { |
|
179 | + if ( ! empty(self::$_registry[$cap_reference])) { |
|
180 | 180 | unset(self::$_registry[$cap_reference]); |
181 | 181 | } |
182 | 182 |