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 / up-project-functions.php

up-project-functions.php in UpStream: a Project Management Plugin for WordPress 2.1.0, at includes/up-project-functions.php

820 lines 21.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Project functions.
4 *
5 * @package UpStream
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Upstream_project_status
15 *
16 * @param int $id Project id.
17 */
18 function upstream_project_status( $id = 0 ) {
19 $project = new UpStream_Project( $id );
20 $result = $project->get_meta( 'status' );
21
22 return apply_filters( 'upstream_project_status', $result, $id );
23 }
24
25 /**
26 * Upstream_project_statuses_colors
27 */
28 function upstream_project_statuses_colors() {
29 $option = get_option( 'upstream_projects' );
30 $colors = wp_list_pluck( $option['statuses'], 'color', 'id' );
31
32 return apply_filters( 'upstream_project_statuses_colors', $colors );
33 }
34
35 /**
36 * Upstream_get_all_project_statuses
37 */
38 function upstream_get_all_project_statuses() {
39 $data = Upstream_Cache::get_instance()->get( 'upstream_get_all_project_statuses' );
40
41 if ( false === $data ) {
42 $data = array();
43
44 $rowset = get_option( 'upstream_projects' );
45 foreach ( $rowset['statuses'] as $status ) {
46 $data[ $status['id'] ] = $status;
47 }
48
49 Upstream_Cache::get_instance()->set( 'upstream_get_all_project_statuses', $data );
50
51 }
52
53 return $data;
54 }
55
56 /**
57 * Upstream_get_open_project_status_ids
58 */
59 function upstream_get_open_project_status_ids() {
60 $all_statuses = upstream_get_all_project_statuses();
61 $open_status_ids = array();
62
63 foreach ( $all_statuses as $key => $status ) {
64 if ( 'open' === $status['type'] ) {
65 $open_status_ids[] = $status['id'];
66 }
67 }
68
69 return $open_status_ids;
70 }
71
72 /**
73 * Upstream_project_status_color
74 *
75 * @param int $project_id Project id.
76 */
77 function upstream_project_status_color( $project_id = 0 ) {
78 $status = array(
79 'status' => '',
80 'color' => '#aaa',
81 );
82
83 $project_status_id = (string) upstream_project_status( $project_id );
84 if ( ! empty( $project_status_id ) ) {
85 $rowset = get_option( 'upstream_projects' );
86 if ( ! empty( $rowset )
87 && ! empty( $rowset['statuses'] )
88 ) {
89 foreach ( $rowset['statuses'] as $row ) {
90 if ( isset( $row['id'] )
91 && $row['id'] === $project_status_id &&
92 isset( $row['name'] ) && isset( $row['color'] )
93 ) {
94 $status['status'] = $row['name'];
95 $status['color'] = $row['color'];
96 break;
97 }
98 }
99 }
100 }
101
102 return apply_filters( 'upstream_project_status_color', $status );
103 }
104
105 /**
106 * Upstream_project_status_type
107 *
108 * @param int $id Project id.
109 */
110 function upstream_project_status_type( $id = 0 ) {
111 $project = new UpStream_Project( $id );
112 $result = $project->get_project_status_type();
113
114 return apply_filters( 'upstream_project_status_type', $result );
115 }
116
117 /**
118 * Upstream_project_progress
119 *
120 * @param int $id Project id.
121 */
122 function upstream_project_progress( $id = 0 ) {
123 $project = new UpStream_Project( $id );
124 $result = $project->get_meta( 'progress' );
125 $result = $result ? $result : '0';
126
127 return apply_filters( 'upstream_project_progress', $result, $id );
128 }
129
130 /**
131 * Upstream_project_owner_id
132 *
133 * @param int $id Project id.
134 */
135 function upstream_project_owner_id( $id = 0 ) {
136 $project = new UpStream_Project( $id );
137 $result = $project->get_meta( 'owner' );
138
139 return apply_filters( 'upstream_project_owner_id', $result, $id );
140 }
141
142 /**
143 * Upstream_project_owner_name
144 *
145 * @param int $id Project id.
146 * @param bool $show_email Show the email or not.
147 */
148 function upstream_project_owner_name( $id = 0, $show_email = false ) {
149 $project = new UpStream_Project( $id );
150 $owner_id = $project->get_meta( 'owner' );
151 $result = $owner_id ? upstream_users_name( $owner_id, $show_email ) : null;
152
153 return apply_filters( 'upstream_project_owner_name', $result, $id, $show_email );
154 }
155
156 /**
157 * Upstream_project_client_id
158 *
159 * @param int $id Project id.
160 */
161 function upstream_project_client_id( $id = 0 ) {
162 $project = new UpStream_Project( $id );
163 $result = $project->get_meta( 'client' );
164
165 return apply_filters( 'upstream_project_client_id', $result, $id );
166 }
167
168 /**
169 * Upstream_project_client_name
170 *
171 * @param int $id Project id.
172 */
173 function upstream_project_client_name( $id = 0 ) {
174 $res = Upstream_Cache::get_instance()->get( 'upstream_project_client_name' . $id );
175
176 if ( false === $res ) {
177 $project = new UpStream_Project( $id );
178 $result = $project->get_client_name();
179
180 $res = apply_filters( 'upstream_project_client_name', $result, $id );
181 Upstream_Cache::get_instance()->set( 'upstream_project_client_name' . $id, $res );
182
183 }
184
185 return $res;
186 }
187
188 /**
189 * Upstream_project_client_users
190 *
191 * @param int $id Project id.
192 */
193 function upstream_project_client_users( $id = 0 ) {
194 $project = new UpStream_Project( $id );
195 $result = (array) $project->get_meta( 'client_users' );
196 $result = ! empty( $result ) ? array_filter( $result, 'is_numeric' ) : '';
197
198 return apply_filters( 'upstream_project_client_users', $result, $id );
199 }
200
201 /**
202 * Upstream_project_members_ids
203 *
204 * @param int $id Project id.
205 */
206 function upstream_project_members_ids( $id = 0 ) {
207 $project = new UpStream_Project( $id );
208 $result = $project->get_meta( 'members' );
209
210 return apply_filters( 'upstream_project_members_ids', $result, $id );
211 }
212
213 /**
214 * Upstream_project_users
215 *
216 * @param int $id Project id.
217 */
218 function upstream_project_users( $id = 0 ) {
219 $project = new UpStream_Project( $id );
220 $result = $project->get_meta( 'members' );
221 $result = isset( $result ) ? array_filter( $result, 'is_numeric' ) : '';
222
223 return apply_filters( 'upstream_project_users', $result, $id );
224 }
225
226 /**
227 * Upstream_project_start_date
228 *
229 * @param int $id Project id.
230 */
231 function upstream_project_start_date( $id = 0 ) {
232 $project = new UpStream_Project( $id );
233 $result = $project->get_meta( 'start' );
234
235 return apply_filters( 'upstream_project_start_date', $result, $id );
236 }
237
238 /**
239 * Upstream_project_end_date
240 *
241 * @param int $id Project id.
242 */
243 function upstream_project_end_date( $id = 0 ) {
244 $project = new UpStream_Project( $id );
245 $result = $project->get_meta( 'end' );
246
247 return apply_filters( 'upstream_project_end_date', $result, $id );
248 }
249
250
251 /**
252 * Upstream_project_files
253 *
254 * @param int $id Project id.
255 */
256 function upstream_project_files( $id = 0 ) {
257 $project = new UpStream_Project( $id );
258 $result = $project->get_meta( 'files' );
259
260 return apply_filters( 'upstream_project_files', $result, $id );
261 }
262
263 /**
264 * Upstream_project_description
265 *
266 * @param int $id Project id.
267 */
268 function upstream_project_description( $id = 0 ) {
269 $project = new UpStream_Project( (int) $id );
270 $result = $project->get_meta( 'description' );
271
272 return apply_filters( 'upstream_project_description', $result, $id );
273 }
274
275 /* ------------ MILESTONES -------------- */
276
277 /**
278 * Upstream_project_milestones
279 *
280 * @param int $id Project id.
281 */
282 function upstream_project_milestones( $id = 0 ) {
283 if ( empty( $id ) ) {
284 $id = get_the_ID();
285 }
286
287 $result = \UpStream\Milestones::getInstance()->get_milestones_as_rowset( $id );
288
289 return apply_filters( 'upstream_project_milestones', $result, $id );
290 }
291
292 /**
293 * Upstream_project_milestone_by_id
294 *
295 * @param int $id Project id.
296 * @param int $milestone_id Milestone id.
297 */
298 function upstream_project_milestone_by_id( $id = 0, $milestone_id = 0 ) {
299 $project = new UpStream_Project( $id );
300 $result = $project->get_item_by_id( $milestone_id, 'milestones' );
301
302 return apply_filters( 'upstream_project_milestone_by_id', $result, $id, $milestone_id );
303 }
304
305 /**
306 * Upstream_project_milestone_colors
307 *
308 * @return mixed|void
309 * @deprecated Each milestone instance returns its color.
310 */
311 function upstream_project_milestone_colors() {
312 return array();
313 }
314
315 /* ------------ TASKS -------------- */
316
317 /**
318 * Upstream_project_tasks
319 *
320 * @param int $id Project id.
321 */
322 function upstream_project_tasks( $id = 0 ) {
323 $project = new UpStream_Project( $id );
324 $result = $project->get_meta( 'tasks' );
325
326 return apply_filters( 'upstream_project_tasks', $result, $id );
327 }
328
329 /**
330 * Upstream_project_task_by_id
331 *
332 * @param int $id Project id.
333 * @param int $task_id Task id.
334 */
335 function upstream_project_task_by_id( $id = 0, $task_id = 0 ) {
336 $project = new UpStream_Project( $id );
337 $result = $project->get_item_by_id( $task_id, 'tasks' );
338
339 return apply_filters( 'upstream_project_task_by_id', $result, $id, $task_id );
340 }
341
342 /**
343 * Upstream_project_tasks_counts
344 *
345 * @param int $id Project id.
346 */
347 function upstream_project_tasks_counts( $id = 0 ) {
348 $project = new UpStream_Project( $id );
349 $result = $project->get_statuses_counts( 'tasks' );
350
351 return apply_filters( 'upstream_project_tasks_statuses_counts', $result, $id );
352 }
353
354 /**
355 * Upstream_project_tasks_counts
356 */
357 function upstream_project_task_statuses_colors() {
358 $option = get_option( 'upstream_tasks' );
359 $colors = wp_list_pluck( $option['statuses'], 'color', 'id' );
360
361 return apply_filters( 'upstream_project_tasks_statuses_colors', $colors );
362 }
363
364 /**
365 * Upstream_project_tasks_counts
366 *
367 * @param int $id Project id.
368 * @param int $item_id Item id.
369 */
370 function upstream_project_task_status_color( $id = 0, $item_id ) {
371 $project = new UpStream_Project( $id );
372 $result = $project->get_item_colors( $item_id, 'tasks', 'status' );
373
374 return apply_filters( 'upstream_project_task_status_color', $result );
375 }
376
377 /* ------------ BUGS -------------- */
378
379 /**
380 * Upstream_project_bugs
381 *
382 * @param int $id Project id.
383 */
384 function upstream_project_bugs( $id = 0 ) {
385 $project = new UpStream_Project( $id );
386 $result = $project->get_meta( 'bugs' );
387
388 return apply_filters( 'upstream_project_bugs', $result, $id );
389 }
390
391 /**
392 * Upstream_project_bug_by_id
393 *
394 * @param int $id Project id.
395 * @param int $bug_id Bug id.
396 */
397 function upstream_project_bug_by_id( $id = 0, $bug_id = 0 ) {
398 $project = new UpStream_Project( $id );
399 $result = $project->get_item_by_id( $bug_id, 'bugs' );
400
401 return apply_filters( 'upstream_project_bug_by_id', $result, $id, $bug_id );
402 }
403
404 /**
405 * Upstream_project_bugs_counts
406 *
407 * @param int $id Project id.
408 */
409 function upstream_project_bugs_counts( $id = 0 ) {
410 $project = new UpStream_Project( $id );
411 $result = $project->get_statuses_counts( 'bugs' );
412
413 return apply_filters( 'upstream_project_bugs_statuses_counts', $result, $id );
414 }
415
416 /**
417 * Upstream_project_bug_statuses_colors
418 */
419 function upstream_project_bug_statuses_colors() {
420 $option = get_option( 'upstream_bugs' );
421 $colors = wp_list_pluck( $option['statuses'], 'color', 'id' );
422
423 return apply_filters( 'upstream_project_bugs_statuses_colors', $colors );
424 }
425
426 /**
427 * Upstream_project_bug_severity_colors
428 */
429 function upstream_project_bug_severity_colors() {
430 $option = get_option( 'upstream_bugs' );
431 $colors = wp_list_pluck( $option['severities'], 'color', 'id' );
432
433 return apply_filters( 'upstream_project_bugs_severity_colors', $colors );
434 }
435
436 /**
437 * Upstream_project_bug_status_color
438 *
439 * @param int $id Project id.
440 * @param int $item_id Item id.
441 */
442 function upstream_project_bug_status_color( $id = 0, $item_id ) {
443 $project = new UpStream_Project( $id );
444 $result = $project->get_item_colors( $item_id, 'bugs', 'status' );
445
446 return apply_filters( 'upstream_project_bug_status_color', $result );
447 }
448
449
450 /**
451 * Upstream_project_item_by_id
452 *
453 * @param int $id Project id.
454 * @param int $item_id Item id.
455 */
456 function upstream_project_item_by_id( $id = 0, $item_id = 0 ) {
457 $project = new UpStream_Project( $id );
458 $result = $project->get_item_by_id( $item_id, 'milestones' );
459 if ( ! $result ) {
460 $result = $project->get_item_by_id( $item_id, 'tasks' );
461 }
462 if ( ! $result ) {
463 $result = $project->get_item_by_id( $item_id, 'bugs' );
464 }
465 if ( ! $result ) {
466 $result = $project->get_item_by_id( $item_id, 'files' );
467 }
468 if ( ! $result ) {
469 $result = $project->get_item_by_id( $item_id, 'discussion' );
470 }
471
472 return apply_filters( 'upstream_project_item_by_id', $result, $id, $item_id );
473 }
474
475 /* ------------ COUNTS -------------- */
476
477
478 /**
479 * Get the count of items for a type.
480 *
481 * @param string $type Type of item such as bug, task etc.
482 * @param int $id Id of the project you want the count for.
483 */
484 function upstream_count_total( $type, $id = 0 ) {
485 if ( ! $id && is_admin() ) {
486 $id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0;
487
488 // checks if the project ID is valid and accessible.
489 if ( ! upstream_user_can_access_project( get_current_user_id(), $id ) ) {
490 return 0;
491 }
492 }
493
494 $count = new Upstream_Counts( $id );
495
496 return $count->total( $type );
497 }
498
499 /**
500 * Get the count of OPEN items for a type.
501 *
502 * @param string $type Type of item such as bug, task etc.
503 * @param int $id Id of the project you want the count for.
504 */
505 function upstream_count_total_open( $type, $id = 0 ) {
506 $count = new Upstream_Counts( $id );
507
508 return $count->total_open( $type );
509 }
510
511 /**
512 * Get the count of items for a type that is assigned to current user.
513 *
514 * @param string $type Type of item such as bug, task etc.
515 * @param int $id Id of the project you want the count for.
516 */
517 function upstream_count_assigned_to( $type, $id = 0 ) {
518 $count = new Upstream_Counts( $id );
519
520 return $count->assigned_to( $type );
521 }
522
523 /**
524 * Get the count of OPEN items for a type that is assigned to current user.
525 *
526 * @param string $type Type of item such as bug, task etc.
527 * @param int $id Id of the project you want the count for.
528 */
529 function upstream_count_assigned_to_open( $type, $id = 0 ) {
530 $count = new Upstream_Counts( $id );
531
532 return $count->assigned_to_open( $type );
533 }
534
535 /**
536 * Retrieve details from a given project.
537 *
538 * @param int $project_id The project ID.
539 *
540 * @return object
541 * @since 1.12.0
542 */
543 function get_up_stream_project_details_by_id( $project_id ) {
544 $post = get_post( $project_id );
545 if ( $post instanceof \WP_Post ) {
546 global $wpdb;
547
548 $project = new stdClass();
549 $project->id = (int) $project_id;
550 $project->title = $post->post_title;
551 $project->description = '';
552 $project->progress = 0;
553 $project->status = null;
554 $project->client_id = 0;
555 $project->client_name = '';
556 $project->owner_id = 0;
557 $project->owner_name = '';
558 $project->date_start = 0;
559 $project->date_end = 0;
560 $project->date_start_ymd = '';
561 $project->date_end_ymd = '';
562 $project->members = array();
563 $project->client_users = array();
564
565 $metas = $wpdb->get_results(
566 $wpdb->prepare(
567 "SELECT meta_key, meta_value
568 FROM $wpdb->postmeta
569 WHERE post_id = %d
570 AND meta_key LIKE %s",
571 array(
572 $project->id,
573 '_upstream_project_%',
574 )
575 )
576 );
577
578 foreach ( $metas as $meta ) {
579 if ( '_upstream_project_description' === $meta->meta_key ) {
580 $project->description = $meta->meta_value;
581 } elseif ( '_upstream_project_progress' === $meta->meta_key ) {
582 $project->progress = (int) $meta->meta_value;
583 } elseif ( '_upstream_project_status' === $meta->meta_key ) {
584 $project->status = $meta->meta_value;
585 } elseif ( '_upstream_project_client' === $meta->meta_key ) {
586 $project->client_id = (int) $meta->meta_value;
587 } elseif ( '_upstream_project_owner' === $meta->meta_key ) {
588 $project->owner_id = (int) $meta->meta_value;
589 } elseif ( '_upstream_project_start' === $meta->meta_key ) {
590 $project->date_start = (int) $meta->meta_value;
591 } elseif ( '_upstream_project_end' === $meta->meta_key ) {
592 $project->date_end = (int) $meta->meta_value;
593 } elseif ( '_upstream_project_start.YMD' === $meta->meta_key ) {
594 $project->date_start_ymd = $meta->meta_value;
595 } elseif ( '_upstream_project_end.YMD' === $meta->meta_key ) {
596 $project->date_end_ymd = $meta->meta_value;
597 } elseif ( '_upstream_project_members' === $meta->meta_key ) {
598 $project->members = (array) maybe_unserialize( $meta->meta_value );
599 } elseif ( '_upstream_project_client_users' === $meta->meta_key ) {
600 $project->client_users = (array) maybe_unserialize( $meta->meta_value );
601 }
602 }
603
604 $users_rowset = (array) get_users(
605 array(
606 'fields' => array( 'ID', 'display_name' ),
607 )
608 );
609
610 $users = array();
611 foreach ( $users_rowset as $user ) {
612 $users[ (int) $user->ID ] = (object) array(
613 'id' => (int) $user->ID,
614 'name' => $user->display_name,
615 );
616 }
617
618 if ( $project->client_id > 0 ) {
619 $client = get_post( $project->client_id );
620 if ( $client instanceof \WP_Post ) {
621 if ( ! empty( $client->post_title ) ) {
622 $project->client_name = $client->post_title;
623 }
624 }
625 }
626
627 if ( $project->owner_id > 0 && isset( $users[ $project->owner_id ] ) ) {
628 $project->owner_name = $users[ $project->owner_id ]->name;
629 }
630
631 if ( count( $project->members ) > 0 ) {
632 foreach ( $project->members as $member_index => $member_id ) {
633 $member_id = (int) $member_id;
634 if ( $member_id > 0 && isset( $users[ $member_id ] ) ) {
635 $project->members[ $member_index ] = $users[ $member_id ];
636 }
637 }
638 }
639
640 if ( count( $project->client_users ) > 0 ) {
641 foreach ( $project->client_users as $client_user_index => $client_user_id ) {
642 $client_user_id = (int) $client_user_id;
643 if ( $client_user_id > 0 && isset( $users[ $client_user_id ] ) ) {
644 $project->client_users[ $client_user_index ] = $users[ $client_user_id ];
645 }
646 }
647 }
648
649 return $project;
650 }
651
652 return false;
653 }
654
655 /**
656 * Count_items_for_user_on_project
657 *
658 * @param string $item_type Item type.
659 * @param int $user_id User id.
660 * @param int $project_id Project id.
661 */
662 function count_items_for_user_on_project( $item_type, $user_id, $project_id ) {
663 $user_id = (int) $user_id;
664 if ( ! in_array( $item_type, array( 'milestones', 'tasks', 'bugs' ), true ) ) {
665 return null;
666 }
667
668 $count = 0;
669
670 if ( 'milestones' === $item_type ) {
671
672 $project_milestones = \UpStream\Milestones::getInstance()->get_milestones_from_project( $project_id );
673
674 $total = 0;
675 if ( count( $project_milestones ) > 0 ) {
676 foreach ( $project_milestones as $milestone ) {
677 $milestone = \UpStream\Factory::get_milestone( $milestone );
678 if ( in_array( $user_id, $milestone->getAssignedTo() ) ) {
679 $count++;
680 }
681 }
682 }
683
684 return $count;
685 }
686
687 $metas = (array) get_post_meta( (int) $project_id, '_upstream_project_' . $item_type );
688 $metas = count( $metas ) > 0 ? (array) $metas[0] : array();
689
690 if ( is_array( $metas ) && count( $metas ) > 0 ) {
691 foreach ( $metas as $meta ) {
692 if ( isset( $meta['assigned_to'] ) ) {
693 $assigned_to = $meta['assigned_to'];
694
695 if (
696 ( is_array( $assigned_to ) && in_array( $user_id, $assigned_to ) )
697 && ( (int) $meta['assigned_to'] === $user_id )
698 ) {
699 $count++;
700 }
701 }
702 }
703 }
704
705 return $count;
706 }
707
708 /**
709 * Retrieve the number of approved comments within a given project.
710 *
711 * @param int $project_id The project ID.
712 *
713 * @return int
714 * @since 1.13.0
715 */
716 function get_project_comments_count( $project_id ) {
717 if ( ! is_numeric( $project_id ) || $project_id < 0 ) {
718 return;
719 }
720
721 $comments_count = get_comments(
722 array(
723 'post_id' => $project_id,
724 'count' => true,
725 'status' => 'approve',
726 )
727 );
728
729 return (int) $comments_count;
730 }
731
732 /**
733 * Upstream_user_projects
734 *
735 * @return array
736 */
737 function upstream_user_projects() {
738 $projects_list = array();
739 $user_id = absint( @$_SESSION['upstream']['user_id'] );
740 $current_user = (object) upstream_user_data( $user_id );
741
742 if ( isset( $current_user->projects ) ) {
743 if ( is_array( $current_user->projects ) && count( $current_user->projects ) > 0 ) {
744 $archive_closed_items = upstream_archive_closed_items();
745 $are_clients_enabled = ! upstream_is_clients_disabled();
746
747 foreach ( $current_user->projects as $project_id => $project ) {
748 $data = (object) array(
749 'id' => $project_id,
750 'title' => $project->post_title,
751 'slug' => $project->post_name,
752 'status' => $project->post_status,
753 'permalink' => get_permalink( $project_id ),
754 'start_date_timestamp' => (int) upstream_project_start_date( $project_id ),
755 'end_date_timestamp' => (int) upstream_project_end_date( $project_id ),
756 'progress' => (float) upstream_project_progress( $project_id ),
757 'status' => (string) upstream_project_status( $project_id ),
758 'client_name' => null,
759 'categories' => array(),
760 'features' => array(
761 '',
762 ),
763 );
764
765 // If should archive closed items, we filter the rowset.
766 if ( $archive_closed_items ) {
767
768 $open_statuses = upstream_get_open_project_status_ids();
769 if ( ! empty( $data->status ) && ! in_array( $data->status, $open_statuses ) ) {
770 continue;
771 }
772 }
773
774 $data->start_date = (string) upstream_format_date( $data->start_date_timestamp );
775 $data->end_date = (string) upstream_format_date( $data->end_date_timestamp );
776
777 if ( $are_clients_enabled ) {
778 $data->client_name = trim( (string) upstream_project_client_name( $project_id ) );
779 }
780
781 $statuses = upstream_get_all_project_statuses();
782
783 if ( isset( $statuses[ $data->status ] ) ) {
784 $data->status = $statuses[ $data->status ];
785 }
786
787 $data->timeframe = $data->start_date;
788 if ( ! empty( $data->end_date ) ) {
789 if ( ! empty( $data->timeframe ) ) {
790 $data->timeframe .= ' - ';
791 } else {
792 $data->timeframe = '<i>' . __( 'Ends at', 'upstream' ) . '</i>';
793 }
794
795 $data->timeframe .= $data->end_date;
796 }
797
798 $categories = (array) wp_get_object_terms( $data->id, 'project_category' );
799 if ( count( $categories ) > 0 ) {
800 foreach ( $categories as $category ) {
801 if ( is_object( $category ) ) {
802 $data->categories[ $category->term_id ] = $category->name;
803 }
804 }
805 }
806
807 $projects_list[ $project_id ] = $data;
808 }
809
810 unset( $project, $project_id );
811 }
812
813 unset( $current_user->projects );
814 }
815
816 unset( $current_user );
817
818 return $projects_list;
819 }
820