2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
9 private $imgpath = null;
10 private $title = null;
11 private $description = null;
15 const err_lonlat_invalid = 1;
17 function __construct ($id, $lon, $lat, $imgpath, $title, $description, $date, $user) {
18 $this->imgpath = $imgpath;
26 $this->title = $title;
29 $this->description = $description;
38 if (!isset ($lon) || !is_numeric ($lon) ||
39 ($lon < -180) || ($lon > 180)) {
40 throw new Exception (self::err_lonlat_invalid);
45 if (!isset ($lat) || !is_numeric ($lat) ||
46 ($lat < -90) || ($lat > 90)) {
47 throw new Exception (self::err_lonlat_invalid);
52 public function __get ($attr) {
53 if (isset ($this->$attr)) return $this->$attr;
54 else throw new Exception ('Unknow attribute '.$attr);
57 public function __set ($attr,$value) {
58 throw new Exception ('properties can only be set in constructor');
63 interface anydbConnection {
64 const err_driver_unavailable = 1;
65 const err_connection = 2;
66 const err_unknown_database = 3;
70 * connect to database; That method may be called multiple times.
72 public function connect($host, $user, $pwd, $dbname, $dbprefix);
75 * return true if users table already exists
77 public function users_table_exists();
81 * throws an err_query error in case users table already exists.
83 public function create_users_table();
86 * return true if items table already exists
88 public function items_table_exists();
92 * throws an err_query error in case items table already exists.
94 public function create_items_table();
97 * returns true if $usrname is name of an existing user, false otherwise.
99 public function user_exists ($usrname);
102 * set password $pwd for user $usrname. If $usrname does not exist, create
104 * throws an err_query error in case $pwd is null
106 public function setpwd($usrname, $pwd);
109 * check that $pwd_md5 is md5 for $username password.
111 public function checkpwdmd5($usrname, $pwd_md5);
114 * saves feature in database. If feature has an id, feature will be updated
115 * in database; otherwise it will be created. Returns saved feature
117 public function save_feature($feature);
120 * delete feature from database. Returns true in case of success, even if
121 * image was not referenced in the database.
123 public function delete_feature($feature);
126 * Returns feature with given id. If none exists, returns null.
128 public function getfeature($id);
131 * returns an array of features managed by $user. If $user is undefined or
132 * if user is "admin", return all available features.
134 public function listfeatures($user);
137 * returns the most recent features sorted by date. If $num_features is not
138 * defined or is null, returns all features sorted by date.
140 public function mostrecentfeatures($num_features);
143 * returns true if a feature with imgpath exists
145 public function imgpath_exists($imgpath);
148 * get name of database backend
150 public function getdbname();