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

(-)a/Koha/SharedContent.pm (-70 / +80 lines)
Lines 52-66 sub manaRequest { Link Here
52
        $mana_request->content( to_json($content) );
52
        $mana_request->content( to_json($content) );
53
    }
53
    }
54
54
55
    my $response  = $userAgent->request($mana_request);
55
    my $response = $userAgent->request($mana_request);
56
56
57
    eval { $result = from_json( $response->decoded_content, { utf8 => 1} ); };
57
    eval { $result = from_json( $response->decoded_content, { utf8 => 1} ); };
58
    $result->{code} = $response->code;
58
    $result->{code} = $response->code;
59
    if ( $@ ){
59
    if ( $@ ){
60
        $result->{msg} = $response->{_msg};
60
        $result->{msg} = $@;
61
    }
61
    }
62
    if ($response->is_error){
62
    if ($response->is_error){
63
        $result->{msg} = "An error occurred, mana server returned: ".$result->{msg};
63
        $result->{msg} = "An error occurred, mana server returned: " . $response->message;
64
    }
64
    }
65
    return $result ;
65
    return $result ;
66
}
66
}
Lines 70-90 sub manaRequest { Link Here
70
=cut
70
=cut
71
71
72
sub manaIncrementRequest {
72
sub manaIncrementRequest {
73
    my $resource = shift;
73
    return manaRequest(buildRequest('increment', @_));
74
    my $id       = shift;
75
    my $field    = shift;
76
    my $step     = shift;
77
    my $param;
78
    $param->{step} = $step || 1;
79
    $param->{id} = $id;
80
    $param->{resource} = $resource;
81
    $param = join '&',
82
       map { defined $param->{$_} ? $_ . "=" . $param->{$_} : () }
83
           keys %$param;
84
    my $url = "$MANA_IP/$resource/$id.json/increment/$field?$param";
85
    my $request = HTTP::Request->new( POST => $url );
86
87
    return manaRequest($request);
88
}
74
}
89
75
90
=head3 manaPostRequest
76
=head3 manaPostRequest
Lines 92-159 sub manaIncrementRequest { Link Here
92
=cut
78
=cut
93
79
94
sub manaPostRequest {
80
sub manaPostRequest {
95
    my $resource = shift;
81
    my ($lang, $loggedinuser, $resourceid, $resourcetype) = @_;
96
    my $content  = shift;
82
83
    my $content = prepareSharedData($lang, $loggedinuser, $resourceid, $resourcetype);
97
84
98
    my $url = "$MANA_IP/$resource.json";
85
    my $result = manaRequest(buildRequest('post', $resourcetype, $content));
99
    my $request = HTTP::Request->new( POST => $url );
100
86
101
    $content->{bulk_import} = 0;
87
    if ( $result and ($result->{code} eq "200" or $result->{code} eq "201") ) {
102
    my $json = to_json( $content, { utf8 => 1 } );
88
        my $packages = "Koha::".ucfirst($resourcetype)."s";
103
    $request->content($json);
89
        my $resource = $packages->find($resourceid);
104
    return manaRequest($request);
90
        eval { $resource->set( { mana_id => $result->{id} } )->store };
91
    }
92
    return $result;
105
}
93
}
106
94
107
=head3 manaShareInfos
95
=head3 prepareSharedData
108
96
109
=cut
97
=cut
110
98
111
sub manaShareInfos{
99
sub prepareSharedData {
112
    my ($query, $loggedinuser, $ressourceid, $ressourcetype) = @_;
100
    my ($lang, $loggedinuser, $ressourceid, $ressourcetype) = @_;
113
    my $mana_language;
101
    $lang ||= C4::Context->preference('language');
114
    if ( $query->param('mana_language') ) {
115
        $mana_language = $query->param('mana_language');
116
    }
117
    else {
118
        my $result = $mana_language = C4::Context->preference('language');
119
    }
120
102
121
    my $mana_email;
103
    my $mana_email;
122
    if ( $loggedinuser ne 0 ) {
104
    if ( $loggedinuser ne 0 ) {
123
        my $borrower = Koha::Patrons->find($loggedinuser);
105
        my $borrower = Koha::Patrons->find($loggedinuser);
124
        if ($borrower){
106
        $mana_email = $borrower->first_valid_email_address
125
            $mana_email = $borrower->email
107
            || Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail
126
              if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
127
            $mana_email = $borrower->emailpro
128
              if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
129
            $mana_email =
130
              Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail
131
              if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
132
        }
133
    }
108
    }
134
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
109
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
135
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
110
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
111
136
    my %versions = C4::Context::get_versions();
112
    my %versions = C4::Context::get_versions();
137
113
138
    my $mana_info = {
114
    my $mana_info = {
139
        language    => $mana_language,
115
        language    => $lang,
140
        kohaversion => $versions{'kohaVersion'},
116
        kohaversion => $versions{'kohaVersion'},
141
        exportemail => $mana_email
117
        exportemail => $mana_email
142
    };
118
    };
143
    my ($ressource, $ressource_mana_info);
119
120
    my $ressource_mana_info;
144
    my $packages = "Koha::".ucfirst($ressourcetype)."s";
121
    my $packages = "Koha::".ucfirst($ressourcetype)."s";
145
    my $package = "Koha::".ucfirst($ressourcetype);
122
    my $package = "Koha::".ucfirst($ressourcetype);
146
    $ressource_mana_info = $package->get_sharable_info($ressourceid);
123
    $ressource_mana_info = $package->get_sharable_info($ressourceid);
147
    $ressource_mana_info = { %$ressource_mana_info, %$mana_info };
124
    $ressource_mana_info = { %$ressource_mana_info, %$mana_info };
148
    $ressource = $packages->find($ressourceid);
149
150
    my $result = Koha::SharedContent::manaPostRequest( $ressourcetype,
151
        $ressource_mana_info );
152
125
153
    if ( $result and ($result->{code} eq "200" or $result->{code} eq "201") ) {
126
    return $ressource_mana_info;
154
       eval { $ressource->set( { mana_id => $result->{id} } )->store };
155
    }
156
    return $result;
157
}
127
}
158
128
159
=head3 manaGetRequestWithId
129
=head3 manaGetRequestWithId
Lines 161-173 sub manaShareInfos{ Link Here
161
=cut
131
=cut
162
132
163
sub manaGetRequestWithId {
133
sub manaGetRequestWithId {
164
    my $resource = shift;
134
    return manaRequest(buildRequest('getwithid', @_));
165
    my $id       = shift;
166
167
    my $url = "$MANA_IP/$resource/$id.json";
168
    my $request = HTTP::Request->new( GET => $url );
169
170
    return manaRequest($request);
171
}
135
}
172
136
173
=head3 manaGetRequest
137
=head3 manaGetRequest
Lines 175-190 sub manaGetRequestWithId { Link Here
175
=cut
139
=cut
176
140
177
sub manaGetRequest {
141
sub manaGetRequest {
178
    my $resource   = shift;
142
    return manaRequest(buildRequest('get', @_));
179
    my $parameters = shift;
143
}
144
145
=head3 buildRequest
180
146
181
    $parameters = join '&',
147
=cut
182
      map { defined $parameters->{$_} ? $_ . "=" . $parameters->{$_} : () }
148
183
      keys %$parameters;
149
sub buildRequest {
184
    my $url = "$MANA_IP/$resource.json?$parameters";
150
    my $type = shift;
185
    my $request = HTTP::Request->new( GET => $url );
151
    my $resource = shift;
186
152
187
    return manaRequest($request);
153
    if ( $type eq 'get' ) {
154
        my $params = shift;
155
        $params = join '&',
156
            map { defined $params->{$_} ? $_ . "=" . $params->{$_} : () }
157
            keys %$params;
158
        my $url = "$MANA_IP/$resource.json?$params";
159
        return HTTP::Request->new( GET => $url );
160
    }
161
162
    if ( $type eq 'getwithid' ) {
163
        my $id = shift;
164
165
        my $url = "$MANA_IP/$resource/$id.json";
166
        return HTTP::Request->new( GET => $url );
167
    }
168
169
    if ( $type eq 'post' ) {
170
        my $content  = shift;
171
172
        my $url = "$MANA_IP/$resource.json";
173
        my $request = HTTP::Request->new( POST => $url );
174
175
        $content->{bulk_import} = 0;
176
        my $json = to_json( $content, { utf8 => 1 } );
177
        $request->content($json);
178
179
        return $request;
180
    }
181
182
    if ( $type eq 'increment' ) {
183
        my $id       = shift;
184
        my $field    = shift;
185
        my $step     = shift;
186
        my $param;
187
188
        $param->{step} = $step || 1;
189
        $param->{id} = $id;
190
        $param->{resource} = $resource;
191
        $param = join '&',
192
           map { defined $param->{$_} ? $_ . "=" . $param->{$_} : () }
193
               keys %$param;
194
        my $url = "$MANA_IP/$resource/$id.json/increment/$field?$param";
195
        my $request = HTTP::Request->new( POST => $url );
196
197
    }
188
}
198
}
189
199
190
1;
200
1;
(-)a/Koha/Subscription/Numberpatterns.pm (+32 lines)
Lines 52-57 sub uniqueLabel { Link Here
52
    return $label;
52
    return $label;
53
}
53
}
54
54
55
=head3 new_or_existing
56
57
=cut
58
59
sub new_or_existing {
60
    my ($self, $params) = @_;
61
62
    my $params_np;
63
    if ( $params->{'numbering_pattern'} eq 'mana' ) {
64
        foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1
65
                   numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2
66
                   label3 add3 every3 whenmorethan3 setto3 numbering3/) {
67
            $params_np->{$_} = $params->{$_} if $params->{$_};
68
        }
69
70
        my $existing = Koha::Subscription::Numberpatterns->search($params_np)->next();
71
72
        if ($existing) {
73
            return $existing->id;
74
        }
75
76
        $params_np->{label} = Koha::Subscription::Numberpatterns->uniqueLabel($params->{'patternname'});
77
        $params_np->{description} = $params->{'sndescription'};
78
79
80
        my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params_np)->store();
81
        return $subscription_np->id;
82
    }
83
84
    return $params->{'numbering_pattern'};
85
}
86
55
=head3 type
87
=head3 type
56
88
57
=cut
89
=cut
(-)a/debian/templates/koha-conf-site.xml.in (+3 lines)
Lines 269-274 __END_SRU_PUBLICSERVER__ Link Here
269
 <logdir>__LOG_DIR__</logdir>
269
 <logdir>__LOG_DIR__</logdir>
270
 <docdir>/usr/share/doc/koha-common</docdir>
270
 <docdir>/usr/share/doc/koha-common</docdir>
271
 <backupdir>/var/spool/koha/__KOHASITE__</backupdir>
271
 <backupdir>/var/spool/koha/__KOHASITE__</backupdir>
272
 <!-- URL of the mana KB server -->
273
 <!-- alternative value http://mana-test.koha-community.org to query the test server -->
274
 <mana_config>https://mana-kb.koha-community.org</mana_config>
272
 <!-- Enable the two following to allow superlibrarians to download
275
 <!-- Enable the two following to allow superlibrarians to download
273
      database and configuration dumps (respectively) from the Export
276
      database and configuration dumps (respectively) from the Export
274
      tool -->
277
      tool -->
(-)a/koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js (-1 / +1 lines)
Lines 5-11 $(document).ready(function(){ Link Here
5
        var myemail = $("#email").val()
5
        var myemail = $("#email").val()
6
        $.ajax( {
6
        $.ajax( {
7
            type: "POST",
7
            type: "POST",
8
            url: "/cgi-bin/koha/svc/mana/getToken",
8
            url: "/cgi-bin/koha/svc/mana/token",
9
            data: { lastname: mylastname, firstname: myfirstname, email: myemail},
9
            data: { lastname: mylastname, firstname: myfirstname, email: myemail},
10
            dataType: "json",
10
            dataType: "json",
11
        })
11
        })
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc (-5 / +26 lines)
Lines 3-8 Link Here
3
[% USE AuthorisedValues %]
3
[% USE AuthorisedValues %]
4
[% USE Branches %]
4
[% USE Branches %]
5
5
6
<script type="text/javascript">
7
//<![CDATA[
8
$(document).ready(function() {
9
    $(document).on('click', 'button.mana-use', function() {
10
        id = $(this).attr('id');
11
        mana_use(id.substr(9));
12
    });
13
14
    $(document).on('change', 'select.mana-actions', function() {
15
        report_id = $(this).attr('id').substr(13);
16
        if ($(this).val() == 'other') {
17
            $('input#selected_id').val(report_id);
18
            $('#comment_box').modal('show');
19
        } else {
20
            comment_id = $(this).val();
21
            mana_increment(comment_id, 'resource_comment', 'nb');
22
        }
23
    });
24
});
25
//]]>
26
</script>
27
6
[% IF statuscode == "200" AND reports %]
28
[% IF statuscode == "200" AND reports %]
7
    <table id="mana_results_datatable" width=100%>
29
    <table id="mana_results_datatable" width=100%>
8
        <thead>
30
        <thead>
Lines 45-58 Link Here
45
67
46
                    [% UNLESS search_only %]
68
                    [% UNLESS search_only %]
47
                        <td>
69
                        <td>
48
                            <button onclick="mana_use([% report.id %])"> <i class="fa fa-inbox"></i> Use</button>
70
                            <button class="mana-use" id="mana-use-[% report.id %]"><i class="fa fa-inbox"></i> Use</button>
49
                            <input hidden type="text" id="selectedcomment">
71
                            <select class="mana-actions" id="mana-actions-[% report.id %]">
50
                            <select>
51
                                <option selected disabled>Report mistake</option>
72
                                <option selected disabled>Report mistake</option>
52
                                [% FOREACH comment IN report.comments %]
73
                                [% FOREACH comment IN report.comments %]
53
                                    <option class="actionreport1" value="[% comment.id %]" onclick="mana_increment('[% comment.id %]', 'resource_comment', 'nb')"> [% comment.message %] ([% comment.nb %])
74
                                    <option value="[% comment.id %]">[% comment.message %] ([% comment.nb %])</option>
54
                                [% END %]
75
                                [% END %]
55
                                    <option data-toggle="modal" onclick="($('#selected_id').val($('.rowid').val()))" data-target="#comment_box"> other
76
                                    <option>other</option>
56
                            </select>
77
                            </select>
57
                            <button hidden class="actionreport2" hidden> Cancel</button>
78
                            <button hidden class="actionreport2" hidden> Cancel</button>
58
                        </td>
79
                        </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-subscription-search-result.inc (-5 / +25 lines)
Lines 3-8 Link Here
3
[% USE AuthorisedValues %]
3
[% USE AuthorisedValues %]
4
[% USE Branches %]
4
[% USE Branches %]
5
5
6
<script type="text/javascript">
7
//<![CDATA[
8
$(document).ready(function() {
9
    $(document).on('click', 'button.mana-use', function() {
10
        id = $(this).attr('id');
11
        mana_use(id.substr(9));
12
    });
13
14
    $(document).on('change', 'select.mana-actions', function() {
15
        report_id = $(this).attr('id').substr(13);
16
        if ($(this).val() == 'other') {
17
            $('input#selected_id').val(report_id);
18
            $('#comment_box').modal('show');
19
        } else {
20
            comment_id = $(this).val();
21
            mana_increment(comment_id, 'resource_comment', 'nb');
22
        }
23
    });
24
});
25
//]]>
26
</script>
6
27
7
[% IF statuscode == "200" %]
28
[% IF statuscode == "200" %]
8
    <table id="mana_results_datatable" width=100%>
29
    <table id="mana_results_datatable" width=100%>
Lines 43-56 Link Here
43
64
44
                        [% UNLESS search_only %]
65
                        [% UNLESS search_only %]
45
                            <td>
66
                            <td>
46
                                <button onclick="mana_use([% subscription.id %])"> <i class="fa fa-inbox"></i> Use</button>
67
                                <button class="mana-use" id="mana-use-[% subscription.id %]"><i class="fa fa-inbox"></i> Use</button>
47
                                <input hidden type="text" id="selectedcomment">
68
                                <select class="mana-actions" id="mana-actions-[% subscription.id %]">
48
                                <select>
49
                                    <option selected disabled>Report mistake</option>
69
                                    <option selected disabled>Report mistake</option>
50
                                    [% FOREACH comment IN subscription.comments %]
70
                                    [% FOREACH comment IN subscription.comments %]
51
                                        <option class="actionreport1" value="[% comment.id %]" onclick="mana_increment('[% comment.id %]', 'resource_comment', 'nb')"> [% comment.message %] ([% comment.nb %])
71
                                        <option value="[% comment.id %]"> [% comment.message %] ([% comment.nb %])</option>
52
                                    [% END %]
72
                                    [% END %]
53
                                        <option data-toggle="modal" onclick="($('#selected_id').val($('.rowid').val()))" data-target="#comment_box"> other
73
                                        <option>other</option>
54
                                </select>
74
                                </select>
55
                                <button hidden class="actionreport2" hidden> Cancel</button>
75
                                <button hidden class="actionreport2" hidden> Cancel</button>
56
                            </td>
76
                            </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc (-2 / +2 lines)
Lines 116-122 $(document).ready(function(){ Link Here
116
    function mana_increment(mana_id, resourcename, fieldvalue, stepvalue = 1){
116
    function mana_increment(mana_id, resourcename, fieldvalue, stepvalue = 1){
117
        $.ajax( {
117
        $.ajax( {
118
            type: "POST",
118
            type: "POST",
119
            url: "/cgi-bin/koha/svc/mana/addvaluetofield",
119
            url: "/cgi-bin/koha/svc/mana/increment",
120
            data: {id: mana_id, field: fieldvalue, resource: resourcename, step: stepvalue},
120
            data: {id: mana_id, field: fieldvalue, resource: resourcename, step: stepvalue},
121
            datatype: "json",
121
            datatype: "json",
122
        }).done( function() {
122
        }).done( function() {
Lines 151-157 $(document).ready(function(){ Link Here
151
        })
151
        })
152
        .done( function( result ) {
152
        .done( function( result ) {
153
            $("#mana_search_result .modal-body").html(result);
153
            $("#mana_search_result .modal-body").html(result);
154
            $("#mana_search_result_label").text("Results from Mana Knowledge Base");
154
            $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
155
            $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults,{
155
            $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults,{
156
                "sPaginationType":"four_button",
156
                "sPaginationType":"four_button",
157
                "autoWidth": false,
157
                "autoWidth": false,
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc (-5 / +5 lines)
Lines 13-21 Link Here
13
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen";
13
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen";
14
        }
14
        }
15
    }
15
    }
16
    function share() {
17
        window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=share";
18
    }
19
16
20
	 $(document).ready(function() {
17
	 $(document).ready(function() {
21
        $("#deletesub").click(function(){
18
        $("#deletesub").click(function(){
Lines 34-39 Link Here
34
            popup([% subscriptionid %]);
31
            popup([% subscriptionid %]);
35
            return false;
32
            return false;
36
        })
33
        })
34
        $("#mana-subscription-share").click(function() {
35
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=share";
36
        });
37
	 });
37
	 });
38
	//]]>
38
	//]]>
39
	</script>
39
	</script>
Lines 50-56 Link Here
50
                [% IF one_language_enabled==0 or mana_id %]
50
                [% IF one_language_enabled==0 or mana_id %]
51
                    <div class="btn-group"><a data-toggle="modal" data-toggle="tooltip" title="Share the subscription with other librairies. Your email address will be associated to your sharing." data-target="#mana_share_modal" class="btn btn-default btn-sm"><i class="fa fa-share-alt"></i> Share</a></div>
51
                    <div class="btn-group"><a data-toggle="modal" data-toggle="tooltip" title="Share the subscription with other librairies. Your email address will be associated to your sharing." data-target="#mana_share_modal" class="btn btn-default btn-sm"><i class="fa fa-share-alt"></i> Share</a></div>
52
                [% ELSE %]
52
                [% ELSE %]
53
                    <div class="btn-group" data-toggle="tooltip" title="Share the subscription with other libraries. Your email address will be associated to your sharing."><a class="btn btn-default btn-sm" onclick="share()"><i class="fa fa-share-alt"></i> Share</a></div>
53
                    <div class="btn-group" id="mana-subscription-share" data-toggle="tooltip" title="Share the subscription with other libraries. Your email address will be associated to your sharing."><a class="btn btn-default btn-sm"><i class="fa fa-share-alt"></i> Share</a></div>
54
                [% END %]
54
                [% END %]
55
            [% END %]
55
            [% END %]
56
        [% END %]
56
        [% END %]
Lines 200-206 Link Here
200
                [% IF one_language_enabled==0 %]
200
                [% IF one_language_enabled==0 %]
201
                    <button type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
201
                    <button type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
202
                [% ELSE %]
202
                [% ELSE %]
203
                    <div class="btn-group"><a class="btn btn-primary" onclick="share()">Share</a></div>
203
                    <div class="btn-group" id="mana-subscription-share"><a class="btn btn-primary">Share</a></div>
204
                [% END %]
204
                [% END %]
205
            </div>
205
            </div>
206
        </div>
206
        </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-5 / +4 lines)
Lines 74-83 function load_group_subgroups () { Link Here
74
    }
74
    }
75
}
75
}
76
76
77
function share() {
78
    window.location="/cgi-bin/koha/reports/guided_reports.pl?phase=Save";
79
}
80
81
$(document).ready(function(){
77
$(document).ready(function(){
82
    $('#limit').change(function() {
78
    $('#limit').change(function() {
83
        $('#limitselect').submit();
79
        $('#limitselect').submit();
Lines 285-290 $("#delColumn").on("click",function(){ Link Here
285
        load_group_subgroups();
281
        load_group_subgroups();
286
    });
282
    });
287
[% END %]
283
[% END %]
284
    $('div#ManaShareButton').click(function() {
285
        window.location="/cgi-bin/koha/reports/guided_reports.pl?phase=Share";
286
    });
288
});
287
});
289
288
290
289
Lines 668-674 canned reports and writing custom SQL reports.</p> Link Here
668
                [% IF one_language_enabled==0 %]
667
                [% IF one_language_enabled==0 %]
669
                    <button id="ManaShareButton" type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
668
                    <button id="ManaShareButton" type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
670
                [% ELSE %]
669
                [% ELSE %]
671
                    <div id="ManaShareButton" class="btn-group"><a class="btn btn-primary"'onclick="share()">Share</a></div>
670
                    <div id="ManaShareButton" class="btn-group"><a class="btn btn-primary">Share</a></div>
672
                [% END %]
671
                [% END %]
673
            </div>
672
            </div>
674
        </div>
673
        </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-19 / +10 lines)
Lines 406-412 function show_page_2() { Link Here
406
}
406
}
407
407
408
function mana_search() {
408
function mana_search() {
409
    $("#mana_search").html("<p>Mana kb is being asked for your subscription..</p>");
409
    $("#mana_search").html("<p>" + _("Mana kb is being asked for your subscription..") + "</p>");
410
    $("#mana_search").show();
410
    $("#mana_search").show();
411
411
412
    $.ajax({
412
    $.ajax({
Lines 417-423 function mana_search() { Link Here
417
    })
417
    })
418
    .done( function( result ) {
418
    .done( function( result ) {
419
        $("#mana_search_result .modal-body").html(result);
419
        $("#mana_search_result .modal-body").html(result);
420
        $("#mana_search_result_label").text("Results from Mana Knowledge Base");
420
        $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
421
        $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, {
421
        $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, {
422
            "sPaginationType": "four_button",
422
            "sPaginationType": "four_button",
423
            "order":[[4, "desc"], [5, "desc"]],
423
            "order":[[4, "desc"], [5, "desc"]],
Lines 432-441 function mana_search() { Link Here
432
            ]
432
            ]
433
        }));
433
        }));
434
        if( $("#mana_results_datatable").length && $("td.dataTables_empty").length == 0){
434
        if( $("#mana_results_datatable").length && $("td.dataTables_empty").length == 0){
435
            $("#mana_search").html("<p>Subscription found on Mana Knowledge Base:</p><p> <a style='cursor:pointer' data-toggle='modal' data-target='#mana_search_result'>Quick fill</a></p>");
435
            $("#mana_search").html("<p>" + _("Subscription found on Mana Knowledge Base:") + "</p><p> <a style='cursor:pointer' data-toggle='modal' data-target='#mana_search_result'>" + _("Quick fill") + "</a></p>");
436
        }
436
        }
437
        else if ( $("#mana_results_datatable").length ){
437
        else if ( $("#mana_results_datatable").length ){
438
            $("#mana_search").html("<p>No subscription found on Mana Knowledge Base :(</p><p> Please feel free to share you pattern with all others librarians once you are done</p>");
438
            $("#mana_search").html("<p>" + _("No subscription found on Mana Knowledge Base :(") + "</p><p>" + _(" Please feel free to share you pattern with all others librarians once you are done") + "</p>");
439
        }
439
        }
440
        else{
440
        else{
441
            $("#mana_search").html( result );
441
            $("#mana_search").html( result );
Lines 468-477 function mana_search() { Link Here
468
            mana_increment($("#selectedcomment").val(), 'resource_comment', 'nb', -1);
468
            mana_increment($("#selectedcomment").val(), 'resource_comment', 'nb', -1);
469
        });
469
        });
470
470
471
    }).fail(function(result, msg, longmsg){
471
    })
472
        console.log( msg );
473
        console.log( longmsg );
474
    });
475
}
472
}
476
473
477
function mana_comment( target_id, manamsg, resource_type ){
474
function mana_comment( target_id, manamsg, resource_type ){
Lines 486-492 function mana_comment( target_id, manamsg, resource_type ){ Link Here
486
function mana_increment(mana_id, resource, fieldvalue, stepvalue = 1){
483
function mana_increment(mana_id, resource, fieldvalue, stepvalue = 1){
487
    $.ajax( {
484
    $.ajax( {
488
        type: "POST",
485
        type: "POST",
489
        url: "/cgi-bin/koha/svc/mana/addvaluetofield",
486
        url: "/cgi-bin/koha/svc/mana/increment",
490
        data: {id: mana_id, resource: resource, field: fieldvalue, step: stepvalue},
487
        data: {id: mana_id, resource: resource, field: fieldvalue, step: stepvalue},
491
        datatype: "json",
488
        datatype: "json",
492
    })
489
    })
Lines 567-582 function mana_use(mana_id){ Link Here
567
    });
564
    });
568
}
565
}
569
566
570
function removeDisabledAttr() {
571
    $('select:disabled').removeAttr('disabled');
572
}
573
574
575
$(document).ready(function() {
567
$(document).ready(function() {
576
568
577
578
579
580
    mana_search();
569
    mana_search();
581
    $("#displayexample").hide();
570
    $("#displayexample").hide();
582
    $("#mana_search_result").modal("hide");
571
    $("#mana_search_result").modal("hide");
Lines 716-722 $(document).ready(function() { Link Here
716
        e.preventDefault();
705
        e.preventDefault();
717
        testPredictionPattern();
706
        testPredictionPattern();
718
    });
707
    });
719
708
    $('#save-subscription').on("click", function(e){
709
        $('select:disabled').removeAttr('disabled');
710
    });
720
711
721
});
712
});
722
//]]>
713
//]]>
Lines 1197-1203 $(document).ready(function() { Link Here
1197
                            <fieldset class="action">
1188
                            <fieldset class="action">
1198
                                <input type="button" id="subscription_add_previous" value="&lt;&lt; Previous" style="float:left;"/>
1189
                                <input type="button" id="subscription_add_previous" value="&lt;&lt; Previous" style="float:left;"/>
1199
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" />
1190
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" />
1200
                                <input type="submit" onclick="removeDisabledAttr()" value="Save subscription" style="float:right;" accesskey="w"/>
1191
                                <input id="save-subscription" type="submit" value="Save subscription" style="float:right;" accesskey="w"/>
1201
                            </fieldset>
1192
                            </fieldset>
1202
                        </div>
1193
                        </div>
1203
                    </div>
1194
                    </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt (-1 / +1 lines)
Lines 42-48 $(document).ready(function() { Link Here
42
   <div id="bd">
42
   <div id="bd">
43
	<div id="yui-main">
43
	<div id="yui-main">
44
	<div class="yui-b">
44
	<div class="yui-b">
45
    [% INCLUDE 'serials-toolbar.inc' mana_id = mana_id %]
45
    [% INCLUDE 'serials-toolbar.inc' %]
46
46
47
    <h1>Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]</h1>
47
    <h1>Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]</h1>
48
    [% IF ( abouttoexpire ) %]
48
    [% IF ( abouttoexpire ) %]
(-)a/reports/guided_reports.pl (-2 / +2 lines)
Lines 181-187 elsif ( $phase eq 'Show SQL'){ Link Here
181
        'notes'      => $report->{notes},
181
        'notes'      => $report->{notes},
182
	'sql'     => $report->{savedsql},
182
	'sql'     => $report->{savedsql},
183
	'showsql' => 1,
183
	'showsql' => 1,
184
        'mana_success' => $input->param('mana_success'),
184
        'mana_success' => scalar $input->param('mana_success'),
185
    );
185
    );
186
}
186
}
187
187
Lines 658-664 elsif ( $phase eq 'Save Report' ) { Link Here
658
}
658
}
659
659
660
elsif ($phase eq 'Share'){
660
elsif ($phase eq 'Share'){
661
    my $result = Koha::SharedContent::manaShareInfos($input, $borrowernumber, $input->param('reportid'), 'report');
661
    my $result = Koha::SharedContent::manaPostRequest($input->param('mana_language'), $borrowernumber, scalar $input->param('reportid'), 'report');
662
    if ( $result ) {
662
    if ( $result ) {
663
        print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=".$result->{msg});
663
        print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=".$result->{msg});
664
    }else{
664
    }else{
(-)a/serials/subscription-add.pl (-44 / +18 lines)
Lines 290-324 sub _guess_enddate { Link Here
290
    return $enddate;
290
    return $enddate;
291
}
291
}
292
292
293
sub manage_subscription_numbering_pattern_id {
293
sub redirect_add_subscription {
294
    my $params;
294
    my $periodicity = $query->param('frequency');
295
    if ( $query->param('numbering_pattern') eq 'mana' ) {
295
    if ($periodicity eq 'mana') {
296
        foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1
297
                   numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2
298
                   label3 add3 every3 whenmorethan3 setto3 numbering3/) {
299
            $params->{$_} = $query->param($_) if $query->param($_);
300
        }
301
302
        my $existing = Koha::Subscription::Numberpatterns->search($params)->next();
303
304
        if ($existing) {
305
            return $existing->id;
306
        }
307
308
        $params->{label} = Koha::Subscription::Numberpatterns->uniqueLabel($query->param('patternname'));
309
        $params->{description} = $query->param('sndescription');
310
311
312
        my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params)->store();
313
        return $subscription_np->id;
314
    }
315
316
    return $query->param('numbering_pattern');
317
}
318
319
sub manage_subscription_frequencies_id {
320
    my $periodicity;
321
    if ( $query->param('frequency') eq 'mana' ) {
322
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
296
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
323
            {
297
            {
324
                description   => $query->param('sfdescription'),
298
                description   => $query->param('sfdescription'),
Lines 329-343 sub manage_subscription_frequencies_id { Link Here
329
        )->store();
303
        )->store();
330
        $periodicity = $subscription_freq->id;
304
        $periodicity = $subscription_freq->id;
331
    }
305
    }
332
    else {
306
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing($query->Vars);
333
        $periodicity = $query->param('frequency');
334
    }
335
    return $periodicity;
336
}
337
338
sub redirect_add_subscription {
339
    my $periodicity = manage_subscription_frequencies_id();
340
    my $numberpattern = manage_subscription_numbering_pattern_id();
341
307
342
    my $auser          = $query->param('user');
308
    my $auser          = $query->param('user');
343
    my $branchcode     = $query->param('branchcode');
309
    my $branchcode     = $query->param('branchcode');
Lines 379-387 sub redirect_add_subscription { Link Here
379
        $mana_id = $query->param('mana_id');
345
        $mana_id = $query->param('mana_id');
380
        Koha::SharedContent::manaIncrementRequest("subscription",$mana_id, "nbofusers");
346
        Koha::SharedContent::manaIncrementRequest("subscription",$mana_id, "nbofusers");
381
    }
347
    }
382
    else {
383
        $mana_id = undef;
384
    }
385
348
386
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
349
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
387
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
350
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
Lines 405-411 sub redirect_add_subscription { Link Here
405
        $skip_serialseq, $mana_id
368
        $skip_serialseq, $mana_id
406
    );
369
    );
407
    if ( (C4::Context->preference('Mana')) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
370
    if ( (C4::Context->preference('Mana')) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
408
        my $result = Koha::SharedContent::manaShareInfos( $query, $loggedinuser, $subscriptionid, 'subscription');
371
        my $result = Koha::SharedContent::manaPostRequest( $query->param('mana_language'), $loggedinuser, $subscriptionid, 'subscription');
409
        $template->param( mana_msg => $result->{msg} );
372
        $template->param( mana_msg => $result->{msg} );
410
    }
373
    }
411
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
374
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
Lines 435-442 sub redirect_mod_subscription { Link Here
435
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
398
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
436
        : $firstacquidate;
399
        : $firstacquidate;
437
400
438
    my $periodicity = manage_subscription_frequencies_id();
401
    my $periodicity = $query->param('frequency');
439
    my $numberpattern = manage_subscription_numbering_pattern_id();
402
    if ($periodicity eq 'mana') {
403
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
404
            {
405
                description   => $query->param('sfdescription'),
406
                unit          => $query->param('unit'),
407
                unitsperissue => $query->param('unitsperissue'),
408
                issuesperunit => $query->param('issuesperunit'),
409
            }
410
        )->store();
411
        $periodicity = $subscription_freq->id;
412
    }
413
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing($query->Vars);
440
414
441
    my $subtype = $query->param('subtype');
415
    my $subtype = $query->param('subtype');
442
    my $sublength = $query->param('sublength');
416
    my $sublength = $query->param('sublength');
(-)a/serials/subscription-detail.pl (-5 / +1 lines)
Lines 33-43 use Koha::Acquisition::Bookseller; Link Here
33
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
33
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
34
use Carp;
34
use Carp;
35
35
36
use LWP::UserAgent;
37
use Koha::SharedContent;
36
use Koha::SharedContent;
38
use Koha::Patrons;
39
use Koha::Subscriptions;
40
use Koha::Libraries;
41
37
42
my $query = new CGI;
38
my $query = new CGI;
43
my $op = $query->param('op') || q{};
39
my $op = $query->param('op') || q{};
Lines 100-106 if ($op eq 'del') { Link Here
100
    }
96
    }
101
}
97
}
102
elsif ( $op and $op eq "share" ) {
98
elsif ( $op and $op eq "share" ) {
103
    my $result = Koha::SharedContent::manaShareInfos($query, $loggedinuser, $subscriptionid, 'subscription');
99
    my $result = Koha::SharedContent::manaPostRequest($query->param('mana_language'), $loggedinuser, $subscriptionid, 'subscription');
104
    $template->param( mana_code => $result->{msg} );
100
    $template->param( mana_code => $result->{msg} );
105
    $subs->{mana_id} = $result->{id};
101
    $subs->{mana_id} = $result->{id};
106
}
102
}
(-)a/svc/mana/addvaluetofield (-1 / +7 lines)
Lines 38-42 my ( $auth_status, $sessionID ) = Link Here
38
if ( $auth_status ne "ok" ) {
38
if ( $auth_status ne "ok" ) {
39
    exit 0;
39
    exit 0;
40
}
40
}
41
my $result = Koha::SharedContent::manaIncrementRequest($input->param('resource'), $input->param('id'), $input->param('field'), $input->param('step') );
41
my $result = Koha::SharedContent::manaIncrementRequest(
42
    scalar $input->param('resource'),
43
    scalar $input->param('id'),
44
    scalar $input->param('field'),
45
    scalar $input->param('step')
46
);
47
42
return $result;
48
return $result;
(-)a/svc/mana/search (-1 / +5 lines)
Lines 39-45 if ( $auth_status ne "ok" ) { Link Here
39
}
39
}
40
40
41
my $templatename;
41
my $templatename;
42
$templatename = "mana/mana-".$input->param( "resource" )."-search-result.tt";
42
if ($input->param( "resource" ) eq 'report') {
43
    $templatename = "mana/mana-report-search-result.tt";
44
} else {
45
    $templatename = "mana/mana-subscription-search-result.tt";
46
}
43
47
44
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45
    {
49
    {
(-)a/svc/mana/share (-4 / +7 lines)
Lines 45-55 $content->{resource_id} = $input->param("resource_id"); Link Here
45
$content->{resource_type} = $input->param("resource");
45
$content->{resource_type} = $input->param("resource");
46
$content->{message} = $input->param("message");
46
$content->{message} = $input->param("message");
47
Koha::SharedContent::manaPostRequest('resource_comment', $content);
47
Koha::SharedContent::manaPostRequest('resource_comment', $content);
48
    my $package = "Koha::".ucfirst($input->param('resource'));
48
my $package = "Koha::".ucfirst($input->param('resource'));
49
    my $resource;
49
my $resource;
50
    my $result;
50
my $result;
51
eval{
51
eval{
52
    $result = Koha::SharedContent::manaGetRequestWithId($input->param('resource'), $input->param('id') );
52
    $result = Koha::SharedContent::manaGetRequestWithId(
53
        scalar $input->param('resource'),
54
        scalar $input->param('id')
55
    );
53
};
56
};
54
if ( $@ or $result->{code} == 500 ){
57
if ( $@ or $result->{code} == 500 ){
55
    $resource->{errmsg} =  "Error: mana access got broken, please try again later\n\n ( error: $@ )";
58
    $resource->{errmsg} =  "Error: mana access got broken, please try again later\n\n ( error: $@ )";
(-)a/svc/mana/use (-1 / +4 lines)
Lines 40-46 if ( $auth_status ne "ok" ) { Link Here
40
    exit 0;
40
    exit 0;
41
}
41
}
42
42
43
my $result = Koha::SharedContent::manaGetRequestWithId($input->param('resource'), $input->param('id') );
43
my $result = Koha::SharedContent::manaGetRequestWithId(
44
    scalar $input->param('resource'),
45
    scalar $input->param('id')
46
);
44
my $package = "Koha::".ucfirst($input->param('resource'));
47
my $package = "Koha::".ucfirst($input->param('resource'));
45
my $resource;
48
my $resource;
46
49
(-)a/t/db_dependent/Koha/SharedContent.t (-2 / +222 lines)
Lines 20-29 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
use Test::More tests => 1;
23
use t::lib::Mocks;
24
use Test::MockModule;
25
use Test::MockObject;
26
use Test::More tests => 43;
24
use Koha::Database;
27
use Koha::Database;
28
use Koha::Patrons;
29
use Koha::Subscriptions;
30
31
use HTTP::Status qw(:constants :is status_message);
25
32
26
use_ok('Koha::SharedContent');
33
use_ok('Koha::SharedContent');
27
34
28
my $schema = Koha::Database->new->schema;
35
my $schema = Koha::Database->new->schema;
29
$schema->storage->txn_begin;    # mode insertion
36
$schema->storage->txn_begin;
37
38
my $builder = t::lib::TestBuilder->new();
39
40
my $want_error = 0;
41
my $post_request = 0;
42
my $query = {};
43
44
$Koha::SharedContent::MANA_IP = 'https://foo.bar';
45
my $result = Koha::SharedContent::manaGetRequest('report', $query);
46
ok($result->{msg} =~ /Can\'t connect to foo.bar:443$/, 'Unable to connect');
47
is($result->{code}, 500, 'Code is 500');
48
49
my $ua = Test::MockModule->new('LWP::UserAgent');
50
$ua->mock('request', sub {
51
        return mock_response();
52
});
53
54
$want_error = 1;
55
$query = {query => 'foo', usecomments => 1};
56
$result = Koha::SharedContent::manaGetRequest('report', $query);
57
ok($result->{msg} =~ /^Error thrown by decoded_content/, 'Error in decoded_content');
58
is($result->{code}, 500, 'Code is 500');
59
60
$want_error = 0;
61
$query = {title => 'foo', usecomments => 1};
62
$result = Koha::SharedContent::manaGetRequest('subscription', $query);
63
is($result->{code}, 200, 'manaGetRequest success');
64
65
$result = Koha::SharedContent::manaGetRequestWithId('subscription', 23);
66
is($result->{code}, 200, 'manaGetRequestWithId success');
67
68
my $params = {
69
    title => 'The English historical review',
70
    issn => '0013-8266',
71
    ean => '',
72
    publishercode => 'Longman'
73
};
74
75
# Search a subscription.
76
my $request = Koha::SharedContent::buildRequest('get', 'subscription', $params);
77
is($request->method, 'GET', 'Get subscription - Method is get');
78
79
my %query = $request->uri->query_form;
80
is($query{title}, 'The English historical review', 'Check title');
81
is($query{issn}, '0013-8266', 'Check issn');
82
is($query{ean}, '', 'Check ean');
83
is($query{publishercode}, 'Longman', 'Check publisher');
84
85
is($request->uri->path, '/subscription.json', 'Path is subscription');
86
87
# Get a report by id.
88
$request = Koha::SharedContent::buildRequest('getwithid', 'report', 26);
89
is($request->method, 'GET', 'Get with id - Method is get');
90
91
is($request->uri->path, '/report/26.json', 'Path is report/26.json');
92
93
# Share a report.
94
my $content = {
95
    'kohaversion' => '17.06.00.008',
96
    'language' => 'fr-FR',
97
    'notes' => 'some notes',
98
    'report_group' => '',
99
    'exportemail' => 'xx@xx.com',
100
    'report_name' => 'A useless report',
101
    'savedsql' => 'SELECT * FROM ITEMS',
102
    'type' => undef
103
};
104
105
$request = Koha::SharedContent::buildRequest('post', 'report', $content);
106
is($request->method, 'POST', 'Share report - Method is post');
107
108
is($request->uri->path, '/report.json', 'Path is report.json');
109
110
# prepare shared data
111
my $loggedinuser = $builder->build({
112
    source => 'Borrower',
113
    value => {
114
        email => '',
115
        emailpro => '',
116
        B_email => ''
117
    }
118
});
119
120
my $library = $builder->build({
121
    source => 'Branch',
122
});
123
124
my $biblio = $builder->build({
125
    source => 'Biblio',
126
});
127
128
my $biblioitem = $builder->build({
129
    source => 'Biblioitem',
130
    value => {
131
        biblionumber => $biblio->{biblionumber}
132
    }
133
});
134
135
my $subscriptionFrequency = $builder->build({
136
    source => 'SubscriptionFrequency'
137
});
138
139
my $subscriptionNumberpattern = $builder->build({
140
    source => 'SubscriptionNumberpattern'
141
});
142
143
my $subscription = $builder->build({
144
    source => 'Subscription',
145
    value => {
146
        biblionumber => $biblio->{biblionumber},
147
        periodicity => $subscriptionFrequency->{id},
148
        numberpattern => $subscriptionNumberpattern->{id},
149
        mana_id => undef
150
    }
151
});
152
153
C4::Context->_new_userenv('xxx');
154
C4::Context->set_userenv(0,0,0,
155
    $loggedinuser->{firstname},
156
    $loggedinuser->{surname},
157
    $library->{branchcode},
158
    'Midway Public Library', '', '', '');
159
160
t::lib::Mocks::mock_preference('language', 'en');
161
162
$post_request = 1;
163
$result = Koha::SharedContent::manaPostRequest('en', $loggedinuser->{borrowernumber}, $subscription->{subscriptionid}, 'subscription');
164
is($result->{code}, 200, 'manaPostRequest success');
165
166
my $s = Koha::Subscriptions->find($subscription->{subscriptionid});
167
is($s->mana_id, 5, 'Mana id is set');
168
169
my $data = Koha::SharedContent::prepareSharedData(
170
    '',
171
    $loggedinuser->{borrowernumber},
172
    $subscription->{subscriptionid},
173
    'subscription'
174
);
175
176
is($data->{language}, 'en', 'Language is set to default');
177
my $branch = Koha::Libraries->find($library->{branchcode});
178
is($data->{exportemail}, $branch->branchemail, 'Email is set with the userenv branch one');
179
is($data->{title}, $biblio->{title}, 'Shared title');
180
is($data->{sfdescription}, $subscriptionFrequency->{description}, 'Shared sfdescription');
181
is($data->{unit}, $subscriptionFrequency->{unit}, 'Shared unit');
182
is($data->{unitsperissue}, $subscriptionFrequency->{unitsperissue}, 'Shared unitsperissue');
183
is($data->{issuesperunit}, $subscriptionFrequency->{issuesperunit}, 'Shared issuesperunit');
184
185
is($data->{label}, $subscriptionNumberpattern->{label}, 'Shared np label');
186
is($data->{sndescription}, $subscriptionNumberpattern->{description}, 'Shared np description');
187
is($data->{numberingmethod}, $subscriptionNumberpattern->{numberingmethod}, 'Shared numberingmethod');
188
is($data->{label1}, $subscriptionNumberpattern->{label1}, 'Shared label1');
189
is($data->{add1}, $subscriptionNumberpattern->{add1}, 'Shared add1');
190
is($data->{every1}, $subscriptionNumberpattern->{every1}, 'Shared every1');
191
is($data->{whenmorethan1}, $subscriptionNumberpattern->{whenmorethan1}, 'Shared whenmorethan1');
192
is($data->{setto1}, $subscriptionNumberpattern->{setto1}, 'Shared setto1');
193
is($data->{numbering1}, $subscriptionNumberpattern->{numbering1}, 'Shared numbering1');
194
is($data->{issn}, $biblioitem->{issn}, 'Shared ISSN');
195
is($data->{ean}, $biblioitem->{ean}, 'Shared EAN');
196
is($data->{publishercode}, $biblioitem->{publishercode}, 'Shared publishercode');
197
198
sub mock_response {
199
    my $response = Test::MockObject->new();
200
201
    if ($want_error) {
202
        $response->mock('code', sub {
203
            return 500;
204
        });
205
        $response->mock('is_error', sub {
206
            return 0;
207
        });
208
        $response->mock('decoded_content', sub {
209
            die 'Error thrown by decoded_content';
210
        });
211
    } elsif ( $post_request ) {
212
        $response->mock('code', sub {
213
            return 200;
214
        });
215
        $response->mock('is_error', sub {
216
            return 0;
217
        });
218
        $response->mock('decoded_content', sub {
219
            return '{"code": "200", "msg": "foo", "id": "5"}';
220
        });
221
    } else {
222
        $response->mock('code', sub {
223
            return 200;
224
        });
225
        $response->mock('is_error', sub {
226
            return 0;
227
        });
228
        $response->mock('decoded_content', sub {
229
            return '';
230
        });
231
    }
232
}
233
234
# Increment request.
235
$request = Koha::SharedContent::buildRequest('increment',
236
                                             'subscription',
237
                                             12,
238
                                             'foo');
239
240
is($request->method, 'POST', 'Increment subscription - Method is post');
241
242
%query = $request->uri->query_form;
243
is($query{id}, 12, 'Check id');
244
is($query{step}, 1, 'Step is default');
245
is($query{resource}, 'subscription', 'Check ressource');
246
247
is($request->uri->path, '/subscription/12.json/increment/foo', 'Path is subscription');
248
249
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Subscription/Numberpatterns.t (+97 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2017 BibLibre
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use t::lib::TestBuilder;
23
use Test::More tests => 6;
24
use Koha::Database;
25
26
use_ok('Koha::Subscription::Numberpatterns');
27
28
my $schema = Koha::Database->new->schema;
29
$schema->storage->txn_begin;
30
my $builder = t::lib::TestBuilder->new;
31
32
my $dbh = C4::Context->dbh;
33
$dbh->do('DELETE FROM subscription_numberpatterns');
34
35
my $numberpattern = $builder->build({
36
    source => 'SubscriptionNumberpattern',
37
    value => {
38
        label => 'Volume, Number, Issue',
39
        description => 'Volume Number Issue 1',
40
        numberingmethod => 'Vol.{X}, Number {Y}, Issue {Z}',
41
        label1 => 'Volume',
42
        add1 => '1',
43
        every1 => '48',
44
        whenmorethan1 => '99999',
45
        setto1 => '1',
46
        numbering1 => undef,
47
        label2 => 'Number',
48
        add2 => '1',
49
        every2 => '4',
50
        whenmorethan2 => '12',
51
        setto2 => '1',
52
        numbering2 => undef,
53
        label3 => 'Issue',
54
        add3 => '1',
55
        every3 => '1',
56
        whenmorethan3 => '4',
57
        setto3 => '1',
58
        numbering3 => undef
59
    }
60
});
61
62
my $search_ok = {
63
    umberingmethod => 'Vol.{X}, Number {Y}, Issue {Z}',
64
    label1 => 'Volume', add1 => '1', every1 => '48',
65
    whenmorethan1 => '99999', setto1 => '1',
66
    label2 => 'Number', add2 => '1', every2 => '4',
67
    whenmorethan2 => '12', setto2 => '1',
68
    label3 => 'Issue', add3 => '1', every3 => '1',
69
    whenmorethan3 => '4', setto3 => '1',
70
    numbering_pattern => 'mana'
71
};
72
73
my $number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing($search_ok);
74
is($number_pattern_id, $numberpattern->{id}, 'new_or_existing method should find the existing number pattern');
75
76
$number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing({numbering_pattern => 1});
77
is($number_pattern_id, 1, 'new_or_existing method should return passed numbering_pattern');
78
79
my $search_not_ok = {
80
    patternname => 'Number',
81
    sndescription => 'Simple Numbering method',
82
    numberingmethod => 'No.{X}',
83
    label1 => 'Number',
84
    add1 => 1,
85
    every1 => 1,
86
    whenmorethan1 => 99999,
87
    setto1 => 1,
88
    numbering_pattern => 'mana'
89
};
90
91
$number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing($search_not_ok);
92
my $new_number_pattern = Koha::Subscription::Numberpatterns->find($number_pattern_id);
93
is($new_number_pattern->label, 'Number');
94
is($new_number_pattern->description, 'Simple Numbering method');
95
is($new_number_pattern->numberingmethod, 'No.{X}');
96
97
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Serials/GetFictiveIssueNumber.t (-114 / +219 lines)
Lines 1-126 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use C4::Context;
3
# This test deals with GetFictiveIssueNumber (from C4::Serials)
4
use Test::More tests => 18;
4
5
use Modern::Perl;
5
use Modern::Perl;
6
use Test::More tests => 5;
7
8
use Koha::Database;
9
use C4::Serials;
10
use C4::Serials::Frequency;
6
11
12
my $schema  = Koha::Database->new->schema;
13
$schema->storage->txn_begin;
7
my $dbh = C4::Context->dbh;
14
my $dbh = C4::Context->dbh;
8
$dbh->{RaiseError} = 1;
9
$dbh->{AutoCommit} = 0;
10
15
11
use C4::Serials::Frequency;
16
subtest 'Tests for irregular frequency' => sub {
12
use C4::Serials;
17
    plan tests => 2;
13
18
14
# TEST CASE - 1 issue per day, no irregularities
19
    # Add a frequency
15
my $frequency = {
20
    my $freq_irr = AddSubscriptionFrequency({
16
    description   => "One issue per day",
21
        description => "Irregular",
17
    unit          => 'day',
22
        unit => undef,
18
    issuesperunit => 1,
23
    });
19
    unitsperissue => 1,
20
};
21
24
22
my $subscription = {
25
    # Test it
23
    firstacquidate     => '1970-01-01',
26
    my $subscription = {
24
    irregularity       => '',
27
        periodicity => $freq_irr,
25
    countissuesperunit => 1,
28
        firstacquidate => '1972-02-07',
26
};
29
    };
27
my $issueNumber;
30
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), undef, 'Irregular: should be undef' );
28
31
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), undef, 'Irregular: still undef' );
29
$issueNumber =
30
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
31
is( $issueNumber, '1' );
32
33
$issueNumber =
34
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
35
is( $issueNumber, '2' );
36
$issueNumber =
37
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
38
is( $issueNumber, '3' );
39
40
# TEST CASE - 2 issues per day, no irregularity
41
$frequency = {
42
    description   => "Two issues per day",
43
    unit          => 'day',
44
    issuesperunit => 2,
45
    unitsperissue => 1,
46
};
32
};
47
$subscription = {
33
48
    firstacquidate     => '1970-01-01',
34
subtest 'Tests for yearly frequencies' => sub {
49
    irregularity       => '',
35
    plan tests => 10;
50
    countissuesperunit => 1,
36
51
};
37
    # First add a few frequencies
52
$issueNumber =
38
    my $freq_1i_1y = AddSubscriptionFrequency({
53
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
39
        description => "1 issue per year",
54
is( $issueNumber, '1' );
40
        unit => 'year',
55
$issueNumber =
41
        issuesperunit => 1,
56
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
42
        unitsperissue => 1,
57
is( $issueNumber, '3' );
43
    });
58
$issueNumber =
44
    my $freq_1i_3y = AddSubscriptionFrequency({
59
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
45
        description => "1 issue per 3 years",
60
is( $issueNumber, '5' );
46
        unit => 'year',
61
47
        issuesperunit => 1,
62
$subscription->{countissuesperunit} = 2;
48
        unitsperissue => 3,
63
$issueNumber =
49
    });
64
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
50
    my $freq_5i_1y = AddSubscriptionFrequency({
65
is( $issueNumber, '2' );
51
        description => "5 issues per year",
66
$issueNumber =
52
        unit => 'year',
67
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
53
        issuesperunit => 5,
68
is( $issueNumber, '4' );
54
        unitsperissue => 1,
69
$issueNumber =
55
    });
70
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
56
    my $freq_366i_1y = AddSubscriptionFrequency({
71
is( $issueNumber, '6' );
57
        description => "366 issue per year",
72
58
        unit => 'year',
73
# TEST CASE - 1 issue every 2 days, no irregularity
59
        issuesperunit => 366,
74
$frequency = {
60
        unitsperissue => 1,
75
    description   => "one issue every two days",
61
    });
76
    unit          => 'day',
62
77
    issuesperunit => 1,
63
    # TEST CASE - 1 issue per year
78
    unitsperissue => 2,
64
    my $subscription = {
65
        periodicity => $freq_1i_1y,
66
        firstacquidate => '1972-02-10',
67
        countissuesperunit => 1,
68
    };
69
70
    my $frequency = GetSubscriptionFrequency($freq_1i_1y);
71
72
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-09', $frequency), 1, 'Feb 9 still 1' );
73
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-10', $frequency), 2, 'Feb 10 goes to 2' );
74
75
    # TEST CASE - 1 issue per 3 years
76
    $subscription->{periodicity} = $freq_1i_3y;
77
    $subscription->{firstacquidate} = '1972-02-20';
78
    $frequency = GetSubscriptionFrequency($freq_1i_3y);
79
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-19', $frequency), 1, 'Feb 19, 1975 still 1' );
80
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-20', $frequency), 2, 'Feb 20, 1975 goes to 2' );
81
82
    # TEST CASE - 5 issues per year
83
    $subscription->{periodicity} = $freq_5i_1y;
84
    $subscription->{firstacquidate} = '1972-02-29'; #leap year
85
    $subscription->{countissuesperunit} = 1;
86
    $frequency = GetSubscriptionFrequency($freq_5i_1y);
87
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-11', $frequency), 1, 'May 11 still 1' );
88
    $subscription->{countissuesperunit} = 2;
89
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-12', $frequency), 2, 'May 12 goes to 2' );
90
    $subscription->{countissuesperunit} = 5;
91
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27', $frequency), 5, 'Feb 27 should still be 5' );
92
    $subscription->{countissuesperunit} = 1;
93
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28', $frequency), 6, 'Feb 28 goes to 6' );
94
95
    # TEST CASE - 366 issues per year (hypothetical example)
96
    # Testing prevention of divide by zero
97
    $subscription->{periodicity} = $freq_366i_1y;
98
    $subscription->{firstacquidate} = '1972-02-29'; #leap year
99
    $subscription->{countissuesperunit} = 366;
100
    $frequency = GetSubscriptionFrequency($freq_366i_1y);
101
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27', $frequency), 366, 'Feb 27 still at 366' );
102
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28', $frequency), 732, 'Feb 28 goes to 732' );
103
79
};
104
};
80
$subscription = {
105
81
    firstacquidate     => '1970-01-01',
106
subtest 'Tests for monthly frequencies' => sub {
82
    irregularity       => '',
107
    plan tests => 8;
83
    countissuesperunit => 1,
108
109
    # First add a few frequencies
110
    my $freq_1i_5m = AddSubscriptionFrequency({
111
        description => "1 issue per 5 months",
112
        unit => 'month',
113
        issuesperunit => 1,
114
        unitsperissue => 5,
115
    });
116
    my $freq_4i_1m = AddSubscriptionFrequency({
117
        description => "4 issue per month",
118
        unit => 'month',
119
        issuesperunit => 4,
120
        unitsperissue => 1,
121
    });
122
123
    # TEST CASE - 1 issue per 5 months
124
    my $subscription = {
125
        periodicity => $freq_1i_5m,
126
        firstacquidate => '1972-02-10',
127
        countissuesperunit => 1,
128
    };
129
    my $frequency = GetSubscriptionFrequency($freq_1i_5m);
130
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-09', $frequency), 1, 'Jul 9 still 1' );
131
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-10', $frequency), 2, 'Jul 10 goes to 2' );
132
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-09', $frequency), 3, 'May 9 still 3' );
133
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-10', $frequency), 4, 'May 10 goes to 4' );
134
135
    # TEST CASE - 4 issue per 1 months
136
    $subscription = {
137
        periodicity => $freq_4i_1m,
138
        firstacquidate => '1972-02-22',
139
        countissuesperunit => 1,
140
    };
141
    $frequency = GetSubscriptionFrequency($freq_4i_1m);
142
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-28', $frequency), 1, 'Feb 28 still 1' );
143
    $subscription->{countissuesperunit} = 2;
144
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-29', $frequency), 2, 'Feb 29 goes to 2' );
145
    $subscription->{countissuesperunit} = 4;
146
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-21', $frequency), 4, 'Mar 21 still 4' );
147
    $subscription->{countissuesperunit} = 1;
148
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-22', $frequency), 5, 'Mar 22 goes to 5' );
149
84
};
150
};
85
$issueNumber =
151
86
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
152
subtest 'Tests for weekly frequencies' => sub {
87
is( $issueNumber, 1 );
153
    plan tests => 4;
88
$issueNumber =
154
89
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
155
    # First add a few frequencies
90
is( $issueNumber, 1 );
156
    my $freq_1i_7w = AddSubscriptionFrequency({
91
$issueNumber =
157
        description => "1 issue per 7 weeks",
92
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
158
        unit => 'week',
93
is( $issueNumber, 2 );
159
        issuesperunit => 1,
94
$issueNumber =
160
        unitsperissue => 7,
95
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-04', $frequency );
161
    });
96
is( $issueNumber, 2 );
162
    my $freq_3i_1w = AddSubscriptionFrequency({
97
$issueNumber =
163
        description => "3 issues per week",
98
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-05', $frequency );
164
        unit => 'week',
99
is( $issueNumber, 3 );
165
        issuesperunit => 3,
100
166
        unitsperissue => 1,
101
# TEST CASE - 1 issue per week, no irregularity
167
    });
102
$frequency = {
168
103
    description   => "one issue per week",
169
    # TEST CASE - 1 issue per 7 weeks
104
    unit          => 'week',
170
    my $subscription = {
105
    issuesperunit => 1,
171
        periodicity => $freq_1i_7w,
106
    unitsperissue => 1,
172
        firstacquidate => '1972-02-10',
173
        countissuesperunit => 1,
174
    };
175
    my $frequency = GetSubscriptionFrequency($freq_1i_7w);
176
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-29', $frequency), 1, 'Mar 29 still 1' );
177
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-30', $frequency), 2, 'Mar 30 goes to 2' );
178
179
    # TEST CASE - 3 issue per 1 week
180
    $subscription = {
181
        periodicity => $freq_3i_1w,
182
        firstacquidate => '1972-02-03',
183
        countissuesperunit => 1,
184
    };
185
    $subscription->{countissuesperunit} = 3;
186
    $frequency = GetSubscriptionFrequency($freq_3i_1w);
187
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-09', $frequency), 3, 'Feb 9 still 3' );
188
    $subscription->{countissuesperunit} = 1;
189
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-10', $frequency), 4, 'Feb 10 goes to 4' );
107
};
190
};
108
$subscription = {
191
109
    firstacquidate     => '1970-01-01',
192
subtest 'Tests for dayly frequencies' => sub {
110
    irregularity       => '',
193
    plan tests => 4;
111
    countissuesperunit => 1,
194
195
    # First add a few frequencies
196
    my $freq_1i_12d = AddSubscriptionFrequency({
197
        description => "1 issue per 12 days",
198
        unit => 'day',
199
        issuesperunit => 1,
200
        unitsperissue => 12,
201
    });
202
    my $freq_3i_1d = AddSubscriptionFrequency({
203
        description => "3 issues per day",
204
        unit => 'day',
205
        issuesperunit => 3,
206
        unitsperissue => 1,
207
    });
208
209
    # TEST CASE - 1 issue per 12 days
210
    my $subscription = {
211
        periodicity => $freq_1i_12d,
212
        firstacquidate => '1972-03-16',
213
        countissuesperunit => 1,
214
    };
215
    my $frequency = GetSubscriptionFrequency($freq_1i_12d);
216
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-27', $frequency), 1, 'Mar 27 still 1' );
217
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-28', $frequency), 2, 'Mar 28 goes to 2' );
218
219
    # TEST CASE - 3 issue per day
220
    $subscription = {
221
        periodicity => $freq_3i_1d,
222
        firstacquidate => '1972-04-23',
223
        countissuesperunit => 1,
224
    };
225
    $subscription->{countissuesperunit} = 3;
226
    $frequency = GetSubscriptionFrequency($freq_3i_1d);
227
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-01', $frequency), 27, 'May 1 still 27' );
228
    $subscription->{countissuesperunit} = 1;
229
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-02', $frequency), 28, 'May 2 goes to 28' );
112
};
230
};
113
$issueNumber =
231
114
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
232
$schema->storage->txn_rollback;
115
is( $issueNumber, 1 );
116
$issueNumber =
117
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
118
is( $issueNumber, 1 );
119
$issueNumber =
120
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-08', $frequency );
121
is( $issueNumber, 2 );
122
$issueNumber =
123
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-15', $frequency );
124
is( $issueNumber, 3 );
125
126
$dbh->rollback;
127
- 

Return to bug 17047