示例#1
0
 /**
  * @covers ::bbp_topic_post_count
  * @covers ::bbp_get_topic_post_count
  */
 public function test_bbp_get_topic_post_count()
 {
     $f = $this->factory->forum->create();
     $int_topics = 1;
     $int_replies = 3;
     $int_value = $int_topics + $int_replies;
     $formatted_value = bbp_number_format($int_value);
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $this->factory->reply->create_many($int_replies, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     bbp_update_topic_reply_count($t);
     // Output
     $this->expectOutputString($formatted_value);
     bbp_topic_post_count($t);
     // Formatted string
     $count = bbp_get_topic_post_count($t, false);
     $this->assertSame($formatted_value, $count);
     // Integer
     $count = bbp_get_topic_post_count($t, true);
     $this->assertSame($int_value, $count);
 }
do_action('bbp_theme_after_topic_meta');
?>

		<?php 
bbp_topic_row_actions();
?>

	</li>

	<li class="bbp-topic-voice-count"><?php 
bbp_topic_voice_count();
?>
</li>

	<li class="bbp-topic-reply-count"><?php 
bbp_show_lead_topic() ? bbp_topic_reply_count() : bbp_topic_post_count();
?>
</li>

	<li class="bbp-topic-freshness">

		<?php 
do_action('bbp_theme_before_topic_freshness_link');
?>

		<?php 
bbp_topic_freshness_link();
?>

		<?php 
do_action('bbp_theme_after_topic_freshness_link');
/**
 * Support Dashboard Shortcode Callback
 *
 * Show:
 *  - open tickets
 *  - assigned tickets
 *  - unassigned tickets
 *  - tickets awaiting answer
 *
 * @since		1.0.0
 * @param		array $atts Shortcode attributes
 * @param		string $content The shortcode content
 * @global		int $user_ID The ID of the current user
 * @return
 */
function edd_bbp_dashboard_shortcode($atts, $content = null)
{
    global $user_ID;
    // Bail if not logged in
    if (!is_user_logged_in()) {
        return edd_login_form();
    }
    // Bail if current user isn't a moderator
    if (!current_user_can('moderate')) {
        return;
    }
    // Enqueue our styles
    wp_enqueue_script('bootstrap', EDD_BBP_URL . 'assets/js/bootstrap.min.js');
    wp_enqueue_style('bootstrap', EDD_BBP_URL . 'assets/css/bootstrap.min.css');
    // Show ticket overview for all mods
    $mods = edd_bbp_get_all_mods();
    ?>

	<?php 
    if ($mods) {
        ?>
		<div class="row" id="mods-grid">
		<?php 
        foreach ($mods as $mod) {
            ?>

			<?php 
            $ticket_count = edd_bbp_count_tickets_of_mod($mod->ID);
            ?>

			<div class="mod col-xs-6 col-sm-3">
				<div class="mod-name"><?php 
            echo $mod->display_name;
            ?>
</div>
				<div class="mod-gravatar"><?php 
            echo get_avatar($mod->ID, 45);
            ?>
</div>
				<div class="mod-ticket-count">
					<a href="<?php 
            echo add_query_arg('mod', $mod->ID);
            ?>
">Tickets: <strong><?php 
            echo $ticket_count;
            ?>
</strong></div></a>
			</div>

		<?php 
        }
        ?>
		</div>
	<?php 
    }
    if (!empty($_GET['mod'])) {
        // Get open, assigned tickets
        $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => '_bbps_topic_status', 'value' => '1'), array('key' => 'bbps_topic_assigned', 'value' => $_GET['mod'])), 'posts_per_page' => -1, 'post_parent__not_in' => array(318));
        $assigned_tickets = new WP_Query($args);
        $mod = get_userdata($_GET['mod']);
        ob_start();
        ?>
		<div class="bbp-tickets">
			<?php 
        if ($assigned_tickets->have_posts()) {
            ?>
				<h4>Tickets assigned to <?php 
            echo $mod->display_name;
            ?>
</h4>
					<table class="table table-striped" width="100%">
						<tr>
							<th width="35%">Topic Title</th>
							<th width="25%">Last Post By</th>
							<th width="25%">Last Updated</th>
							<th width="15%">Post Count</th>
						</tr>
						<?php 
            while ($assigned_tickets->have_posts()) {
                $assigned_tickets->the_post();
                ?>
							<?php 
                $parent = get_post_field('post_parent', get_the_ID());
                ?>
							<?php 
                $row_class = $parent == 499 ? 'danger' : '';
                ?>
							<?php 
                $last_reply_id = bbp_get_topic_last_reply_id(get_the_ID());
                ?>
							<?php 
                $last_reply_data = get_post($last_reply_id);
                ?>
							<tr class = "<?php 
                echo $row_class;
                ?>
">
								<td>
								<a href="<?php 
                the_permalink();
                ?>
"><?php 
                the_title();
                ?>
</a>
								</td>
								<td><?php 
                the_author_meta('display_name', $last_reply_data->post_author);
                ?>
</td>
								<td><?php 
                bbp_topic_freshness_link();
                ?>
</td>
								<td><?php 
                bbp_topic_post_count(get_the_ID());
                ?>
</td>
							</tr>
						<?php 
            }
            ?>
					<?php 
            wp_reset_postdata();
            ?>
					</table>
			<?php 
        } else {
            ?>
				<div>This mod has no assigned tickets.</div>
			<?php 
        }
        ?>
		</div>
		<?php 
        return ob_get_clean();
    }
    // Get tickets awaiting answer
    $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => '_bbps_topic_pending'), array('key' => '_bbps_topic_status', 'value' => '1'), array('key' => 'bbps_topic_assigned', 'value' => $user_ID)), 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => '_bbp_last_active_time', 'posts_per_page' => -1, 'post_parent__not_in' => array(318));
    $waiting_tickets = new WP_Query($args);
    // Get open, assigned tickets
    $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => '_bbps_topic_status', 'value' => '1'), array('key' => 'bbps_topic_assigned', 'value' => $user_ID)), 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => '_bbp_last_active_time', 'posts_per_page' => -1, 'post_parent__not_in' => array(318));
    $assigned_tickets = new WP_Query($args);
    // Get unassigned tickets
    $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => 'bbps_topic_assigned', 'compare' => 'NOT EXISTS', 'value' => '1'), array('key' => '_bbps_topic_status', 'value' => '1')), 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => '_bbp_last_active_time', 'posts_per_page' => -1, 'post_status' => 'publish', 'post_parent__not_in' => array(318));
    $unassigned_tickets = new WP_Query($args);
    // Get tickets with no replies
    $args = array('post_type' => 'topic', 'meta_query' => array('relation' => 'AND', array('key' => '_bbp_voice_count', 'value' => '1'), array('key' => '_bbps_topic_status', 'value' => '1')), 'posts_per_page' => -1, 'post_status' => 'publish');
    $no_reply_tickets = new WP_Query($args);
    // Get unresolved tickets
    $args = array('post_type' => 'topic', 'post_parent__not_in' => array(318), 'posts_per_page' => -1, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => '_bbp_last_active_time', 'meta_query' => array(array('key' => '_bbps_topic_status', 'value' => '1')));
    $unresolved_tickets = new WP_Query($args);
    // Get unresolved tickets
    $args = array('post_type' => 'topic', 'post_parent' => 318, 'posts_per_page' => 30, 'post_status' => 'publish');
    $feature_requests = new WP_Query($args);
    $open_count = 0;
    $unassigned_count = 0;
    $unresolved_count = 0;
    ob_start();
    ?>
	<style>
	#support-tabs { padding-left: 0; }
	#support-tabs li { list-style: none; margin-left: 0; font-size: 95%;}
	#support-tabs li a { padding: 4px; }
	#mods-grid { margin-bottom: 20px; }
	</style>
	<ul class="nav nav-tabs" id="support-tabs">
		<li><a href="#your-waiting-tickets" data-toggle="tab">Awaiting Your Response (<?php 
    echo $waiting_tickets->post_count;
    ?>
)</a></li>
		<li><a href="#your-tickets" data-toggle="tab">Your Open Tickets (<?php 
    echo $assigned_tickets->post_count;
    ?>
)</a></li>
		<li><a href="#unassigned" data-toggle="tab">Unassigned Tickets (<?php 
    echo $unassigned_tickets->post_count;
    ?>
)</a></li>
		<li><a href="#no-replies" data-toggle="tab">No Replies (<?php 
    echo $no_reply_tickets->post_count;
    ?>
)</a></li>
		<li><a href="#unresolved" data-toggle="tab">Unresolved Tickets (<?php 
    echo $unresolved_tickets->post_count;
    ?>
)</a></li>
		<li><a href="#feature-requests" data-toggle="tab">Feature Requests</a></li>
	</ul>
	<div class="tab-content">
		<div class="tab-pane active" id="your-waiting-tickets">
			<ul class="bbp-tickets">
				<?php 
    if ($waiting_tickets->have_posts()) {
        ?>
					<form class="form-table" method="post">
						<table class="table table-striped" width="100%">
							<tr>
								<th></th>
								<th width="40%">Topic Title</th>
								<th width="25%">Last Updated</th>
								<th width="25%">Actions</th>
							</tr>
							<?php 
        while ($waiting_tickets->have_posts()) {
            $waiting_tickets->the_post();
            ?>
								<?php 
            $parent = get_post_field('post_parent', get_the_ID());
            ?>
								<?php 
            $row_class = $parent == 499 ? 'danger' : '';
            ?>
								<?php 
            $remove_url = add_query_arg(array('topic_id' => get_the_ID(), 'bbps_action' => 'remove_pending'));
            ?>
								<tr class = "<?php 
            echo $row_class;
            ?>
">
									<td>
										<input type="checkbox" name="tickets[]" value="<?php 
            echo esc_attr(get_the_ID());
            ?>
"/>
									</td>
									<td>
										<a href="<?php 
            the_permalink();
            ?>
"><?php 
            the_title();
            ?>
</a>
									</td>
									<td><?php 
            bbp_topic_freshness_link(get_the_ID());
            ?>
</td>
									<td><a href="<?php 
            echo $remove_url;
            ?>
">Remove Pending Status</a></td>
								</tr>
							<?php 
        }
        ?>
						</table>
						<input type="hidden" name="edd_action" value="remove_ticket_pending_status"/>
						<input type="submit" value="Remove Pending Status"/>
						<?php 
        wp_reset_postdata();
        ?>
					</form>
				<?php 
    } else {
        ?>
					<li>No tickets awaiting your reply. Excellent, now go grab some unresolved or unassigned tickets.</li>
				<?php 
    }
    ?>
			</ul>
		</div>
		<div class="tab-pane" id="your-tickets">
			<ul class="bbp-tickets">
				<?php 
    if ($assigned_tickets->have_posts()) {
        ?>
					<table class="table table-striped" width="100%">
						<tr>
							<th width="40%">Topic Title</th>
							<th width="30%">Last Post By</th>
							<th width="30%">Last Updated</th>
						</tr>
						<?php 
        while ($assigned_tickets->have_posts()) {
            $assigned_tickets->the_post();
            ?>
							<?php 
            $parent = get_post_field('post_parent', get_the_ID());
            ?>
							<?php 
            $row_class = $parent == 499 ? 'danger' : '';
            ?>
							<?php 
            $last_reply_id = bbp_get_topic_last_reply_id(get_the_ID());
            ?>
							<?php 
            $last_reply_data = get_post($last_reply_id);
            ?>
							<tr class = "<?php 
            echo $row_class;
            ?>
">
								<td>
								<a href="<?php 
            the_permalink();
            ?>
"><?php 
            the_title();
            ?>
</a>
								</td>
								<td><?php 
            the_author_meta('display_name', $last_reply_data->post_author);
            ?>
</td>
								<td><?php 
            bbp_topic_freshness_link(get_the_ID());
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
					<?php 
        wp_reset_postdata();
        ?>
					</table>
				<?php 
    } else {
        ?>
					<li>No unresolved tickets, yay! Now go grab some unresolved or unassigned tickets.</li>
				<?php 
    }
    ?>
			</ul>
		</div>
		<div class="tab-pane" id="unassigned">
			<ul class="bbp-tickets">
				<?php 
    if ($unassigned_tickets->have_posts()) {
        ?>
					<table class="table table-striped" width="100%">
						<tr>
							<th width="40%">Topic Title</th>
							<th width="30%">Last Post By</th>
							<th width="30%">Last Updated</th>
						</tr>
						<?php 
        while ($unassigned_tickets->have_posts()) {
            $unassigned_tickets->the_post();
            ?>
							<?php 
            $parent = get_post_field('post_parent', get_the_ID());
            ?>
							<?php 
            $row_class = $parent == 499 ? 'danger' : '';
            ?>
							<?php 
            $last_reply_id = bbp_get_topic_last_reply_id(get_the_ID());
            ?>
							<?php 
            $last_reply_data = get_post($last_reply_id);
            ?>
							<tr class = "<?php 
            echo $row_class;
            ?>
">
								<td>
								<a href="<?php 
            the_permalink();
            ?>
"><?php 
            the_title();
            ?>
</a>
								</td>
								<td><?php 
            the_author_meta('display_name', $last_reply_data->post_author);
            ?>
</td>
								<td><?php 
            bbp_topic_freshness_link(get_the_ID());
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
					<?php 
        wp_reset_postdata();
        ?>
					</table>
				<?php 
    } else {
        ?>
					<li>No unassigned tickets, yay!</li>
				<?php 
    }
    ?>
			</ul>
		</div>
		<div class="tab-pane" id="no-replies">
			<ul class="bbp-tickets">
				<?php 
    if ($no_reply_tickets->have_posts()) {
        ?>
					<table class="table table-striped" width="100%">
						<tr>
							<th width="40%">Topic Title</th>
							<th width="30%">Posted</th>
							<th width="30%">Assignee</th>
						</tr>
						<?php 
        while ($no_reply_tickets->have_posts()) {
            $no_reply_tickets->the_post();
            ?>
							<?php 
            $parent = get_post_field('post_parent', get_the_ID());
            ?>
							<?php 
            $row_class = $parent == 499 ? 'danger' : '';
            ?>

							<?php 
            $assignee_id = edd_bbp_get_topic_assignee_id(get_the_ID());
            ?>
							<?php 
            $assignee_name = edd_bbp_get_topic_assignee_name($assignee_id);
            ?>
							<tr class = "<?php 
            echo $row_class;
            ?>
">
								<td>
								<a href="<?php 
            the_permalink();
            ?>
"><?php 
            the_title();
            ?>
</a>
								</td>
								<td><?php 
            bbp_topic_freshness_link(get_the_ID());
            ?>
</td>
								<td><?php 
            echo !empty($assignee_name) ? $assignee_name : 'Unassigned';
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
					<?php 
        wp_reset_postdata();
        ?>
					</table>
				<?php 
    } else {
        ?>
					<li>No tickets without replies, yay!</li>
				<?php 
    }
    ?>
			</ul>
		</div>
		<div class="tab-pane" id="unresolved">
			<ul class="bbp-tickets">
				<?php 
    if ($unresolved_tickets->have_posts()) {
        ?>
					<table class="table table-striped" width="100%">
						<tr>
							<th width="35%">Topic Title</th>
							<th width="25%">Last Updated</th>
							<th width="25%">Assignee</th>
							<th width="15%">Post Count</th>
						</tr>
						<?php 
        while ($unresolved_tickets->have_posts()) {
            $unresolved_tickets->the_post();
            ?>
							<?php 
            $parent = get_post_field('post_parent', get_the_ID());
            ?>
							<?php 
            $row_class = $parent == 499 ? 'danger' : '';
            ?>

							<?php 
            $assignee_id = edd_bbp_get_topic_assignee_id(get_the_ID());
            ?>
							<?php 
            $assignee_name = edd_bbp_get_topic_assignee_name($assignee_id);
            ?>
							<tr class = "<?php 
            echo $row_class;
            ?>
">
								<td>
								<a href="<?php 
            the_permalink();
            ?>
"><?php 
            the_title();
            ?>
</a>
								</td>
								<td><?php 
            bbp_topic_freshness_link(get_the_ID());
            ?>
</td>
								<td><?php 
            echo !empty($assignee_name) ? $assignee_name : 'Unassigned';
            ?>
</td>
								<td><?php 
            bbp_topic_post_count(get_the_ID());
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
					<?php 
        wp_reset_postdata();
        ?>
					</table>
				<?php 
    } else {
        ?>
					<li>No unassigned tickets, yay!</li>
				<?php 
    }
    ?>
			</ul>
		</div>
		<div class="tab-pane" id="feature-requests">
			<ul class="bbp-tickets">
				<?php 
    if ($feature_requests->have_posts()) {
        ?>
					<?php 
        while ($feature_requests->have_posts()) {
            $feature_requests->the_post();
            ?>
						<li><a href="<?php 
            the_permalink();
            ?>
"><?php 
            the_title();
            ?>
</a></li>
					<?php 
        }
        ?>
					<?php 
        wp_reset_postdata();
        ?>
				<?php 
    }
    ?>
			</ul>
		</div>
	</div>

	<script>
	jQuery( function($) {
		$('#support-tabs a:first').tab('show');
	})
	</script>
	<?php 
    return ob_get_clean();
}
				in <a class="topic-location" href="<?php 
    bbp_forum_permalink(bbp_get_topic_forum_id());
    ?>
" title="Browse this forum"><?php 
    bbp_forum_title(bbp_get_topic_forum_id());
    ?>
</a>
			<?php 
}
?>
		</p>
	</div>
	
	<div class="forum-count">
		<?php 
bbp_topic_post_count();
?>
	</div>
	
	<div class="forum-freshness">
		<?php 
echo apoc_get_avatar(array('user_id' => bbp_get_reply_author_id(bbp_get_topic_last_active_id()), 'link' => true, 'size' => 50));
?>
		<div class="freshest-meta">
			<span class="freshest-author">By <?php 
bbp_author_link(array('post_id' => bbp_get_topic_last_active_id(), 'type' => 'name'));
?>
</span>
			<span class="freshest-time"><?php 
bbp_topic_last_active_time();
?>