Skip to content

Commit 7fdf2d8

Browse files
author
Nolan Perry
committedMar 21, 2023
Add Roster Shortcode
1 parent 7254cda commit 7fdf2d8

4 files changed

+161
-3
lines changed
 

‎core/class-api-for-apex-towncontrol.php

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public static function instance() {
114114
self::$instance->options->towncontrol_register_stuff();
115115
new RR_APX_Shortcodes_Arrests();
116116
new RR_APX_Shortcodes_Phonebook();
117+
new RR_APX_Shortcodes_Roster();
118+
117119
}
118120

119121
return self::$instance;
@@ -134,6 +136,7 @@ private function includes() {
134136
require_once APIFORAPEX_PLUGIN_DIR . 'core/includes/classes/class-api-for-apex-towncontrol-options.php';
135137
require_once APIFORAPEX_PLUGIN_DIR . 'core/includes/classes/class-rr-apx-shortcodes-arrests.php';
136138
require_once APIFORAPEX_PLUGIN_DIR . 'core/includes/classes/class-rr-apx-shortcodes-phonebook.php';
139+
require_once APIFORAPEX_PLUGIN_DIR . 'core/includes/classes/class-rr-apx-shortcodes-roster.php';
137140

138141

139142
}

‎core/includes/classes/class-api-for-apex-towncontrol-options.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,15 @@ public function towncontrol_sanitize($input) {
8383
}
8484

