Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
/**
17
 * @package   moodlecore
18
 * @subpackage backup-imscc
19
 * @copyright 2011 Darko Miletic (dmiletic@moodlerooms.com)
20
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 */
22
 
23
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
24
 
25
class cc11_lti extends entities11 {
26
 
27
    public function generate_node() {
28
 
29
        cc2moodle::log_action('Creating BasicLTI mods');
30
 
31
        $response = '';
32
 
33
        if (!empty(cc2moodle::$instances['instances'][MOODLE_TYPE_LTI])) {
34
            foreach (cc2moodle::$instances['instances'][MOODLE_TYPE_LTI] as $instance) {
35
                $response .= $this->create_node_course_modules_mod_basiclti($instance);
36
            }
37
        }
38
 
39
        return $response;
40
    }
41
 
42
    private function create_node_course_modules_mod_basiclti($instance) {
43
 
44
        $sheet_mod_basiclti = cc112moodle::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD_LTI);
45
 
46
        $topic_data = $this->get_basiclti_data($instance);
47
 
48
        $result = '';
49
        if (!empty($topic_data)) {
50
 
51
            $find_tags = array('[#mod_instance#]'        ,
52
                               '[#mod_basiclti_name#]'   ,
53
                               '[#mod_basiclti_intro#]'  ,
54
                               '[#mod_basiclti_timec#]'  ,
55
                               '[#mod_basiclti_timem#]'  ,
56
                               '[#mod_basiclti_toolurl#]',
57
                               '[#mod_basiclti_icon#]'
58
                               );
59
 
60
            $replace_values = array($instance['instance'],
61
                                    $topic_data['title'],
62
                                    $topic_data['description'],
63
                                    time(),time(),
64
                                    $topic_data['launchurl'],
65
                                    $topic_data['icon']
66
                                    );
67
 
68
            $result = str_replace($find_tags, $replace_values, $sheet_mod_basiclti);
69
 
70
        }
71
 
72
        return $result;
73
    }
74
 
75
    protected function getValue($node, $default = '') {
76
        $result = $default;
77
        if (is_object($node) && ($node->length > 0) && !empty($node->item(0)->nodeValue)) {
78
            $result = htmlspecialchars(trim($node->item(0)->nodeValue), ENT_COMPAT, 'UTF-8', false);
79
        }
80
        return $result;
81
    }
82
 
83
    public function get_basiclti_data($instance) {
84
 
85
        $topic_data = array();
86
 
87
        $basiclti_file = $this->get_external_xml($instance['resource_indentifier']);
88
 
89
        if (!empty($basiclti_file)) {
90
            $basiclti_file_path = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $basiclti_file;
91
            $basiclti_file_dir = dirname($basiclti_file_path);
92
            $basiclti = $this->load_xml_resource($basiclti_file_path);
93
            if (!empty($basiclti)) {
94
                $xpath = cc2moodle::newx_path($basiclti, cc112moodle::$basicltins);
95
                $topic_title = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:title'),'Untitled');
96
                $blti_description = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:description'));
97
                $launch_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:launch_url'));
98
                $launch_icon = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:icon'));
99
                $tool_raw = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:code'),null);
100
                $tool_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:url'),null);
101
                $tool_desc = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:description'),null);
102
                $topic_data['title'      ] = $topic_title;
103
                $topic_data['description'] = $blti_description;
104
                $topic_data['launchurl'  ] = $launch_url;
105
                $topic_data['icon'       ] = $launch_icon;
106
                $topic_data['orgid'      ] = $tool_raw;
107
                $topic_data['orgurl'     ] = $tool_url;
108
                $topic_data['orgdesc'    ] = $tool_desc;
109
            }
110
        }
111
 
112
        return $topic_data;
113
    }
114
 
115
}
116