0, 'mine' => 0, 'overdue' => 0, 'finished' => 0, 'total' => 0, ); $all = $counter->get_items_of_type( 'milestones' ); $milestones_counts['total'] = count( $all ); if ( $milestones_counts['total'] > 0 ) { $milestones_counts['mine'] = $counter->get_total_assigned_to_current_user_of_type( 'milestones' ); $milestones_counts['open'] = $counter->get_total_open_items_of_type( 'milestones' ); foreach ( $all as $milestone ) { $progress = isset( $milestone['progress'] ) ? (float) $milestone['progress'] : 0; if ( $progress < 100 ) { if ( isset( $milestone['end_date'] ) && (int) $milestone['end_date'] > 0 && (int) $milestone['end_date'] < $current_timestamp ) { $milestones_counts['overdue']++; } } else { $milestones_counts['finished']++; } } } $upstream_allcounts['milestonesCounts'] = $milestones_counts; } $are_tasks_enabled = ! upstream_are_tasks_disabled() && ! upstream_disable_tasks(); if ( $are_tasks_enabled ) { $tasks_counts = array( 'open' => 0, 'mine' => 0, 'overdue' => 0, 'closed' => 0, 'total' => 0, ); $tasks_options = get_option( 'upstream_tasks' ); $tasks_map = array(); foreach ( $tasks_options['statuses'] as $task ) { if ( isset( $task['type'] ) ) { $tasks_map[ $task['id'] ] = $task['type']; } } unset( $tasks_options ); $tasks = get_post_meta( $project_id, '_upstream_project_tasks' ); $tasks = ! empty( $tasks ) ? (array) $tasks[0] : array(); if ( isset( $tasks[0] ) && ! isset( $tasks[0]['id'] ) ) { $tasks = (array) $tasks[0]; } $tasks_counts['total'] = count( $tasks ); if ( $tasks_counts['total'] > 0 ) { foreach ( $tasks as $task ) { if ( isset( $task['assigned_to'] ) ) { $assigned_to = $task['assigned_to']; if ( is_array( $assigned_to ) && in_array( $user_id, $assigned_to ) ) { $tasks_counts['mine']++; } } $progress = isset( $task['progress'] ) ? (float) $task['progress'] : 0; if ( $progress < 100 ) { if ( isset( $task['status'] ) && isset( $tasks_map[ $task['status'] ] ) && 'closed' === $tasks_map[ $task['status'] ] ) { $tasks_counts['closed']++; } else { $tasks_counts['open']++; if ( isset( $task['end_date'] ) && (int) $task['end_date'] > 0 && (int) $task['end_date'] < $current_timestamp ) { $tasks_counts['overdue']++; } } } else { $tasks_counts['closed']++; } } } $upstream_allcounts['tasksCounts'] = $tasks_counts; } $are_bugs_enabled = ! upstream_disable_bugs() && ! upstream_are_bugs_disabled(); if ( $are_bugs_enabled ) { $bugs_counts = array( 'open' => 0, 'mine' => 0, 'overdue' => 0, 'closed' => 0, 'total' => 0, ); $bugs_options = get_option( 'upstream_bugs' ); $bugs_map = array(); foreach ( $bugs_options['statuses'] as $bug ) { $bugs_map[ $bug['id'] ] = $bug['type']; } unset( $bugs_options ); $bugs = get_post_meta( $project_id, '_upstream_project_bugs' ); $bugs = ! empty( $bugs ) ? (array) $bugs[0] : array(); if ( isset( $bugs[0] ) && ! isset( $bugs[0]['id'] ) ) { $bugs = (array) $bugs[0]; } $bugs_counts['total'] = count( $bugs ); if ( $bugs_counts['total'] > 0 ) { foreach ( $bugs as $bug ) { if ( isset( $bug['assigned_to'] ) ) { $assigned_to = $bug['assigned_to']; if ( is_array( $assigned_to ) && in_array( $user_id, $assigned_to ) ) { $bugs_counts['mine']++; } } if ( isset( $bug['status'] ) && ! empty( $bug['status'] ) && isset( $bugs_map[ $bug['status'] ] ) && 'closed' === $bugs_map[ $bug['status'] ] ) { $bugs_counts['closed']++; } else { $bugs_counts['open']++; if ( isset( $bug['due_date'] ) && (int) $bug['due_date'] > 0 && (int) $bug['due_date'] < $current_timestamp ) { $bugs_counts['overdue']++; } } } } $upstream_allcounts['bugsCounts'] = $bugs_counts; } ?>