Permalink
Browse files

MDL-30778: Implemented intendeduserrole support

  • Loading branch information...
1 parent 2117dcb commit 7db3d6216d642650c0a55538cd2c27dc8505ff28 Darko Miletic committed Dec 30, 2011
View
@@ -177,6 +177,28 @@ protected function create_code_info_details_mod () {
return $result . $blti_mod;
}
+ /**
+ * (non-PHPdoc)
+ * @see cc2moodle::get_module_visible()
+ */
+ protected function get_module_visible($identifier) {
+ //Should item be hidden or not
+ $mod_visible = 1;
+ if (!empty($identifier)) {
+ $xpath = static::newx_path(static::$manifest, static::$namespaces);
+ $query = '/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $identifier . '"]';
+ $query .= '//lom:intendedEndUserRole/lom:value';
+ $intendeduserrole = $xpath->query($query);
+ if (!empty($intendeduserrole) && ($intendeduserrole->length > 0)) {
+ $role = trim($intendeduserrole->item(0)->nodeValue);
+ if ((strcasecmp('Instructor', $role) === 0) || (strcasecmp('Mentor', $role) === 0)) {
+ $mod_visible = 0;
+ }
+ }
+ }
+ return $mod_visible;
+ }
+
protected function create_node_course_modules_mod () {
$labels = new cc_label();
$resources = new cc11_resource();
View
@@ -426,6 +426,30 @@ protected function create_node_course_blocks_block () {
}
+ /**
+ *
+ * Is activity visible or not
+ * @param string $identifier
+ * @return number
+ */
+ protected function get_module_visible($identifier) {
+ //Should item be hidden or not
+ $mod_visible = 1;
+ if (!empty($identifier)) {
+ $xpath = static::newx_path(static::$manifest, static::$namespaces);
+ $query = '/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $identifier . '"]';
+ $query .= '//lom:intendedEndUserRole/voc:vocabulary/lom:value';
+ $intendeduserrole = $xpath->query($query);
+ if (!empty($intendeduserrole) && ($intendeduserrole->length > 0)) {
+ $role = trim($intendeduserrole->item(0)->nodeValue);
+ if (strcasecmp('Instructor', $role) == 0) {
+ $mod_visible = 0;
+ }
+ }
+ }
+ return $mod_visible;
+ }
+
protected function create_node_course_sections_section_mods_mod ($root_parent) {
$sheet_course_sections_section_mods_mod = static::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD);
@@ -459,13 +483,15 @@ protected function create_node_course_sections_section_mods_mod ($root_parent) {
'[#mod_instance_id#]',
'[#mod_type#]',
'[#date_now#]',
- '[#mod_indent#]');
+ '[#mod_indent#]',
+ '[#mod_visible#]');
$replace_values = array($child['index'],
$child['instance'],
$child['moodle_type'],
time(),
- $indent);
+ $indent,
+ $this->get_module_visible($child['resource_indentifier']));
$node_course_sections_section_mods_mod .= str_replace($find_tags, $replace_values, $sheet_course_sections_section_mods_mod);
}
@@ -132,32 +132,33 @@ private function create_node_course_modules_mod_resource ($sheet_mod_resource, $
$cdir = getcwd();
chdir($dirpath);
try {
- $doc->loadHTML($mod_alltext);
- $xpath = new DOMXPath($doc);
- $attributes = array('href', 'src', 'background', 'archive', 'code');
- $qtemplate = "//*[@##][not(contains(@##,'://'))]/@##";
- $query = '';
- foreach ($attributes as $attrname) {
- if (!empty($query)) {
- $query .= " | ";
+ if (!empty($mod_alltext) && $doc->loadHTML($mod_alltext)) {
+ $xpath = new DOMXPath($doc);
+ $attributes = array('href', 'src', 'background', 'archive', 'code');
+ $qtemplate = "//*[@##][not(contains(@##,'://'))]/@##";
+ $query = '';
+ foreach ($attributes as $attrname) {
+ if (!empty($query)) {
+ $query .= " | ";
+ }
+ $query .= str_replace('##', $attrname, $qtemplate);
}
- $query .= str_replace('##', $attrname, $qtemplate);
- }
- $list = $xpath->query($query);
- $searches = array();
- $replaces = array();
- foreach ($list as $resrc) {
- $rpath = $resrc->nodeValue;
- $rtp = realpath($rpath);
- if (($rtp !== false) && is_file($rtp)) {
- //file is there - we are in business
- $strip = str_replace("\\", "/", str_ireplace($rootpath, '', $rtp));
- $encoded_file = '$@FILEPHP@$'.str_replace('/', '$@SLASH@$', $strip);
- $searches[] = $resrc->nodeValue;
- $replaces[] = $encoded_file;
+ $list = $xpath->query($query);
+ $searches = array();
+ $replaces = array();
+ foreach ($list as $resrc) {
+ $rpath = $resrc->nodeValue;
+ $rtp = realpath($rpath);
+ if (($rtp !== false) && is_file($rtp)) {
+ //file is there - we are in business
+ $strip = str_replace("\\", "/", str_ireplace($rootpath, '', $rtp));
+ $encoded_file = '$@FILEPHP@$'.str_replace('/', '$@SLASH@$', $strip);
+ $searches[] = $resrc->nodeValue;
+ $replaces[] = $encoded_file;
+ }
}
+ $mod_alltext = str_replace($searches, $replaces, $mod_alltext);
}
- $mod_alltext = str_replace($searches, $replaces, $mod_alltext);
} catch (Exception $e) {
//silence the complaints
}
@@ -5,7 +5,7 @@
<ADDED>[#date_now#]</ADDED>
<SCORE>0</SCORE>
<INDENT>[#mod_indent#]</INDENT>
- <VISIBLE>1</VISIBLE>
+ <VISIBLE>[#mod_visible#]</VISIBLE>
<GROUPMODE>0</GROUPMODE>
<GROUPINGID>0</GROUPINGID>
<GROUPMEMBERSONLY>0</GROUPMEMBERSONLY>

0 comments on commit 7db3d62

Please sign in to comment.