function data_preprocessing(&$default_values) { if ($this->current->instance) { $draftitemid = file_get_submitted_draft_itemid('jclicfile'); file_prepare_draft_area($draftitemid, $this->context->id, 'mod_jclic', 'content', 0, jclic::get_filemanager_options()); $default_values['jclicfile'] = $draftitemid; } }
/** * Removes an instance of the jclic from the database * * Given an ID of an instance of this module, * this function will permanently delete the instance * and any data that depends on it. * * @param int $id Id of the module instance * @return boolean Success/Failure */ function jclic_delete_instance($id) { global $CFG; require_once $CFG->dirroot . '/mod/jclic/locallib.php'; $cm = get_coursemodule_from_instance('jclic', $id, 0, false, MUST_EXIST); $context = context_module::instance($cm->id); $jclic = new jclic($context, $cm, null); return $jclic->delete_instance(); }
function jclic_set_mainfile($data) { $jclic = new jclic(); $jclic->set_instance($data); return $jclic->set_mainfile(); }
public function test_mod_jclic_duplicate() { global $USER, $DB, $CFG; require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php'; require_once $CFG->dirroot . '/backup/util/includes/restore_includes.php'; $this->resetAfterTest(true); $this->setUser(2); // Admin user. // Create a course with some availability data set. $generator = $this->getDataGenerator(); $course = $generator->create_course(array('format' => 'topics', 'numsections' => 3, 'enablecompletion' => COMPLETION_ENABLED), array('createsections' => true)); $jclic = $generator->create_module('jclic', array('course' => $course->id)); $cmid = $jclic->cmid; // Do backup. $bc = new backup_controller(backup::TYPE_1ACTIVITY, $cmid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id); $backupid = $bc->get_backupid(); $bc->execute_plan(); $bc->destroy(); // Do restore. $rc = new restore_controller($backupid, $course->id, backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id, backup::TARGET_CURRENT_ADDING); $this->assertTrue($rc->execute_precheck()); $rc->execute_plan(); // Find cmid. $tasks = $rc->get_plan()->get_tasks(); $cmcontext = context_module::instance($cmid); $newcmid = 0; foreach ($tasks as $task) { if (is_subclass_of($task, 'restore_activity_task')) { if ($task->get_old_contextid() == $cmcontext->id) { $newcmid = $task->get_moduleid(); break; } } } $rc->destroy(); if (!$newcmid) { throw new coding_exception('Unexpected: failure to find restored cmid'); } // Check settings in new course. $newjclic = new jclic(context_module::instance($newcmid), false, false); $newjclicmodule = $newjclic->get_instance(); $this->assertNotEmpty($newjclic); $jclic = new jclic(context_module::instance($jclic->cmid), false, false); $jclicmodule = $jclic->get_instance(); $fields = (array) $jclicmodule; unset($fields['id']); unset($fields['course']); foreach ($fields as $key => $unused) { $this->assertEquals($newjclicmodule->{$key}, $jclicmodule->{$key}, "Failed on field {$key}"); } // Avoid errors... ini_set('max_execution_time', 0); }