Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Content-Type: application/json");
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Restapi extends CI_Controller {
- function routes() {
- $type = $this->input->get('cluster');
- $data['type'] = "FeatureCollection";
- $data['features'] = [];
- $features['type'] = "Feature";
- $features['properties'] = ['color' => $this->getTopPackage($type), 'opacity' => 0.6];
- $coordinates = [];
- $geometry = [];
- $geometry['coordinates'] = [];
- $q = $this->db->query("SELECT * FROM `tb_outer_point` WHERE cluster IN ('$type')")->result();
- foreach ($q as $p) {
- $point = [(double) $p->lng, (double) $p->lat];
- array_push($coordinates, $point);
- }
- $ft = $coordinates;
- $features['geometry'] = ['type' => "Polygon", "coordinates" => [$ft]];
- array_push($data['features'], $features);
- echo json_encode($data);
- }
- private function getTopPackage($cluster) {
- if ($cluster == "ALL") {
- $topOne = $this->db->query("SELECT * FROM `v_package_most_used_all` LIMIT 1")->row();
- } else {
- $topOne = $this->db->query("SELECT PACKAGE, COUNT(PACKAGE) as used, colors FROM `package_trx_171_1911`
- INNER JOIN tb_package ON PACKAGE=tb_package.package_name
- WHERE MICRO_CLUSTER IN ('$cluster') GROUP BY PACKAGE ORDER BY used DESC LIMIT 1")->row();
- }
- return $topOne->colors;
- }
- }
- /* End of file Restapi.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement