public function definition() { global $CFG, $DB, $PAGE, $OUTPUT, $USER, $COURSE; require_once $CFG->dirroot . '/blocks/pearson/locallib.php'; // check capabilities and throw error if needed has_capability('mod/pearson:addinstance', context_course::instance($COURSE->id)); $this->typeid = 0; $mform =& $this->_form; if (pearsondirect_is_global_configured()) { if (pearsondirect_course_has_config($COURSE->id)) { $data = $this->current; $mform->addElement('hidden', 'pdcourseid', $data->course); $mform->addElement('hidden', 'pdsection', $data->section); $mform->addElement('header', 'product', get_string('addlinkheader', 'mod_pearson')); $availablelinks = array(); foreach (lti_get_types_for_add_instance() as $id => $type) { if ($type->course == $COURSE->id) { $idnumber = $type->tooldomain; if (!strncmp($idnumber, 'pearson:', strlen('pearson:'))) { $availablelinks[$type->id] = $type->name; } } } $mform->addElement('select', 'selectedlink', get_string('selectedlink', 'mod_pearson'), $availablelinks); $mform->addHelpButton('selectedlink', 'selectedlink', 'mod_pearson'); $mform->setType('selectedlink', PARAM_TEXT); $mform->addRule('selectedlink', null, 'required', null, 'client'); $mform->addElement('text', 'linktitle', get_string('linktitle', 'mod_pearson'), ''); $mform->addHelpButton('linktitle', 'linktitle', 'mod_pearson'); $mform->addElement('text', 'customparams', get_string('customparams', 'mod_pearson'), array('size' => '64')); $mform->addHelpButton('customparams', 'customparams', 'mod_pearson'); $mform->addElement('header', 'media', get_string('addmediaheader', 'mod_pearson')); $mform->addElement('text', 'mediaurl', get_string('mediaurl', 'mod_pearson'), array('size' => '64')); $mform->addHelpButton('mediaurl', 'mediaurl', 'mod_pearson'); $mform->addElement('text', 'mediaurltitle', get_string('mediaurltitle', 'mod_pearson'), ''); $mform->addHelpButton('mediaurltitle', 'mediaurltitle', 'mod_pearson'); $mform->addElement('header', 'lauchpresentation', get_string('lauchpresentationheader', 'mod_pearson')); $mform->addElement('checkbox', 'inframe', get_string('inframe', 'mod_pearson')); $mform->addHelpButton('inframe', 'inframe', 'mod_pearson'); // add standard elements, common to all modules $this->standard_coursemodule_elements(); // add standard buttons, common to all modules $this->add_action_buttons(); } else { $mform->addElement('header', 'moduleheader', 'Module settings'); $mform->addElement('static', 'info', '', get_string('pearson_blocknotconfigured', 'block_pearson')); // add standard elements, common to all modules $this->standard_coursemodule_elements(); // add standard buttons, common to all modules $this->add_action_buttons(true, false, false); } } else { $mform->addElement('header', 'moduleheader', 'Module settings'); $mform->addElement('static', 'info', '', get_string('pearson_notconfigured', 'block_pearson')); // add standard elements, common to all modules $this->standard_coursemodule_elements(); // add standard buttons, common to all modules $this->add_action_buttons(true, false, false); } }
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; }