aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/files_dashboard.php
blob: 7268afd3c616752ce9336b0d2d9975407c079f0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/*
 * files_dashboard.php - files dashboard page controller
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @license  http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category Stud.IP
 * @since    4.1
 */

use FilesSearch\Filter;
use FilesSearch\Query;
use FilesSearch\Search;

require_once 'app/controllers/files_dashboard/helpers.php';
require_once 'app/controllers/files_dashboard/sidebar.php';

/**
 * This controller shows the files dashboard and the files dashboard's
 * search.
 *
 * @license GPL2 or any later version
 *
 * @since   Stud.IP 4.1
 */
class FilesDashboardController extends AuthenticatedController
{
    use FilesDashboard\Helpers;
    use FilesDashboard\Sidebar;

    /**
     * Callback function being called before an action is executed.
     *
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
     * @SuppressWarnings(PHPMD.Superglobals)
     */
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        PageLayout::setHelpKeyword('Basis.FilesDashboard'); // set keyword for new help

        $this->user = $GLOBALS['user'];
    }


    // ***** SEARCH *****

    /**
     * Entry point of the controller that displays the dashboard's
     * search page of Stud.IP.
     *
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
     */
    public function search_action()
    {
        // FilesController::getRangeLink
        require_once 'app/controllers/files.php';

        if (Navigation::hasItem('/contents/files/search')) {
            Navigation::activateItem('/contents/files/search');
        }
        PageLayout::setTitle(_('Dokumentensuche'));

        $this->query = new Query();
        $this->query
            ->setQuery($this->getQuery())
            ->setPage($this->getPage())
            ->setFilter($this->getFilter())
            ->setSort(Query::SORT_RELEVANCE);

        $this->result = Search::query($this->query);

        $this->addSearchSidebar();
    }

    private function getQuery()
    {
        return \Request::get('q', null);
    }

    /**
     * This method return the requested page.
     *
     * @return int the requested page.
     */
    public function getPage()
    {
        return \Request::get('page', 0);
    }

    /**
     * This method creates a new Filter object from the request.
     *
     * @return Filter the new Filter object
     */
    public function getFilter()
    {
        $filterArray = \Request::getArray('filter');

        $filter = new Filter();

        if (isset($filterArray['category'])) {
            $filter->setCategory($filterArray['category']);
        }

        if (isset($filterArray['semester'])) {
            $filter->setSemester(\Semester::find($filterArray['semester']));
        }

        return $filter;
    }
}