Merge branch 'MDL-30778_t2' of git://github.com/kiklop74/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2012-01-09 00:41:55 +01:00
commit 3c4500f5c7
4 changed files with 75 additions and 26 deletions

View File

@ -177,6 +177,28 @@ class cc112moodle extends cc2moodle {
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 File

@ -426,6 +426,30 @@ class cc2moodle {
}
/**
*
* 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 @@ class cc2moodle {
'[#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);
}

View File

@ -132,32 +132,33 @@ class cc_resource extends entities {
$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
}

View File

@ -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>