View | Details | Raw Unified | Return to bug 37389
Collapse All | Expand All

(-)a/Koha/ILL/Requests.pm (-37 / +37 lines)
Lines 119-161 Returns a list of relation accessor names. Link Here
119
119
120
=cut
120
=cut
121
121
122
sub _build_extended_attributes_relations {
122
# sub _build_extended_attributes_relations {
123
    my ($self) = @_;
123
#     my ($self) = @_;
124
124
125
    my @distinct_types = Koha::ILL::Request::Attributes->_resultset->search(
125
#     my @distinct_types = Koha::ILL::Request::Attributes->_resultset->search(
126
        {},    # No specific conditions
126
#         {},    # No specific conditions
127
        {
127
#         {
128
            select   => ['type'],
128
#             select   => ['type'],
129
            group_by => ['type']
129
#             group_by => ['type']
130
        }
130
#         }
131
    )->get_column('type')->all;
131
#     )->get_column('type')->all;
132
132
133
    for my $type (@distinct_types) {
133
#     for my $type (@distinct_types) {
134
        my $test = $self->_resultset->_result_class->has_many(
134
#         my $test = $self->_resultset->_result_class->has_many(
135
            "extended_attributes_$type",
135
#             "extended_attributes_$type",
136
            "Koha::Schema::Result::Illrequestattribute",
136
#             "Koha::Schema::Result::Illrequestattribute",
137
            sub {
137
#             sub {
138
                my $args = shift;
138
#                 my $args = shift;
139
139
140
                return {
140
#                 return {
141
                    "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
141
#                     "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
142
                    "$args->{foreign_alias}.type"          => { '=', $type },
142
#                     "$args->{foreign_alias}.type"          => { '=', $type },
143
                };
143
#                 };
144
            },
144
#             },
145
            { cascade_copy => 0, cascade_delete => 0 },
145
#             { cascade_copy => 0, cascade_delete => 0 },
146
        );
146
#         );
147
147
148
        my $schema = $self->_resultset->result_source->schema;
148
#         my $schema = $self->_resultset->result_source->schema;
149
149
150
        $schema->unregister_source('Koha::Schema::Result::Illrequest');
150
#         $schema->unregister_source('Koha::Schema::Result::Illrequest');
151
        $schema->register_class( 'Koha::Schema::Result::Illrequest', $test );
151
#         $schema->register_class( 'Koha::Schema::Result::Illrequest', $test );
152
152
153
        # Testing to check if the dynamically added method has been aded. It's not been!!
153
#         # Testing to check if the dynamically added method has been aded. It's not been!!
154
        $self->find(1)->extended_attributes_article_title;
154
#         $self->find(1)->extended_attributes_article_title;
155
    }
155
#     }
156
156
157
    return map { 'extended_attributes_'.$_ } @distinct_types;
157
#     return map { 'extended_attributes_'.$_ } @distinct_types;
158
}
158
# }
159
159
160
=head3 _type
160
=head3 _type
161
161
(-)a/Koha/REST/Plugin/Query.pm (-38 / +24 lines)
Lines 179-201 Generates the DBIC join attribute based on extended_attributes query entries, an Link Here
179
                && reftype( $attributes->{prefetch} ) eq 'ARRAY'
179
                && reftype( $attributes->{prefetch} ) eq 'ARRAY'
180
                && grep ( /extended_attributes/, @{ $attributes->{prefetch} } ) )
180
                && grep ( /extended_attributes/, @{ $attributes->{prefetch} } ) )
181
            {
181
            {
182
                # my $ea_entries = $self->_get_extended_attributes_entries( $filtered_params, 0 );
182
                my @array = $self->_get_extended_attributes_entries( $filtered_params, 0 );
183
                
183
                
184
                # Calling our private method to build the extended attributes relations
184
                foreach my $test (@array) {
185
                $result_set->_build_extended_attributes_relations();
185
                    push( @{ $attributes->{join} }, 'extended_attributes_'.$test );
186
187
                # Testing out the extended attributes join (hardcoded for now)
188
                my @test = qw( extended_attributes_article_title extended_attributes_issue extended_attributes_volume );
189
                foreach my $test (@test) {
190
                    push( @{ $attributes->{join} }, $test );
191
                }
186
                }
192
193
                # while ( $ea_entries > 0 ) {
194
                #     push( @{ $attributes->{join} }, 'extended_attributes_title' );
195
                #     push( @{ $attributes->{join} }, 'extended_attributes_author' );
196
                #     $ea_entries--;
197
                # }
198
199
            }
187
            }
