Skip to content

Commit

Permalink
MDL-30778: Implemented intendeduserrole support
Browse files Browse the repository at this point in the history
  • Loading branch information
Darko Miletic committed Dec 30, 2011
1 parent 2117dcb commit 7db3d62
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 26 deletions.
22 changes: 22 additions & 0 deletions backup/cc/cc112moodle.php
Expand Up @@ -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();
Expand Down
30 changes: 28 additions & 2 deletions backup/cc/cc2moodle.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
47 changes: 24 additions & 23 deletions backup/cc/entity.resource.class.php
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion backup/cc/sheets/course_sections_section_mods_mod.xml
Expand Up @@ -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>
Expand Down

0 comments on commit 7db3d62

Please sign in to comment.