コード例 #1
0
 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . "/mod/turnitintooltwo/lib.php";
     require_once $CFG->dirroot . "/mod/turnitintooltwo/turnitintooltwo_view.class.php";
     $data = (array) $this->get_custom_data();
     // Make sure we are still wanted.
     $submission = $DB->get_record('turnitintooltwo_submissions', array('id' => $data['submissionid']));
     if (!$submission) {
         return true;
     }
     cli_writeln("Processing Turnitintooltwo submission: " . $data['submissionid']);
     $user = $DB->get_record('user', array('id' => $data['userid']));
     \core\session\manager::set_user($user);
     $turnitintooltwo = $DB->get_record('turnitintooltwo', array('id' => $data['tiiid']));
     list($course, $cm) = get_course_and_cm_from_instance($turnitintooltwo, 'turnitintooltwo');
     try {
         $turnitintooltwoassignment = new \turnitintooltwo_assignment($turnitintooltwo->id, $turnitintooltwo);
         $turnitintooltwosubmission = new \turnitintooltwo_submission($data['submissionid'], "moodle", $turnitintooltwoassignment);
         $parts = $turnitintooltwoassignment->get_parts();
         $tiisubmission = $turnitintooltwosubmission->do_tii_submission($cm, $turnitintooltwoassignment);
         // Update submission.
         $DB->update_record('turnitintooltwo_submissions', array('id' => $data['submissionid'], 'submission_modified' => $data['subtime']));
     } catch (\Exception $e) {
         $tiisubmission = array('success' => false, 'message' => $e->getMessage());
         cli_writeln($e->getMessage());
     }
     $digitalreceipt = $tiisubmission;
     $digitalreceipt['is_manual'] = 0;
     $digitalreceipt = json_encode($digitalreceipt);
     $this->update_sub_status($data['submissionid'], $tiisubmission['success'], $digitalreceipt);
     if ($tiisubmission['success'] === true) {
         $lockedassignment = new \stdClass();
         $lockedassignment->id = $turnitintooltwoassignment->turnitintooltwo->id;
         $lockedassignment->submitted = 1;
         $DB->update_record('turnitintooltwo', $lockedassignment);
         $lockedpart = new \stdClass();
         $lockedpart->id = $data['submissionpart'];
         $lockedpart->submitted = 1;
         // Disable anonymous marking if post date has passed.
         if ($parts[$data['submissionpart']]->dtpost <= time()) {
             $lockedpart->unanon = 1;
         }
         $DB->update_record('turnitintooltwo_parts', $lockedpart);
         cli_writeln("Finished processing successful submission: " . $data['submissionid']);
     } else {
         turnitintooltwo_add_to_log($course->id, "errored submission", 'view.php?id=' . $cm->id, "Failed to submit '" . $turnitintooltwosubmission->submission_title . "'", $cm->id, $user->id, array('submissionid' => $data['submissionid']));
         cli_writeln("Finished processing unsuccessful submission: " . $data['submissionid']);
     }
     \core\session\manager::set_user(get_admin());
     return $tiisubmission['success'];
 }
コード例 #2
0
ファイル: testgen.php プロジェクト: unikent/moodle-tool_kent
 * @copyright  2015 Skylar Kelty <*****@*****.**>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('CLI_SCRIPT', true);
require __DIR__ . '/../../../../config.php';
require_once $CFG->libdir . '/clilib.php';
require_once $CFG->libdir . '/coursecatlib.php';
require_once $CFG->dirroot . '/lib/phpunit/classes/util.php';
cli_writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
cli_writeln('Welcome to the school generator!');
cli_writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
cli_writeln('');
$category = $DB->get_record('course_categories', array('name' => 'School of Witchcraft and Wizardry'));
if (!$category) {
    cli_writeln('Creating category...');
    $category = \coursecat::create(array('name' => 'School of Witchcraft and Wizardry', 'description' => 'A school like no other!', 'descriptionformat' => 1, 'parent' => 0, 'sortorder' => 520000, 'coursecount' => 0, 'visible' => 1, 'visibleold' => 1, 'timemodified' => 0, 'depth' => 1, 'path' => '/2', 'theme' => ''));
} else {
    cli_writeln('Using existing category.');
}
$courses = array('Astronomy', 'Charms', 'Dark Arts', 'Defence Against the Dark Arts', 'Flying', 'Herbology', 'History of Magic', 'Muggle Studies', 'Potions', 'Transfiguration', 'Alchemy', 'Apparition', 'Arithmancy', 'Care of Magical Creatures', 'Divination', 'Study of Ancient Runes', 'Extra-curricular subjects', 'Ancient Studies', 'Art', 'Frog Choir', 'Ghoul Studies', 'Magical Theory', 'Muggle Art', 'Music', 'Muggle Music', 'Orchestra', 'Xylomancy');
cli_writeln('Creating courses...');
$generator = \phpunit_util::get_data_generator();
$id = 1000;
foreach ($courses as $course) {
    if ($DB->record_exists('course', array('fullname' => $course))) {
        continue;
    }
    $courserecord = array('shortname' => "WZ{$id}", 'fullname' => $course, 'numsections' => 10, 'startdate' => usergetmidnight(time()), 'category' => $category->id);
    $generator->create_course($courserecord, array('createsections' => true));
    $id += 100;
}
コード例 #3
0
ファイル: clilib.php プロジェクト: jeffthestampede/excelsior
/**
 * Write to standard error output and exit with the given code
 *
 * @param string $text
 * @param int $errorcode
 * @return void (does not return)
 */
function cli_error($text, $errorcode = 1)
{
    cli_writeln($text . PHP_EOL, STDERR);
    die($errorcode . " " . $text);
}