Skip to content

Commit

Permalink
Add Roster Shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolan Perry committed Mar 21, 2023
1 parent 7254cda commit 7fdf2d8
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 3 deletions.
3 changes: 3 additions & 0 deletions core/class-api-for-apex-towncontrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public static function instance() {
self::$instance->options->towncontrol_register_stuff();
new RR_APX_Shortcodes_Arrests();
new RR_APX_Shortcodes_Phonebook();
new RR_APX_Shortcodes_Roster();

}

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


}
Expand Down
10 changes: 8 additions & 2 deletions core/includes/classes/class-api-for-apex-towncontrol-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ public function towncontrol_sanitize($input) {
}

public function towncontrol_section_info() {
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>
echo "Set your API Key and Town UUID Below<br><br>The following shortcodes are available<br>
<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>
<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>
<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>
<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>
</ul>
Expand Down
147 changes: 147 additions & 0 deletions core/includes/classes/class-rr-apx-shortcodes-roster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;

/**
* HELPER COMMENT START
*
* This class is used to bring your plugin to life.
* All the other registered classed bring features which are
* controlled and managed by this class.
*
* Within the add_hooks() function, you can register all of
* your WordPress related actions and filters as followed:
*
* add_action( 'my_action_hook_to_call', array( $this, 'the_action_hook_callback', 10, 1 ) );
* or
* add_filter( 'my_filter_hook_to_call', array( $this, 'the_filter_hook_callback', 10, 1 ) );
* or
* add_shortcode( 'my_shortcode_tag', array( $this, 'the_shortcode_callback', 10 ) );
*
* Once added, you can create the callback function, within this class, as followed:
*
* public function the_action_hook_callback( $some_variable ){}
* or
* public function the_filter_hook_callback( $some_variable ){}
* or
* public function the_shortcode_callback( $attributes = array(), $content = '' ){}
*
*
* HELPER COMMENT END
*/

/**
* Class RR_APX_Shortcodes_Roster
*
* Thats where we bring the plugin to life
*
* @package APIFORAPEX
* @subpackage Classes/RR_APX_Shortcodes_Roster
* @author Nolan Perry, LLC
* @since 1.0.0
*/
class RR_APX_Shortcodes_Roster{

/**
* Our RR_APX_Shortcodes_Roster constructor
* to run the plugin logic.
*
* @since 1.0.0
*/
function __construct(){
$this->add_hooks();
}

/**
* ######################
* ###
* #### WORDPRESS HOOKS
* ###
* ######################
*/

/**
* Registers all WordPress and plugin related hooks
*
* @access private
* @since 1.0.0
* @return void
*/
private function add_hooks(){
add_shortcode( 'show_town_roster', array( $this, 'create_show_town_roster_shortcode' ));
add_action( 'wp_enqueue_scripts', array( $this, 'rr_apx_requirements' ) );


}
public function rr_apx_requirements(){
wp_enqueue_style( 'datatables-apex', APIFORAPEX_PLUGIN_URL . 'assets/jquery.dataTables.min.css', false, '1.1', 'all');
wp_enqueue_script( 'datatables-script-apex', APIFORAPEX_PLUGIN_URL . 'assets/jquery.dataTables.min.js', array( 'jquery' ), 1.1 );

}

public function create_show_town_roster_shortcode( $atts = array(), $content = '' ) {


// Attributes
$atts = shortcode_atts(
array(
'group' => 'police',
),
$atts
);

$api_key_0 = get_option( 'rr_apx_api_key' ); // Array of All Options
$townuuid_1 = get_option( 'rr_apx_townuuid' );

$theurltouse = 'http://www.apexdesignssl.com/api/towncontrol/PersonnelRoster/List/' . $townuuid_1 . '/' . $atts['group'];
$args = array(
'headers' => array(
'token' => $api_key_0
)
);
$response = wp_remote_get( $theurltouse, $args );

$bodyofchrist = wp_remote_retrieve_body( $response );
$d1 = json_decode($bodyofchrist);
$results = "";
foreach ($d1 as $query)
{

$data1 = "<tr><td>" . $query->fullName . "(". $query->slUsername .")</td><td>" . $query->rank ."</td><td>" . $query->section ."</td></tr>";
$results .= $data1;
}

$output = '
<table id="apexRoster">
<thead>
<tr>
<th>Name</th>
<th>Rank/Title</th>
<th>Section</th>
</tr>
</thead>
<tbody>
'.
$results

.'
</tbody>
</table>
<script>
let table = new DataTable("#apexRoster");
</script>
';
return $output;
}




}



4 changes: 3 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This is a plugin for Second Life and the Apex TownControl available from Virtual
The following shortcodes are available
[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.
[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.)
[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.


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

== Changelog ==

= 1.0.2: March 21, 2023 =
* Added Roster Shortcode
= 1.0.1: March 14, 2023 =
* Added Phonebook Shortcode
= 1.0.0: March 10, 2023 =
Expand Down

0 comments on commit 7fdf2d8

Please sign in to comment.