daily pastebin goal
29%
SHARE
TWEET

PP: PF Dashboard Example Code Block

globiws May 12th, 2018 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // find the url parameter for widget
  3. $widget = json_decode($pf_payload, true)["GET"]['widget'];
  4.  
  5. function widget_1_progress () {
  6.     $pct = call_pf_script("report_get_single.pf", ["widget_id" => 80325645]);
  7.     $html = '<h4 class="card-title">Lorem Ipsum</h4>';
  8.     $html .= '<p class="card-text">Some Metric</p>';
  9.     $html .= '<div class="progress" id="prg1">';
  10.     $html .= '<div class="progress-bar progress-bar-striped bg-primary" role="progressbar" style="width: '.$pct.'%" aria-valuenow="'.$pct.'" aria-valuemin="0" aria-valuemax="100">'.$pct.'%</div>';
  11.     $html .= '</div>';
  12.     return $html;
  13. }
  14.  
  15. function widget_2_counter() {
  16.     $num = call_pf_script("report_get_single.pf", ["widget_id" => 80325685]);
  17.     $html = '<h4 class="card-title">Another Metric</h4>';
  18.     $html .= '<div class="float-left"><h1>';
  19.     // font-awesome icon
  20.     $html .= '<i class="fa fa-bar-chart" aria-hidden="true" style="color: rgba(54, 162, 235, 0.5)"></i>';
  21.     $html .= '</h1></div>';
  22.     $html .= '<div class="float-right">';
  23.     $html .= '<h1 class="card-title font-weight-bold text-right mb-0">'.$num.'</h1>';
  24.     $html .= '</div><div class="clearfix"></div><p class="" style="color: #888">Lorem Ipsum dolor</p>';
  25.     return $html;
  26. }
  27.  
  28. function widget_3_gauge() {
  29.     $pct = call_pf_script("report_get_single.pf", ["widget_id" => 80325645]);
  30.     $html = '<h4 class="card-title">Google Gauge</h4>';
  31.     $html .= '<p class="card-text text-center">';
  32.     $html .= '<img src="https://chart.googleapis.com/chart?chs=175x85&cht=gom&chd=t:'.$pct.'&chco=00FF00,FFFF00,FF0000">';
  33.     $html .= '</p>';
  34.     return $html;
  35. }
  36.  
  37. function widget_4_text() {
  38.     $html = '<h4 class="card-title">Some Text</h4>';
  39.     $html .= '<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>';
  40.     return $html;
  41. }
  42.  
  43. function widget_5_barchart() {
  44.     $view = json_decode(call_pf_script("podio_view_get.pf", ["app_id" => 20894955, "view_id" => 38147362, "raw" => 0]), true);
  45.     $data = [
  46.         "labels" => array_column($view, "title"),
  47.         "datasets" =>  [[
  48.             "data" => array_column($view, "progress"),
  49.             "backgroundColor" => ["red", "blue", "green", "grey", "orange", "purple"],
  50.         ]]
  51.     ];
  52.     $options = [
  53.         "scales" => [ "yAxes" => [ "ticks" => [ "beginAtZero" => true ] ] ],
  54.         "legend" =>  [ "display" => false ],
  55.         "elements" => [ "point" =>  [ "radius" =>  0 ] ]
  56.     ];
  57.     $html = '<h4 class="card-title">Bar chart</h4>';
  58.     $html .= '<canvas id="barChart" style="height:230px"></canvas>';
  59.     $html .= '<script>';
  60.     $html .= 'var data = ' . json_encode($data) . ';' . "\n";
  61.     $html .= 'var options = ' . json_encode($options) . ';' . "\n";
  62.     $html .= 'if ($("#barChart").length) { ';
  63.     $html .= 'var barChartCanvas = $("#barChart").get(0).getContext("2d");' . "\n";
  64.     $html .= 'var barChart = new Chart(barChartCanvas, {type: "bar", data: data, options: options});' . "\n";
  65.     $html .= '}';
  66.     $html .= '</script>';
  67.     return $html;
  68. }
  69.  
  70. function cmpdate($a, $b) {
  71.     return ($a['due-date'] > $b['due-date']);
  72. }
  73.  
  74.  
  75. function widget_6_linechart() {
  76.     $view = json_decode(call_pf_script("podio_view_get.pf", ["app_id" => 20894955, "view_id" => 38147362, "raw" => 0]), true);
  77.     usort($view, 'cmpdate');   
  78.     $data = [
  79.         "labels" => array_column($view, "due-date"),
  80.         "datasets" =>  [[
  81.             "data" => array_column($view, "count"),
  82.             "backgroundColor" => "blue",
  83.         ]]
  84.     ];
  85.     $options = [
  86.         "scales" => [ "yAxes" => [ "ticks" => [ "beginAtZero" => true ] ] ],
  87.         "legend" =>  [ "display" => false ],
  88.         "elements" => [ "point" =>  [ "radius" =>  0 ] ]
  89.     ];
  90.     $html = '<h4 class="card-title">Line chart</h4>';
  91.     $html .= '<canvas id="lineChart" style="height:250px"></canvas>';
  92.     $html .= '<script>';
  93.     $html .= 'var data = ' . json_encode($data) . ';' . "\n";
  94.     $html .= 'var options = ' . json_encode($options) . ';' . "\n";
  95.     $html .= 'if ($("#lineChart").length) { ';
  96.     $html .= 'var lineChartCanvas = $("#lineChart").get(0).getContext("2d");' . "\n";
  97.     $html .= 'var lineChart = new Chart(lineChartCanvas, {type: "line", data: data, options: options});' . "\n";
  98.     $html .= '}';
  99.     $html .= '</script>';
  100.     return $html;
  101. }
  102.  
  103. function cmpname($a, $b) {
  104.     return ($a['title'] > $b['title']);
  105. }
  106.  
  107. function widget_7_table() {
  108.     $view = json_decode(call_pf_script("podio_view_get.pf", ["app_id" => 20894955, "view_id" => 38147362, "raw" => 0]), true);
  109.     $html = '<h4 class="card-title">Tabular Data</h4>';
  110.     $html .= '<table class="table table-bordered"><thead><tr><th>Name</th><th>Progress</th><th class="text-right">Amount</th><th class="text-center">Due Date</th></tr></thead><tbody>';
  111.     $cnt = intval(rand(2, 9));
  112.     foreach ( $view as $row ) {
  113.         $barclass = "bg-success";
  114.         if ( $row['progress'] < 80 ) $barclass="bg-primary";
  115.         if ( $row['progress'] < 60 ) $barclass="bg-warning";
  116.         if ( $row['progress'] < 40 ) $barclass="bg-info";
  117.         if ( $row['progress'] < 20 ) $barclass="bg-danger";
  118.         $bar = '<div class="progress-bar '.$barclass.'" role="progressbar" style="width: '.$row['progress'].'%" aria-valuenow="'.$row['progress'].'" aria-valuemin="0" aria-valuemax="100">'.$row['progress'].'%</div>';
  119.         $html .= '<tr><td>' . $row['title'] . '</td><td>' .
  120.             $bar . '</td><td class="text-right">$ ' . number_format($row['amount'], 0, '.', ',') .
  121.             '</td><td class="text-center">'.$row['due-date'].'</td></tr>';
  122.     }
  123.     $html .= '</tbody></table>';
  124.     return $html;
  125. }
  126.  
  127. if ( $widget == 1 ) return widget_1_progress();
  128. if ( $widget == 2 ) return widget_2_counter();
  129. if ( $widget == 3 ) return widget_3_gauge();
  130. if ( $widget == 4 ) return widget_4_text();
  131. if ( $widget == 5 ) return widget_5_barchart();
  132. if ( $widget == 6 ) return widget_6_linechart();
  133. if ( $widget == 7 ) return widget_7_table();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top