Ejemplo n.º 1
0
 /**
  * Create a URL object.
  *
  * @param stdClass $course The course to apply to.
  */
 public function get_instance($course)
 {
     $data = (object) $this->get_data();
     // Create url object.
     $instance = new \stdClass();
     $instance->course = $course->id;
     $instance->name = $data->name;
     $instance->intro = isset($data->intro) ? $data->intro : null;
     $instance->introformat = \FORMAT_HTML;
     $instance->display = \RESOURCELIB_DISPLAY_AUTO;
     $instance->externalurl = $data->url;
     $instance->id = url_add_instance($instance, null);
     return $instance;
 }
Ejemplo n.º 2
0
 public function add_link($section, $name, $url)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/url/lib.php';
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->libdir . '/resourcelib.php';
     $params = self::validate_parameters(self::add_link_parameters(), array('section' => (int) $section, 'name' => $name, 'url' => $url));
     $section = $DB->get_record('course_sections', array('id' => $section), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
     self::require_access($course->id);
     // first add course_module record because we need the context
     $newcm = new stdClass();
     $newcm->course = $course->id;
     $newcm->module = $DB->get_field('modules', 'id', array('name' => 'url'));
     // not known yet, will be updated later (this is similar to restore code)
     $newcm->instance = 0;
     $newcm->section = $params['section'];
     $newcm->visible = 1;
     $newcm->groupmode = 0;
     $newcm->groupingid = 0;
     $newcm->groupmembersonly = 0;
     if (!($coursemodule = add_course_module($newcm))) {
         throw new invalid_parameter_exception('Error creating course module');
     }
     $config = get_config('url');
     $module = new stdClass();
     $module->course = $course->id;
     $module->name = format_string($params['name']);
     $module->intro = '<p></p>';
     $module->introformat = 1;
     $module->externalurl = $params['url'];
     $module->display = $config->display;
     $module->popupwidth = $config->popupwidth;
     $module->popupheight = $config->popupheight;
     $module->printheading = $config->printheading;
     $module->printintro = $config->printintro;
     $module->instance = url_add_instance($module, array());
     $module->coursemodule = $coursemodule;
     $module->section = $section->section;
     $DB->set_field('course_modules', 'instance', $module->instance, array('id' => $coursemodule));
     add_mod_to_section($module);
     rebuild_course_cache($course->id);
     return array('id' => $coursemodule);
 }
Ejemplo n.º 3
0
/**
 * Handle a file that has been uploaded
 * @param object $uploadinfo details of the file / content that has been uploaded
 * @return int instance id of the newly created mod
 */
function mod_url_dndupload_handle($uploadinfo)
{
    // Gather all the required data.
    $data = new stdClass();
    $data->course = $uploadinfo->course->id;
    $data->name = $uploadinfo->displayname;
    $data->intro = '<p>' . $uploadinfo->displayname . '</p>';
    $data->introformat = FORMAT_HTML;
    $data->externalurl = clean_param($uploadinfo->content, PARAM_URL);
    $data->timemodified = time();
    // Set the display options to the site defaults.
    $config = get_config('url');
    $data->display = $config->display;
    $data->popupwidth = $config->popupwidth;
    $data->popupheight = $config->popupheight;
    $data->printheading = $config->printheading;
    $data->printintro = $config->printintro;
    return url_add_instance($data, null);
}
Ejemplo n.º 4
0
    $data->display = RESOURCELIB_DISPLAY_AUTO;
}
if ($type == 'Files') {
    // Create the relevant file
    $fs = get_file_storage();
    $cmcontext = get_context_instance(CONTEXT_MODULE, $data->coursemodule);
    $fileinfo = array('contextid' => $cmcontext->id, 'component' => 'mod_resource', 'filearea' => 'content', 'itemid' => 0, 'filepath' => '/', 'filename' => $filename, 'userid' => $USER->id, 'license' => $CFG->sitedefaultlicense, 'author' => fullname($USER));
    $fs->create_file_from_pathname($fileinfo, $filesrc);
    // Create the resouce database entry
    $data->instance = resource_add_instance($data, $data);
} else {
    if ($type == 'url') {
        // Create the url database entry
        unset($data->id);
        $data->externalurl = $contents;
        $data->instance = url_add_instance($data, $data);
    } else {
        // Create the page database entry
        unset($data->id);
        $data->page = array('text' => $contents, 'itemid' => false);
        if ($type == 'text') {
            $data->page['format'] = FORMAT_PLAIN;
        } else {
            $data->page['format'] = FORMAT_HTML;
        }
        $data->printheading = true;
        $data->printintro = false;
        $data->instance = page_add_instance($data, $data);
    }
}
// Update the 'instance' field for the course module