conversionRule.php 5.62 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
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
<?php
/*
 * Copyright (C) 2015 Maarch
 *
 * This file is part of bundle digitalResource.
 *
 * Bundle digitalResource 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 digitalResource 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 digitalResource.  If not, see <http://www.gnu.org/licenses/>.
 */
namespace Presentation\maarchRM\Presenter\digitalResource;

/**
 * Serializer html conversion rule
 *
 * @package DigitalResource
 * @author  Alexis Ragot <alexis.ragot@maarch.com>
 */
class conversionRule
{
    use \presentation\maarchRM\Presenter\exceptions\exceptionTrait;

    public $view;

    protected $json;

    protected $translator;

    /**
     * Constuctor of cluster html serializer
     * @param \dependency\html\Document                    $view       The view
     * @param \dependency\json\JsonObject                  $json       The JSOn object
     * @param \dependency\localisation\TranslatorInterface $translator The translator
     */
    public function __construct(\dependency\html\Document $view, \dependency\json\JsonObject $json, \dependency\localisation\TranslatorInterface $translator)
    {
        $this->view = $view;

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

        $this->translator = $translator;
        $this->translator->setCatalog('digitalResource/conversionRule');
    }

    /**
     * Get conversion rules
     * @param array $conversionRules Array of digitalResource/conversionRule objects
     *
     * @return string
     */
    public function index(array $conversionRules)
    {
63
        $conversionServices = \laabs::configuration("dependency.fileSystem")["conversionServices"];
Prosper De Laure's avatar
Prosper De Laure committed
64
65
66
67
68
        $this->view->addContentFile('digitalResource/conversionRule/index.html');

        foreach ( $conversionRules as $conversionRule ) {
            $conversionRule->puidName = \laabs::callService('digitalResource/format/readGet', $conversionRule->puid)->name;
            $conversionRule->targetPuidName = \laabs::callService('digitalResource/format/readGet', $conversionRule->targetPuid)->name;
69
70
71
72
73
74

            foreach ($conversionServices as $conversionService) {
                if ($conversionService['serviceName'] == $conversionRule->conversionService) {
                    $conversionRule->conversionServiceName = $conversionService['softwareName'];
                }
            }
Prosper De Laure's avatar
Prosper De Laure committed
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
        }

        $dataTable = $this->view->getElementsByClass("dataTable")->item(0)->plugin['dataTable'];
        $dataTable->setPaginationType("full_numbers");
        $dataTable->setUnsortableColumns(3);

        $this->view->translate();

        $this->view->setSource("conversionRules", $conversionRules);
        $this->view->merge();

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

    /**
     * Edit a conversion rule
     *
     * @return string
     */
    public function edit()
    {
        $conversionServices = \laabs::configuration("dependency.fileSystem")["conversionServices"];
        $inputFormats = [];

        for ($i = 0, $count = count($conversionServices); $i < $count; $i++) {
            $formats = [];
            foreach ($conversionServices[$i]["inputFormats"] as $inputformat) {
                $formats['input'][] = \laabs::callService('digitalResource/format/readGet', $inputformat);
            }
            $inputFormats = array_merge($formats['input'], $inputFormats);
            $conversionServices[$i]["inputFormats"] = $inputFormats;

            $outputFormats = array_keys($conversionServices[$i]["outputFormats"]);
            foreach ($outputFormats as $outputFormat) {
                $formats['output'][$outputFormat] = \laabs::callService('digitalResource/format/readGet', $outputFormat);
            }

            $conversionServices[$i]["outputFormats"] = $formats['output'];
        }

        $conversionServicesEncoded = json_encode($conversionServices);
        $this->view->addContentFile('digitalResource/conversionRule/edit.html');

        $this->view->translate();

        $this->view->setSource("inputFormats", $inputFormats);
        $this->view->setSource("conversionServicesEncoded", $conversionServicesEncoded);
        $this->view->merge();

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

    // JSON
    /**
     * Serializer JSON for create method
     *
     * @return object JSON object with a status and message parameters
     */
    public function create()
    {
        $this->json->message = "Conversion rule created";
        $this->json->message = $this->translator->getText($this->json->message);

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

    /**
     * Serializer JSON for update method
     *
     * @return object JSON object with a status and message parameters
     */
    public function update()
    {
        $this->json->message = "Conversion rule updated";
        $this->json->message = $this->translator->getText($this->json->message);

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

    /**
     * Serializer JSON for update method
     *
     * @return object JSON object with a status and message parameters
     */
    public function delete()
    {
        $this->json->message = "Conversion rule deleted";
        $this->json->message = $this->translator->getText($this->json->message);

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