forked from cristiroma/countries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
56 lines (47 loc) · 1.57 KB
/
bootstrap.php
File metadata and controls
56 lines (47 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require __DIR__ . '/vendor/autoload.php';
global $cfg;
$cfg = json_decode(file_get_contents(__DIR__ . '/config.json'));
$isDevMode = TRUE;
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => $cfg->database->user,
'password' => $cfg->database->pass,
'dbname' => $cfg->database->db,
);
$config = Setup::createYAMLMetadataConfiguration(array(__DIR__ . "/src/Entity"), $isDevMode);
$em = EntityManager::create($dbParams, $config);
function slugify($string) {
$result = strtolower($string);
$result = preg_replace("/[^a-z0-9\s-]/", "", $result);
$result = trim(preg_replace("/[\s-]+/", " ", $result));
$result = preg_replace("/\s/", "-", $result);
return $result;
}
function get_countries() {
global $em;
$q = $em->createQuery('SELECT c FROM Country c ORDER by c.name');
return $q->getResult();
}
function get_country_by_code3l($code3l) {
global $em;
$q = $em->createQuery('SELECT c FROM Country c WHERE c.code3l = ?1');
$q->setParameter(1, $code3l);
return $q->getOneOrNullResult();
}
function get_country_regions($id) {
global $em;
$q = $em->createQuery('SELECT r FROM CountryRegion cr JOIN Region r WHERE cr.regionId = r.id AND cr.countryId = ?1');
$q->setParameter(1, $id);
return $q->getResult();
}
function set_country_gis($country_id, $latitude, $longitude, $zoom) {
$conn = db_connect();
$stmt = $conn->prepare('UPDATE country SET latitude=?, longitude=?, zoom=? WHERE id=?');
$stmt->bind_param("ddii", $latitude, $longitude, $zoom, $country_id);
$stmt->execute();
$stmt->close();
$conn->close();
}