log.php 5.77 KB
Newer Older
Prosper De Laure's avatar
Prosper De Laure committed
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
<?php
/*
 * Copyright (C) 2015 Maarch
 *
 * This file is part of bundle recordsManagement.
 *
 * Bundle recordsManagement 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 3 of the License, or
 * (at your option) any later version.
 *
 * Bundle recordsManagement is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with bundle recordsManagement.  If not, see <http://www.gnu.org/licenses/>.
 */
namespace presentation\maarchRM\Presenter\recordsManagement;

/**
 * Description of log
 *
 * @author Alexis Ragot <alexis.ragot@maarch.org>
 */
Alexis Ragot's avatar
Alexis Ragot committed
27
class log
Prosper De Laure's avatar
Prosper De Laure committed
28
29
{
    use \presentation\maarchRM\Presenter\exceptions\exceptionTrait;
Alexis Ragot's avatar
Alexis Ragot committed
30

Prosper De Laure's avatar
Prosper De Laure committed
31
32
33
34
35
    public $view;
    protected $json;

    /**
     * Constuctor of archival Agreement html serializer
Alexis Ragot's avatar
Alexis Ragot committed
36
37
     * @param \dependency\html\Document   $view The view
     * @param \dependency\json\JsonObject $json The view
Prosper De Laure's avatar
Prosper De Laure committed
38
39
40
41
42
43
44
45
46
47
48
     */
    public function __construct(\dependency\html\Document $view, \dependency\json\JsonObject $json)
    {
        $this->view = $view;

        $this->json = $json;
        $this->json->status = true;
    }

    /**
     * Show the log search form
Alexis Ragot's avatar
Alexis Ragot committed
49
     *
Prosper De Laure's avatar
Prosper De Laure committed
50
51
52
53
54
55
56
     * @return string
     */
    public function search()
    {
        $this->view->addContentFile('recordsManagement/log/searchForm.html');
        $this->view->translate();

57
58
59
60
61
62
63
64
        $maxResults = null;
        if (isset(\laabs::configuration('presentation.maarchRM')['maxResults'])) {
            $maxResults = \laabs::configuration('presentation.maarchRM')['maxResults'];
        }
        $this->view->setSource("maxResults", $maxResults);
        $this->view->translate();
        $this->view->merge();

Prosper De Laure's avatar
Prosper De Laure committed
65
66
        return $this->view->saveHtml();
    }
Alexis Ragot's avatar
Alexis Ragot committed
67

Prosper De Laure's avatar
Prosper De Laure committed
68
69
    /**
     * Show result log search
70
71
72
     *
     * @param array   $logs         The arry of object
     * @param integer $totalResults Max number of total results from query
Alexis Ragot's avatar
Alexis Ragot committed
73
     *
Prosper De Laure's avatar
Prosper De Laure committed
74
75
     * @return string
     */
76
    public function find($logs, $totalResults)
Prosper De Laure's avatar
Prosper De Laure committed
77
78
79
80
81
82
83
84
    {
        $this->view->addContentFile('recordsManagement/log/result.html');
        $this->view->translate();

        $dataTable = $this->view->getElementsByClass("dataTable")->item(0)->plugin['dataTable'];
        $dataTable->setPaginationType("full_numbers");
        $dataTable->setUnsortableColumns(5);
        $dataTable->setSorting(array(array(1, 'desc')));
Alexis Ragot's avatar
Alexis Ragot committed
85

Prosper De Laure's avatar
Prosper De Laure committed
86
        foreach ($logs as $log) {
Alexandre Morin's avatar
Alexandre Morin committed
87
            $log->typeTranslate = $this->view->translator->getText($log->type, false, 'recordsManagement/log');
Alexis Ragot's avatar
Alexis Ragot committed
88
89

            $log->resId = \laabs::callService('recordsManagement/archives/readArchivecontents_archive_', (string) $log->archiveId)->digitalResources[0]->resId;
Prosper De Laure's avatar
Prosper De Laure committed
90
        }
Alexis Ragot's avatar
Alexis Ragot committed
91

92
93
94
95
96
97
98
99
        $hasReachMaxResults = false;
        if (isset(\laabs::configuration('presentation.maarchRM')['maxResults'])
            && $totalResults >= \laabs::configuration('presentation.maarchRM')['maxResults']) {
            $hasReachMaxResults = true;
        }

        $this->view->setSource('hasReachMaxResults', $hasReachMaxResults);
        $this->view->setSource('totalResults', $totalResults);
Prosper De Laure's avatar
Prosper De Laure committed
100
101
102
103
104
        $this->view->setSource("logs", $logs);
        $this->view->merge();

        return $this->view->saveHtml();
    }
Alexis Ragot's avatar
Alexis Ragot committed
105

Alexandre Morin's avatar
Alexandre Morin committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

    /**
     *
     */
    public function contents($res)
    {
        $journal = explode(PHP_EOL, $res);
        $id = str_getcsv($journal[1]);
        $head = str_getcsv($journal[2]);

        $events = [];
        for ($i = 3; $i < count($journal) - 1; $i++) {
            $events[] = str_getcsv($journal[$i]);
        }

        $type = $journal[0];
        $typeTranslate = $this->view->translator->getText($type, false, 'recordsManagement/log');

        $this->view->addContentFile("recordsManagement/log/view.html");
        $this->view->translate();

        $dataTable = $this->view->getElementsByClass("dataTable")->item(0)->plugin['dataTable'];
        $dataTable->setPaginationType("full_numbers");
129
130
131
132
133
134
135
136
137
        $dataTable->setSorting(array(array(0, 'desc')));

        if ($type === "lifeCycle") {
            $dataTable->setUnsortableColumns(2);
        } else if ( $type === "application") {
            for ($i = 0; $i < count($events);  $i++) {
                $events[$i][2] = $this->view->translator->getText($events[$i][2], false, 'audit/messages');
            }
        }
Alexandre Morin's avatar
Alexandre Morin committed
138
139
140
141
142
143
144
145
146
147
148
149

        $this->view->setSource("archiveId", $id[0]);
        $this->view->setSource("resourceId", $id[1]);
        $this->view->setSource("type", $type);
        $this->view->setSource("typeTranslate", $typeTranslate);
        $this->view->setSource("head", $head);
        $this->view->setSource("events", $events);
        $this->view->merge();

        return $this->view->saveHtml();
    }

Prosper De Laure's avatar
Prosper De Laure committed
150
151
152
    /**
     * View log
     * @param recordsManagement/log $log The log object
Alexis Ragot's avatar
Alexis Ragot committed
153
     *
Prosper De Laure's avatar
Prosper De Laure committed
154
155
156
157
158
159
     * @return string
     */
    public function read($log)
    {
        $this->view->addContentFile("recordsManagement/log/log.table.html");
        $this->view->translate();
Alexis Ragot's avatar
Alexis Ragot committed
160

Prosper De Laure's avatar
Prosper De Laure committed
161
162
163
164
165
166
167
168
        $this->view->setSource("log", $log);
        $this->view->merge();

        return $this->view->saveHtml();
    }

    /**
     * Chech integrity
Alexis Ragot's avatar
Alexis Ragot committed
169
170
     * @param object $chainEvent The chain event
     *
Prosper De Laure's avatar
Prosper De Laure committed
171
172
173
174
175
176
177
178
179
180
181
182
     * @return string
     */
    public function checkIntegrity($chainEvent)
    {
        $this->json->message = "success";

        return $this->json->save();

    }

    /**
     * Chech integrity
Alexis Ragot's avatar
Alexis Ragot committed
183
184
     * @param object $exception The exception
     *
Prosper De Laure's avatar
Prosper De Laure committed
185
186
187
188
189
190
191
192
193
194
     * @return string
     */
    public function jounalException($exception)
    {
        $this->json->message = "failure";

        return $this->json->save();

    }
}