1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* |
5
|
|
|
* @Project |
6
|
|
|
* @Copyright Djoudi |
7
|
|
|
* @Created 2018-02-13 |
8
|
|
|
* @Filename EditorAjaxRepogitory.php |
9
|
|
|
* @Description |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Djoudi\LaravelH5p\Repositories; |
14
|
|
|
|
15
|
|
|
use DB; |
16
|
|
|
use Djoudi\LaravelH5p\Eloquents\H5pLibrariesHubCache; |
17
|
|
|
use H5PEditorAjaxInterface; |
18
|
|
|
use Illuminate\Support\Facades\Auth; |
19
|
|
|
|
20
|
|
|
class EditorAjaxRepository implements H5PEditorAjaxInterface |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
public function getAuthorsRecentlyUsedLibraries() |
24
|
|
|
{ |
25
|
|
|
// Get latest version of local libraries |
26
|
|
|
$major_versions_sql = 'SELECT hl.name, |
27
|
|
|
MAX(hl.major_version) AS majorVersion |
28
|
|
|
FROM h5p_libraries hl |
29
|
|
|
WHERE hl.runnable = 1 |
30
|
|
|
GROUP BY hl.name'; |
31
|
|
|
|
32
|
|
|
$minor_versions_sql = "SELECT hl2.name, |
33
|
|
|
hl2.majorVersion, |
34
|
|
|
MAX(hl2.minorVersion) AS minorVersion |
35
|
|
|
FROM ({$major_versions_sql}) hl1 |
36
|
|
|
JOIN h5p_libraries hl2 |
37
|
|
|
ON hl1.name = hl2.name |
38
|
|
|
AND hl1.majorVersion = hl2.majorVersion |
39
|
|
|
GROUP BY hl2.name, hl2.majorVersion"; |
40
|
|
|
|
41
|
|
|
return DB::select("SELECT hl4.id, |
42
|
|
|
hl4.name AS machine_name, |
43
|
|
|
hl4.major_version, |
44
|
|
|
hl4.minor_version, |
45
|
|
|
hl4.patch_version, |
46
|
|
|
hl4.restricted, |
47
|
|
|
hl4.has_icon |
48
|
|
|
FROM ({$minor_versions_sql}) hl3 |
49
|
|
|
JOIN h5p_libraries hl4 |
50
|
|
|
ON hl3.name = hl4.name |
51
|
|
|
AND hl3.major_version = hl4.major_version |
52
|
|
|
AND hl3.minor_version = hl4.minor_version |
53
|
|
|
GROUP BY hl4.name, hl4.major_version, hl4.minor_version"); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getContentTypeCache($machineName = null) |
57
|
|
|
{ |
58
|
|
|
$where = H5pLibrariesHubCache::select(); |
59
|
|
|
if ($machineName) { |
60
|
|
|
return $where->where('machine_name', $machineName)->pluck('id', 'is_recommended'); |
61
|
|
|
} else { |
62
|
|
|
return $where->where('machine_name', $machineName)->get(); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getLatestLibraryVersions() |
67
|
|
|
{ |
68
|
|
|
$recently_used = []; |
69
|
|
|
$result = DB::table('h5p_events') |
70
|
|
|
->select([ |
71
|
|
|
'library_name', |
72
|
|
|
'max(created_at) AS max_created_at', |
73
|
|
|
]) |
74
|
|
|
->where('type', 'content') |
75
|
|
|
->where('sub_type', 'create') |
76
|
|
|
->where('user_id', Auth::id()) |
77
|
|
|
->groupBy('library_name') |
78
|
|
|
->orderBy('max_created_at', 'DESC') |
79
|
|
|
->get(); |
80
|
|
|
|
81
|
|
|
foreach ($result as $row) { |
82
|
|
|
$recently_used[] = $row->library_name; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
dd($recently_used); |
86
|
|
|
exit; |
|
|
|
|
87
|
|
|
|
88
|
|
|
return $recently_used; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function validateEditorToken($token) |
92
|
|
|
{ |
93
|
|
|
// return (Helpers::nonce($token) == 'h5p_editor_ajax'); |
94
|
|
|
return true; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getTranslations($libraries, $language_code){} |
98
|
|
|
} |
99
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.