Advertisement
sigitsuryono25

rest api

Oct 21st, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2.  
  3. header("Content-Type: application/json");
  4.  
  5. defined('BASEPATH') OR exit('No direct script access allowed');
  6.  
  7. class Restapi extends CI_Controller {
  8.  
  9. function routes() {
  10. $type = $this->input->get('cluster');
  11. $data['type'] = "FeatureCollection";
  12. $data['features'] = [];
  13. $features['type'] = "Feature";
  14. $features['properties'] = ['color' => $this->getTopPackage($type), 'opacity' => 0.6];
  15. $coordinates = [];
  16. $geometry = [];
  17. $geometry['coordinates'] = [];
  18.  
  19. $q = $this->db->query("SELECT * FROM `tb_outer_point` WHERE cluster IN ('$type')")->result();
  20. foreach ($q as $p) {
  21. $point = [(double) $p->lng, (double) $p->lat];
  22. array_push($coordinates, $point);
  23. }
  24. $ft = $coordinates;
  25. $features['geometry'] = ['type' => "Polygon", "coordinates" => [$ft]];
  26. array_push($data['features'], $features);
  27.  
  28.  
  29. echo json_encode($data);
  30. }
  31.  
  32. private function getTopPackage($cluster) {
  33. if ($cluster == "ALL") {
  34. $topOne = $this->db->query("SELECT * FROM `v_package_most_used_all` LIMIT 1")->row();
  35. } else {
  36. $topOne = $this->db->query("SELECT PACKAGE, COUNT(PACKAGE) as used, colors FROM `package_trx_171_1911`
  37. INNER JOIN tb_package ON PACKAGE=tb_package.package_name
  38. WHERE MICRO_CLUSTER IN ('$cluster') GROUP BY PACKAGE ORDER BY used DESC LIMIT 1")->row();
  39. }
  40. return $topOne->colors;
  41. }
  42.  
  43. }
  44.  
  45. /* End of file Restapi.php */
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement