Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
BulkActionControllerTrait
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 1
 redirectToSource
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3/**
4 * VuFind Action Feature Trait - Controller bulk action helper methods
5 * Depends on access to the config loader and the cart_followup session container.
6 *
7 * PHP version 8
8 *
9 * Copyright (C) Villanova University 2024
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2,
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 *
24 * @category VuFind
25 * @package  Controller_Plugins
26 * @author   Demian Katz <demian.katz@villanova.edu>
27 * @author   Thomas Wagener <wagener@hebis.uni-frankfurt.de>
28 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
29 * @link     https://vufind.org Main Page
30 */
31
32namespace VuFind\Controller\Feature;
33
34/**
35 * VuFind Action Feature Trait - Controller bulk action helper methods
36 *
37 * @category VuFind
38 * @package  Controller_Plugins
39 * @author   Demian Katz <demian.katz@villanova.edu>
40 * @author   Thomas Wagener <wagener@hebis.uni-frankfurt.de>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org Main Page
43 */
44trait BulkActionControllerTrait
45{
46    use \VuFind\Feature\BulkActionTrait;
47
48    /**
49     * Support method: redirect to the page we were on when the bulk action was
50     * initiated.
51     *
52     * @param string $flashNamespace     Namespace for flash message (null for none)
53     * @param string $flashMsg           Flash message to set (ignored if namespace null)
54     * @param bool   $redirectInLightbox If the redirects are performed even if in lightbox
55     *
56     * @return mixed
57     */
58    public function redirectToSource($flashNamespace = null, $flashMsg = null, $redirectInLightbox = false)
59    {
60        // Set flash message if requested:
61        if (null !== $flashNamespace && !empty($flashMsg)) {
62            $this->flashMessenger()->addMessage($flashMsg, $flashNamespace);
63        }
64
65        // Do not redirect if in lightbox only if required
66        if (
67            !$this->params()->fromPost('redirectInLightbox', false)
68            && !$redirectInLightbox
69            && $this->inLightbox()
70        ) {
71            return false;
72        }
73
74        // If we entered the controller in the expected way (i.e. via the
75        // myresearchbulk action), we should have a source set in the followup
76        // memory. If that's missing for some reason, just forward to MyResearch.
77        if (isset($this->session->url)) {
78            $target = $this->session->url;
79            unset($this->session->url);
80        } else {
81            $target = $this->url()->fromRoute('myresearch-home');
82        }
83        return $this->redirect()->toUrl($target);
84    }
85}