/
Location.php
53 lines (50 loc) · 1.59 KB
/
Location.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* Location
* @package: Omeka
*/
class Location extends Omeka_Record_AbstractRecord implements Zend_Acl_Resource_Interface
{
public $item_id;
public $latitude;
public $longitude;
public $zoom_level;
public $map_type;
public $address;
/**
* Validate this location before saving.
*/
protected function _validate()
{
if (empty($this->item_id)) {
$this->addError('item_id', __('Location requires an item ID.'));
}
// An item must exist.
if (!$this->getTable('Item')->exists($this->item_id)) {
$this->addError('item_id', __('Location requires a valid item ID.'));
}
// An item can only have one location. This assumes that updating an
// existing location will never modify the item ID.
if (!$this->exists() && $this->getTable()->findBy(array('item_id' => $this->item_id))) {
$this->addError('latitude', __('A location already exists for the provided item.'));
}
if (empty($this->latitude)) {
$this->addError('latitude', __('Location requires a latitude.'));
}
if (empty($this->longitude)) {
$this->addError('longitude', __('Location requires a longitude.'));
}
if (empty($this->zoom_level)) {
$this->addError('zoom_level', __('Location requires a zoom level.'));
}
}
/**
* Identify Location records as relating to the Locations ACL resource.
*
* @return string
*/
public function getResourceId()
{
return 'Locations';
}
}