-
Notifications
You must be signed in to change notification settings - Fork 0
/
cases-shortcode.php
163 lines (148 loc) · 4.85 KB
/
cases-shortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
// Add Shortcode
function cases_shortcode()
{
// ---------------------------------------------------------------------
// Setting vars and pre-processing
// ---------------------------------------------------------------------
$user_table = piklist(get_users(
array(
'orderby' => 'display_name', 'order' => 'asc',
), 'objects'
), array('ID', 'display_name')
);
$link = $_GET['link'];
$status = $_GET['status'];
$cat_id = $_GET['category'];
$cat_name = $cat_id !== '' ? get_term( $cat_id, 'case_category' ) : '';
$cat_name = $cat_name->name;
$owner_id = $_GET['owner'];
$owner_name = $user_table[$owner_id];
//$submitter_id = $_GET['submitter'];
//$submitter_name = $user_table[$submitter_id];
?>
<!--for debugging only
Search options:
<br>link: <?php //echo $link; ?>
<br>status: <?php //echo $status; ?>
<br>category: <?php //echo $cat_id; ?>
<br>owner: <?php //echo $owner_name; ?>
<br>submitter: <?php //echo $submitter_name; ?><br>
-->
<?php
// -- query arguments
$args = array('post_type' => 'plagiarism_case' , // only show post plagiarism_case data
'orderby' => 'date',
'order' => 'ASC', // sort on date, olders to newest
'meta_key' => 'assigned_user', // optional filter: Owner
'title' => $link, // optional filter for links
'post_status' => $status, // optional filter for status
'meta_value' => $owner_id, // owner value
'author' => $submitter_id, // optional filter for submitter
'posts_per_page' => '-1'
);
if ($cat_id != '') {
$args['tax_query'] = array(array(
'taxonomy' => 'case_category',
'field' => 'term_id',
'terms' => $cat_id,
));
};
// ---------------------------------------------------------------------
// Add quick actions
// ---------------------------------------------------------------------
$current_user = wp_get_current_user();
?>
<div class="quick-actions">
<!--<h4>Quick actions</h4>-->
<a class="btn btn-default" href="<?php echo get_site_url() . '?status=in_progress&owner=' . $current_user->ID; ?>">Show cases assigned to me</a>
<a class="btn btn-default" href="<?php echo get_site_url() . '?status=open'; ?>">Show all open cases</a>
</div>
<h4>Results</h4>
<div class="wpt-search-terms">
<?php
function wrap($key, $value){
return sprintf("<div class='wpt-search-term-item'>%s: <i>%s</i></div>", $key, $value);
}
$atts = '';
if ( $link != '' ) $atts .= wrap('Link', $link);
if ( $status != '' ) $atts .= wrap('Status', $status);
if ( $cat_name != '' ) $atts .= wrap('Category', $cat_name);
if ( $owner_name != '' ) $atts .= wrap('Owner', $owner_name);
echo $atts;
?>
</div>
<?php
// ---------------------------------------------------------------------
// The loop, query and display plagiarism cases
// ---------------------------------------------------------------------
$the_query = new WP_Query($args);
//$the_query = new WP_Query( );
if ($the_query->have_posts()) :
// Start the Loop
?>
<table class="plagiarism-cases-table stripe">
<thead>
<tr>
<th>ID</th>
<th>Status</th>
<th>Assigned User</th>
<th>Category</th>
<th>Links</th>
<th>Date</th>
<!--<th>Submitter</th>-->
<th>Go</th>
</tr>
</thead>
<tbody>
<?php while ($the_query->have_posts()) : $the_query->the_post();
?>
<tr>
<td><?php echo get_the_ID() ?></td>
<!-- Status -->
<td><?php echo get_post_status($post->ID);
?></td>
<!-- Owner -->
<td><?php echo $user_table[get_post_meta(get_the_ID(), 'assigned_user', true)];
?></td>
<!-- Category -->
<td><?php $cats = get_the_terms($post->ID, 'case_category');
?>
<ul>
<?php if ($cats == false) {
echo '<li>none</li>';
}
foreach ($cats as $cat) {
echo '<li>'.$cat->name.'</li>';
}
?>
</ul>
</td>
<!-- Links, copied and original -->
<td>
COPIED: <?php the_title();
?><br>
ORIGINAL: <?php echo get_post_meta(get_the_ID(), 'original', true) ?>
</td>
<!-- Date -->
<td><?php echo get_the_date('M j, Y');
?> @ <?php the_time();
?></td>
<!-- Author -->
<!--<td><?php //the_author(); ?></td>-->
<td><?php the_shortlink('view');
?></td>
</tr>
<?php // End the Loop
endwhile;
wp_reset_postdata(); else :
// If no posts match this query, output this text.
_e('Sorry, no posts matched your criteria.', 'textdomain');
endif;
?>
</tbody>
</table>
<?php
}
add_shortcode('plagiarism_cases', 'cases_shortcode');
?>