Schema/Result/Message.pm

filter: Statementstmt 100% 63 / 63 Branchbran 100% 16 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 86 / 86 CC 9 SCAR 17.0
CC
9
Cov
100%
insert
8.0
FOREIGNBUILDARGS
2.0
BEGIN
1.0
CRAP 5.5
« Schema/Result/Zone.pm ↑ Summary Schema/Populate/StateLocale.pm »
1 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Interchange6::Schema::Result::Message;
4  
5 =head1 NAME
6  
7 Interchange6::Schema::Result::Message
8  
9 =cut
10  
11 2 use Interchange6::Schema::Candy -components =>
12 2 ▶ [qw(Tree::AdjacencyList InflateColumn::DateTime TimeStamp)];
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 DESCRIPTION
17  
18 Shared messages table for blog, order comments, reviews, bb, etc.
19  
20 =head1 ACCESSORS
21  
22 =head2 type
23  
24 A short-cut accessor which takes a message type name (L<Interchange6::Schema::Result::MessageType/name>) as argument and sets L</message_types_id> to the appropriate value;
25  
26 =cut
27  
28 2 has type => ( is => 'rw', );
29  
30 =head2 messages_id
31  
32 Primary key.
33  
34 =cut
35  
36 2 primary_column messages_id => {
37 data_type => "integer",
38 is_auto_increment => 1,
39 };
40  
41 =head2 title
42  
43 The title of the message.
44  
45 =cut
46  
47 2 column title => {
48 data_type => "varchar",
49 default_value => "",
50 size => 255
51 };
52  
53 =head2 message_types_id
54  
55 Foreign key constraint on L<Interchange6::Schema::Result::MessageType/message_types_id>
56 via L</message_type> relationship.
57  
58 =cut
59  
60 2 column message_types_id => {
61 data_type => "integer",
62 };
63  
64 =head2 uri
65  
66 The uri of the message data.
67  
68 Unique constraint.
69  
70 =cut
71  
72 2 unique_column uri => {
73 data_type => "varchar",
74 is_nullable => 1,
75 size => 255
76 };
77  
78 =head2 format
79  
80 The format of the text held in L</content>, e.g. plain, html or markdown.
81 Defaults to 'plain'.
82  
83 =cut
84  
85 2 column format => {
86 data_type => "varchar",
87 size => 32,
88 default_value => "plain",
89 };
90  
91 =head2 content
92  
93 Content for the message.
94  
95 =cut
96  
97 2 column content => {
98 data_type => "text"
99 };
100  
101 =head2 summary
102  
103 Summary/teaser for L</content>.
104  
105 Defaults to empty string.
106  
107 =cut
108  
109 2 column summary => {
110 data_type => "varchar",
111 size => 1024,
112 default_value => '',
113 };
114  
115 =head2 author_users_id
116  
117 Foreign key constraint on L<Interchange6::Schema::Result::User/users_id>
118 via L</author> relationship. Is nullable.
119  
120 =cut
121  
122 2 column author_users_id => {
123 data_type => "integer",
124 is_nullable => 1
125 };
126  
127 =head2 rating
128  
129 Numeric rating of the message by a user.
130  
131 =cut
132  
133 2 column rating => {
134 data_type => "numeric",
135 default_value => 0,
136 size => [ 4, 2 ],
137 };
138  
139 =head2 recommend
140  
141 Do you recommend the message? Default is no. Is nullable.
142  
143 =cut
144  
145 2 column recommend => {
146 data_type => "boolean",
147 is_nullable => 1
148 };
149  
150 =head2 public
151  
152 Is this public viewable? Default is no.
153  
154 =cut
155  
156 2 column public => {
157 data_type => "boolean",
158 default_value => 0,
159 };
160  
161 =head2 approved
162  
163 Has this been approved by someone with proper rights?
164  
165 =cut
166  
167 2 column approved => {
168 data_type => "boolean",
169 default_value => 0,
170 };
171  
172 =head2 approved_by_users_id
173  
174 Foreign key constraint on L<Interchange6::Schema::Result::User/users_id>
175 via L</approved_by> relationship. Is nullable
176  
177 =cut
178  
179 2 column approved_by_users_id => {
180 data_type => "integer",
181 is_nullable => 1
182 };
183  
184 =head2 parent_id
185  
186 For use by L<DBIx::Class::Tree::AdjacencyList> this defines the L</messages_id>
187 of the parent of this message (if any).
188  
189 =cut
190  
191 2 column parent_id => { data_type => "integer", is_nullable => 1 };
192  
193 =head2 created
194  
195 Date and time when this record was created returned as L<DateTime> object.
196 Value is auto-set on insert.
197  
198 =cut
199  
200 2 column created => {
201 data_type => "datetime",
202 set_on_create => 1,
203 };
204  
205 =head2 last_modified
206  
207 Date and time when this record was last modified returned as L<DateTime> object.
208 Value is auto-set on insert and update.
209  
210 =cut
211  
212 2 column last_modified => {
213 data_type => "datetime",
214 set_on_create => 1,
215 set_on_update => 1,
216 };
217  
218 =head1 RELATIONS
219  
220 =head2 author
221  
222 Type: belongs_to
223  
224 Related object: L<Interchange6::Schema::Result::User>
225  
226 =cut
227  
228 2 belongs_to
229 author => 'Interchange6::Schema::Result::User',
230 { 'foreign.users_id' => 'self.author_users_id' },
231 { join_type => 'left' };
232  
233 =head2 approved_by
234  
235 Type: belongs_to
236  
237 Related object: L<Interchange6::Schema::Result::User>
238  
239 =cut
240  
241 2 belongs_to
242 approved_by => 'Interchange6::Schema::Result::User',
243 { 'foreign.users_id' => 'self.approved_by_users_id' },
244 { join_type => 'left' };
245  
246 =head2 message_type
247  
248 Type: belongs_to
249  
250 Related object: L<Interchange6::Schema::Result::MessageType>
251  
252 =cut
253  
254 2 belongs_to
255 message_type => 'Interchange6::Schema::Result::MessageType',
256 'message_types_id';
257  
258 =head2 order_comment
259  
260 Type: might_have
261  
262 Related object: L<Interchange6::Schema::Result::OrderComment>
263  
264 =cut
265  
266 2 might_have
267 order_comment => 'Interchange6::Schema::Result::OrderComment',
268 'messages_id';
269  
270 =head2 orders
271  
272 Type: many_to_many
273  
274 Accessor to related Order results.
275  
276 =cut
277  
278 2 many_to_many orders => "order_comment", "order";
279  
280 =head2 product_messages
281  
282 Type: has_many
283  
284 Related object: L<Interchange6::Schema::Result::ProductMessage>
285  
286 =cut
287  
288 2 has_many
289 product_messages => 'Interchange6::Schema::Result::ProductMessage',
290 'messages_id';
291  
292 =head2 products
293  
294 Type: many_to_many
295  
296 Accessor to related Product results.
297  
298 =cut
299  
300 2 many_to_many products => "product_messages", "product";
301  
302 =head2 navigation_messages
303  
304 Type: has_many
305  
306 Related object: L<Interchange6::Schema::Result::NavigationMessage>
307  
308 =cut
309  
310 2 has_many
311 navigation_messages => 'Interchange6::Schema::Result::NavigationMessage',
312 'messages_id';
313  
314 =head2 navigations
315  
316 Type: many_to_many
317  
318 Accessor to related Navigation results.
319  
320 =cut
321  
322 2 many_to_many navigations => "navigation_messages", "navigation";
323  
324 =head2 media_messages
325  
326 Type: has_many
327  
328 Related object: L<Interchange6::Schema::Result::MediaMessage>
329  
330 =cut
331  
332 2 has_many
333 media_messages => "Interchange6::Schema::Result::MediaMessage",
334 "messages_id",
335 { cascade_copy => 0, cascade_delete => 0 };
336  
337 =head2 media
338  
339 Type: many_to_many with media
340  
341 =cut
342  
343 2 many_to_many media => "media_messages", "media";
344  
345 =head1 INHERITED METHODS
346  
347 =head2 DBIx::Class::Tree::AdjacencyList
348  
349 =over 4
350  
351 =item *
352  
353 L<parent|DBIx::Class::Tree::AdjacencyList/parent>
354  
355 =item *
356  
357 L<ancestors|DBIx::Class::Tree::AdjacencyList/ancestors>
358  
359 =item *
360  
361 L<has_descendant|DBIx::Class::Tree::AdjacencyList/has_descendant>
362  
363 =item *
364  
365 L<parents|DBIx::Class::Tree::AdjacencyList/parents>
366  
367 =item *
368  
369 L<children|DBIx::Class::Tree::AdjacencyList/children>
370  
371 =item *
372  
373 L<attach_child|DBIx::Class::Tree::AdjacencyList/attach_child>
374  
375 =item *
376  
377 L<siblings|DBIx::Class::Tree::AdjacencyList/siblings>
378  
379 =item *
380  
381 L<attach_sibling|DBIx::Class::Tree::AdjacencyList/attach_sibling>
382  
383 =item *
384  
385 L<is_leaf|DBIx::Class::Tree::AdjacencyList/is_leaf>
386  
387 =item *
388  
389 L<is_root|DBIx::Class::Tree::AdjacencyList/is_root>
390  
391 =item *
392  
393 L<is_branch|DBIx::Class::Tree::AdjacencyList/is_branch>
394  
395 =back
396  
397 =cut
398  
399 # define parent column
400  
401 2 __PACKAGE__->parent_column('parent_id');
402  
403 =head1 METHODS
404  
405 =head2 FOREIGNBUILDARGS
406  
407 Remove L</type> attribute from call to parent class.
408  
409 =cut
410  
411 sub FOREIGNBUILDARGS {
412 105 ▶ my ( $self, $attrs ) = @_;
Subroutine FOREIGNBUILDARGS: called CC=2 SCAR=6.9
Pod documented
413  
414 105 ▶ if ( defined $attrs->{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs->{"type"}) 102 3 105
415 102 delete $attrs->{type};
416 }
417 105 return $attrs;
418 }
419  
420 =head2 insert
421  
422 Overload insert to set message_types_id if required. Throw exception if requested message type
423 is not active. See L<Interchange6::Schema::Result::MessageType/active>.
424  
425 =cut
426  
427 sub insert {
428 105 ▶ my $self = shift;
Subroutine insert: called CC=8 SCAR=20.8
Pod documented
429  
430 105 my $rset_message_type =
431 $self->result_source->schema->resultset("MessageType");
432  
433 105 ▶ if ( defined $self->type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->type) 102 3 105
434  
435 102 my $name = $self->type;
436  
437 102 ▶ if ( defined $self->message_types_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->message_types_id) { } 3 99 102
438 3 ▶ $self->throw_exception("mismatched type settings")
Branch: 1 branch
BranchTrueFalseTotal
if $name ne $self->message_type->name 2 1 3
439 if $name ne $self->message_type->name;
440 }
441 else {
442  
443 99 my $rset = $rset_message_type->search( { name => $self->type } );
444  
445 99 ▶ if ( $rset->has_rows ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rset->has_rows) { } 97 2 99
446 97 my $result = $rset->next;
447 97 $self->set_column( message_types_id => $result->id );
448 }
449 else {
450 2 $self->throw_exception(
451 qq(MessageType with name "$name" does not exist));
452 }
453 }
454 }
455  
456 101 ▶ if ( defined $self->message_types_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->message_types_id) { } 99 2 101
457  
458 # make sure message type is active
459  
460 99 my $rset = $rset_message_type->search(
461 { message_types_id => $self->message_types_id } );
462  
463 99 ▶ if ( $rset->has_rows ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rset->has_rows) { } 98 1 99
464 98 my $result = $rset->next;
465 98 ▶ if ( $result->active ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->active) { } 96 2 98
466 96 return $self->next::method;
467 }
468 else {
469 2 $self->throw_exception( q(MessageType with name ")
470 . $result->name
471 . q(" is not active) );
472 }
473 }
474 else {
475 1 $self->throw_exception(
476 q(message_types_id value does not exist in MessageType));
477 }
478 }
479 else {
480 2 $self->throw_exception("Cannot create message without type");
481 }
482 }
483  
484 2 1;
« Schema/Result/Zone.pm ↑ Summary Schema/Populate/StateLocale.pm »