8585
public function towncontrol_section_info() {
86-
echo "Set your API Key and Town UUID Below<br><br>The following shortcodes are available<br><ul><li><b>[show_town_arrests time='720']</b> - This shows all the towns arrests in within the last 30 days by default but can be changed by changing the attribute 'time', which is in hours. </li>
86+
echo "Set your API Key and Town UUID Below<br><br>The following shortcodes are available<br>
8787
88-
<li><b>[show_town_phonebook]</b> - This shows the entirety of citizens registered in your town by their name, address, and the phone number. (hint: this is a solution for the NorPhone.)</li></ul>
88+
89+
<ul>
90+
91+
<li><b>[show_town_arrests time='720']</b> - This shows all the towns arrests in within the last 30 days by default but can be changed by changing the attribute 'time', which is in hours. </li>
92+
<li><b>[show_town_phonebook]</b> - This shows the entirety of citizens registered in your town by their name, address, and the phone number. (hint: this is a solution for the NorPhone.)</li>
93+
<li><b>[show_town_roster group='police']</b> - This shows all your staff on the roster for the specified group, group can be 'police', 'fire', 'legal','service', 'education', and will default to police if you don't specify</li>
94+
</ul>
8995
9096
9197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
3+
// Exit if accessed directly.
4+
if ( ! defined( 'ABSPATH' ) ) exit;
5+
6+
/**
7+
* HELPER COMMENT START
8+
*
9+
* This class is used to bring your plugin to life.
10+
* All the other registered classed bring features which are
11+
* controlled and managed by this class.
12+
*
13+
* Within the add_hooks() function, you can register all of
14+
* your WordPress related actions and filters as followed:
15+
*
16+
* add_action( 'my_action_hook_to_call', array( $this, 'the_action_hook_callback', 10, 1 ) );
17+
* or
18+
* add_filter( 'my_filter_hook_to_call', array( $this, 'the_filter_hook_callback', 10, 1 ) );
19+
* or
20+
* add_shortcode( 'my_shortcode_tag', array( $this, 'the_shortcode_callback', 10 ) );
21+
*
22+
* Once added, you can create the callback function, within this class, as followed:
23+
*
24+
* public function the_action_hook_callback( $some_variable ){}
25+
* or
26+
* public function the_filter_hook_callback( $some_variable ){}
27+
* or
28+
* public function the_shortcode_callback( $attributes = array(), $content = '' ){}
29+
*
30+
*
31+
* HELPER COMMENT END
32+
*/
33+
34+
/**
35+
* Class RR_APX_Shortcodes_Roster
36+
*
37+
* Thats where we bring the plugin to life
38+
*
39+
* @package APIFORAPEX
40+
* @subpackage Classes/RR_APX_Shortcodes_Roster
41+
* @author Nolan Perry, LLC
42+
* @since 1.0.0
43+
*/
44+
class RR_APX_Shortcodes_Roster{
45+
46+
/**
47+
* Our RR_APX_Shortcodes_Roster constructor
48+
* to run the plugin logic.
49+
*
50+
* @since 1.0.0
51+
*/
52+
function __construct(){
53+
$this->add_hooks();
54+
}
55+
56+
/**
57+
* ######################
58+
* ###
59+
* #### WORDPRESS HOOKS
60+
* ###
61+
* ######################
62+
*/
63+
64+
/**
65+
* Registers all WordPress and plugin related hooks
66+
*
67+
* @access private
68+
* @since 1.0.0
69+
* @return void
70+
*/
71+
private function add_hooks(){
72+
add_shortcode( 'show_town_roster', array( $this, 'create_show_town_roster_shortcode' ));
73+
add_action( 'wp_enqueue_scripts', array( $this, 'rr_apx_requirements' ) );
74+
75+
76+
}
77+
public function rr_apx_requirements(){
78+
wp_enqueue_style( 'datatables-apex', APIFORAPEX_PLUGIN_URL . 'assets/jquery.dataTables.min.css', false, '1.1', 'all');
79+
wp_enqueue_script( 'datatables-script-apex', APIFORAPEX_PLUGIN_URL . 'assets/jquery.dataTables.min.js', array( 'jquery' ), 1.1 );
80+
81+
}
82+
83+
public function create_show_town_roster_shortcode( $atts = array(), $content = '' ) {
84+
85+
86+
// Attributes
87+
$atts = shortcode_atts(
88+
array(
89+
'group' => 'police',
90+
),
91+
$atts
92+
);
93+
94+
$api_key_0 = get_option( 'rr_apx_api_key' ); // Array of All Options
95+
$townuuid_1 = get_option( 'rr_apx_townuuid' );
96+
97+
$theurltouse = 'http://www.apexdesignssl.com/api/towncontrol/PersonnelRoster/List/' . $townuuid_1 . '/' . $atts['group'];
98+
$args = array(
99+
'headers' => array(
100+
'token' => $api_key_0
101+
)
102+
);
103+
$response = wp_remote_get( $theurltouse, $args );
104+
105+
$bodyofchrist = wp_remote_retrieve_body( $response );
106+
$d1 = json_decode($bodyofchrist);
107+
$results = "";
108+
foreach ($d1 as $query)
109+
{
110+
111+
$data1 = "<tr><td>" . $query->fullName . "(". $query->slUsername .")</td><td>" . $query->rank ."</td><td>" . $query->section ."</td></tr>";
112+
$results .= $data1;
113+
}
114+
115+
$output = '
116+
117+
<table id="apexRoster">
118+
<thead>
119+
<tr>
120+
<th>Name</th>
121+
<th>Rank/Title</th>
122+
<th>Section</th>
123+
</tr>
124+
</thead>
125+
<tbody>
126+
'.
127+
$results
128+
129+
.'
130+
131+
</tbody>
132+
</table>
133+
<script>
134+
let table = new DataTable("#apexRoster");
135+
</script>
136+
137+
';
138+
return $output;
139+
}
140+
141+
142+
143+
144+
}
145+
146+
147+

‎readme.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This is a plugin for Second Life and the Apex TownControl available from Virtual
1616
The following shortcodes are available
1717
[show_town_arrests time=\'720\'] - This shows all the towns arrests in within the last 30 days by default but can be changed by changing the attribute \'time\', which is in hours.
1818
[show_town_phonebook] - This shows the entirety of citizens registered in your town by their name, address, and the phone number. (hint: this is a solution for the NorPhone.)
19+
[show_town_roster group='police']- This shows all your staff on the roster for the specified group, group can be 'police', 'fire', 'legal','service', 'education', and will default to police if you don't specify.
1920

2021

2122
The following command are under development and will be available in a further update:
@@ -43,7 +44,8 @@ none yet!
4344
2. Demo Arrests Page
4445

4546
== Changelog ==
46-
47+
= 1.0.2: March 21, 2023 =
48+
* Added Roster Shortcode
4749
= 1.0.1: March 14, 2023 =
4850
* Added Phonebook Shortcode
4951
= 1.0.0: March 10, 2023 =

0 commit comments

Comments
 (0)