From 7fdf2d8deca068073c57a4249269b3454539feff Mon Sep 17 00:00:00 2001 From: Nolan Perry Date: Tue, 21 Mar 2023 11:57:10 -0400 Subject: [PATCH] Add Roster Shortcode --- core/class-api-for-apex-towncontrol.php | 3 + ...class-api-for-apex-towncontrol-options.php | 10 +- .../class-rr-apx-shortcodes-roster.php | 147 ++++++++++++++++++ readme.txt | 4 +- 4 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 core/includes/classes/class-rr-apx-shortcodes-roster.php diff --git a/core/class-api-for-apex-towncontrol.php b/core/class-api-for-apex-towncontrol.php index f37e534..09c4958 100644 --- a/core/class-api-for-apex-towncontrol.php +++ b/core/class-api-for-apex-towncontrol.php @@ -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; @@ -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'; } diff --git a/core/includes/classes/class-api-for-apex-towncontrol-options.php b/core/includes/classes/class-api-for-apex-towncontrol-options.php index 46bbd15..cb6674a 100644 --- a/core/includes/classes/class-api-for-apex-towncontrol-options.php +++ b/core/includes/classes/class-api-for-apex-towncontrol-options.php @@ -83,9 +83,15 @@ public function towncontrol_sanitize($input) { } public function towncontrol_section_info() { - echo "Set your API Key and Town UUID Below

The following shortcodes are available
+ + diff --git a/core/includes/classes/class-rr-apx-shortcodes-roster.php b/core/includes/classes/class-rr-apx-shortcodes-roster.php new file mode 100644 index 0000000..06a2a11 --- /dev/null +++ b/core/includes/classes/class-rr-apx-shortcodes-roster.php @@ -0,0 +1,147 @@ +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 = "" . $query->fullName . "(". $query->slUsername .")" . $query->rank ."" . $query->section .""; +$results .= $data1; +} + +$output = ' + + + + + + + + + + + '. + $results + + .' + + +
NameRank/TitleSection
+ + +'; +return $output; +} + + + + +} + + + diff --git a/readme.txt b/readme.txt index f596e63..45ae17b 100644 --- a/readme.txt +++ b/readme.txt @@ -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: @@ -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 =