Skip to content

Commit be283a2

Browse files
Plugin: BBB: Add pre-upload of slides, update upstream PHP API library, fix global conf links #add - refs #3244
1 parent 9328204 commit be283a2

File tree

8 files changed

+986
-837
lines changed

8 files changed

+986
-837
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"a2lix/translation-form-bundle": "^3.0",
6868
"api-platform/core": "^3.0",
6969
"beberlei/doctrineextensions": "^1.3",
70+
"bigbluebutton/bigbluebutton-api-php": "^2.0",
7071
"chamilo/google-map-form-type-bundle": "1.7",
7172
"chamilo/settings-bundle": "1.3.0",
7273
"clue/graph": "^0.9.2",

composer.lock

Lines changed: 143 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/main/inc/ajax/plugin.ajax.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use Chamilo\CoreBundle\Framework\Container;
55
use Michelf\MarkdownExtra;
66
use Chamilo\CoreBundle\Entity\Plugin as PluginEntity;
7+
use Chamilo\CoreBundle\Entity\ResourceNode;
8+
use Chamilo\CourseBundle\Entity\CDocument;
79

810
/**
911
* Responses to AJAX calls.
@@ -49,9 +51,98 @@
4951
exit;
5052
}
5153

54+
/**
55+
* From here on, everything returns JSON.
56+
*/
5257
header('Content-Type: application/json; charset=utf-8');
5358
api_block_anonymous_users();
5459

60+
if ($action === 'list_documents') {
61+
try {
62+
header('Content-Type: application/json; charset=utf-8');
63+
64+
$courseId = api_get_course_int_id();
65+
$isAdmin = api_is_platform_admin();
66+
67+
// Require edit rights inside a course; otherwise only admins can list globally
68+
if ($courseId > 0) {
69+
if (!api_is_allowed_to_edit()) {
70+
http_response_code(403);
71+
echo json_encode(['error' => 'Forbidden']);
72+
exit;
73+
}
74+
} else {
75+
if (!$isAdmin) {
76+
http_response_code(403);
77+
echo json_encode(['error' => 'Forbidden (admin required for global listing)']);
78+
exit;
79+
}
80+
}
81+
82+
$em = Database::getManager();
83+
$repo = $em->getRepository(ResourceNode::class);
84+
85+
$qb = $em->createQueryBuilder()
86+
->select('DISTINCT d')
87+
->from(CDocument::class, 'd')
88+
->innerJoin('d.resourceNode', 'rn')
89+
->innerJoin('rn.resourceFiles', 'rf')
90+
->innerJoin('rn.resourceLinks', 'rl')
91+
->where('d.filetype = :type')
92+
->setParameter('type', 'file');
93+
94+
if ($courseId > 0) {
95+
$qb->andWhere('IDENTITY(rl.course) = :cId')
96+
->setParameter('cId', (int)$courseId);
97+
}
98+
99+
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 500;
100+
$limit = max(1, min($limit, 2000));
101+
$qb->setMaxResults($limit)
102+
->orderBy('d.iid', 'DESC');
103+
104+
$docs = $qb->getQuery()->getResult();
105+
$out = [];
106+
107+
$sysBase = rtrim(str_replace('/public/', '', api_get_path(SYS_PATH)), '/');
108+
foreach ($docs as $doc) {
109+
$files = $doc->getResourceNode()->getResourceFiles();
110+
if ($files->isEmpty()) {
111+
continue;
112+
}
113+
114+
$file = $files->first();
115+
$orig = $file->getOriginalName();
116+
$ext = strtolower(pathinfo($orig, PATHINFO_EXTENSION));
117+
if (!in_array($ext, ['pdf','ppt','pptx','odp'], true)) {
118+
continue;
119+
}
120+
121+
$relPath = $repo->getFilename($file); // e.g. "/a1/b2/file.pdf"
122+
$diskPath = $sysBase . '/var/upload/resource' . $relPath;
123+
124+
// Only list entries that truly exist on disk
125+
if (!is_file($diskPath) || !is_readable($diskPath)) {
126+
continue;
127+
}
128+
129+
$out[] = [
130+
'id' => $doc->getIid(),
131+
'url' => $diskPath,
132+
'filename' => $orig,
133+
'size' => @filesize($diskPath) ?: null,
134+
];
135+
}
136+
137+
echo json_encode($out);
138+
} catch (\Throwable $e) {
139+
error_log('[plugin.ajax list_documents] '.$e->getMessage());
140+
http_response_code(500);
141+
echo json_encode(['error' => 'Internal error']);
142+
}
143+
exit;
144+
}
145+
55146
try {
56147
if (!api_is_platform_admin()) {
57148
http_response_code(403);
@@ -165,6 +256,7 @@
165256
}
166257
}
167258

259+
// If it is a course plugin, propagate enable/disable to all courses
168260
if ($instance && !empty($instance->isCoursePlugin)) {
169261
if ($action === 'enable') {
170262
$instance->install_course_fields_in_all_courses(true);

0 commit comments

Comments
 (0)