@@ 14-187 (lines=174) @@ | ||
11 | * @property string $URLSegment |
|
12 | * @property int $BlogID |
|
13 | */ |
|
14 | class BlogCategory extends DataObject implements CategorisationObject |
|
15 | { |
|
16 | ||
17 | /** |
|
18 | * Use an exception code so that attempted writes can continue on |
|
19 | * duplicate errors. |
|
20 | * |
|
21 | * @const string |
|
22 | * This must be a string because ValidationException has decided we can't use int |
|
23 | */ |
|
24 | const DUPLICATE_EXCEPTION = "DUPLICATE"; |
|
25 | ||
26 | /** |
|
27 | * @var array |
|
28 | */ |
|
29 | private static $db = array( |
|
30 | 'Title' => 'Varchar(255)', |
|
31 | ); |
|
32 | ||
33 | /** |
|
34 | * @var array |
|
35 | */ |
|
36 | private static $has_one = array( |
|
37 | 'Blog' => 'Blog', |
|
38 | ); |
|
39 | ||
40 | /** |
|
41 | * @var array |
|
42 | */ |
|
43 | private static $belongs_many_many = array( |
|
44 | 'BlogPosts' => 'BlogPost', |
|
45 | ); |
|
46 | ||
47 | /** |
|
48 | * @var array |
|
49 | */ |
|
50 | private static $extensions = array( |
|
51 | 'URLSegmentExtension', |
|
52 | ); |
|
53 | ||
54 | /** |
|
55 | * @return DataList |
|
56 | */ |
|
57 | public function BlogPosts() |
|
58 | { |
|
59 | $blogPosts = parent::BlogPosts(); |
|
60 | ||
61 | $this->extend("updateGetBlogPosts", $blogPosts); |
|
62 | ||
63 | return $blogPosts; |
|
64 | } |
|
65 | ||
66 | /** |
|
67 | * {@inheritdoc} |
|
68 | */ |
|
69 | public function getCMSFields() |
|
70 | { |
|
71 | $fields = new FieldList( |
|
72 | TextField::create('Title', _t('BlogCategory.Title', 'Title')) |
|
73 | ); |
|
74 | ||
75 | $this->extend('updateCMSFields', $fields); |
|
76 | ||
77 | return $fields; |
|
78 | } |
|
79 | ||
80 | /** |
|
81 | * {@inheritdoc} |
|
82 | */ |
|
83 | protected function validate() |
|
84 | { |
|
85 | $validation = parent::validate(); |
|
86 | if($validation->valid()) { |
|
87 | // Check for duplicate categories |
|
88 | $blog = $this->Blog(); |
|
89 | if($blog && $blog->exists()) { |
|
90 | $existing = $blog->Categories()->filter('Title', $this->Title); |
|
91 | if($this->ID) { |
|
92 | $existing = $existing->exclude('ID', $this->ID); |
|
93 | } |
|
94 | if($existing->count() > 0) { |
|
95 | $validation->error(_t( |
|
96 | 'BlogCategory.Duplicate', |
|
97 | 'A blog category already exists with that name' |
|
98 | ), BlogCategory::DUPLICATE_EXCEPTION); |
|
99 | } |
|
100 | } |
|
101 | } |
|
102 | return $validation; |
|
103 | } |
|
104 | ||
105 | /** |
|
106 | * Returns a relative link to this category. |
|
107 | * |
|
108 | * @return string |
|
109 | */ |
|
110 | public function getLink() |
|
111 | { |
|
112 | return Controller::join_links($this->Blog()->Link(), 'category', $this->URLSegment); |
|
113 | } |
|
114 | ||
115 | /** |
|
116 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
|
117 | * |
|
118 | * @param null|Member $member |
|
119 | * |
|
120 | * @return bool |
|
121 | */ |
|
122 | public function canView($member = null) |
|
123 | { |
|
124 | $extended = $this->extendedCan(__FUNCTION__, $member); |
|
125 | ||
126 | if ($extended !== null) { |
|
127 | return $extended; |
|
128 | } |
|
129 | ||
130 | return $this->Blog()->canView($member); |
|
131 | } |
|
132 | ||
133 | /** |
|
134 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
|
135 | * |
|
136 | * @param null|Member $member |
|
137 | * |
|
138 | * @return bool |
|
139 | */ |
|
140 | public function canCreate($member = null) |
|
141 | { |
|
142 | $extended = $this->extendedCan(__FUNCTION__, $member); |
|
143 | ||
144 | if ($extended !== null) { |
|
145 | return $extended; |
|
146 | } |
|
147 | ||
148 | $permission = Blog::config()->grant_user_permission; |
|
149 | ||
150 | return Permission::checkMember($member, $permission); |
|
151 | } |
|
152 | ||
153 | /** |
|
154 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
|
155 | * |
|
156 | * @param null|Member $member |
|
157 | * |
|
158 | * @return bool |
|
159 | */ |
|
160 | public function canDelete($member = null) |
|
161 | { |
|
162 | $extended = $this->extendedCan(__FUNCTION__, $member); |
|
163 | ||
164 | if ($extended !== null) { |
|
165 | return $extended; |
|
166 | } |
|
167 | ||
168 | return $this->Blog()->canEdit($member); |
|
169 | } |
|
170 | ||
171 | /** |
|
172 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
|
173 | * |
|
174 | * @param null|Member $member |
|
175 | * |
|
176 | * @return bool |
|
177 | */ |
|
178 | public function canEdit($member = null) |
|
179 | { |
|
180 | $extended = $this->extendedCan(__FUNCTION__, $member); |
|
181 | ||
182 | if ($extended !== null) { |
|
183 | return $extended; |
|
184 | } |
|
185 | ||
186 | return $this->Blog()->canEdit($member); |
|
187 | } |
|
188 | } |
|
189 |
@@ 15-187 (lines=173) @@ | ||
12 | * @property string $URLSegment |
|
13 | * @property int $BlogID |
|
14 | */ |
|
15 | class BlogTag extends DataObject implements CategorisationObject |
|
16 | { |
|
17 | ||
18 | /** |
|
19 | * Use an exception code so that attempted writes can continue on |
|
20 | * duplicate errors. |
|
21 | * |
|
22 | * @const string |
|
23 | * This must be a string because ValidationException has decided we can't use int |
|
24 | */ |
|
25 | const DUPLICATE_EXCEPTION = "DUPLICATE"; |
|
26 | ||
27 | /** |
|
28 | * @var array |
|
29 | */ |
|
30 | private static $db = array( |
|
31 | 'Title' => 'Varchar(255)', |
|
32 | ); |
|
33 | ||
34 | /** |
|
35 | * @var array |
|
36 | */ |
|
37 | private static $has_one = array( |
|
38 | 'Blog' => 'Blog', |
|
39 | ); |
|
40 | ||
41 | /** |
|
42 | * @var array |
|
43 | */ |
|
44 | private static $belongs_many_many = array( |
|
45 | 'BlogPosts' => 'BlogPost', |
|
46 | ); |
|
47 | ||
48 | /** |
|
49 | * @var array |
|
50 | */ |
|
51 | private static $extensions = array( |
|
52 | 'URLSegmentExtension', |
|
53 | ); |
|
54 | ||
55 | /** |
|
56 | * @return DataList |
|
57 | */ |
|
58 | public function BlogPosts() |
|
59 | { |
|
60 | $blogPosts = parent::BlogPosts(); |
|
61 | ||
62 | $this->extend("updateGetBlogPosts", $blogPosts); |
|
63 | ||
64 | return $blogPosts; |
|
65 | } |
|
66 | ||
67 | /** |
|
68 | * {@inheritdoc} |
|
69 | */ |
|
70 | public function getCMSFields() |
|
71 | { |
|
72 | $fields = new FieldList( |
|
73 | TextField::create('Title', _t('BlogTag.Title', 'Title')) |
|
74 | ); |
|
75 | ||
76 | $this->extend('updateCMSFields', $fields); |
|
77 | ||
78 | return $fields; |
|
79 | } |
|
80 | ||
81 | /** |
|
82 | * {@inheritdoc} |
|
83 | */ |
|
84 | protected function validate() |
|
85 | { |
|
86 | $validation = parent::validate(); |
|
87 | if($validation->valid()) { |
|
88 | // Check for duplicate tags |
|
89 | $blog = $this->Blog(); |
|
90 | if($blog && $blog->exists()) { |
|
91 | $existing = $blog->Tags()->filter('Title', $this->Title); |
|
92 | if($this->ID) { |
|
93 | $existing = $existing->exclude('ID', $this->ID); |
|
94 | } |
|
95 | if($existing->count() > 0) { |
|
96 | $validation->error(_t( |
|
97 | 'BlogTag.Duplicate', |
|
98 | 'A blog tags already exists with that name' |
|
99 | ), BlogTag::DUPLICATE_EXCEPTION); |
|
100 | } |
|
101 | } |
|
102 | } |
|
103 | return $validation; |
|
104 | } |
|
105 | ||
106 | /** |
|
107 | * Returns a relative URL for the tag link. |
|
108 | * |
|
109 | * @return string |
|
110 | */ |
|
111 | public function getLink() |
|
112 | { |
|
113 | return Controller::join_links($this->Blog()->Link(), 'tag', $this->URLSegment); |
|
114 | } |
|
115 | ||
116 | /** |
|
117 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
|
118 | * |
|
119 | * @param null|Member $member |
|
120 | * |
|
121 | * @return bool |
|
122 | */ |
|
123 | public function canView($member = null) |
|
124 | { |
|
125 | $extended = $this->extendedCan(__FUNCTION__, $member); |
|
126 | ||
127 | if ($extended !== null) { |
|
128 | return $extended; |
|
129 | } |
|
130 | ||
131 | return $this->Blog()->canView($member); |
|
132 | } |
|
133 | ||
134 | /** |
|
135 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
|
136 | * |
|
137 | * @param null|Member $member |
|
138 | * |
|
139 | * @return bool |
|
140 | */ |
|
141 | public function canCreate($member = null) |
|
142 | { |
|
143 | $extended = $this->extendedCan(__FUNCTION__, $member); |
|
144 | ||
145 | if ($extended !== null) { |
|
146 | return $extended; |
|
147 | } |
|
148 | ||
149 | $permission = Blog::config()->grant_user_permission; |
|
150 | ||
151 | return Permission::checkMember($member, $permission); |
|
152 | } |
|
153 | ||
154 | /** |
|
155 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
|
156 | * |
|
157 | * @param null|Member $member |
|
158 | * |
|
159 | * @return bool |
|
160 | */ |
|
161 | public function canDelete($member = null) |
|
162 | { |
|
163 | $extended = $this->extendedCan(__FUNCTION__, $member); |
|
164 | ||
165 | if ($extended !== null) { |
|
166 | return $extended; |
|
167 | } |
|
168 | ||
169 | return $this->Blog()->canEdit($member); |
|
170 | } |
|
171 | ||
172 | /** |
|
173 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
|
174 | * |
|
175 | * @param null|Member $member |
|
176 | * |
|
177 | * @return bool |
|
178 | */ |
|
179 | public function canEdit($member = null) |
|
180 | { |
|
181 | $extended = $this->extendedCan(__FUNCTION__, $member); |
|
182 | ||
183 | if ($extended !== null) { |
|
184 | return $extended; |
|
185 | } |
|
186 | ||
187 | return $this->Blog()->canEdit($member); |
|
188 | } |
|
189 | } |
|
190 |