Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-autograde
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CS-107
moodle-autograde
Commits
314ee6ab
Commit
314ee6ab
authored
4 months ago
by
El Hassan Jamaly
Browse files
Options
Downloads
Patches
Plain Diff
feat (frontend) : Add a download button
parent
baa56531
No related branches found
No related tags found
1 merge request
!323
feat (frontend) : Add a download button
Pipeline
#248771
passed
4 months ago
Stage: prepare-pipeline
Stage: build
Stage: test
Stage: coverage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
autograde-plugins/assignsubmission_autograde/src/download.php
+105
-0
105 additions, 0 deletions
...grade-plugins/assignsubmission_autograde/src/download.php
autograde-plugins/assignsubmission_autograde/src/locallib.php
+35
-4
35 additions, 4 deletions
...grade-plugins/assignsubmission_autograde/src/locallib.php
with
140 additions
and
4 deletions
autograde-plugins/assignsubmission_autograde/src/download.php
0 → 100644
+
105
−
0
View file @
314ee6ab
<?php
require_once
(
'../../../../config.php'
);
require_once
(
$CFG
->
dirroot
.
'/mod/assign/locallib.php'
);
require_once
(
'utils.php'
);
use
function
assignsubmission_autograde\utils\assignsubmission_autograde_get_assignment
;
global
$DB
,
$USER
,
$CFG
;
// Get the assignment ID from the request
$assignmentid
=
required_param
(
'id'
,
PARAM_INT
);
$course_id
=
$DB
->
get_field
(
'assign'
,
'course'
,
array
(
'id'
=>
$assignmentid
));
// HR : Check if the user has the necessary capabilities
//require_capability('assignsubmission/autograde:exportsubmissions',
// context_course::instance($course_id), $USER->id, false);
// HR : Fetch the correct assignment instance
$assignment
=
assignsubmission_autograde_get_assignment
(
$assignmentid
);
// Check if group submissions are enabled
$is_group_submission
=
$DB
->
get_field
(
'assign'
,
'teamsubmission'
,
[
'id'
=>
$assignmentid
]);
//Fetch the submissions from the DB
$submissions
=
$is_group_submission
?
$DB
->
get_records_select
(
'assign_submission'
,
'assignment = :assignmentid AND groupid != 0'
,
[
'assignmentid'
=>
$assignmentid
]
)
:
$DB
->
get_records
(
'assign_submission'
,
[
'assignment'
=>
$assignmentid
])
;
if
(
empty
(
$submissions
))
{
throw
new
moodle_exception
(
'nosubmissions'
,
'mod_assign'
);
}
$files_to_zip
=
[];
foreach
(
$submissions
as
$submission
){
$group_name
=
''
;
if
(
$is_group_submission
)
{
// Handle group submissions
// Fetch group members
$group_members
=
$DB
->
get_records
(
'groups_members'
,
[
'groupid'
=>
$submission
->
groupid
],
''
,
'userid'
);
if
(
empty
(
$group_members
))
{
throw
new
moodle_exception
(
'invalidgroup'
,
'mod_assign'
,
''
,
'Group has no members.'
);
}
// Concatenate idnumbers of group members to create the group name
$group_idnumbers
=
[];
foreach
(
$group_members
as
$member
)
{
$user
=
$DB
->
get_record
(
'user'
,
[
'id'
=>
$member
->
userid
],
'idnumber'
,
MUST_EXIST
);
$group_idnumbers
[]
=
$user
->
idnumber
;
}
$group_name
=
implode
(
'_'
,
$group_idnumbers
);
// Example: "idnumber1_idnumber2"
}
else
{
// Handle individual submissions
if
(
!
empty
(
$submission
->
userid
))
{
$user
=
$DB
->
get_record
(
'user'
,
[
'id'
=>
$submission
->
userid
],
'idnumber'
,
MUST_EXIST
);
$group_name
=
$user
->
idnumber
;
}
else
{
throw
new
moodle_exception
(
'invalidsubmission'
,
'mod_assign'
,
''
,
'Submission has no valid user or group ID.'
);
}
}
// HR : Retrieve the files associated with the specified area and item
$submission_files
=
array
();
foreach
(
$assignment
->
get_submission_plugins
()
as
$plugin
){
if
(
$plugin
->
is_enabled
()
&&
$plugin
->
is_visible
()
&&
$plugin
->
allow_submissions
())
$submission_files
+=
$plugin
->
get_files
(
$submission
,
new
stdClass
());
}
foreach
(
$submission_files
as
$file
)
{
$filepath
=
$file
->
get_filepath
();
$filename
=
$file
->
get_filename
();
// We observed by looking in the $DB that the $filepath always starts and ends with
// '/'. If the filepath is empty, then it's the single character '/'
$files_to_zip
[
$group_name
.
'/'
.
$submission
->
attemptnumber
.
$filepath
.
$filename
]
=
$file
;
}
}
if
(
empty
(
$files_to_zip
))
{
throw
new
moodle_exception
(
'nofiles'
,
'mod_assign'
);
}
//Prepare a temporary file for zipping
$tempdir
=
make_temp_directory
(
'submission_files'
)
;
$zipfilename
=
"assignment_
{
$assignmentid
}
_submissions.zip"
;
$tempzipfile
=
"
$tempdir
/
$zipfilename
"
;
//Use Moodle's packer to create a zip file
$packer
=
get_file_packer
(
'application/zip'
)
;
//Pack the files into the zip archive
if
(
!
$packer
->
archive_to_pathname
(
$files_to_zip
,
$tempzipfile
))
{
throw
new
moodle_exception
(
'couldnotcreatezip'
);
}
//Send the zip file as a response using Moodle's API
send_temp_file
(
$tempzipfile
,
$zipfilename
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
autograde-plugins/assignsubmission_autograde/src/locallib.php
+
35
−
4
View file @
314ee6ab
...
@@ -209,7 +209,7 @@ final class assign_submission_autograde extends assign_submission_plugin
...
@@ -209,7 +209,7 @@ final class assign_submission_autograde extends assign_submission_plugin
* @return bool
* @return bool
*/
*/
public
function
is_empty
(
stdClass
$submissionorgrade
):
bool
{
public
function
is_empty
(
stdClass
$submissionorgrade
):
bool
{
return
tru
e
;
return
fals
e
;
}
}
...
@@ -231,7 +231,7 @@ final class assign_submission_autograde extends assign_submission_plugin
...
@@ -231,7 +231,7 @@ final class assign_submission_autograde extends assign_submission_plugin
MoodleQuickForm
$mform
,
MoodleQuickForm
$mform
,
stdClass
$data
,
stdClass
$data
,
$userid
):
bool
{
$userid
):
bool
{
return
fals
e
;
return
tru
e
;
}
}
// ============================================================================================
// ============================================================================================
...
@@ -304,7 +304,7 @@ final class assign_submission_autograde extends assign_submission_plugin
...
@@ -304,7 +304,7 @@ final class assign_submission_autograde extends assign_submission_plugin
* @return bool true to include in the summary, false otherwise
* @return bool true to include in the summary, false otherwise
*/
*/
public
function
has_user_summary
():
bool
{
public
function
has_user_summary
():
bool
{
return
fals
e
;
return
tru
e
;
}
}
/**
/**
...
@@ -316,7 +316,38 @@ final class assign_submission_autograde extends assign_submission_plugin
...
@@ -316,7 +316,38 @@ final class assign_submission_autograde extends assign_submission_plugin
* @return string ???
* @return string ???
*/
*/
public
function
view_summary
(
$submission
,
&
$showviewlink
)
:
string
{
public
function
view_summary
(
$submission
,
&
$showviewlink
)
:
string
{
return
''
;
global
$PAGE
,
$USER
,
$DB
;
// Get the assignment ID
$assignmentid
=
$submission
->
id
;
// Get the course ID from the assignment
$courseid
=
$DB
->
get_field
(
'assign'
,
'course'
,
[
'id'
=>
$assignmentid
]);
// Get the course context
$context
=
context_course
::
instance
(
$courseid
);
// Check if the user is a teacher (has grading capability)
if
(
!
has_capability
(
'mod/assign:grade'
,
$context
,
$USER
->
id
))
{
return
''
;
// Return empty string for students (no button displayed)
}
// Generate the URL for downloading all submissions
$url
=
new
\moodle_url
(
'/mod/assign/submission/autograde/download.php'
,
[
'id'
=>
$assignmentid
]);
// Get Moodle renderer
$this
->
output
=
$PAGE
->
get_renderer
(
'mod_assign'
,
null
);
// Generate button HTML
$button
=
\html_writer
::
tag
(
'a'
,
'📥 Download all submissions'
,
[
'href'
=>
$url
->
out
(
false
),
'class'
=>
'btn btn-primary'
,
]);
return
$button
;
}
}
// ============================================================================================
// ============================================================================================
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment