|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverCommerce\ContactAdmin\Model; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\ORM\DataObject; |
|
6
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText as HTMLText; |
|
7
|
|
|
use SilverStripe\Security\Member; |
|
8
|
|
|
use SilverStripe\Security\Permission; |
|
9
|
|
|
use SilverStripe\Forms\RequiredFields; |
|
10
|
|
|
use SilverStripe\Forms\GridField\GridField; |
|
11
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
|
12
|
|
|
use SilverStripe\TagField\TagField; |
|
13
|
|
|
use SilverCommerce\ContactAdmin\Model\ContactTag; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Notes on a particular contact |
|
17
|
|
|
* |
|
18
|
|
|
* @property string Content |
|
19
|
|
|
* @property bool Flag |
|
20
|
|
|
* |
|
21
|
|
|
* @method Contact Contact |
|
22
|
|
|
* |
|
23
|
|
|
* @author ilateral |
|
24
|
|
|
* @package Contacts |
|
25
|
|
|
*/ |
|
26
|
|
|
class ContactNote extends DataObject |
|
27
|
|
|
{ |
|
28
|
|
|
private static $table_name = 'ContactNote'; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
private static $db = [ |
|
|
|
|
|
|
31
|
|
|
"Content" => "Text", |
|
32
|
|
|
"Flag" => "Boolean" |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
36
|
|
|
"Contact" => Contact::class |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
private static $casting = [ |
|
|
|
|
|
|
40
|
|
|
'FlaggedNice' => 'Boolean' |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
private static $summary_fields = [ |
|
|
|
|
|
|
44
|
|
|
"FlaggedNice" => "Flagged", |
|
45
|
|
|
"Content.Summary" => "Content", |
|
46
|
|
|
"Created" => "Created" |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Has this note been flagged? If so, return a HTML Object that |
|
51
|
|
|
* can be loaded into a gridfield. |
|
52
|
|
|
* |
|
53
|
|
|
* @return DBHTMLText |
|
|
|
|
|
|
54
|
|
|
*/ |
|
55
|
|
|
public function getFlaggedNice() |
|
56
|
|
|
{ |
|
57
|
|
|
$obj = HTMLText::create(); |
|
58
|
|
|
$obj->setValue(($this->Flag)? '<span class="red">✱</span>' : ''); |
|
59
|
|
|
|
|
60
|
|
|
$this->extend("updateFlaggedNice", $obj); |
|
61
|
|
|
|
|
62
|
|
|
return $obj; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function canView($member = null) |
|
66
|
|
|
{ |
|
67
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
68
|
|
|
|
|
69
|
|
|
if ($extended !== null) { |
|
70
|
|
|
return $extended; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $this->Contact()->canView($member); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function canCreate($member = null, $context = []) |
|
77
|
|
|
{ |
|
78
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member, $context); |
|
79
|
|
|
|
|
80
|
|
|
if ($extended !== null) { |
|
81
|
|
|
return $extended; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if (!$member) { |
|
85
|
|
|
$member = Member::currentUser(); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if ($member && Permission::checkMember($member->ID, "CONTACTS_MANAGE")) { |
|
89
|
|
|
return true; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return false; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function canEdit($member = null) |
|
96
|
|
|
{ |
|
97
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
98
|
|
|
|
|
99
|
|
|
if ($extended !== null) { |
|
100
|
|
|
return $extended; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $this->Contact()->canEdit($member); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function canDelete($member = null, $context = []) |
|
|
|
|
|
|
107
|
|
|
{ |
|
108
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
109
|
|
|
|
|
110
|
|
|
if ($extended !== null) { |
|
111
|
|
|
return $extended; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $this->Contact()->canDelete($member); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|