یک پلاگین لوکال برای سورس مودلم ۵ (با عنوان azad_score) که یک فرم داشته باشد و در آن فرم یک لیست انتخابی از بانک های سوال موجود و یک نمره فیلد باشد. کار این پلاگین این است که به عنوان نمره در همه گزینه های غیر 100 درصد در سوالات بانک سوال انتخابی اعمال می شود.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
برای ایجاد پلاگین لوکال Moodle 5 با نام azad_score که نمره مشخصی را به گزینههای غیر 100% در بانک سوال انتخابی اعمال کند، کدهای زیر را پیادهسازی کنید:
<?php
// lang/en/local_azad_score.php
$string['pluginname'] = 'Azad Score Adjuster';
$string['scoreadjustpage'] = 'Adjust Scores in Question Bank';
$string['scoreadjustdescription'] = 'Select a question bank and a score to apply to all non-100% answers.';
$string['selectquestionbank'] = 'Select Question Bank';
$string['newscorefraction'] = 'New Score (0 to 1)';
$string['submitbutton'] = 'Apply Score';
$string['scoreappliedsuccess'] = 'Score applied successfully. Updated {$a->answer_count} answers in {$a->question_count} questions.';
$string['noquestionsfound'] = 'No questions found in the selected context.';
$string['invalidscore'] = 'The score must be a number between 0 and 1.';
php
<?php
// classes/form/score_adjust_form.php
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formlib.php');
class local_azad_score_score_adjust_form extends moodleform {
protected function definition() {
$mform = $this->_form;
$mform->addElement('header', 'generalheader', get_string('scoreadjustpage', 'local_azad_score'));
// Question bank contexts dropdown
$contexts = $this->get_question_contexts();
$options = array();
foreach ($contexts as $context) {
$displayname = $this->format_context_name($context);
$options[$context->id] = $displayname;
}
$select = $mform->addElement('select', 'contextid', get_string('selectquestionbank', 'local_azad_score'), $options);
$mform->addRule('contextid', get_string('required'), 'required');
// Score field
$mform->addElement('number', 'newscore', get_string('newscorefraction', 'local_azad_score'),
array('min' => 0.0, 'max' => 1.0, 'step' => 0.01));
$mform->addRule('newscore', get_string('required'), 'required');
$mform->setType('newscore', PARAM_FLOAT);
$this->add_action_buttons(false);
}
private function get_question_contexts() {
global $DB;
$sql = "SELECT DISTINCT c.* FROM {context} c
JOIN {question} q ON q.contextid = c.id
WHERE c.contextlevel IN (?, ?, ?)
ORDER BY c.path";
return $DB->get_records_sql($sql, [CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE]);
}
private function format_context_name($context) {
global $DB;
switch ($context->contextlevel) {
case CONTEXT_SYSTEM:
return 'System';
case CONTEXT_COURSECAT:
$category = $DB->get_record('course_categories', ['id' => $context->instanceid]);
return 'Category: ' . ($category ? $category->name : $context->instanceid);
case CONTEXT_COURSE:
$course = $DB->get_record('course', ['id' => $context->instanceid]);
return 'Course: ' . ($course ? $course->fullname : $context->instanceid);
default:
return 'Context ID: ' . $context->id;
}
}
}