@@ -13,354 +13,354 @@ |
||
| 13 | 13 | { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @return Messages_Admin_Page |
|
| 18 | - */ |
|
| 19 | - public function get_admin_page() |
|
| 20 | - { |
|
| 21 | - return $this->_admin_page; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Setup data object |
|
| 27 | - */ |
|
| 28 | - protected function _setup_data() |
|
| 29 | - { |
|
| 30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 31 | - $this->_per_page, |
|
| 32 | - $this->_view, |
|
| 33 | - false |
|
| 34 | - ); |
|
| 35 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
| 36 | - $this->_per_page, |
|
| 37 | - $this->_view, |
|
| 38 | - true, |
|
| 39 | - true |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Set internal properties |
|
| 46 | - */ |
|
| 47 | - protected function _set_properties() |
|
| 48 | - { |
|
| 49 | - $this->_wp_list_args = array( |
|
| 50 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
| 51 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
| 52 | - 'ajax' => true, // for now, |
|
| 53 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
| 54 | - ); |
|
| 55 | - $this->_columns = array( |
|
| 56 | - // 'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
| 57 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
| 58 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
| 59 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
| 60 | - ); |
|
| 61 | - |
|
| 62 | - $this->_sortable_columns = array( |
|
| 63 | - 'messenger' => array('MTP_messenger' => true), |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - $this->_hidden_columns = array(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
| 72 | - * message_type or messenger object before generating the row. |
|
| 73 | - * |
|
| 74 | - * @param EE_Message_Template_Group $item |
|
| 75 | - * @return string |
|
| 76 | - * @throws EE_Error |
|
| 77 | - */ |
|
| 78 | - public function single_row($item) |
|
| 79 | - { |
|
| 80 | - $message_type = $item->message_type_obj(); |
|
| 81 | - $messenger = $item->messenger_obj(); |
|
| 82 | - |
|
| 83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 84 | - echo ''; |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - parent::single_row($item); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return array |
|
| 94 | - * @throws EE_Error |
|
| 95 | - */ |
|
| 96 | - protected function _get_table_filters() |
|
| 97 | - { |
|
| 98 | - $filters = array(); |
|
| 99 | - |
|
| 100 | - // get select inputs |
|
| 101 | - $select_inputs = array( |
|
| 102 | - $this->_get_messengers_dropdown_filter(), |
|
| 103 | - $this->_get_message_types_dropdown_filter(), |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - // set filters to select inputs if they aren't empty |
|
| 107 | - foreach ($select_inputs as $select_input) { |
|
| 108 | - if ($select_input) { |
|
| 109 | - $filters[] = $select_input; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - return $filters; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * We're just removing the search box for message templates, not needed. |
|
| 117 | - * |
|
| 118 | - * @param string $text |
|
| 119 | - * @param string $input_id |
|
| 120 | - * @return string ; |
|
| 121 | - */ |
|
| 122 | - public function search_box($text, $input_id) |
|
| 123 | - { |
|
| 124 | - return ''; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Add counts to the _views property |
|
| 130 | - */ |
|
| 131 | - protected function _add_view_counts() |
|
| 132 | - { |
|
| 133 | - foreach ($this->_views as $view => $args) { |
|
| 134 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 135 | - $this->_per_page, |
|
| 136 | - $view, |
|
| 137 | - true, |
|
| 138 | - true |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param EE_Message_Template_Group $item |
|
| 146 | - * @return string |
|
| 147 | - */ |
|
| 148 | - public function column_cb($item) |
|
| 149 | - { |
|
| 150 | - return ''; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @param EE_Message_Template_Group $item |
|
| 156 | - * @return string |
|
| 157 | - * @throws EE_Error |
|
| 158 | - */ |
|
| 159 | - public function column_description($item) |
|
| 160 | - { |
|
| 161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param EE_Message_Template_Group $item |
|
| 167 | - * @return string |
|
| 168 | - * @throws EE_Error |
|
| 169 | - */ |
|
| 170 | - public function column_messenger($item) |
|
| 171 | - { |
|
| 172 | - // Return the name contents |
|
| 173 | - return sprintf( |
|
| 174 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
| 175 | - /* $1%s */ |
|
| 176 | - ucwords($item->messenger_obj()->label['singular']), |
|
| 177 | - /* $2%s */ |
|
| 178 | - $item->GRP_ID(), |
|
| 179 | - /* %4$s */ |
|
| 180 | - $this->_get_context_links($item), |
|
| 181 | - $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * column_message_type |
|
| 187 | - * |
|
| 188 | - * @param EE_Message_Template_Group $item message info for the row |
|
| 189 | - * @return string message_type name |
|
| 190 | - * @throws EE_Error |
|
| 191 | - */ |
|
| 192 | - public function column_message_type($item) |
|
| 193 | - { |
|
| 194 | - return ucwords($item->message_type_obj()->label['singular']); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Generate dropdown filter select input for messengers |
|
| 200 | - * |
|
| 201 | - * @param bool $global |
|
| 202 | - * @return string |
|
| 203 | - * @throws EE_Error |
|
| 204 | - */ |
|
| 205 | - protected function _get_messengers_dropdown_filter($global = true) |
|
| 206 | - { |
|
| 207 | - $messenger_options = array(); |
|
| 208 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
| 209 | - array( |
|
| 210 | - array( |
|
| 211 | - 'MTP_is_active' => true, |
|
| 212 | - 'MTP_is_global' => $global, |
|
| 213 | - ), |
|
| 214 | - 'group_by' => 'MTP_messenger', |
|
| 215 | - ) |
|
| 216 | - ); |
|
| 217 | - |
|
| 218 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
| 219 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 220 | - $messenger = $active_message_template_group->messenger_obj(); |
|
| 221 | - $messenger_label = $messenger instanceof EE_messenger |
|
| 222 | - ? $messenger->label['singular'] |
|
| 223 | - : $active_message_template_group->messenger(); |
|
| 224 | - $messenger_options[ $active_message_template_group->messenger() ] = ucwords($messenger_label); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Generate dropdown filter select input for message types |
|
| 233 | - * |
|
| 234 | - * @param bool $global |
|
| 235 | - * @return string |
|
| 236 | - * @throws EE_Error |
|
| 237 | - */ |
|
| 238 | - protected function _get_message_types_dropdown_filter($global = true) |
|
| 239 | - { |
|
| 240 | - $message_type_options = array(); |
|
| 241 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
| 242 | - array( |
|
| 243 | - array( |
|
| 244 | - 'MTP_is_active' => true, |
|
| 245 | - 'MTP_is_global' => true, |
|
| 246 | - ), |
|
| 247 | - 'group_by' => 'MTP_message_type', |
|
| 248 | - ) |
|
| 249 | - ); |
|
| 250 | - |
|
| 251 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
| 252 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 253 | - $message_type = $active_message_template_group->message_type_obj(); |
|
| 254 | - $message_type_label = $message_type instanceof EE_message_type |
|
| 255 | - ? $message_type->label['singular'] |
|
| 256 | - : $active_message_template_group->message_type(); |
|
| 257 | - $message_type_options[ $active_message_template_group->message_type() ] = ucwords($message_type_label); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Return the edit url for the message template group. |
|
| 266 | - * |
|
| 267 | - * @param EE_Message_Template_Group $item |
|
| 268 | - * @return string |
|
| 269 | - * @throws EE_Error |
|
| 270 | - */ |
|
| 271 | - protected function _get_edit_url(EE_Message_Template_Group $item) |
|
| 272 | - { |
|
| 273 | - $edit_url = ''; |
|
| 274 | - // edit link but only if item isn't trashed. |
|
| 275 | - if (! $item->get('MTP_deleted') |
|
| 276 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 277 | - 'ee_edit_message', |
|
| 278 | - 'espresso_messages_edit_message_template', |
|
| 279 | - $item->ID() |
|
| 280 | - )) { |
|
| 281 | - $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 282 | - array( |
|
| 283 | - 'action' => 'edit_message_template', |
|
| 284 | - 'id' => $item->GRP_ID(), |
|
| 285 | - ), |
|
| 286 | - EE_MSG_ADMIN_URL |
|
| 287 | - ); |
|
| 288 | - } |
|
| 289 | - return $edit_url; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Get the context link string for the messenger column. |
|
| 295 | - * |
|
| 296 | - * @param EE_Message_Template_Group $item |
|
| 297 | - * @return string |
|
| 298 | - * @throws EE_Error |
|
| 299 | - */ |
|
| 300 | - protected function _get_context_links(EE_Message_Template_Group $item) |
|
| 301 | - { |
|
| 302 | - // first check if we even show the context links or not. |
|
| 303 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 304 | - 'ee_edit_message', |
|
| 305 | - 'espresso_messages_edit_message_template', |
|
| 306 | - $item->ID() |
|
| 307 | - ) |
|
| 308 | - || $item->get('MTP_deleted') |
|
| 309 | - ) { |
|
| 310 | - return ''; |
|
| 311 | - } |
|
| 312 | - // we want to display the contexts in here so we need to set them up |
|
| 313 | - $c_label = $item->context_label(); |
|
| 314 | - $c_configs = $item->contexts_config(); |
|
| 315 | - $ctxt = array(); |
|
| 316 | - $context_templates = $item->context_templates(); |
|
| 317 | - foreach ($context_templates as $context => $template_fields) { |
|
| 318 | - $mtp_to = ! empty($context_templates[ $context ]['to']) |
|
| 319 | - && $context_templates[ $context ]['to'] instanceof EE_Message_Template |
|
| 320 | - ? $context_templates[ $context ]['to']->get('MTP_content') |
|
| 321 | - : null; |
|
| 322 | - $inactive_class = ( |
|
| 323 | - empty($mtp_to) |
|
| 324 | - && ! empty($context_templates[ $context ]['to']) |
|
| 325 | - ) |
|
| 326 | - || ! $item->is_context_active($context) |
|
| 327 | - ? ' mtp-inactive' |
|
| 328 | - : ''; |
|
| 329 | - $context_title = sprintf( |
|
| 330 | - /* translators: Placeholder represents the context label. Example "Edit Event Admin" */ |
|
| 331 | - esc_html__('Edit %1$s', 'event_espresso'), |
|
| 332 | - ucwords($c_configs[ $context ]['label']) |
|
| 333 | - ); |
|
| 334 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 335 | - array( |
|
| 336 | - 'action' => 'edit_message_template', |
|
| 337 | - 'id' => $item->GRP_ID(), |
|
| 338 | - 'context' => $context, |
|
| 339 | - ), |
|
| 340 | - EE_MSG_ADMIN_URL |
|
| 341 | - ); |
|
| 342 | - $ctxt[] = '<a' |
|
| 343 | - . ' href="' . $edit_link . '"' |
|
| 344 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' . $inactive_class . '"' |
|
| 345 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
| 346 | - . $context_title |
|
| 347 | - . '</a>'; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Returns the actions for the messenger column. |
|
| 356 | - * |
|
| 357 | - * Note: Children classes may override this so do not remove it. |
|
| 358 | - * |
|
| 359 | - * @param EE_Message_Template_Group $item |
|
| 360 | - * @return array |
|
| 361 | - */ |
|
| 362 | - protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
| 363 | - { |
|
| 364 | - return []; |
|
| 365 | - } |
|
| 16 | + /** |
|
| 17 | + * @return Messages_Admin_Page |
|
| 18 | + */ |
|
| 19 | + public function get_admin_page() |
|
| 20 | + { |
|
| 21 | + return $this->_admin_page; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Setup data object |
|
| 27 | + */ |
|
| 28 | + protected function _setup_data() |
|
| 29 | + { |
|
| 30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 31 | + $this->_per_page, |
|
| 32 | + $this->_view, |
|
| 33 | + false |
|
| 34 | + ); |
|
| 35 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
| 36 | + $this->_per_page, |
|
| 37 | + $this->_view, |
|
| 38 | + true, |
|
| 39 | + true |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Set internal properties |
|
| 46 | + */ |
|
| 47 | + protected function _set_properties() |
|
| 48 | + { |
|
| 49 | + $this->_wp_list_args = array( |
|
| 50 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
| 51 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
| 52 | + 'ajax' => true, // for now, |
|
| 53 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
| 54 | + ); |
|
| 55 | + $this->_columns = array( |
|
| 56 | + // 'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
| 57 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
| 58 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
| 59 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
| 60 | + ); |
|
| 61 | + |
|
| 62 | + $this->_sortable_columns = array( |
|
| 63 | + 'messenger' => array('MTP_messenger' => true), |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + $this->_hidden_columns = array(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
| 72 | + * message_type or messenger object before generating the row. |
|
| 73 | + * |
|
| 74 | + * @param EE_Message_Template_Group $item |
|
| 75 | + * @return string |
|
| 76 | + * @throws EE_Error |
|
| 77 | + */ |
|
| 78 | + public function single_row($item) |
|
| 79 | + { |
|
| 80 | + $message_type = $item->message_type_obj(); |
|
| 81 | + $messenger = $item->messenger_obj(); |
|
| 82 | + |
|
| 83 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 84 | + echo ''; |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + parent::single_row($item); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return array |
|
| 94 | + * @throws EE_Error |
|
| 95 | + */ |
|
| 96 | + protected function _get_table_filters() |
|
| 97 | + { |
|
| 98 | + $filters = array(); |
|
| 99 | + |
|
| 100 | + // get select inputs |
|
| 101 | + $select_inputs = array( |
|
| 102 | + $this->_get_messengers_dropdown_filter(), |
|
| 103 | + $this->_get_message_types_dropdown_filter(), |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + // set filters to select inputs if they aren't empty |
|
| 107 | + foreach ($select_inputs as $select_input) { |
|
| 108 | + if ($select_input) { |
|
| 109 | + $filters[] = $select_input; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + return $filters; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * We're just removing the search box for message templates, not needed. |
|
| 117 | + * |
|
| 118 | + * @param string $text |
|
| 119 | + * @param string $input_id |
|
| 120 | + * @return string ; |
|
| 121 | + */ |
|
| 122 | + public function search_box($text, $input_id) |
|
| 123 | + { |
|
| 124 | + return ''; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Add counts to the _views property |
|
| 130 | + */ |
|
| 131 | + protected function _add_view_counts() |
|
| 132 | + { |
|
| 133 | + foreach ($this->_views as $view => $args) { |
|
| 134 | + $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 135 | + $this->_per_page, |
|
| 136 | + $view, |
|
| 137 | + true, |
|
| 138 | + true |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param EE_Message_Template_Group $item |
|
| 146 | + * @return string |
|
| 147 | + */ |
|
| 148 | + public function column_cb($item) |
|
| 149 | + { |
|
| 150 | + return ''; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @param EE_Message_Template_Group $item |
|
| 156 | + * @return string |
|
| 157 | + * @throws EE_Error |
|
| 158 | + */ |
|
| 159 | + public function column_description($item) |
|
| 160 | + { |
|
| 161 | + return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param EE_Message_Template_Group $item |
|
| 167 | + * @return string |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function column_messenger($item) |
|
| 171 | + { |
|
| 172 | + // Return the name contents |
|
| 173 | + return sprintf( |
|
| 174 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
| 175 | + /* $1%s */ |
|
| 176 | + ucwords($item->messenger_obj()->label['singular']), |
|
| 177 | + /* $2%s */ |
|
| 178 | + $item->GRP_ID(), |
|
| 179 | + /* %4$s */ |
|
| 180 | + $this->_get_context_links($item), |
|
| 181 | + $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * column_message_type |
|
| 187 | + * |
|
| 188 | + * @param EE_Message_Template_Group $item message info for the row |
|
| 189 | + * @return string message_type name |
|
| 190 | + * @throws EE_Error |
|
| 191 | + */ |
|
| 192 | + public function column_message_type($item) |
|
| 193 | + { |
|
| 194 | + return ucwords($item->message_type_obj()->label['singular']); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Generate dropdown filter select input for messengers |
|
| 200 | + * |
|
| 201 | + * @param bool $global |
|
| 202 | + * @return string |
|
| 203 | + * @throws EE_Error |
|
| 204 | + */ |
|
| 205 | + protected function _get_messengers_dropdown_filter($global = true) |
|
| 206 | + { |
|
| 207 | + $messenger_options = array(); |
|
| 208 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
| 209 | + array( |
|
| 210 | + array( |
|
| 211 | + 'MTP_is_active' => true, |
|
| 212 | + 'MTP_is_global' => $global, |
|
| 213 | + ), |
|
| 214 | + 'group_by' => 'MTP_messenger', |
|
| 215 | + ) |
|
| 216 | + ); |
|
| 217 | + |
|
| 218 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
| 219 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 220 | + $messenger = $active_message_template_group->messenger_obj(); |
|
| 221 | + $messenger_label = $messenger instanceof EE_messenger |
|
| 222 | + ? $messenger->label['singular'] |
|
| 223 | + : $active_message_template_group->messenger(); |
|
| 224 | + $messenger_options[ $active_message_template_group->messenger() ] = ucwords($messenger_label); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Generate dropdown filter select input for message types |
|
| 233 | + * |
|
| 234 | + * @param bool $global |
|
| 235 | + * @return string |
|
| 236 | + * @throws EE_Error |
|
| 237 | + */ |
|
| 238 | + protected function _get_message_types_dropdown_filter($global = true) |
|
| 239 | + { |
|
| 240 | + $message_type_options = array(); |
|
| 241 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
| 242 | + array( |
|
| 243 | + array( |
|
| 244 | + 'MTP_is_active' => true, |
|
| 245 | + 'MTP_is_global' => true, |
|
| 246 | + ), |
|
| 247 | + 'group_by' => 'MTP_message_type', |
|
| 248 | + ) |
|
| 249 | + ); |
|
| 250 | + |
|
| 251 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
| 252 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 253 | + $message_type = $active_message_template_group->message_type_obj(); |
|
| 254 | + $message_type_label = $message_type instanceof EE_message_type |
|
| 255 | + ? $message_type->label['singular'] |
|
| 256 | + : $active_message_template_group->message_type(); |
|
| 257 | + $message_type_options[ $active_message_template_group->message_type() ] = ucwords($message_type_label); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Return the edit url for the message template group. |
|
| 266 | + * |
|
| 267 | + * @param EE_Message_Template_Group $item |
|
| 268 | + * @return string |
|
| 269 | + * @throws EE_Error |
|
| 270 | + */ |
|
| 271 | + protected function _get_edit_url(EE_Message_Template_Group $item) |
|
| 272 | + { |
|
| 273 | + $edit_url = ''; |
|
| 274 | + // edit link but only if item isn't trashed. |
|
| 275 | + if (! $item->get('MTP_deleted') |
|
| 276 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 277 | + 'ee_edit_message', |
|
| 278 | + 'espresso_messages_edit_message_template', |
|
| 279 | + $item->ID() |
|
| 280 | + )) { |
|
| 281 | + $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 282 | + array( |
|
| 283 | + 'action' => 'edit_message_template', |
|
| 284 | + 'id' => $item->GRP_ID(), |
|
| 285 | + ), |
|
| 286 | + EE_MSG_ADMIN_URL |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | + return $edit_url; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Get the context link string for the messenger column. |
|
| 295 | + * |
|
| 296 | + * @param EE_Message_Template_Group $item |
|
| 297 | + * @return string |
|
| 298 | + * @throws EE_Error |
|
| 299 | + */ |
|
| 300 | + protected function _get_context_links(EE_Message_Template_Group $item) |
|
| 301 | + { |
|
| 302 | + // first check if we even show the context links or not. |
|
| 303 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 304 | + 'ee_edit_message', |
|
| 305 | + 'espresso_messages_edit_message_template', |
|
| 306 | + $item->ID() |
|
| 307 | + ) |
|
| 308 | + || $item->get('MTP_deleted') |
|
| 309 | + ) { |
|
| 310 | + return ''; |
|
| 311 | + } |
|
| 312 | + // we want to display the contexts in here so we need to set them up |
|
| 313 | + $c_label = $item->context_label(); |
|
| 314 | + $c_configs = $item->contexts_config(); |
|
| 315 | + $ctxt = array(); |
|
| 316 | + $context_templates = $item->context_templates(); |
|
| 317 | + foreach ($context_templates as $context => $template_fields) { |
|
| 318 | + $mtp_to = ! empty($context_templates[ $context ]['to']) |
|
| 319 | + && $context_templates[ $context ]['to'] instanceof EE_Message_Template |
|
| 320 | + ? $context_templates[ $context ]['to']->get('MTP_content') |
|
| 321 | + : null; |
|
| 322 | + $inactive_class = ( |
|
| 323 | + empty($mtp_to) |
|
| 324 | + && ! empty($context_templates[ $context ]['to']) |
|
| 325 | + ) |
|
| 326 | + || ! $item->is_context_active($context) |
|
| 327 | + ? ' mtp-inactive' |
|
| 328 | + : ''; |
|
| 329 | + $context_title = sprintf( |
|
| 330 | + /* translators: Placeholder represents the context label. Example "Edit Event Admin" */ |
|
| 331 | + esc_html__('Edit %1$s', 'event_espresso'), |
|
| 332 | + ucwords($c_configs[ $context ]['label']) |
|
| 333 | + ); |
|
| 334 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 335 | + array( |
|
| 336 | + 'action' => 'edit_message_template', |
|
| 337 | + 'id' => $item->GRP_ID(), |
|
| 338 | + 'context' => $context, |
|
| 339 | + ), |
|
| 340 | + EE_MSG_ADMIN_URL |
|
| 341 | + ); |
|
| 342 | + $ctxt[] = '<a' |
|
| 343 | + . ' href="' . $edit_link . '"' |
|
| 344 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link' . $inactive_class . '"' |
|
| 345 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
| 346 | + . $context_title |
|
| 347 | + . '</a>'; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Returns the actions for the messenger column. |
|
| 356 | + * |
|
| 357 | + * Note: Children classes may override this so do not remove it. |
|
| 358 | + * |
|
| 359 | + * @param EE_Message_Template_Group $item |
|
| 360 | + * @return array |
|
| 361 | + */ |
|
| 362 | + protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
| 363 | + { |
|
| 364 | + return []; |
|
| 365 | + } |
|
| 366 | 366 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $message_type = $item->message_type_obj(); |
| 81 | 81 | $messenger = $item->messenger_obj(); |
| 82 | 82 | |
| 83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 83 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 84 | 84 | echo ''; |
| 85 | 85 | return; |
| 86 | 86 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | protected function _add_view_counts() |
| 132 | 132 | { |
| 133 | 133 | foreach ($this->_views as $view => $args) { |
| 134 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 134 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 135 | 135 | $this->_per_page, |
| 136 | 136 | $view, |
| 137 | 137 | true, |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | public function column_description($item) |
| 160 | 160 | { |
| 161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 161 | + return '<p>'.$item->message_type_obj()->description.'</p>'; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $messenger_label = $messenger instanceof EE_messenger |
| 222 | 222 | ? $messenger->label['singular'] |
| 223 | 223 | : $active_message_template_group->messenger(); |
| 224 | - $messenger_options[ $active_message_template_group->messenger() ] = ucwords($messenger_label); |
|
| 224 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | $message_type_label = $message_type instanceof EE_message_type |
| 255 | 255 | ? $message_type->label['singular'] |
| 256 | 256 | : $active_message_template_group->message_type(); |
| 257 | - $message_type_options[ $active_message_template_group->message_type() ] = ucwords($message_type_label); |
|
| 257 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | { |
| 273 | 273 | $edit_url = ''; |
| 274 | 274 | // edit link but only if item isn't trashed. |
| 275 | - if (! $item->get('MTP_deleted') |
|
| 275 | + if ( ! $item->get('MTP_deleted') |
|
| 276 | 276 | && EE_Registry::instance()->CAP->current_user_can( |
| 277 | 277 | 'ee_edit_message', |
| 278 | 278 | 'espresso_messages_edit_message_template', |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | protected function _get_context_links(EE_Message_Template_Group $item) |
| 301 | 301 | { |
| 302 | 302 | // first check if we even show the context links or not. |
| 303 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 303 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 304 | 304 | 'ee_edit_message', |
| 305 | 305 | 'espresso_messages_edit_message_template', |
| 306 | 306 | $item->ID() |
@@ -315,13 +315,13 @@ discard block |
||
| 315 | 315 | $ctxt = array(); |
| 316 | 316 | $context_templates = $item->context_templates(); |
| 317 | 317 | foreach ($context_templates as $context => $template_fields) { |
| 318 | - $mtp_to = ! empty($context_templates[ $context ]['to']) |
|
| 319 | - && $context_templates[ $context ]['to'] instanceof EE_Message_Template |
|
| 320 | - ? $context_templates[ $context ]['to']->get('MTP_content') |
|
| 318 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
| 319 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
| 320 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
| 321 | 321 | : null; |
| 322 | 322 | $inactive_class = ( |
| 323 | 323 | empty($mtp_to) |
| 324 | - && ! empty($context_templates[ $context ]['to']) |
|
| 324 | + && ! empty($context_templates[$context]['to']) |
|
| 325 | 325 | ) |
| 326 | 326 | || ! $item->is_context_active($context) |
| 327 | 327 | ? ' mtp-inactive' |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | $context_title = sprintf( |
| 330 | 330 | /* translators: Placeholder represents the context label. Example "Edit Event Admin" */ |
| 331 | 331 | esc_html__('Edit %1$s', 'event_espresso'), |
| 332 | - ucwords($c_configs[ $context ]['label']) |
|
| 332 | + ucwords($c_configs[$context]['label']) |
|
| 333 | 333 | ); |
| 334 | 334 | $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
| 335 | 335 | array( |
@@ -340,14 +340,14 @@ discard block |
||
| 340 | 340 | EE_MSG_ADMIN_URL |
| 341 | 341 | ); |
| 342 | 342 | $ctxt[] = '<a' |
| 343 | - . ' href="' . $edit_link . '"' |
|
| 344 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' . $inactive_class . '"' |
|
| 345 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
| 343 | + . ' href="'.$edit_link.'"' |
|
| 344 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link'.$inactive_class.'"' |
|
| 345 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
| 346 | 346 | . $context_title |
| 347 | 347 | . '</a>'; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
| 350 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])).implode(' | ', $ctxt); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | |