Browse Source

Use 'Paris' ORM

master
Chimo 2 years ago
parent
commit
9e6cbace1e
4 changed files with 137 additions and 43 deletions
  1. +2
    -1
      private/composer.json
  2. +126
    -1
      private/composer.lock
  3. +3
    -32
      private/src/class/Site.php
  4. +6
    -9
      public/index.php

+ 2
- 1
private/composer.json View File

@ -1,5 +1,6 @@
{
"require": {
"guzzlehttp/guzzle": "~6.0"
"guzzlehttp/guzzle": "~6.0",
"j4mie/paris": "^1.5"
}
}

+ 126
- 1
private/composer.lock View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "35a239f26f96a30f3493aef7e0f87f9b",
"content-hash": "9c0f474e365a7b8c8b056361cdbf31a7",
"packages": [
{
"name": "guzzlehttp/guzzle",
@ -189,6 +189,131 @@
],
"time": "2018-12-04T20:46:45+00:00"
},
{
"name": "j4mie/idiorm",
"version": "v1.5.6",
"source": {
"type": "git",
"url": "https://github.com/j4mie/idiorm.git",
"reference": "ee3022fcf71232309112714ca4a7760105002f99"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/j4mie/idiorm/zipball/ee3022fcf71232309112714ca4a7760105002f99",
"reference": "ee3022fcf71232309112714ca4a7760105002f99",
"shasum": ""
},
"require": {
"php": ">=5.2.0"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"phpunit/phpunit": "^4.8"
},
"type": "library",
"autoload": {
"classmap": [
"idiorm.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-2-Clause",
"BSD-3-Clause",
"BSD-4-Clause"
],
"authors": [
{
"name": "Simon Holywell",
"email": "treffynnon@php.net",
"homepage": "http://simonholywell.com",
"role": "Maintainer"
},
{
"name": "Jamie Matthews",
"email": "jamie.matthews@gmail.com",
"homepage": "http://j4mie.org",
"role": "Developer"
},
{
"name": "Durham Hale",
"email": "me@durhamhale.com",
"homepage": "http://durhamhale.com",
"role": "Maintainer"
}
],
"description": "A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5",
"homepage": "http://j4mie.github.com/idiormandparis",
"keywords": [
"idiorm",
"orm",
"query builder"
],
"time": "2018-05-30T23:57:49+00:00"
},
{
"name": "j4mie/paris",
"version": "v1.5.6",
"source": {
"type": "git",
"url": "https://github.com/j4mie/paris.git",
"reference": "ec43a1f7f59d237c147495d29523da52e375f9e7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/j4mie/paris/zipball/ec43a1f7f59d237c147495d29523da52e375f9e7",
"reference": "ec43a1f7f59d237c147495d29523da52e375f9e7",
"shasum": ""
},
"require": {
"j4mie/idiorm": "1.5.*",
"php": ">=5.2.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
},
"type": "library",
"autoload": {
"classmap": [
"paris.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-2-Clause",
"BSD-3-Clause",
"BSD-4-Clause"
],
"authors": [
{
"name": "Simon Holywell",
"email": "treffynnon@php.net",
"homepage": "http://simonholywell.com",
"role": "Maintainer"
},
{
"name": "Jamie Matthews",
"email": "jamie.matthews@gmail.com",
"homepage": "http://j4mie.org",
"role": "Developer"
},
{
"name": "Durham Hale",
"email": "me@durhamhale.com",
"homepage": "http://durhamhale.com",
"role": "Maintainer"
}
],
"description": "A lightweight Active Record implementation for PHP5, built on top of Idiorm",
"homepage": "http://j4mie.github.com/idiormandparis",
"keywords": [
"Active Record",
"model",
"orm",
"paris"
],
"time": "2017-03-21T02:13:30+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",


+ 3
- 32
private/src/class/Site.php View File

@ -3,36 +3,7 @@
require realpath(dirname(__FILE__)) . '/Coords.php';
require realpath(dirname(__FILE__)) . '/CurrentConditions.php';
class Site {
private $id;
private $code;
private $coords;
private $name;
private $province;
public function __construct($code, $name, $province, $coords = null) {
$this->code = (string)$code;
$this->coords = $coords;
$this->name = (string)$name;
$this->province = (string)$province;
}
public function getName() {
return $this->name;
}
public function getCode() {
return $this->code;
}
public function getProvince() {
return $this->province;
}
public function getCoords() {
return $this->coords;
}
class Site extends Model {
public function fillCoords() {
$code = $this->code;
$province = $this->province;
@ -48,9 +19,9 @@ class Site {
$location = $this->getLocationInfo($xml);
$coords = new Coords((string)$location['lat'], (string)$location['lon']);
$location = new Coords((string)$location['lat'], (string)$location['lon']);
$this->coords = $coords;
$this->location = $location;
return $this;
}


+ 6
- 9
public/index.php View File

@ -17,17 +17,14 @@ if (!isset($_GET['lat']) || !isset($_GET['lon'])) {
}
// DB Connection
$dbh = db($config['dbUser'], $config['dbPassword'], $config['dbName']);
ORM::configure('pgsql:dbname=' . $config['dbName']);
ORM::configure('username', $config['dbUser']);
ORM::configure('password', $config['dbPassword']);
// Get the closest weather station to us
$statement = $dbh->prepare('SELECT code, name, province FROM site order by location <-> ST_MakePoint(:lon, :lat) limit 1');
$statement->bindValue(':lon', $_GET['lon'], PDO::PARAM_INT);
$statement->bindValue(':lat', $_GET['lat'], PDO::PARAM_INT);
$statement->execute();
$row = $statement->fetch(PDO::FETCH_ASSOC);
$site = new Site($row['code'], $row['name'], $row['province']);
$site = Site::raw_query(
'SELECT * FROM site order by location <-> ST_MakePoint(:lon, :lat)',
array('lon' => $_GET['lon'], 'lat' => $_GET['lat']))->find_one();
$currentConditions = $site->getCurrentConditions();


Loading…
Cancel
Save