Skip to content

Instantly share code, notes, and snippets.

@gthomas2
Last active March 17, 2017 16:24
Show Gist options
  • Save gthomas2/8bf0a6b8825a1a56505021fd3b050eeb to your computer and use it in GitHub Desktop.
Save gthomas2/8bf0a6b8825a1a56505021fd3b050eeb to your computer and use it in GitHub Desktop.
Modify moodle data_generator to add cover images via unsplash
diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php
index cf191f5..301885b 100644
--- a/lib/testing/generator/data_generator.php
+++ b/lib/testing/generator/data_generator.php
@@ -420,7 +420,29 @@ EOD;
}
$course = create_course((object)$record);
- context_course::instance($course->id);
+
+ $context = context_course::instance($course->id);
+
+ // GT Mod
+ $curl = new curl();
+ $jpegdata = $curl->get('https://source.unsplash.com/random');
+
+ $newfilename = 'rawcoverimage.jpg';
+
+ $fileinfo = array(
+ 'contextid' => $context->id,
+ 'component' => 'course',
+ 'filearea' => 'overviewfiles',
+ 'itemid' => 0,
+ 'filepath' => '/',
+ 'filename' => $newfilename);
+
+ $fs = get_file_storage();
+ $storedfile = $fs->create_file_from_string($fileinfo, $jpegdata);
+ $storedfile instanceof \stored_file;
+ \theme_snap\local::process_coverimage($context, $storedfile);
+
if (!empty($options['createsections'])) {
if (isset($course->numsections)) {
course_create_sections_if_missing($course, range(0, $course->numsections));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment