1 | <?php |
||
16 | abstract class EE_Messages_Base extends EE_Base { |
||
17 | |||
18 | /** DETAILS PROPERTIES **/ |
||
19 | /** |
||
20 | * The following are used to hold details on the type for reference (i.e. on admin screens) |
||
21 | * and also used by the EE_message_type object to figure out where to get template data. |
||
22 | */ |
||
23 | public $name; |
||
24 | public $description; |
||
25 | protected $_messages_item_type; //messenger OR message_type? |
||
26 | |||
27 | |||
28 | /** |
||
29 | * This is an array describing the ui facing labels |
||
30 | * that will be used whenever the messenger is referenced in the ui |
||
31 | * |
||
32 | * array( |
||
33 | * 'singular' => __('something'), |
||
34 | * 'plural' => __('somethings') |
||
35 | * ) |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | public $label; |
||
40 | |||
41 | |||
42 | |||
43 | |||
44 | /** |
||
45 | * This property when set will hold the slugs of all EE admin pages that we will need to retrieve fields for |
||
46 | * (and used to determine which callback method to call from the child class) |
||
47 | * |
||
48 | * structure should be |
||
49 | * array( |
||
50 | * 'page_action' => true |
||
51 | * ) |
||
52 | * |
||
53 | *@var array |
||
54 | */ |
||
55 | public $admin_registered_pages = array(); |
||
56 | |||
57 | |||
58 | |||
59 | |||
60 | |||
61 | |||
62 | |||
63 | |||
64 | /** |
||
65 | * this property holds any specific fields for holding any settings related to a messenger (if any needed) |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $_admin_settings_fields = array(); |
||
69 | |||
70 | |||
71 | |||
72 | |||
73 | |||
74 | /** |
||
75 | * this property will hold any existing settings that may have been set in the admin. |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $_existing_admin_settings = array(); |
||
79 | |||
80 | |||
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * this property will hold an array of valid shortcodes for this message type and messengers. |
||
86 | * #For Message Types: |
||
87 | * This is an array of strings that correspond to defined EE_Shortcode libraries and per context. |
||
88 | * For example: |
||
89 | * array( 'admin' => array('transaction', 'event', 'attendee') ) |
||
90 | * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php' |
||
91 | * for the admin context; |
||
92 | * |
||
93 | * |
||
94 | * #For Messengers: |
||
95 | * For example: |
||
96 | * array('subject' => array('transaction', 'event', 'attendee')) |
||
97 | * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php' |
||
98 | * for the 'subject' field; |
||
99 | * NOTE: by default, with messengers, if the valid shortcodes for a field is left blank, |
||
100 | * that field will inherit whatever are set as valid shortcodes by message_type. |
||
101 | * This is so messenger can set specific valid codes for fields and leave other |
||
102 | * valid shortcodes up to the message type matched with the messenger. |
||
103 | * |
||
104 | * @access protected |
||
105 | * @var array |
||
106 | */ |
||
107 | protected $_valid_shortcodes = array(); |
||
108 | |||
109 | |||
110 | |||
111 | |||
112 | |||
113 | public function __construct() { |
||
114 | $this->_set_admin_settings_fields(); |
||
115 | $this->_set_valid_shortcodes(); |
||
116 | $this->_set_admin_pages(); |
||
117 | } |
||
118 | |||
119 | |||
120 | |||
121 | |||
122 | |||
123 | /** |
||
124 | * sets the _admin_settings_fields property which needs to be defined by child classes. |
||
125 | * You will want to set the _admin_settings_fields properties as a multi-dimensional array with the following format |
||
126 | * array( |
||
127 | * {field_name - also used for setting index} => array( |
||
128 | * 'field_type' => {type of field: 'text', 'textarea', 'checkbox'}, |
||
129 | * 'value_type' => {type of value: 'string', 'int', 'array', 'bool'}, |
||
130 | * 'required' => {bool, required or not}, |
||
131 | * 'validation' => {bool, true if we want validation, false if not}, |
||
132 | * 'format' => {%d, or %s}, |
||
133 | * 'label' => {label for the field, make sure it's localized}, |
||
134 | * 'default' => {default value for the setting} |
||
135 | * ), |
||
136 | * ); |
||
137 | * |
||
138 | * @abstract |
||
139 | * @access protected |
||
140 | * @return void |
||
141 | */ |
||
142 | abstract protected function _set_admin_settings_fields(); |
||
143 | |||
144 | |||
145 | |||
146 | |||
147 | |||
148 | /** |
||
149 | * sets any properties on whether a message type or messenger interface shows up on a ee administration page. |
||
150 | * Child classes have to define this method but don't necessarily have to set the flags |
||
151 | * as they will be set to false by default. |
||
152 | * |
||
153 | * Child classes use this method to set the `_admin_registered_page` property. |
||
154 | * That property is to indicate what EE admin pages we have a corresponding callback for in the child class |
||
155 | * so Message Type/messenger fields/content is included on that admin page. |
||
156 | * |
||
157 | * @abstract |
||
158 | * @access protected |
||
159 | * @return void |
||
160 | */ |
||
161 | abstract protected function _set_admin_pages(); |
||
162 | |||
163 | |||
164 | |||
165 | |||
166 | |||
167 | /** |
||
168 | * Child classes must declare the $_valid_shortcodes property using this method. |
||
169 | * See comments for $_valid_shortcodes property for details on what it is used for. |
||
170 | * |
||
171 | * @access protected |
||
172 | * @return void |
||
173 | */ |
||
174 | abstract protected function _set_valid_shortcodes(); |
||
175 | |||
176 | |||
177 | |||
178 | /** |
||
179 | * sets the _existing_admin_settings property can be overridden by child classes. |
||
180 | * We do this so we only do database calls if needed. |
||
181 | * |
||
182 | * @access protected |
||
183 | * @param string $messenger |
||
184 | */ |
||
185 | protected function _set_existing_admin_settings( $messenger = '' ) { |
||
205 | |||
206 | |||
207 | |||
208 | |||
209 | |||
210 | |||
211 | /** |
||
212 | * get_existing_admin_settings |
||
213 | * (if needed) sets and returns the _existing_admin_settings property. |
||
214 | * |
||
215 | * @access public |
||
216 | * @param string $messenger |
||
217 | * @return array settings |
||
218 | */ |
||
219 | public function get_existing_admin_settings( $messenger = '' ) { |
||
228 | |||
229 | |||
230 | |||
231 | |||
232 | |||
233 | |||
234 | /** |
||
235 | * This returns the array of valid shortcodes for a message type or messenger as set by the child in the $_valid_shortcode property. |
||
236 | * @return array an array of valid shortcodes. |
||
237 | */ |
||
238 | public function get_valid_shortcodes() { |
||
248 | |||
249 | |||
250 | |||
251 | |||
252 | /** |
||
253 | * getter that returns the protected admin_settings_fields property |
||
254 | * |
||
255 | * @access public |
||
256 | * @return array admin settings fields |
||
257 | */ |
||
258 | public function get_admin_settings_fields() { |
||
261 | |||
262 | |||
263 | |||
264 | |||
265 | |||
266 | /** |
||
267 | * this public method accepts a page slug (for an EE_admin page) |
||
268 | * and will return the response from the child class callback function |
||
269 | * if that page is registered via the `_admin_registered_page` property set by the child class. |
||
270 | * |
||
271 | * @param string $page the slug of the EE admin page |
||
272 | * @param array $actives an array of active message type (or messenger) objects. |
||
273 | * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages) |
||
274 | * @param array $extra This is just an extra argument that can be used |
||
275 | * to pass additional data for setting up page content. |
||
276 | * @access protected |
||
277 | * @return string $content for page. |
||
278 | */ |
||
279 | protected function _get_admin_page_content( $page, $action, $extra, $actives ) { |
||
301 | |||
302 | |||
303 | /** |
||
304 | * Allows a message type to specifically exclude template fields for the provided messenger. |
||
305 | * Filtered so this can be programmatically altered as well. |
||
306 | * @param string $messenger_name name of messenger |
||
307 | * @return array |
||
308 | */ |
||
309 | public function excludedFieldsForMessenger($messenger_name) |
||
319 | } |
||
320 |