/** * MType: Description: Data provided as MData: 1 Simple message, not important Text, if necessary with HTML formatting 2 Simple message, important Text, if necessary with HTML formatting 3 Simple question, to be answered Yes/No Text, if necessary with HTML formatting 4 Single choice question, to be answered with one out of n alternatives Text, if necessary with HTML formatting; n different text pieces in structured writing 5 Multiple choice question, to be answered with any number out of n alternatives Text, if necessary with HTML formatting; n different text pieces in structured writing 1000 LO recommendation List of LOs and priorities 2000 + x Emulation of USE, with value x is any valid MType < 1000 As required by the corresponding MType 100 Text question, to be answered with a natural language text Text, if necessary with HTML formatting 200 Audio message URI of the audio stream or audio file 300 Video message URI of the video stream or video file * <INTUITEL> <Learner mId="12345678-1234-abcd-ef12-123456789012" uId="jmb0001"> <Lore uId="jmb0001" mId="12345678-1234-abcd-ef12-123456789013"> <LorePrio loId="LO4711" value="42"/> <LorePrio loId="LO4712" value="50"/> </Lore> <Tug uId="jmb0001" mId="12345678-1234-abcd-ef12-123456789014"> <MType>1</MType> <MData>Good Morning, dear Learner!</MData> </Tug> </INTUITEL> * @param SimpleXMLElement $doc * @return string HTML */ function block_intuitel_generateHtmlForTugAndLore(SimpleXMLElement $intuitel_elements, $courseid) { global $OUTPUT, $CFG, $PAGE; $html = ''; foreach ($intuitel_elements->Learner->Tug as $tug) { $mtype = (string) $tug->MType; $mid = IntuitelXMLSerializer::get_required_attribute($tug, 'mId'); //escape dots from $mid for HTML $mid = str_replace('.', '_', $mid); $tug_mdata = (string) $tug->MData; // filter $tug_mdata to decorate loIds $tug_mdata = block_intuitel_add_loId_decorations($tug_mdata); if ($mtype == '1') { //Simple message, not important $html .= block_intuitel_write_form_start($mid, $courseid) . '<p>' . $tug_mdata . '</p>' . block_intuitel_write_form_end($mid, false); $html = block_intuitel_add_popup_notification($mid, $html); $html = block_intuitel_add_fadeIn_jscript($mid, $html); } else { if ($mtype == '2') { //Simple message, important $html .= block_intuitel_write_form_start($mid, $courseid) . '<p>' . $OUTPUT->pix_icon('warning', 'notice!', 'block_intuitel', array('width' => 32)) . $tug_mdata . '</p>'; //TODO printing code. $html .= block_intuitel_write_form_end($mid, false); $html = block_intuitel_add_fadeIn_jscript($mid, $html); $html = block_intuitel_add_printing_code($mid, $html); $html = block_intuitel_add_popup_notification($mid, $html); } else { if ($mtype == '3') { //Simple question, to be answered Yes/No $html .= block_intuitel_write_form_start($mid, $courseid) . '<p>' . $tug_mdata . '</p> <input type="RADIO" NAME="YesNo" value="Yes" checked >' . get_string('yes', 'moodle') . '<br> <input type="RADIO" NAME="YesNo" value="No" >' . get_string('no', 'moodle') . '<br>' . block_intuitel_write_form_end($mid); $html = block_intuitel_add_fadeIn_jscript($mid, $html); $html = block_intuitel_add_popup_notification($mid, $html); } else { if ($mtype == '4') { //Single choice question, to be answered with one out of n alternatives $tug_mdata = block_intuitel_change_select_into_radio($tug_mdata); $tug_mdata = block_intuitel_filter_out_trailing_lang_mark($tug_mdata); // TUG xml is supposed to be encoded as a W3C form $html .= block_intuitel_write_form_start($mid, $courseid) . '<p>' . $tug_mdata . '</p>' . block_intuitel_write_form_end($mid); $html = block_intuitel_add_fadeIn_jscript($mid, $html); $html = block_intuitel_add_popup_notification($mid, $html); } else { if ($mtype == '5') { // Multiple choice question, to be answered with any number out of n alternatives // TUG xml is supposed to be encoded as a W3C form $html .= block_intuitel_write_form_start($mid, $courseid) . '<p>' . $tug_mdata . '</p>' . block_intuitel_write_form_end($mid); $html = block_intuitel_add_fadeIn_jscript($mid, $html); $html = block_intuitel_add_popup_notification($mid, $html); } else { if ($mtype == '100') { //Text question, to be answered with a natural language text $html .= block_intuitel_write_form_start($mid, $courseid) . '<p>' . $tug_mdata . '</p>' . '<textarea name="text" rows="10" cols="30"></textarea>' . block_intuitel_write_form_end($mid); $html = block_intuitel_add_fadeIn_jscript($mid, $html); $html = block_intuitel_add_popup_notification($mid, $html); } else { if ($mtype == '200') { //Audio message URI of the audio stream or audio file $html .= block_intuitel_write_form_start($mid, $courseid); $html .= format_text('You have a recommendation in this Sound Message: <a href="' . $tug_mdata . '">Sound</a>'); $html .= block_intuitel_write_form_end($mid, false); } else { if ($mtype == '300') { //Video message URI of the video stream or video file $html .= block_intuitel_write_form_start($mid, $courseid); $html .= format_text('You have a recommendation in this Video Message: <a href="' . $tug_mdata . '">Video message</a>'); $html .= block_intuitel_write_form_end($mid, false); $html = block_intuitel_add_popup_notification($mid, $html); $html = block_intuitel_add_fadeIn_jscript($mid, $html); } } } } } } } } } // different Tugs /** * LORE Messages */ $idFactory = Intuitel::getIDFactory(); $html .= '<div id="INTUITEL_LORE">'; $header_shown = false; foreach ($intuitel_elements->Learner->Lore as $lore) { $html .= '<ul id="intuitel_lore_recommendations">'; $ids = array(); foreach ($lore->LorePrio as $lorePrio) { $atts = $lorePrio->attributes(); $loId = (string) $atts['loId']; $value = (string) $atts['value']; if (!$header_shown) { $html .= get_string('personalized_recommendations', 'block_intuitel'); $header_shown = true; } $cmid = $idFactory->getIdfromLoId(new LOId($loId)); $module_link = block_intuitel_generateHtmlModuleLink($cmid); $html .= "<li loid=\"{$loId}\" id=\"intuitel_lore_{$cmid}\" >"; if ($module_link) { $html .= $module_link; } else { // TODO: labels are reported and can't be rendered nor hyper-linked // labels are excluded from rendering, other unknown KO are reported form debugging $type = Intuitel::getIDFactory()->getType(new LOId($loId)); if ($type != 'label') { $html .= "Activity with loId= {$loId} of type {$type} not found in this course. (Please report to developers)"; } } $html .= ' <span id="intuitel_lore_score_navigation">' . $value / 20 . '</span> '; $html .= '</li>'; } $html .= '</ul>'; } $html .= '</div>'; return $html; }
global $log; block_intuitel_disable_moodle_page_exception_handler(); if (!isset($_SESSION['user_validated'])) { block_intuitel_check_access(); } else { $log->LogDebug("Mapping request authenticated as:" . join(',', $_SESSION['user_ids_validated'])); } $params = array(); $serializer = new IntuitelXMLSerializer(); $xml = block_intuitel_get_input_message(); $log->LogDebug("loMapping Request: {$xml}"); $intuitel_elements = IntuitelController::getIntuitelXML($xml); $loMappings = IntuitelXMLSerializer::get_required_element($intuitel_elements, 'LoMapping'); $loMappingResults = array(); foreach ($loMappings as $loMapping) { $mid = IntuitelXMLSerializer::get_required_attribute($loMapping, 'mId'); if (isset($loMappingResults[$mid])) { throw new ProtocolErrorException("Duplicated message id: {$mid}"); } $params = $serializer->parse_mapping_request($loMapping); // support sending KVP for testing foreach ($_GET as $name => $value) { if ($name != 'xml' && $name != 'XDEBUG_SESSION_START') { $val = optional_param($name, null, PARAM_TEXT); if (isset($val)) { // CHECK if NULL is valid parameter $params[$name] = $val; } } } $result = Intuitel::getAdaptorInstanceForCourse(null)->findLObyAttributes($params);
// along with INTUITEL for Moodle Adaptor. If not, see <http://www.gnu.org/licenses/>. /** * REST interface. * * @package block_intuitel * @author Juan Pablo de Castro, Elena Verdú. * @copyright 2015 Intuitel Consortium * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ use intuitel\IntuitelXMLSerializer; use intuitel\Intuitel; use intuitel\ProtocolErrorException; use intuitel\IntuitelController; require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once 'locallib.php'; require_once 'model/exceptions.php'; require_once 'model/intuitelController.php'; block_intuitel_disable_moodle_page_exception_handler(); block_intuitel_check_access(); global $CFG; $xml = block_intuitel_get_input_message(); $intuitel_msg = IntuitelController::getIntuitelXML($xml); $lmsProfile = $intuitel_msg->LmsProfile; $mid = IntuitelXMLSerializer::get_required_attribute($lmsProfile, 'mId'); if (!isset($mid)) { throw new ProtocolErrorException("Bad LmsProfile request."); } $serializer = new IntuitelXMLSerializer(); $properties = Intuitel::getAdaptorInstance()->getLMSProfile(); header('Content-type: text/xml'); echo $serializer->serializeLMSProfile($mid, $properties);
/** * Parse xml response and generate proper html to be inserted in a DIV in the user interface * @throws ProtocolErrorException if userId is not current user * * * @param string $xml * @return array(string,SimpleXMLElement) */ public static function ProcessUpdateLearnerRequest($xml, $courseid) { $intuitel_elements = IntuitelController::getIntuitelXML($xml); $learner = IntuitelXMLSerializer::get_required_element($intuitel_elements, 'Learner'); $user_id = IntuitelXMLSerializer::get_required_attribute($learner, 'uId'); $adaptor = Intuitel::getAdaptorInstanceForCourse(); $user = $adaptor->getNativeUserFromUId(new UserId($user_id)); global $USER; if ($USER->id != $user->id) { throw new AccessDeniedException("User {$user->id} is not current user"); } // Generate HTML for the TUG and LORE parts $html = $adaptor->generateHtmlForTugAndLore($intuitel_elements, $courseid); return array($html, $intuitel_elements); }