|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* saves all places searched for on the site. |
|
4
|
|
|
* |
|
5
|
|
|
* |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class GoogleMapSearchRecord extends DataObject |
|
9
|
|
|
{ |
|
10
|
|
|
private static $db = array( |
|
|
|
|
|
|
11
|
|
|
"IPAddres" => "Varchar(32)", |
|
12
|
|
|
"SearchedFor" => "Text" |
|
13
|
|
|
); |
|
14
|
|
|
|
|
15
|
|
|
private static $searcheabl_fields = array( |
|
16
|
|
|
"SearchedFor" => "PartialMatchFilter" |
|
17
|
|
|
); |
|
18
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
19
|
|
|
"SearchedFor" => "Searched for ..." |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
private static $has_one = array( |
|
|
|
|
|
|
23
|
|
|
"Member" => "Member", |
|
24
|
|
|
"Parent" => "SiteTree", |
|
25
|
|
|
"GoogleMapLocationsObject" => "GoogleMapLocationsObject" |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
public static function create_new($searchedFor, $parentID = 0, $addGoogleMapLocationsObjectOrItsID = false) |
|
29
|
|
|
{ |
|
30
|
|
|
$obj = new GoogleMapSearchRecord(); |
|
31
|
|
|
$obj->SearchedFor = $searchedFor; |
|
|
|
|
|
|
32
|
|
|
$obj->ParentID = $parentID; |
|
|
|
|
|
|
33
|
|
|
if ($addGoogleMapLocationsObjectOrItsID) { |
|
34
|
|
|
if ($addGoogleMapLocationsObjectOrItsID === true || $addGoogleMapLocationsObjectOrItsID === 1) { |
|
35
|
|
|
//create object |
|
36
|
|
|
$location = new GoogleMapLocationsObject(); |
|
37
|
|
|
$location->Address = $searchedFor; |
|
|
|
|
|
|
38
|
|
|
$location->Manual = false; |
|
|
|
|
|
|
39
|
|
|
$location->write(); |
|
40
|
|
|
$obj->GoogleMapLocationsObjectID = $location->ID; |
|
|
|
|
|
|
41
|
|
|
} else { |
|
42
|
|
|
$obj->GoogleMapLocationsObjectID = intval($addGoogleMapLocationsObjectOrItsID); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
$obj->write(); |
|
46
|
|
|
return $obj; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
public function onBeforeWrite() |
|
51
|
|
|
{ |
|
52
|
|
|
parent::onBeforeWrite(); |
|
53
|
|
|
$m = Member::currentUser(); |
|
54
|
|
|
if ($m) { |
|
55
|
|
|
$this->MemberID = $m->ID; |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
$this->IPAddres = Controller::curr()->getRequest()->getIP(); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
|
|
public function canDelete($member = null) |
|
64
|
|
|
{ |
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return bool |
|
70
|
|
|
*/ |
|
71
|
|
|
public function canEdit($member = null) |
|
72
|
|
|
{ |
|
73
|
|
|
return false; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|