| 1 | package Crop::Object::Extern::Content; | ||
| 2 | use base qw / Crop::Object::Extern /; | ||
| 3 | |||
| 4 | =begin nd | ||
| 5 | Class: Crop::Object::Extern::Content | ||
| 6 | Link many-to-many. | ||
| 7 | |||
| 8 | Class that contains 'Content' declaration has a semantics 'main'. And this class presents 'table' content | ||
| 9 | with multiple strings. | ||
| 10 | |||
| 11 | (start code) | ||
| 12 | # Product has the order schema My::Order, My::Product, My::Order::Product | ||
| 13 | # Order class has EXT | ||
| 14 | product => { | ||
| 15 | cross => [ | ||
| 16 | type => 'content', | ||
| 17 | 'My::Order::Product' => {id => 'id_order'}, | ||
| 18 | 'My::Product' => {id_product => 'id'} | ||
| 19 | ], | ||
| 20 | view => 'product', | ||
| 21 | }, | ||
| 22 | (end code) | ||
| 23 | =cut | ||
| 24 | |||
| 25 | use v5.14; | ||
| 26 | use warnings; | ||
| 27 | |||
| 28 | use Crop::Error; | ||
| 29 | use Crop::Util 'load_class'; | ||
| 30 | use Crop::Object::Constants; | ||
| 31 | use Crop::Object::Warehouse::Lang::SQL::Query::Select::Node::Cross; | ||
| 32 | use Crop::Object::Warehouse::Lang::SQL::Query::Select::Node::Content; | ||
| 33 | |||
| 34 | use Crop::Debug; | ||
| 35 | |||
| 36 | =begin nd | ||
| 37 | Variable: our %Attributes | ||
| 38 | Class attributes: | ||
| 39 | |||
| 40 | cross - link definition | ||
| 41 | view - cached attribute where reuslt goes to | ||
| 42 | =cut | ||
| 43 | our %Attributes = ( | ||
| 44 | cross => undef, | ||
| 45 | view => {mode => 'read'}, | ||
| 46 | ); | ||
| 47 | |||
| 48 | =begin nd | ||
| 49 | Method: make_link ($parent) | ||
| 50 | Create node and link it to the $parent. | ||
| 51 | |||
| 52 | The 'clause' attribute of new node will not be established. Calling code musth to do that work. | ||
| 53 | |||
| 54 | Returns the 'content' node since calling code could set the 'clause' attribute for it. And the 'content' | ||
| 55 | attribute is the 'bottom' child of two new nodes. | ||
| 56 | |||
| 57 | Parameters: | ||
| 58 | $parent - parent node | ||
| 59 | |||
| 60 | Returns: | ||
| 61 | 'content' node - if ok | ||
| 62 | undef - otherwise | ||
| 63 | |||
| 64 | =cut | ||
| 65 | sub make_link { | ||
| 66 | my ($self, $parent) = @_; | ||
| 67 | |||
| 68 | my ($cross_class, $cross_bind, $content_class, $content_bind) = @{$self->{cross}}; | ||
| 69 | |||
| 70 | load_class $cross_class or return warn "OBJECT|CRIT: Can not parse declaration for non-existing class $cross_class"; | ||
| 71 | load_class $content_class or return warn "OBJECT|CRIT: Can not parse declaration for non-existing class $content_class"; | ||
| 72 | |||
| 73 | my $cross_node = Crop::Object::Warehouse::Lang::SQL::Query::Select::Node::Cross->new( | ||
| 74 | class => $cross_class, | ||
| 75 | parent => $parent, | ||
| 76 | parent_link => $cross_bind, | ||
| 77 | ); | ||
| 78 | |||
| 79 | $parent->child->Push($cross_node); | ||
| 80 | |||
| 81 | $parent = $cross_node; | ||
| 82 | my $content_node = Crop::Object::Warehouse::Lang::SQL::Query::Select::Node::Content->new( | ||
| 83 | class => $content_class, | ||
| 84 | parent => $parent, | ||
| 85 | parent_link => $content_bind, | ||
| 86 | parent_view => $self->{view}, | ||
| 87 | ); | ||
| 88 | $parent->child->Push($content_node); | ||
| 89 | |||
| 90 | $content_node; | ||
| 91 | } | ||
| 92 | |||
| 93 | 1; |