/** * Retrieve event stats * * @access public * @since 1.4 * @param str|bool $start_date The starting date for which we'd like to filter our sale stats. If false, we'll use the default start date of `this_month` * @param str|bool $end_date The end date for which we'd like to filter our sale stats. If false, we'll use the default end date of `this_month` * @param str|bool $event_date The event start date for which we'd like to filter our event stats. If false, we'll use the default start date of `this_month` * @param str|arr $status The event status(es) to count. Only valid when retrieving global stats * @return float|int Total amount of events based on the passed arguments. */ public function get_events($start_date = false, $end_date = false, $event_date = false, $status = 'publish') { $this->setup_dates($start_date, $end_date); // Make sure start date is valid if (is_wp_error($this->start_date)) { return $this->start_date; } // Make sure end date is valid if (is_wp_error($this->end_date)) { return $this->end_date; } add_filter('mdjm_count_events_where', array($this, 'count_events_where')); if (is_array($status)) { $count = 0; foreach ($status as $event_status) { $count += mdjm_count_events()->{$event_status}; } } else { $count = mdjm_count_events()->{$status}; } remove_filter('mdjm_count_events_where', array($this, 'count_events_where')); return $count; }
/** * Add event count to At a glance widget * * @since 1.4 * @return void */ function mdjm_dashboard_at_a_glance_widget($items) { $num_posts = mdjm_count_events(); $count = 0; $statuses = mdjm_all_event_status(); foreach ($statuses as $status => $label) { if (!empty($num_posts->{$status})) { $count += $num_posts->{$status}; } } if ($num_posts && $count > 0) { $text = _n('%s ' . mdjm_get_label_singular(), '%s ' . mdjm_get_label_plural(), $count, 'mobile-dj-manager'); $text = sprintf($text, number_format_i18n($count)); if (mdjm_employee_can('read_events')) { $text = sprintf('<a class="event-count" href="edit.php?post_type=mdjm-event">%1$s</a>', $text); } else { $text = sprintf('<span class="event-count">%1$s</span>', $text); } $items[] = $text; } return $items; }
/** * Customise the view filter counts * * @since 1.0 * @param arr $views Array of views * @return arr $views Filtered Array of views */ function mdjm_event_view_filters($views) { if (!is_post_type_archive('mdjm-event')) { return; } $args = array(); if (!empty($_GET['mdjm_filter_employee']) || !mdjm_employee_can('read_events_all')) { $args['employee'] = get_current_user_id(); } $active_only = mdjm_get_option('show_active_only'); $num_posts = mdjm_count_events($args); $count = 0; $statuses = mdjm_all_event_status(); $active_statuses = mdjm_active_event_statuses(); $active_statuses[] = 'mdjm-unattended'; foreach ($statuses as $status => $label) { if (!empty($num_posts->{$status})) { $views[$status] = preg_replace('/\\(.+\\)/U', '(' . number_format_i18n($num_posts->{$status}) . ')', $views[$status]); if (!$active_only || in_array($status, $active_statuses)) { $count += $num_posts->{$status}; } } } $views['all'] = preg_replace('/\\(.+\\)/U', '(' . number_format_i18n($count) . ')', $views['all']); if ($active_only) { $search = __('All', 'mobile-dj-manager'); $replace = sprintf(__('Active %s', 'mobile-dj-manager'), mdjm_get_label_plural()); $views['all'] = str_replace($search, $replace, $views['all']); } foreach ($views as $status => $link) { if ($status != 'all' && !array_key_exists($status, $statuses)) { unset($views[$status]); } } return apply_filters('mdjm_event_views', $views); }