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