|
| 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 | + |
0 commit comments