PluginProbe
UpStream: a Project Management Plugin for WordPress / 2.1.0
UpStream: a Project Management Plugin for WordPress v2.1.0
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / admin / options / class-upstream-options-bugs.php

class-upstream-options-bugs.php in UpStream: a Project Management Plugin for WordPress 2.1.0, at includes/admin/options/class-upstream-options-bugs.php

323 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UpStream_Options_Bugs
4 *
5 * @package UpStream
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 if ( ! class_exists( 'UpStream_Options_Bugs' ) ) :
14
15 /**
16 * CMB2 Theme Options
17 *
18 * @version 0.1.0
19 */
20 class UpStream_Options_Bugs {
21
22
23 /**
24 * ID of metabox
25 *
26 * @var array
27 */
28 public $id = 'upstream_bugs';
29
30 /**
31 * Page title
32 *
33 * @var string
34 */
35 protected $title = '';
36
37 /**
38 * Menu Title
39 *
40 * @var string
41 */
42 protected $menu_title = '';
43
44 /**
45 * Menu Title
46 *
47 * @var string
48 */
49 protected $description = '';
50
51 /**
52 * Holds an instance of the object
53 *
54 * @var Myprefix_Admin
55 **/
56 public static $instance = null;
57
58 /**
59 * Constructor
60 *
61 * @since 0.1.0
62 */
63 public function __construct() {
64 // Set our title.
65 $this->title = upstream_bug_label_plural();
66 $this->menu_title = $this->title;
67 }
68
69 /**
70 * Returns the running object
71 *
72 * @return Myprefix_Admin
73 **/
74 public static function get_instance() {
75 if ( is_null( self::$instance ) ) {
76 self::$instance = new self();
77 }
78
79 return self::$instance;
80 }
81
82 /**
83 * Add the options metabox to the array of metaboxes
84 *
85 * @since 0.1.0
86 */
87 public function options() {
88 $options = apply_filters(
89 $this->id . '_option_fields',
90 array(
91 'id' => $this->id, // upstream_tasks.
92 'title' => $this->title,
93 'menu_title' => $this->menu_title,
94 'desc' => $this->description,
95 'show_on' => array(
96 'key' => 'options-page',
97 'value' => array( $this->id ),
98 ),
99 'show_names' => true,
100 'fields' => array(
101 array(
102 'name' => __( 'Statuses', 'upstream' ),
103 'id' => 'status_title',
104 'type' => 'title',
105 'desc' => sprintf(
106 // translators: %1$s: upstream_bug_label_plural.
107 // translators: %2$s: upstream_bug_label.
108 // translators: %3$s: upstream_bug_label.
109 __(
110 'The statuses and colors that can be used for the status of %1$s.<br>These will become available in the %2$s Status dropdown within each %3$s',
111 'upstream'
112 ),
113 upstream_bug_label_plural(),
114 upstream_bug_label(),
115 upstream_bug_label()
116 ),
117 ),
118 array(
119 'id' => 'statuses',
120 'type' => 'group',
121 'name' => 'Statuses',
122 'description' => '',
123 'options' => array(
124 'group_title' => __( 'Status {#}', 'upstream' ),
125 'add_button' => __( 'Add Status', 'upstream' ),
126 'remove_button' => __( 'Remove Entry', 'upstream' ),
127 'sortable' => true, // beta.
128 ),
129 'sanitization_cb' => array( 'UpStream_Admin', 'on_before_save' ),
130 'fields' => array(
131 array(
132 'name' => __( 'Hidden', 'upstream' ),
133 'id' => 'id',
134 'type' => 'hidden',
135 ),
136 array(
137 'name' => __( 'Status Color', 'upstream' ),
138 'id' => 'color',
139 'type' => 'colorpicker',
140 'attributes' => array(
141 'data-colorpicker' => json_encode(
142 array(
143 // Iris Options set here as values in the 'data-colorpicker' array.
144 'palettes' => upstream_colorpicker_default_colors(),
145 'width' => 300,
146 )
147 ),
148 ),
149 ),
150 array(
151 'name' => __( 'Status Name', 'upstream' ),
152 'id' => 'name',
153 'type' => 'text',
154 ),
155 array(
156 'name' => __( 'Type of Status', 'upstream' ),
157 'id' => 'type',
158 'type' => 'radio',
159 'default' => 'open',
160 'desc' => __(
161 "A Status Name such as 'In Progress' or 'Overdue' would be considered Open.",
162 'upstream'
163 ) . '<br>' . __(
164 "A Status Name such as 'Complete' or 'Cancelled' would be considered Closed.",
165 'upstream'
166 ),
167 'options' => array(
168 'open' => __( 'Open', 'upstream' ),
169 'closed' => __( 'Closed', 'upstream' ),
170 ),
171 ),
172 ),
173 ),
174 array(
175 'name' => __( 'Severity', 'upstream' ),
176 'id' => 'severity_title',
177 'type' => 'title',
178 'desc' => sprintf(
179 // translators: %1$s: upstream_bug_label_plural.
180 // translators: %2$s: upstream_bug_label.
181 // translators: %3$s: upstream_bug_label.
182 __(
183 'The severity and colors that can be used for the severity of %1$s.<br>These will become available in the %2$s Severity dropdown within each %3$s',
184 'upstream'
185 ),
186 upstream_bug_label_plural(),
187 upstream_bug_label(),
188 upstream_bug_label()
189 ),
190 ),
191 array(
192 'id' => 'severities',
193 'type' => 'group',
194 'name' => 'Severities',
195 'description' => '',
196 'options' => array(
197 'group_title' => __( 'Severity {#}', 'upstream' ),
198 'add_button' => __( 'Add Severity', 'upstream' ),
199 'remove_button' => __( 'Remove Entry', 'upstream' ),
200 'sortable' => true, // beta.
201 ),
202 'sanitization_cb' => array( 'UpStream_Admin', 'on_before_save' ),
203 'fields' => array(
204 array(
205 'name' => __( 'Hidden', 'upstream' ),
206 'id' => 'id',
207 'type' => 'hidden',
208 ),
209 array(
210 'name' => __( 'Severity Color', 'upstream' ),
211 'id' => 'color',
212 'type' => 'colorpicker',
213 'attributes' => array(
214 'data-colorpicker' => wp_json_encode(
215 array(
216 // Iris Options set here as values in the 'data-colorpicker' array.
217 'palettes' => upstream_colorpicker_default_colors(),
218 'width' => 300,
219 )
220 ),
221 ),
222 ),
223 array(
224 'name' => __( 'Severity Name', 'upstream' ),
225 'id' => 'name',
226 'type' => 'text',
227 ),
228 ),
229 ),
230
231 ),
232 )
233 );
234
235 return $options;
236 }
237
238 /**
239 * Create ids for all existent bugs statuses/severities.
240 *
241 * @since 1.17.0
242 * @static
243 */
244 public static function create_bugs_statuses_ids() {
245 $continue = ! (bool) get_option( 'upstream:created_bugs_args_ids' );
246 if ( ! $continue ) {
247 return;
248 }
249
250 $bugs = get_option( 'upstream_bugs' );
251 if ( isset( $bugs['statuses'] ) && isset( $bugs['severities'] ) ) {
252 $bugs['statuses'] = UpStream_Admin::create_missing_ids_in_set( $bugs['statuses'] );
253 $bugs['severities'] = UpStream_Admin::create_missing_ids_in_set( $bugs['severities'] );
254
255 update_option( 'upstream_bugs', $bugs );
256
257 // Update existent Bugs statuses/severities across all Projects.
258 global $wpdb;
259
260 $metas = $wpdb->get_results(
261 sprintf(
262 'SELECT `post_id`, `meta_value`
263 FROM `%s`
264 WHERE `meta_key` = "_upstream_project_bugs"',
265 $wpdb->prefix . 'postmeta'
266 )
267 );
268
269 if ( count( $metas ) > 0 ) {
270 $get_bug_arg_id_by_title = function ( $needle, $arg_name = 'statuses' ) use ( &$bugs ) {
271 foreach ( $bugs[ $arg_name ] as $bug ) {
272 if ( $needle === $bug['name'] ) {
273 return $bug['id'];
274 }
275 }
276
277 return false;
278 };
279
280 $replace_bug_args_with_its_ids = function ( $bug ) use ( &$get_bug_arg_id_by_title ) {
281 if ( isset( $bug['status'] )
282 && ! empty( $bug['status'] )
283 ) {
284 $bug_arg_id = $get_bug_arg_id_by_title( $bug['status'] );
285 if ( false !== $bug_arg_id ) {
286 $bug['status'] = $bug_arg_id;
287 }
288 }
289
290 if ( isset( $bug['severity'] )
291 && ! empty( $bug['severity'] )
292 ) {
293 $bug_arg_id = $get_bug_arg_id_by_title( $bug['severity'], 'severities' );
294 if ( false !== $bug_arg_id ) {
295 $bug['severity'] = $bug_arg_id;
296 }
297 }
298
299 return $bug;
300 };
301
302 foreach ( $metas as $meta ) {
303 if ( empty( $meta->meta_value ) ) {
304 continue;
305 }
306
307 $project_id = (int) $meta->post_id;
308
309 $data = array_filter( maybe_unserialize( (string) $meta->meta_value ) );
310 $data = array_map( $replace_bug_args_with_its_ids, $data );
311
312 update_post_meta( $project_id, '_upstream_project_bugs', $data );
313 }
314 }
315
316 update_option( 'upstream:created_bugs_args_ids', 1 );
317 }
318 }
319 }
320
321
322 endif;
323