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