function pearsondirect_updateexistinglink($courseid, $link, $placement) { global $CFG, $DB; $retval = NULL; $coursemodules = $DB->get_records('course_modules', array('course' => $courseid, 'module' => pearsondirect_get_lti_module())); if ($coursemodules) { foreach ($coursemodules as $coursemodule) { if (!strncmp($coursemodule->idnumber, 'pearson:' . $link->id, strlen('pearson:' . $link->id))) { $lti = $DB->get_record('lti', array('id' => $coursemodule->instance), '*', IGNORE_MISSING); if ($lti) { $DB->set_field("lti", "resourcekey", $CFG->pearson_key, array("id" => $coursemodule->instance)); $DB->set_field("lti", "password", $CFG->pearson_secret, array("id" => $coursemodule->instance)); $use_icons = $CFG->pearson_use_icons; if ($use_icons) { $DB->set_field("lti", "icon", $CFG->wwwroot . '/blocks/pearson/pix/icon.png', array("id" => $coursemodule->instance)); } $DB->set_field("lti", "toolurl", $link->launchUrl, array("id" => $coursemodule->instance)); $DB->set_field("course_modules", "idnumber", pearsondirect_construct_id_for_lti($link->id, $courseid, $lti->id, $placement), array("id" => $coursemodule->id)); $retval = $lti->id; } } } } return $retval; }
public function get_content() { global $CFG, $COURSE, $USER, $PAGE, $DB; require_once $CFG->dirroot . '/blocks/pearson/locallib.php'; require_once $CFG->dirroot . '/lib/modinfolib.php'; $this->content = new stdClass(); $this->content->text = ''; $strHTML = ''; $courseid = $COURSE->id; // check capabilities and throw error if needed has_capability('block/pearson:view', context_course::instance($courseid)); if (pearsondirect_is_global_configured()) { // this means that the base url, key and secret are configured correctly if (pearsondirect_is_block_configured($this)) { // this means there is a product code associated with this block $strInstHTML = ''; $strStuHTML = ''; $strPlatform = ''; $code = ''; $codes = $this->config->codes; $customcodes = $this->config->customcodes; if (isset($customcodes) && trim($customcodes) !== '') { $code = $customcodes; } else { $code = $codes; } $parameters = $this->config->parameters; if ($courseconfig = pearsondirect_course_has_config($courseid)) { // this means we've loaded and associated this link bundle to this course before $strPlatform = $courseconfig->platform; // check to see if the config has changed $currentcode = $courseconfig->code; $currentparams = $courseconfig->parameters; $codediff = strcasecmp($currentcode, $code); $paramdiff = strcasecmp($currentparams, $parameters); if ($codediff != 0) { pearsondirect_handle_code_change($courseconfig, $code, $parameters); $product = pearsondirect_get_product(trim($code), trim($parameters)); if ($product) { // this means the code is valid $strIds = ''; $links = $product->bundle->links; foreach ($links as $link) { if ($strIds != '') { $strIds .= ','; } $strIds .= $link->id; $isinstructorlink = pearsondirect_is_instructor_link($link); if (pearsondirect_is_content_placement($link) && !$isinstructorlink) { pearsondirect_create_lti_type($link, $courseid, $USER->id); } else { pearsondirect_create_lti($link, $courseid); } } $pearsonmmconfig = new stdClass(); $pearsonmmconfig->id = $courseconfig->id; $pearsonmmconfig->course = $courseid; $pearsonmmconfig->code = $code; $pearsonmmconfig->parameters = $parameters; $pearsonmmconfig->platform = $product->platform; $pearsonmmconfig->links = $strIds; pearsondirect_update_pearson_mm_config($pearsonmmconfig); rebuild_course_cache($courseid); redirect($PAGE->url); } } if ($paramdiff != 0) { pearsondirect_handle_param_change($courseconfig, $parameters); } $highlander_ids = explode(',', $courseconfig->links); $coursemodules = $DB->get_records('course_modules', array('course' => $courseid, 'module' => pearsondirect_get_lti_module())); foreach ($highlander_ids as $highlanderid) { foreach ($coursemodules as $coursemodule) { if (!strncmp($coursemodule->idnumber, pearsondirect_construct_id_for_ltitypes($highlanderid, $courseid), strlen(pearsondirect_construct_id_for_ltitypes($highlanderid, $courseid)))) { if (substr($coursemodule->idnumber, strlen($coursemodule->idnumber) - strlen('t')) == 't') { $isinstructorlink = $coursemodule->visible == 0; $link = $DB->get_record('lti', array('id' => $coursemodule->instance)); $title = trim(str_replace($strPlatform, '', $link->name)); $title = trim(str_replace('Mastering', '', $title)); $url = $CFG->wwwroot . "/mod/lti/view.php?l=" . $link->id; if ($isinstructorlink) { $strInstHTML .= '<li>'; $strInstHTML .= '<a href="' . $url . '" >'; $strInstHTML .= $title; $strInstHTML .= '</a>'; $strInstHTML .= '</li>'; } else { $strStuHTML .= '<li>'; $strStuHTML .= '<a href="' . $url . '" >'; $strStuHTML .= $title; $strStuHTML .= '</a>'; $strStuHTML .= '</li>'; } } } } } } else { $product = pearsondirect_get_product(trim($code), trim($parameters)); $strPlatform = $product->platform; if ($product) { // this means the code is valid $links = $product->bundle->links; $strIds = ''; foreach ($links as $link) { if ($strIds != '') { $strIds .= ','; } $strIds .= $link->id; $isinstructorlink = pearsondirect_is_instructor_link($link); if (pearsondirect_is_content_placement($link) && !$isinstructorlink) { pearsondirect_updateexistinglink($courseid, $link, 'c'); pearsondirect_create_lti_type($link, $courseid, $USER->id); } else { $id = NULL; $id = pearsondirect_updateexistinglink($courseid, $link, 't'); if (!isset($id)) { $id = pearsondirect_create_lti($link, $courseid); } $title = trim(str_replace($product->platform, '', $link->title)); $title = trim(str_replace('Mastering', '', $title)); $url = $CFG->wwwroot . "/mod/lti/view.php?l=" . $id; if ($isinstructorlink) { $strInstHTML .= '<li>'; $strInstHTML .= '<a href="' . $url . '" >'; $strInstHTML .= $title; $strInstHTML .= '</a>'; $strInstHTML .= '</li>'; } else { $strStuHTML .= '<li>'; $strStuHTML .= '<a href="' . $url . '" >'; $strStuHTML .= $title; $strStuHTML .= '</a>'; $strStuHTML .= '</li>'; } } } $pearsonmmconfig = new stdClass(); $pearsonmmconfig->course = $courseid; $pearsonmmconfig->code = $code; $pearsonmmconfig->parameters = $parameters; $pearsonmmconfig->platform = $product->platform; $pearsonmmconfig->links = $strIds; pearsondirect_create_pearson_mm_config($pearsonmmconfig); rebuild_course_cache($courseid); redirect($PAGE->url); } else { $strHTML = get_string('pearson_couldnotaccessproduct', 'block_pearson'); } } $strHTML .= '<div id="' . 'block_pearson_tree' . '" >'; $strHTML .= '<ul style="' . 'list-style-type: none;margin: 0;padding:2px 0px 0px 2px;' . '">'; $strHTML .= '<li>' . $strPlatform; if (!pearsondirect_is_student($USER, $courseid) && $strInstHTML != '') { $strHTML .= '<ul style="' . 'list-style-type: none;margin: 0;padding:2px 0px 0px 4px;' . '"><li>Instructor links'; $strHTML .= '<ul style="' . 'list-style-type: none;margin: 0;padding:2px 0px 0px 6px;' . '">' . $strInstHTML . '</ul>'; $strHTML .= '</li></ul>'; } if ($strStuHTML != '') { $strHTML .= '<ul style="' . 'list-style-type: none;margin: 0;padding:2px 0px 0px 4px;' . '"><li>Student links'; $strHTML .= '<ul style="' . 'list-style-type: none;margin: 0;padding:2px 0px 0px 6px;' . '">' . $strStuHTML . '</ul>'; $strHTML .= '</li></ul>'; } $strHTML .= '</li></ul>'; $strHTML .= '</div>'; } else { // this means there is no product code associated with this block $strHTML = get_string('pearson_blocknotconfigured', 'block_pearson'); } } else { // this means that the base url, key and secret are not configured correctly $strHTML = get_string('pearson_notconfigured', 'block_pearson'); } $this->content->text = format_text($strHTML, FORMAT_HTML); $this->content->footer = ''; return $this->content; }
/** * Given an object containing all the necessary data, * (defined by the form in mod.html) this function * will create a new instance and return the id number * of the new instance. * * @param object $instance An object from the form in mod.html * @return int The id of the newly inserted basiclti record **/ function pearson_add_instance($pd, $mform) { global $DB, $CFG; require_once $CFG->dirroot . '/mod/lti/locallib.php'; require_once $CFG->dirroot . '/course/lib.php'; require_once $CFG->dirroot . '/blocks/pearson/locallib.php'; require_once $CFG->dirroot . '/lib/modinfolib.php'; $pd_c = clean_param($pd->pdcourseid, PARAM_INT); $pd_s = clean_param($pd->pdsection, PARAM_INT); $launchpresentation = 4; if (isset($pd->inframe)) { $launchpresentation = 2; } $templatelink = $DB->get_record('lti_types', array('id' => $pd->selectedlink), '*', MUST_EXIST); $ltilink = new stdClass(); $ltilink->course = $templatelink->course; $linkname = ''; if (isset($pd->mediaurltitle) && trim($pd->mediaurltitle) !== '') { $linkname = clean_param($pd->mediaurltitle, PARAM_TEXT); } else { if (isset($pd->linktitle) && trim($pd->linktitle) !== '') { $linkname = clean_param($pd->linktitle, PARAM_TEXT); } else { $linkname = $templatelink->name; } } $ltilink->name = format_string($linkname); $ltilink->timecreated = time(); $ltilink->timemodified = $ltilink->timecreated; $ltilink->typeid = 0; $ltilink->toolurl = $templatelink->baseurl; $ltilink->instructorchoicesendname = 1; $ltilink->instructorchoicesendemailaddr = 1; $strCustomParams = $DB->get_field('lti_types_config', 'value', array('typeid' => $templatelink->id, 'name' => 'customparameters'), IGNORE_MISSING); if ($strCustomParams == null) { $strCustomParams = ''; } $pd_customparams = clean_param($pd->customparams, PARAM_TEXT); if (isset($pd_customparams) && trim($pd_customparams) !== '') { if (strpos($pd_customparams, ',') !== false) { $cp_array = explode(',', $pd_customparams); foreach ($cp_array as $cpa) { $kv_array = explode('=', $cpa); $key = $kv_array[0]; $length = strlen('custom_'); if (substr($key, 0, $length) === 'custom_') { $key = substr($key, $length, strlen($key)); } $strCustomParams .= $key . '=' . $kv_array[1] . "\n"; } } else { $kv_array = explode('=', $pd_customparams); $key = $kv_array[0]; $length = strlen('custom_'); if (substr($key, 0, $length) === 'custom_') { $key = substr($key, $length, strlen($key)); } $strCustomParams .= $key . '=' . $kv_array[1] . "\n"; } } $pd_mediaurl = clean_param($pd->mediaurl, PARAM_URL); if (isset($pd_mediaurl) && trim($pd_mediaurl) !== '') { $strCustomParams .= 'genericmediaurl=' . $pd_mediaurl . "\n"; } if ($strCustomParams != null) { $ltilink->instructorcustomparameters = $strCustomParams; } $ltilink->launchcontainer = $launchpresentation; $ltilink->resourcekey = $CFG->pearson_key; $ltilink->password = $CFG->pearson_secret; $ltilink->debuglaunch = 0; $ltilink->showtitlelaunch = 0; $ltilink->showdescriptionlaunch = 0; $use_icons = $CFG->pearson_use_icons; if ($use_icons) { $ltilink->icon = $CFG->wwwroot . '/blocks/pearson/pix/icon.png'; } $ltilink->id = $DB->insert_record('lti', $ltilink); $cm = new stdClass(); $cm->course = $pd_c; $cm->module = pearsondirect_get_lti_module(); $cm->instance = $ltilink->id; $cm->section = $pd_s; $cm->idnumber = $templatelink->tooldomain . ':' . $ltilink->id . ':c'; $cm->added = time(); $cm->score = 0; $cm->indent = 0; $cm->visible = 1; $cm->visibleold = 1; $cm->groupmode = 0; $cm->groupingid = 0; $cm->groupmembersonly = 0; $cm->completion = 0; $cm->completionview = 0; $cm->completionexpected = 0; $cm->showavailability = 0; $cm->showdescription = 0; $cm->coursemodule = add_course_module($cm); $sectionid = course_add_cm_to_section($cm->course, $cm->coursemodule, $cm->section, null); $DB->set_field("course_modules", "section", $sectionid, array("id" => $cm->coursemodule)); rebuild_course_cache($pd_c); redirect("{$CFG->wwwroot}/course/view.php?id={$pd_c}#section-" . $pd_s); return $ltilink->id; }