200
        }
188
        }
201
    );
189
    );
Lines 570-605 Example: Returns 2 if given a $filtered_params containing the below: Link Here
570
=cut
558
=cut
571
559
572
sub _get_extended_attributes_entries {
560
sub _get_extended_attributes_entries {
573
    my ( $self, $params, $extended_attributes_entries ) = @_;
561
    my ( $self, $params, $extended_attributes_entries, @array ) = @_;
574
562
575
    if ( reftype($params) && reftype($params) eq 'HASH' ) {
563
    if ( reftype($params) && reftype($params) eq 'HASH' ) {
576
564
577
        # rewrite additional_field_values table query params
565
        # rewrite additional_field_values table query params
578
        $extended_attributes_entries =
566
        @array =
579
            _rewrite_related_metadata_query( $params, $extended_attributes_entries, 'field_id', 'value' )
567
            _rewrite_related_metadata_query( $params, 'field_id', 'value', @array )
580
            if $params->{'extended_attributes.field_id'};
568
            if $params->{'extended_attributes.field_id'};
581
569
582
        # rewrite borrower_attributes table query params
570
        # rewrite borrower_attributes table query params
583
        $extended_attributes_entries =
571
        @array =
584
            _rewrite_related_metadata_query( $params, $extended_attributes_entries, 'code', 'attribute' )
572
            _rewrite_related_metadata_query( $params, 'code', 'attribute', @array )
585
            if $params->{'extended_attributes.code'};
573
            if $params->{'extended_attributes.code'};
586
574
587
        # rewrite illrequestattributes table query params
575
        # rewrite illrequestattributes table query params
588
        $extended_attributes_entries =
576
        @array =
589
            _rewrite_related_metadata_query( $params, $extended_attributes_entries, 'type', 'value' )
577
            _rewrite_related_metadata_query( $params, 'type', 'value', @array )
590
            if $params->{'extended_attributes.type'};
578
            if $params->{'extended_attributes.type'};
591
579
592
        foreach my $key ( keys %{$params} ) {
580
        foreach my $key ( keys %{$params} ) {
593
            return $self->_get_extended_attributes_entries( $params->{$key}, $extended_attributes_entries );
581
            return $self->_get_extended_attributes_entries( $params->{$key}, $extended_attributes_entries, @array );
594
        }
582
        }
595
    } elsif ( reftype($params) && reftype($params) eq 'ARRAY' ) {
583
    } elsif ( reftype($params) && reftype($params) eq 'ARRAY' ) {
596
        foreach my $ea_instance (@$params) {
584
        foreach my $ea_instance (@$params) {
597
            $extended_attributes_entries =
585
             @array = $self->_get_extended_attributes_entries( $ea_instance, $extended_attributes_entries, @array );
598
                +$self->_get_extended_attributes_entries( $ea_instance, $extended_attributes_entries );
599
        }
586
        }
600
        return $extended_attributes_entries;
587
        return @array;
601
    } else {
588
    } else {
602
        return $extended_attributes_entries;
589
        return @array;
603
    }
590
    }
604
}
591
}
605
592
Lines 638-657 It'll be rewritten as: Link Here
638
=cut
625
=cut
639
626
640
sub _rewrite_related_metadata_query {
627
sub _rewrite_related_metadata_query {
641
    my ( $params, $extended_attributes_entries, $key, $value ) = @_;
628
    my ( $params, $key, $value, @array ) = @_;
642
629
643
    $extended_attributes_entries++;
630
    my $old_key_value = delete $params->{ 'extended_attributes.' . $key };
644
    if ( $extended_attributes_entries > 1 ) {
631
    my $new_key_value = "extended_attributes_$old_key_value" . "." . $key;
645
        my $old_key_value = delete $params->{ 'extended_attributes.' . $key };
632
    $params->{$new_key_value} = $old_key_value;
646
        my $new_key_value = "extended_attributes_$key" . "." . $key;
647
        $params->{$new_key_value} = $old_key_value;
648
633
649
        my $old_value_value = delete $params->{ 'extended_attributes.' . $value };
634
    my $old_value_value = delete $params->{ 'extended_attributes.' . $value };
650
        my $new_value_value = "extended_attributes_$key" . "." . $value;
635
    my $new_value_value = "extended_attributes_$old_key_value" . "." . $value;
651
        $params->{$new_value_value} = $old_value_value;
636
    $params->{$new_value_value} = $old_value_value;
652
    }
637
638
    push @array, $old_key_value;
653
639
654
    return $extended_attributes_entries;
640
    return @array;
655
}
641
}
656
642
657
1;
643
1;
(-)a/Koha/Schema/Result/Illrequest.pm (-1 / +112 lines)
Lines 408-413 __PACKAGE__->has_many( Link Here
408
  { cascade_copy => 0, cascade_delete => 0 },
408
  { cascade_copy => 0, cascade_delete => 0 },
409
);
409
);
410
410
411
__PACKAGE__->has_many(
412
    "extended_attributes_author",
413
    "Koha::Schema::Result::Illrequestattribute",
414
    sub {
415
        my $args = shift;
416
417
        return {
418
            "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
419
            "$args->{foreign_alias}.type"          => { '=', 'author' },
420
        };
421
    },
422
    { cascade_copy => 0, cascade_delete => 0 },
423
);
424
425
__PACKAGE__->has_many(
426
    "extended_attributes_title",
427
    "Koha::Schema::Result::Illrequestattribute",
428
    sub {
429
        my $args = shift;
430
431
        return {
432
            "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
433
            "$args->{foreign_alias}.type"          => { '=', 'title' },
434
        };
435
    },
436
    { cascade_copy => 0, cascade_delete => 0 },
437
);
438
439
__PACKAGE__->has_many(
440
      "extended_attributes_article_title",
441
      "Koha::Schema::Result::Illrequestattribute",
442
      sub {
443
          my $args = shift;
444
445
          return {
446
              "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
447
            "$args->{foreign_alias}.type" => { '=', 'article_title' },
448
          };
449
      },
450
      { cascade_copy => 0, cascade_delete => 0 },
451
  );
