first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,38 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Grade export event.
*
* @package gradeexport_txt
* @copyright 2016 Zane Karl <zkarl@oid.ucla.edu>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace gradeexport_txt\event;
defined('MOODLE_INTERNAL') || die();
/**
* Grade export event class.
*
* @package gradeexport_txt
* @since Moodle 3.2
* @copyright 2016 Zane Karl <zkarl@oid.ucla.edu>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grade_exported extends \core\event\grade_exported {
}
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for gradeexport_txt.
*
* @package gradeexport_txt
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace gradeexport_txt\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for gradeexport_txt implementing null_provider.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Capabilities gradeexport plugin.
*
* @package gradeexport_txt
* @copyright 2007 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'gradeexport/txt:view' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
'gradeexport/txt:publish' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'manager' => CAP_ALLOW
)
)
);
+57
View File
@@ -0,0 +1,57 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
define('NO_MOODLE_COOKIES', true); // session not used here
require_once '../../../config.php';
require_once($CFG->dirroot.'/grade/export/txt/grade_export_txt.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT);
$itemids = required_param('itemids', PARAM_RAW);
$exportfeedback = optional_param('export_feedback', 0, PARAM_BOOL);
$separator = optional_param('separator', 'comma', PARAM_ALPHA);
$displaytype = optional_param('displaytype', $CFG->grade_export_displaytype, PARAM_RAW);
$decimalpoints = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
$onlyactive = optional_param('export_onlyactive', 0, PARAM_BOOL);
if (!$course = $DB->get_record('course', array('id'=>$id))) {
throw new \moodle_exception('invalidcourseid');
}
require_user_key_login('grade/export', $id); // we want different keys for each course
if (empty($CFG->gradepublishing)) {
throw new \moodle_exception('gradepubdisable');
}
$context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/txt:publish', $context);
require_capability('gradeexport/txt:view', $context);
if (!groups_group_visible($groupid, $COURSE)) {
throw new \moodle_exception('cannotaccessgroup', 'grades');
}
// Get all url parameters and create an object to simulate a form submission.
$formdata = grade_export::export_bulk_export_data($id, $itemids, $exportfeedback, $onlyactive, $displaytype,
$decimalpoints, null, $separator);
$export = new grade_export_txt($course, $groupid, $formdata);
$export->print_grades();
+71
View File
@@ -0,0 +1,71 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/export/lib.php';
require_once 'grade_export_txt.php';
$id = required_param('id', PARAM_INT); // course id
$PAGE->set_url('/grade/export/txt/export.php', array('id'=>$id));
if (!$course = $DB->get_record('course', array('id'=>$id))) {
throw new \moodle_exception('invalidcourseid');
}
require_login($course);
$context = context_course::instance($id);
$groupid = groups_get_course_group($course, true);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/txt:view', $context);
// We need to call this method here before any print otherwise the menu won't display.
// If you use this method without this check, will break the direct grade exporting (without publishing).
$key = optional_param('key', '', PARAM_RAW);
if (!empty($CFG->gradepublishing) && !empty($key)) {
$actionbar = new \core_grades\output\export_publish_action_bar($context, 'txt');
print_grade_page_head($COURSE->id, 'export', 'txt',
get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_txt'),
false, false, true, null, null, null, $actionbar);
}
if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
if (!groups_is_member($groupid, $USER->id)) {
throw new \moodle_exception('cannotaccessgroup', 'grades');
}
}
$params = array(
'includeseparator'=>true,
'publishing' => true,
'simpleui' => true,
'multipledisplaytypes' => true
);
$mform = new grade_export_form(null, $params);
$data = $mform->get_data();
$export = new grade_export_txt($course, $groupid, $data);
// If the gradepublishing is enabled and user key is selected print the grade publishing link.
if (!empty($CFG->gradepublishing) && !empty($key)) {
groups_print_course_menu($course, 'index.php?id='.$id);
echo $export->get_grade_publishing_url();
echo $OUTPUT->footer();
} else {
$event = \gradeexport_txt\event\grade_exported::create(array('context' => $context));
$event->trigger();
$export->print_grades();
}
+126
View File
@@ -0,0 +1,126 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot.'/grade/export/lib.php');
require_once($CFG->libdir . '/csvlib.class.php');
class grade_export_txt extends grade_export {
public $plugin = 'txt';
public $separator; // default separator
/**
* Constructor should set up all the private variables ready to be pulled
* @param object $course
* @param int $groupid id of selected group, 0 means all
* @param stdClass $formdata The validated data from the grade export form.
*/
public function __construct($course, $groupid, $formdata) {
parent::__construct($course, $groupid, $formdata);
$this->separator = $formdata->separator;
// Overrides.
$this->usercustomfields = true;
}
public function get_export_params() {
$params = parent::get_export_params();
$params['separator'] = $this->separator;
return $params;
}
public function print_grades() {
global $CFG;
$export_tracking = $this->track_exports();
$strgrades = get_string('grades');
$profilefields = grade_helper::get_user_profile_fields($this->course->id, $this->usercustomfields);
$shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id)));
$downloadfilename = clean_filename("$shortname $strgrades");
$csvexport = new csv_export_writer($this->separator);
$csvexport->set_filename($downloadfilename);
// Print names of all the fields
$exporttitle = array();
foreach ($profilefields as $field) {
$exporttitle[] = $field->fullname;
}
if (!$this->onlyactive) {
$exporttitle[] = get_string("suspended");
}
// Add grades and feedback columns.
foreach ($this->columns as $grade_item) {
foreach ($this->displaytype as $gradedisplayname => $gradedisplayconst) {
$exporttitle[] = $this->format_column_name($grade_item, false, $gradedisplayname);
}
if ($this->export_feedback) {
$exporttitle[] = $this->format_column_name($grade_item, true);
}
}
// Last downloaded column header.
$exporttitle[] = get_string('timeexported', 'gradeexport_txt');
$csvexport->add_data($exporttitle);
// Print all the lines of data.
$geub = new grade_export_update_buffer();
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
$gui->require_active_enrolment($this->onlyactive);
$gui->allow_user_custom_fields($this->usercustomfields);
$gui->init();
while ($userdata = $gui->next_user()) {
$exportdata = array();
$user = $userdata->user;
foreach ($profilefields as $field) {
$fieldvalue = grade_helper::get_user_field_value($user, $field);
$exportdata[] = $fieldvalue;
}
if (!$this->onlyactive) {
$issuspended = ($user->suspendedenrolment) ? get_string('yes') : '';
$exportdata[] = $issuspended;
}
foreach ($userdata->grades as $itemid => $grade) {
if ($export_tracking) {
$status = $geub->track($grade);
}
foreach ($this->displaytype as $gradedisplayconst) {
$exportdata[] = $this->format_grade($grade, $gradedisplayconst);
}
if ($this->export_feedback) {
$exportdata[] = $this->format_feedback($userdata->feedbacks[$itemid], $grade);
}
}
// Time exported.
$exportdata[] = time();
$csvexport->add_data($exportdata);
}
$gui->close();
$geub->close();
$csvexport->download_file();
exit;
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/export/lib.php';
require_once 'grade_export_txt.php';
$id = required_param('id', PARAM_INT); // course id
$PAGE->set_url('/grade/export/txt/index.php', array('id'=>$id));
if (!$course = $DB->get_record('course', array('id'=>$id))) {
throw new \moodle_exception('invalidcourseid');
}
require_login($course);
$context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/txt:view', $context);
$actionbar = new \core_grades\output\export_action_bar($context, null, 'txt');
print_grade_page_head($COURSE->id, 'export', 'txt',
get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_txt'),
false, false, true, null, null, null, $actionbar);
export_verify_grades($COURSE->id);
if (!empty($CFG->gradepublishing)) {
$CFG->gradepublishing = has_capability('gradeexport/txt:publish', $context);
}
$actionurl = new moodle_url('/grade/export/txt/export.php');
$formoptions = array(
'includeseparator'=>true,
'publishing' => true,
'simpleui' => true,
'multipledisplaytypes' => true
);
$mform = new grade_export_form($actionurl, $formoptions);
$groupmode = groups_get_course_groupmode($course); // Groups are being used.
$currentgroup = groups_get_course_group($course, true);
if (($groupmode == SEPARATEGROUPS) &&
(!$currentgroup) &&
(!has_capability('moodle/site:accessallgroups', $context))) {
echo $OUTPUT->heading(get_string("notingroup"));
echo $OUTPUT->footer();
die;
}
groups_print_course_menu($course, 'index.php?id='.$id);
echo '<div class="clearer"></div>';
$mform->display();
echo $OUTPUT->footer();
@@ -0,0 +1,31 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'gradeexport_txt', language 'en', branch 'MOODLE_20_STABLE'
*
* @package gradeexport_txt
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['eventgradeexported'] = 'TXT grade exported';
$string['pluginname'] = 'Plain text file';
$string['privacy:metadata'] = 'The Plain text file grade export plugin does not store any personal data.';
$string['timeexported'] = 'Last downloaded from this course';
$string['txt:publish'] = 'Publish TXT grade export';
$string['txt:view'] = 'Use text grade export';
@@ -0,0 +1,77 @@
@gradeexport @gradeexport_txt
Feature: I need to export grades as text
In order to easily review marks
As a teacher
I need to have a export grades as text
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | course | idnumber | name | intro | assignsubmission_onlinetext_enabled |
| assign | C1 | a1 | Test assignment name | Submit your online text | 1 |
| assign | C1 | a2 | Test assignment name 2 | Submit your online text | 1 |
And the following "grade grades" exist:
| gradeitem | user | grade |
| Test assignment name | student1 | 80.00 |
And I am on the "Course 1" "grades > Grader report > View" page logged in as "teacher1"
@javascript
Scenario: Export grades as text
When I navigate to "Plain text file" export page in the course gradebook
And I expand all fieldsets
And I click on "Course total" "checkbox"
And I set the field "Grade export decimal places" to "1"
And I press "Download"
Then I should see "Student,1"
And I should see "80.0"
And I should not see "Course total"
And I should not see "80.00"
@javascript
Scenario: Export grades as text using real
When I navigate to "Plain text file" export page in the course gradebook
And I expand all fieldsets
And I set the following fields to these values:
| Real | 1 |
And I click on "Course total" "checkbox"
And I press "Download"
Then I should see "Student,1"
And I should see "80.00"
@javascript
Scenario: Export grades as text using percentages and letters
When I navigate to "Plain text file" export page in the course gradebook
And I set the following fields to these values:
| Percentage | 1 |
| Letter | 1 |
And I press "Download"
Then I should see "Student,1"
And I should see "80.00 %"
And I should see "B-"
And I should not see "40.00 %"
And I should not see ",F,"
@javascript
Scenario: Export grades as text using real, percentages and letters
When I navigate to "Plain text file" export page in the course gradebook
And I set the following fields to these values:
| Real | 1 |
| Percentage | 1 |
| Letter | 1 |
And I press "Download"
Then I should see "Student,1"
And I should see "80.00"
And I should see "80.00 %"
And I should see "B-"
And I should not see "40.00 %"
And I should not see ",F,"
@@ -0,0 +1,57 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace gradeexport_txt\event;
/**
* TXT grade export events test cases.
*
* @package gradeexport_txt
* @copyright 2016 Zane Karl zkarl@oid.ucla.edu
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class events_test extends \advanced_testcase {
/**
* Setup is called before calling test case.
*/
public function setUp(): void {
$this->resetAfterTest();
}
/**
* Test course_module_instance_list_viewed event.
*/
public function test_logging(): void {
// There is no proper API to call to trigger this event, so what we are
// doing here is simply making sure that the events returns the right information.
$course = $this->getDataGenerator()->create_course();
$params = array(
'context' => \context_course::instance($course->id)
);
$event = \gradeexport_txt\event\grade_exported::create($params);
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\gradeexport_txt\event\grade_exported', $event);
$this->assertEquals(\context_course::instance($course->id), $event->get_context());
$this->assertEquals('txt', $event->get_export_type());
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details
*
* @package gradeexport
* @subpackage txt
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'gradeexport_txt'; // Full name of the plugin (used for diagnostics)