]> dev.renevier.net Git - syp.git/blob - inc/db/anydb.php
c88367a46277fb081309b020288e58eed88a6647
[syp.git] / inc / db / anydb.php
1 <?php
2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
3    license. */
4
5 class feature {
6     private $id = null;
7     private $lon = null;
8     private $lat = null;
9     private $imgpath = null;
10     private $title = null;
11     private $description = null;
12
13     const err_lonlat_invalid = 1;
14
15     function __construct ($id, $lon, $lat, $imgpath, $title, $description) {
16         $this->imgpath = $imgpath;
17
18         // id
19         if (isset ($id)) {
20             $this->id = $id;
21         }
22
23         // title
24         $this->title = $title;
25
26         // description
27         $this->description = $description;
28
29         // longitude
30         if (!isset ($lon) || !is_numeric ($lon) ||
31              ($lon < -180) || ($lon > 180)) {
32             throw new Exception ($this->err_lonlat_invalid);
33         }
34         $this->lon = $lon;
35
36         // latitude
37         if (!isset ($lat) || !is_numeric ($lat) ||
38              ($lat < -90) || ($lat > 90)) {
39             throw new Exception ($this->err_lonlat_invalid);
40         }
41         $this->lat = $lat;
42     }
43
44     public function __get ($attr) {
45         if (isset ($this->$attr)) return $this->$attr;
46             else throw new Exception ('Unknow attribute '.$attr);
47     }
48
49     public function __set ($attr,$value) {
50         throw new Exception ('properties can only be set in constructor');
51     }
52
53 }
54
55 interface anydbConnection {
56     const err_driver_unavailable = 1;
57     const err_connection = 2;
58     const err_unknown_database = 3;
59     const err_query = 3;
60
61     /*
62      * connect to database; That method may be called multiple times.
63      */
64     public function connect($host, $user, $pwd, $dbname, $dbprefix);
65
66     /*
67      * return true if users table already exists
68      */
69     public function users_table_exists();
70
71     /*
72      * create users table; if $error_if_exists is true; throws an err_query
73      * error in case users table already exists.
74      */
75     public function create_users_table($error_if_exists);
76
77     /*
78      * return true if items table already exists
79      */
80     public function items_table_exists();
81
82     /*
83      * create items table; if $error_if_exists is true; throws an err_query
84      * error in case items table already exists.
85      */
86     public function create_items_table($error_if_exists);
87
88     /*
89      * set password $pwd for user $usrname. If $usrname does not exist, create
90      * it.
91      */
92     public function setpwd($usrname, $pwd);
93
94     /*
95      * check that $pwd_md5 is md5 for $username password.
96      */
97     public function checkpwdmd5($usrname, $pwd_md5);
98
99     /*
100      * saves feature in database. If feature has an id, feature will be updated
101      * in database; otherwise it will be created. Returns saved feature
102      */
103     public function save_feature($feature);
104
105     /*
106      * delete feature from database. Returns true in case of success, even if
107      * image was not referenced in the database.
108      */
109     public function delete_feature($feature);
110
111     /*
112      * Returns feature with given id. If none exists, returns null.
113      */
114     public function getfeature($id);
115
116     /*
117      * returns an array of available features
118      */
119     public function listfeatures();
120
121     /*
122      * returns true if a feature with imgpath exists
123      */
124     public function imgpath_exists($imgpath);
125
126     /*
127      * returns Minimum Bounding Rectangle containing all feature locations.
128      * That function must return a result even if database is not functional.
129      * Minimum Bounding Rectangle is presented as an Array:
130      *      [bottom, left, top, right]
131      */
132     public function mbr();
133
134     /*
135      * get name of database backend
136      */
137     public function getdbname();
138 }
139 ?>