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

(-)a/mainpage.pl (-87 / +130 lines)
Lines 80-201 my $branch = Link Here
80
    ? C4::Context->userenv()->{'branch'}
80
    ? C4::Context->userenv()->{'branch'}
81
    : undef;
81
    : undef;
82
82
83
my $pendingcomments = Koha::Reviews->search_limited( { approved => 0 } )->count;
83
my @staff_mainpage_notifications = split /,/, C4::Context->preference('StaffMainPageNotifications');
84
my $pendingtags     = get_count_by_tag_status(0);
84
my %enabled_notifications        = map { $_ => 1 } @staff_mainpage_notifications;
85
85
86
# Get current branch count and total viewable count, if they don't match then pass
86
if ( $enabled_notifications{'Comments'} ) {
87
# both to template
87
    my $pendingcomments = Koha::Reviews->search_limited( { approved => 0 } )->count;
88
89
if ( C4::Context->only_my_library ) {
90
    my $local_pendingsuggestions_count = Koha::Suggestions->search(
91
        { status => "ASKED", branchcode => C4::Context->userenv()->{'branch'}, archived => 0 } )->count();
92
    $template->param( pendingsuggestions => $local_pendingsuggestions_count );
93
} else {
94
    my $pendingsuggestions = Koha::Suggestions->search( { status => "ASKED", archived => 0 } );
95
    my $local_pendingsuggestions_count =
96
        $pendingsuggestions->search( { 'me.branchcode' => C4::Context->userenv()->{'branch'} } )->count();
97
    my $pendingsuggestions_count = $pendingsuggestions->count();
98
    $template->param(
88
    $template->param(
99
        all_pendingsuggestions => $pendingsuggestions_count != $local_pendingsuggestions_count
89
        pendingcomments => $pendingcomments,
100
        ? $pendingsuggestions_count
101
        : 0,
102
        pendingsuggestions => $local_pendingsuggestions_count
103
    );
90
    );
104
}
91
}
105
92
106
my $pending_borrower_modifications   = Koha::Patron::Modifications->pending_count($branch);
93
if ( $enabled_notifications{'Tags'} ) {
107
my $local_pendingmodifications_count = Koha::Patron::Modifications->pending_count( C4::Context->userenv()->{'branch'} );
94
    my $pendingtags = get_count_by_tag_status(0);
95
    $template->param(
96
        pendingtags => $pendingtags,
97
    );
98
}
108
99
109
my $pending_discharge_requests = Koha::Patron::Discharge::count( { pending => 1 } );
100
if ( $enabled_notifications{'Suggestions'} ) {
110
my $pending_article_requests   = Koha::ArticleRequests->search_limited(
101
    if ( C4::Context->only_my_library ) {
111
    {
102
        my $local_pendingsuggestions_count = Koha::Suggestions->search(
112
        status => Koha::ArticleRequest::Status::Requested,
103
            { status => "ASKED", branchcode => C4::Context->userenv()->{'branch'}, archived => 0 } )->count();
113
        $branch ? ( 'me.branchcode' => $branch ) : (),
104
        $template->param( pendingsuggestions => $local_pendingsuggestions_count );
105
    } else {
106
        my $pendingsuggestions = Koha::Suggestions->search( { status => "ASKED", archived => 0 } );
107
        my $local_pendingsuggestions_count =
108
            $pendingsuggestions->search( { 'me.branchcode' => C4::Context->userenv()->{'branch'} } )->count();
109
        my $pendingsuggestions_count = $pendingsuggestions->count();
110
        $template->param(
111
            all_pendingsuggestions => $pendingsuggestions_count != $local_pendingsuggestions_count
112
            ? $pendingsuggestions_count
113
            : 0,
114
            pendingsuggestions => $local_pendingsuggestions_count
115
        );
114
    }
116
    }
115
)->count;
117
}
116
my $pending_problem_reports = Koha::ProblemReports->search( { status => 'New' } );
118
119
if ( $enabled_notifications{'PatronModifications'} ) {
120
    my $pending_borrower_modifications = Koha::Patron::Modifications->pending_count($branch);
121
    my $local_pendingmodifications_count =
122
        Koha::Patron::Modifications->pending_count( C4::Context->userenv()->{'branch'} );
123
    $template->param(
124
        pending_borrower_modifications => $pending_borrower_modifications,
125
        pending_local_borrowermods     => $local_pendingmodifications_count,
126
    );
127
}
128
129
if ( $enabled_notifications{'DischargeRequests'} ) {
130
    my $pending_discharge_requests = Koha::Patron::Discharge::count( { pending => 1 } );
131
    $template->param(
132
        pending_discharge_requests => $pending_discharge_requests,
133
    );
134
}
117
135
118
if ( C4::Context->preference('OpacCatalogConcerns') || C4::Context->preference('CatalogConcerns') ) {
136
if ( $enabled_notifications{'ArticleRequests'} ) {
119
    my $pending_biblio_tickets = Koha::Tickets->search(
137
    my $pending_article_requests = Koha::ArticleRequests->search_limited(
120
        {
138
        {
121
            resolved_date => undef,
139
            status => Koha::ArticleRequest::Status::Requested,
122
            biblio_id     => { '!=' => undef }
140
            $branch ? ( 'me.branchcode' => $branch ) : (),
123
        }
141
        }
142
    )->count;
143
    $template->param(
144
        pending_article_requests => $pending_article_requests,
124
    );
145
    );
125
    $template->param( pending_biblio_tickets => $pending_biblio_tickets->count );
126
}
146
}
127
147
128
unless ( $logged_in_user->has_permission( { parameters => 'manage_background_jobs' } ) ) {
148
if ( $enabled_notifications{'ProblemReports'} ) {
129
    my $already_ran_jobs =
149
    my $pending_problem_reports = Koha::ProblemReports->search( { status => 'New' } );
130
        Koha::BackgroundJobs->search( { borrowernumber => $logged_in_user->borrowernumber } )->count ? 1 : 0;
150
    $template->param(
131
    $template->param( already_ran_jobs => $already_ran_jobs );
151
        pending_problem_reports => $pending_problem_reports,
152
    );
132
}
153
}
133
154
134
$template->param(
155
if ( $enabled_notifications{'BiblioTickets'} ) {
135
    holds_with_cancellation_requests => Koha::Holds->waiting->filter_by_has_cancellation_requests->count );
156
    if ( C4::Context->preference('OpacCatalogConcerns') || C4::Context->preference('CatalogConcerns') ) {
136
157
        my $pending_biblio_tickets = Koha::Tickets->search(
137
my $holds_to_pull_start_date = C4::Context->preference('HoldsToPullStartDate') || 2;
158
            {
138
my $reserves_to_pull_from    = dt_from_string()->subtract( days => $holds_to_pull_start_date );
159
                resolved_date => undef,
160
                biblio_id     => { '!=' => undef }
161
            }
162
        );
163
        $template->param( pending_biblio_tickets => $pending_biblio_tickets->count );
164
    }
165
}
139
166
140
my $holds_to_pull = Koha::Holds->search(
167
if ( $enabled_notifications{'Jobs'} ) {
141
    {
168
    unless ( $logged_in_user->has_permission( { parameters => 'manage_background_jobs' } ) ) {
142
        found       => undef,
169
        my $already_ran_jobs =
143
        reservedate => { '>=' => $reserves_to_pull_from->ymd() }
170
            Koha::BackgroundJobs->search( { borrowernumber => $logged_in_user->borrowernumber } )->count ? 1 : 0;
171
        $template->param( already_ran_jobs => $already_ran_jobs );
144
    }
172
    }
145
)->count;
173
}
146
174
147
#get local holds to pull by looking for holds with an item homebranch that matches the loggedinuser's location
175
if ( $enabled_notifications{'HoldCancellations'} ) {
148
my $local_holds_to_pull = Koha::Holds->search(
176
    $template->param(
149
    {
177
        holds_with_cancellation_requests => Koha::Holds->waiting->filter_by_has_cancellation_requests->count );
150
        'me.found'        => undef,
178
}
151
        'item.homebranch' => C4::Context->userenv()->{'branch'},
152
        'me.reservedate'  => { '>=' => $reserves_to_pull_from->ymd() }
153
    },
154
    { join => 'item' }
155
)->count;
156
179
157
my $holds_queue_count = Koha::Hold::HoldsQueueItems->search()->count;
180
if ( $enabled_notifications{'HoldsToPull'} ) {
181
    my $holds_to_pull_start_date = C4::Context->preference('HoldsToPullStartDate') || 2;
182
    my $reserves_to_pull_from    = dt_from_string()->subtract( days => $holds_to_pull_start_date );
158
183
159
my $local_holds_queue_count =
184
    my $holds_to_pull = Koha::Holds->search(
160
    Koha::Hold::HoldsQueueItems->search( { 'me.holdingbranch' => C4::Context->userenv()->{'branch'} } )->count;
185
        {
186
            found       => undef,
187
            reservedate => { '>=' => $reserves_to_pull_from->ymd() }
188
        }
189
    )->count;
161
190
162
$template->param(
191
    #get local holds to pull by looking for holds with an item homebranch that matches the loggedinuser's location
163
    holds_queue_count       => $holds_queue_count,
192
    my $local_holds_to_pull = Koha::Holds->search(
164
    local_holds_queue_count => $local_holds_queue_count,
193
        {
165
);
194
            'me.found'        => undef,
195
            'item.homebranch' => C4::Context->userenv()->{'branch'},
196
            'me.reservedate'  => { '>=' => $reserves_to_pull_from->ymd() }
197
        },
198
        { join => 'item' }
199
    )->count;
166
200
167
if ( C4::Context->preference('CurbsidePickup') ) {
168
    $template->param(
201
    $template->param(
169
        new_curbside_pickups => Koha::CurbsidePickups->search(
202
        holds_to_pull       => $holds_to_pull,
170
            {
203
        local_holds_to_pull => $local_holds_to_pull,
171
                branchcode => $homebranch,
172
            }
173
        )->filter_by_to_be_staged->filter_by_scheduled_today,
174
    );
204
    );
175
}
205
}
176
206
177
if ( C4::Context->preference('PatronSelfRegistrationAlert') ) {
207
if ( $enabled_notifications{'HoldsQueue'} ) {
178
    my $categorycode = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
208
    my $holds_queue_count = Koha::Hold::HoldsQueueItems->search()->count;
179
    my $branchcode   = C4::Context::mybranch();
180
209
181
    my $rs = Koha::Patrons->search( { categorycode => $categorycode } );
210
    my $local_holds_queue_count =
211
        Koha::Hold::HoldsQueueItems->search( { 'me.holdingbranch' => C4::Context->userenv()->{'branch'} } )->count;
182
212
183
    $template->param(
213
    $template->param(
184
        self_registered_count          => $rs->count,
214
        holds_queue_count       => $holds_queue_count,
185
        self_registered_mybranch_count => $rs->search( { branchcode => $branchcode } )->count,
215
        local_holds_queue_count => $local_holds_queue_count,
186
    );
216
    );
187
}
217
}
188
218
189
$template->param(
219
if ( $enabled_notifications{'CurbsidePickups'} ) {
190
    pendingcomments                => $pendingcomments,
220
    if ( C4::Context->preference('CurbsidePickup') ) {
191
    pendingtags                    => $pendingtags,
221
        $template->param(
192
    pending_borrower_modifications => $pending_borrower_modifications,
222
            new_curbside_pickups => Koha::CurbsidePickups->search(
193
    pending_local_borrowermods     => $local_pendingmodifications_count,
223
                {
194
    pending_discharge_requests     => $pending_discharge_requests,
224
                    branchcode => $homebranch,
195
    pending_article_requests       => $pending_article_requests,
225
                }
196
    pending_problem_reports        => $pending_problem_reports,
226
            )->filter_by_to_be_staged->filter_by_scheduled_today,
197
    holds_to_pull                  => $holds_to_pull,
227
        );
198
    local_holds_to_pull            => $local_holds_to_pull,
228
    }
199
);
229
}
230
231
if ( $enabled_notifications{'SelfRegistrations'} ) {
232
    if ( C4::Context->preference('PatronSelfRegistrationAlert') ) {
233
        my $categorycode = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
234
        my $branchcode   = C4::Context::mybranch();
235
236
        my $rs = Koha::Patrons->search( { categorycode => $categorycode } );
237
238
        $template->param(
239
            self_registered_count          => $rs->count,
240
            self_registered_mybranch_count => $rs->search( { branchcode => $branchcode } )->count,
241
        );
242
    }
243
}
200
244
201
output_html_with_http_headers $query, $cookie, $template->output;
245
output_html_with_http_headers $query, $cookie, $template->output;
202
- 

Return to bug 41513