H5pImplementation::getMessages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
// For licensing terms, see /license.txt
4
5
namespace Chamilo\PluginBundle\H5pImport\H5pImporter;
6
7
use Chamilo\PluginBundle\Entity\H5pImport\H5pImport;
8
use Chamilo\PluginBundle\Entity\H5pImport\H5pImportLibrary;
9
10
class H5pImplementation implements \H5PFrameworkInterface
11
{
12
    private $h5pImport;
13
    private $h5pImportLibraries;
14
15
    public function __construct(H5pImport $h5pImport)
16
    {
17
        $this->h5pImport = $h5pImport;
18
        $this->h5pImportLibraries = $h5pImport->getLibraries();
19
    }
20
21
    public function getPlatformInfo()
22
    {
23
        // TODO: Implement getPlatformInfo() method.
24
    }
25
26
    public function fetchExternalData($url, $data = null, $blocking = true, $stream = null)
27
    {
28
        // TODO: Implement fetchExternalData() method.
29
    }
30
31
    public function setLibraryTutorialUrl($machineName, $tutorialUrl)
32
    {
33
        // TODO: Implement setLibraryTutorialUrl() method.
34
    }
35
36
    public function setErrorMessage($message, $code = null)
37
    {
38
        // TODO: Implement setErrorMessage() method.
39
    }
40
41
    public function setInfoMessage($message)
42
    {
43
        // TODO: Implement setInfoMessage() method.
44
    }
45
46
    public function getMessages($type)
47
    {
48
        // TODO: Implement getMessages() method.
49
    }
50
51
    public function t($message, $replacements = [])
52
    {
53
        return get_lang($message);
54
    }
55
56
    public function getLibraryFileUrl($libraryFolderName, $fileName)
57
    {
58
        // TODO: Implement getLibraryFileUrl() method.
59
    }
60
61
    public function getUploadedH5pFolderPath()
62
    {
63
        // TODO: Implement getUploadedH5pFolderPath() method.
64
    }
65
66
    public function getUploadedH5pPath()
67
    {
68
        // TODO: Implement getUploadedH5pPath() method.
69
    }
70
71
    public function loadAddons()
72
    {
73
        $addons = [];
74
        $sql = "
75
                SELECT l1.machine_name, l1.major_version, l1.minor_version, l1.patch_version,
76
                      l1.iid, l1.preloaded_js, l1.preloaded_css
77
                FROM plugin_h5p_import_library AS l1
78
                LEFT JOIN plugin_h5p_import_library AS l2
79
                ON l1.machine_name = l2.machine_name AND
80
                    (l1.major_version < l2.major_version OR
81
                    (l1.major_version = l2.major_version AND
82
                    l1.minor_version < l2.minor_version))
83
                WHERE l2.machine_name IS null
84
        ";
85
86
        $result = \Database::query($sql);
87
        while ($row = \Database::fetch_array($result)) {
88
            $addons[] = \H5PCore::snakeToCamel($row);
89
        }
90
91
        return $addons;
92
    }
93
94
    public function getLibraryConfig($libraries = null)
95
    {
96
        // TODO: Implement getLibraryConfig() method.
97
    }
98
99
    public function loadLibraries()
100
    {
101
        // TODO: Implement loadLibraries() method.
102
    }
103
104
    public function getAdminUrl()
105
    {
106
        // TODO: Implement getAdminUrl() method.
107
    }
108
109
    public function getLibraryId($machineName, $majorVersion = null, $minorVersion = null)
110
    {
111
        // TODO: Implement getLibraryId() method.
112
    }
113
114
    public function getWhitelist($isLibrary, $defaultContentWhitelist, $defaultLibraryWhitelist)
115
    {
116
        // TODO: Implement getWhitelist() method.
117
    }
118
119
    public function isPatchedLibrary($library)
120
    {
121
        // TODO: Implement isPatchedLibrary() method.
122
    }
123
124
    public function isInDevMode()
125
    {
126
        // TODO: Implement isInDevMode() method.
127
    }
128
129
    public function mayUpdateLibraries()
130
    {
131
        // TODO: Implement mayUpdateLibraries() method.
132
    }
133
134
    public function saveLibraryData(&$libraryData, $new = true)
135
    {
136
        // TODO: Implement saveLibraryData() method.
137
    }
138
139
    public function insertContent($content, $contentMainId = null)
140
    {
141
        // TODO: Implement insertContent() method.
142
    }
143
144
    public function updateContent($content, $contentMainId = null)
145
    {
146
        // TODO: Implement updateContent() method.
147
    }
148
149
    public function resetContentUserData($contentId)
150
    {
151
        // TODO: Implement resetContentUserData() method.
152
    }
153
154
    public function saveLibraryDependencies($libraryId, $dependencies, $dependency_type)
155
    {
156
        // TODO: Implement saveLibraryDependencies() method.
157
    }
158
159
    public function copyLibraryUsage($contentId, $copyFromId, $contentMainId = null)
160
    {
161
        // TODO: Implement copyLibraryUsage() method.
162
    }
163
164
    public function deleteContentData($contentId)
165
    {
166
        // TODO: Implement deleteContentData() method.
167
    }
168
169
    public function deleteLibraryUsage($contentId)
170
    {
171
        // TODO: Implement deleteLibraryUsage() method.
172
    }
173
174
    public function saveLibraryUsage($contentId, $librariesInUse)
175
    {
176
        // TODO: Implement saveLibraryUsage() method.
177
    }
178
179
    public function getLibraryUsage($libraryId, $skipContent = false)
180
    {
181
        // TODO: Implement getLibraryUsage() method.
182
    }
183
184
    public function loadLibrary($machineName, $majorVersion, $minorVersion)
185
    {
186
        if ($this->h5pImportLibraries) {
187
            $foundLibrary = $this->h5pImportLibraries->filter(
188
                function (H5pImportLibrary $library) use ($machineName, $majorVersion, $minorVersion) {
189
                    return $library->getLibraryByMachineNameAndVersions($machineName, $majorVersion, $minorVersion);
190
                }
191
            )->first();
192
            if ($foundLibrary) {
193
                return [
194
                    'libraryId' => $foundLibrary->getIid(),
195
                    'title' => $foundLibrary->getTitle(),
196
                    'machineName' => $foundLibrary->getMachineName(),
197
                    'majorVersion' => $foundLibrary->getMajorVersion(),
198
                    'minorVersion' => $foundLibrary->getMinorVersion(),
199
                    'patchVersion' => $foundLibrary->getPatchVersion(),
200
                    'runnable' => $foundLibrary->getRunnable(),
201
                    'preloadedJs' => $foundLibrary->getPreloadedJsFormatted(),
202
                    'preloadedCss' => $foundLibrary->getPreloadedCssFormatted(),
203
                ];
204
            }
205
        }
206
207
        return false;
208
    }
209
210
    public function loadLibrarySemantics($machineName, $majorVersion, $minorVersion)
211
    {
212
        // TODO: Implement loadLibrarySemantics() method.
213
    }
214
215
    public function alterLibrarySemantics(&$semantics, $machineName, $majorVersion, $minorVersion)
216
    {
217
        // TODO: Implement alterLibrarySemantics() method.
218
    }
219
220
    public function deleteLibraryDependencies($libraryId)
221
    {
222
        // TODO: Implement deleteLibraryDependencies() method.
223
    }
224
225
    public function lockDependencyStorage()
226
    {
227
        // TODO: Implement lockDependencyStorage() method.
228
    }
229
230
    public function unlockDependencyStorage()
231
    {
232
        // TODO: Implement unlockDependencyStorage() method.
233
    }
234
235
    public function deleteLibrary($library)
236
    {
237
        // TODO: Implement deleteLibrary() method.
238
    }
239
240
    public function loadContent($id): array
241
    {
242
        $contentJson = H5pPackageTools::getJson($this->h5pImport->getPath().'/content.json');
243
        $h5pJson = H5pPackageTools::getJson($this->h5pImport->getPath().'/h5p.json');
244
245
        if ($contentJson && $h5pJson) {
246
            $params = json_encode($contentJson);
247
            $embedType = implode(',', $h5pJson->embedTypes);
248
            $title = $this->h5pImport->getName();
249
            $language = $h5pJson->language;
250
            $libraryId = $this->h5pImport->getMainLibrary()->getIid();
251
            $libraryName = $this->h5pImport->getMainLibrary()->getMachineName();
252
            $libraryMajorVersion = $this->h5pImport->getMainLibrary()->getMajorVersion();
253
            $libraryMinorVersion = $this->h5pImport->getMainLibrary()->getMinorVersion();
254
            $libraryEmbedTypes = $this->h5pImport->getMainLibrary()->getEmbedTypesFormatted();
255
256
            // Create the associative array with the loaded content information. Use the unique folder name as id.
257
            return [
258
                'contentId' => basename($this->h5pImport->getPath()),
259
                'params' => $params,
260
                'embedType' => $embedType,
261
                'title' => $title,
262
                'language' => $language,
263
                'libraryId' => $libraryId,
264
                'libraryName' => $libraryName,
265
                'libraryMajorVersion' => $libraryMajorVersion,
266
                'libraryMinorVersion' => $libraryMinorVersion,
267
                'libraryEmbedTypes' => $libraryEmbedTypes,
268
                'libraryFullscreen' => 0,
269
            ];
270
        }
271
272
        return [];
273
    }
274
275
    public function loadContentDependencies($id, $type = null): array
276
    {
277
        $h5pImportLibraries = $this->h5pImportLibraries;
278
        $dependencies = [];
279
280
        /** @var H5pImportLibrary|null $library */
281
        foreach ($h5pImportLibraries as $library) {
282
            $dependencies[] = [
283
                'libraryId' => $library->getIid(),
284
                'machineName' => $library->getMachineName(),
285
                'majorVersion' => $library->getMajorVersion(),
286
                'minorVersion' => $library->getMinorVersion(),
287
                'patchVersion' => $library->getPatchVersion(),
288
                'preloadedJs' => $library->getPreloadedJsFormatted(),
289
                'preloadedCss' => $library->getPreloadedCssFormatted(),
290
            ];
291
        }
292
293
        return $dependencies;
294
    }
295
296
    public function getOption($name, $default = null)
297
    {
298
        return api_get_course_plugin_setting('h5pimport', $name);
299
    }
300
301
    public function setOption($name, $value)
302
    {
303
        // TODO: Implement setOption() method.
304
    }
305
306
    public function updateContentFields($id, $fields)
307
    {
308
        // TODO: Implement updateContentFields() method.
309
    }
310
311
    public function clearFilteredParameters($library_ids)
312
    {
313
        // TODO: Implement clearFilteredParameters() method.
314
    }
315
316
    public function getNumNotFiltered()
317
    {
318
        // TODO: Implement getNumNotFiltered() method.
319
    }
320
321
    public function getNumContent($libraryId, $skip = null)
322
    {
323
        // TODO: Implement getNumContent() method.
324
    }
325
326
    public function isContentSlugAvailable($slug)
327
    {
328
        return true;
329
    }
330
331
    public function getLibraryStats($type)
332
    {
333
        // TODO: Implement getLibraryStats() method.
334
    }
335
336
    public function getNumAuthors()
337
    {
338
        // TODO: Implement getNumAuthors() method.
339
    }
340
341
    public function saveCachedAssets($key, $libraries)
342
    {
343
        // TODO: Implement saveCachedAssets() method.
344
    }
345
346
    public function deleteCachedAssets($library_id)
347
    {
348
        // TODO: Implement deleteCachedAssets() method.
349
    }
350
351
    public function getLibraryContentCount()
352
    {
353
        // TODO: Implement getLibraryContentCount() method.
354
    }
355
356
    public function afterExportCreated($content, $filename)
357
    {
358
        // TODO: Implement afterExportCreated() method.
359
    }
360
361
    public function hasPermission($permission, $id = null)
362
    {
363
        // TODO: Implement hasPermission() method.
364
    }
365
366
    public function replaceContentTypeCache($contentTypeCache)
367
    {
368
        // TODO: Implement replaceContentTypeCache() method.
369
    }
370
371
    public function libraryHasUpgrade($library)
372
    {
373
        // TODO: Implement libraryHasUpgrade() method.
374
    }
375
}
376