3 * Table Definition for notice_location
6 class Notice_location extends Managed_DataObject
8 public $__table = 'notice_location'; // table name
9 public $notice_id; // int(4) primary_key not_null
10 public $lat; // decimal(10,7)
11 public $lon; // decimal(10,7)
12 public $location_id; // int(4)
13 public $location_ns; // int(4)
14 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
16 public static function schemaDef()
20 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice that is the reply'),
21 'lat' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'),
22 'lon' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'),
23 'location_id' => array('type' => 'int', 'description' => 'location id if possible'),
24 'location_ns' => array('type' => 'int', 'description' => 'namespace for location'),
25 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
27 'primary key' => array('notice_id'),
28 'foreign keys' => array(
29 'notice_location_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
32 'notice_location_location_id_idx' => array('location_id'),
37 static function locFromStored(Notice $stored)
39 $loc = new Notice_location();
40 $loc->notice_id = $stored->getID();
41 if (!$loc->find(true)) {
42 throw new NoResultException($loc);
44 return $loc->asLocation();
47 static function fromLocation(Location $location)
49 $notloc = new Notice_location();
50 $notloc->lat = $location->lat;
51 $notloc->lon = $location->lon;
52 $notloc->location_ns = $location->location_ns;
53 $notloc->location_id = $location->location_id;
57 public function asLocation()
61 if (!empty($this->location_id) && !empty($this->location_ns)) {
62 $location = Location::fromId($this->location_id, $this->location_ns);
65 if (is_null($location)) { // no ID, or Location::fromId() failed
66 $location = Location::fromLatLon($this->lat, $this->lon);
69 if (is_null($location)) {
70 throw new ServerException('Location could not be looked up from existing data.');