452
453
__PACKAGE__->has_many(
454
    "extended_attributes_issue",
455
    "Koha::Schema::Result::Illrequestattribute",
456
    sub {
457
        my $args = shift;
458
459
        return {
460
            "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
461
            "$args->{foreign_alias}.type" => { '=', 'issue' },
462
        };
463
    },
464
    { cascade_copy => 0, cascade_delete => 0 },
465
);
466
467
__PACKAGE__->has_many(
468
    "extended_attributes_volume",
469
    "Koha::Schema::Result::Illrequestattribute",
470
    sub {
471
        my $args = shift;
472
473
        return {
474
            "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
475
            "$args->{foreign_alias}.type"          => { '=', 'volume' },
476
        };
477
    },
478
    { cascade_copy => 0, cascade_delete => 0 },
479
);
480
481
__PACKAGE__->has_many(
482
    "extended_attributes_year",
483
    "Koha::Schema::Result::Illrequestattribute",
484
    sub {
485
        my $args = shift;
486
487
        return {
488
            "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
489
            "$args->{foreign_alias}.type"          => { '=', 'year' },
490
        };
491
    },
492
    { cascade_copy => 0, cascade_delete => 0 },
493
);
494
495
__PACKAGE__->has_many(
496
    "extended_attributes_pages",
497
    "Koha::Schema::Result::Illrequestattribute",
498
    sub {
499
        my $args = shift;
500
501
        return {
502
            "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
503
            "$args->{foreign_alias}.type"          => { '=', 'pages' },
504
        };
505
    },
506
    { cascade_copy => 0, cascade_delete => 0 },
507
);
508
509
__PACKAGE__->has_many(
510
    "extended_attributes_type",
511
    "Koha::Schema::Result::Illrequestattribute",
512
    sub {
513
        my $args = shift;
514
515
        return {
516
            "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
517
            "$args->{foreign_alias}.type"          => { '=', 'type' },
518
        };
519
    },
520
    { cascade_copy => 0, cascade_delete => 0 },
521
);
522
411
__PACKAGE__->belongs_to(
523
__PACKAGE__->belongs_to(
412
  "ill_batch",
524
  "ill_batch",
413
  "Koha::Schema::Result::Illbatch",
525
  "Koha::Schema::Result::Illbatch",
414
- 

Return to bug 37389