Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/lti/lib.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // This file is part of BasicLTI4Moodle
00018 //
00019 // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)
00020 // consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web
00021 // based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI
00022 // specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS
00023 // are already supporting or going to support BasicLTI. This project Implements the consumer
00024 // for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.
00025 // BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem
00026 // at the GESSI research group at UPC.
00027 // SimpleLTI consumer for Moodle is an implementation of the early specification of LTI
00028 // by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a
00029 // Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.
00030 //
00031 // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis
00032 // of the Universitat Politecnica de Catalunya http://www.upc.edu
00033 // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu
00034 
00050 defined('MOODLE_INTERNAL') || die;
00051 
00057 function lti_supports($feature) {
00058     switch($feature) {
00059         case FEATURE_GROUPS:                  return false;
00060         case FEATURE_GROUPINGS:               return false;
00061         case FEATURE_GROUPMEMBERSONLY:        return true;
00062         case FEATURE_MOD_INTRO:               return true;
00063         case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
00064         case FEATURE_GRADE_HAS_GRADE:         return true;
00065         case FEATURE_GRADE_OUTCOMES:          return true;
00066         case FEATURE_BACKUP_MOODLE2:          return true;
00067         case FEATURE_SHOW_DESCRIPTION:        return true;
00068 
00069         default: return null;
00070     }
00071 }
00072 
00082 function lti_add_instance($lti, $mform) {
00083     global $DB, $CFG;
00084     require_once($CFG->dirroot.'/mod/lti/locallib.php');
00085 
00086     $lti->timecreated = time();
00087     $lti->timemodified = $lti->timecreated;
00088     $lti->servicesalt = uniqid('', true);
00089 
00090     if (!isset($lti->grade)) {
00091         $lti->grade = 100; // TODO: Why is this harcoded here and default @ DB
00092     }
00093 
00094     $lti->id = $DB->insert_record('lti', $lti);
00095 
00096     if ($lti->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS) {
00097         if (!isset($lti->cmidnumber)) {
00098             $lti->cmidnumber = '';
00099         }
00100 
00101         lti_grade_item_update($lti);
00102     }
00103 
00104     return $lti->id;
00105 }
00106 
00115 function lti_update_instance($lti, $mform) {
00116     global $DB, $CFG;
00117     require_once($CFG->dirroot.'/mod/lti/locallib.php');
00118 
00119     $lti->timemodified = time();
00120     $lti->id = $lti->instance;
00121 
00122     if (!isset($lti->showtitlelaunch)) {
00123         $lti->showtitlelaunch = 0;
00124     }
00125 
00126     if (!isset($lti->showdescriptionlaunch)) {
00127         $lti->showdescriptionlaunch = 0;
00128     }
00129 
00130     if (!isset($lti->grade)) {
00131         $lti->grade = $DB->get_field('lti', 'grade', array('id' => $lti->id));
00132     }
00133 
00134     if ($lti->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS) {
00135         lti_grade_item_update($lti);
00136     } else {
00137         lti_grade_item_delete($lti);
00138     }
00139 
00140     return $DB->update_record('lti', $lti);
00141 }
00142 
00151 function lti_delete_instance($id) {
00152     global $DB;
00153 
00154     if (! $basiclti = $DB->get_record("lti", array("id" => $id))) {
00155         return false;
00156     }
00157 
00158     $result = true;
00159 
00160     # Delete any dependent records here #
00161     lti_grade_item_delete($basiclti);
00162 
00163     return $DB->delete_records("lti", array("id" => $basiclti->id));
00164 }
00165 
00175 function lti_get_coursemodule_info($coursemodule) {
00176     global $DB, $CFG;
00177     require_once($CFG->dirroot.'/mod/lti/locallib.php');
00178 
00179     if (!$lti = $DB->get_record('lti', array('id' => $coursemodule->instance),
00180             'icon, secureicon, intro, introformat, name')) {
00181         return null;
00182     }
00183 
00184     $info = new cached_cm_info();
00185 
00186     // We want to use the right icon based on whether the
00187     // current page is being requested over http or https.
00188     if (lti_request_is_using_ssl() && !empty($lti->secureicon)) {
00189         $info->iconurl = new moodle_url($lti->secureicon);
00190     } else if (!empty($lti->icon)) {
00191         $info->iconurl = new moodle_url($lti->icon);
00192     }
00193 
00194     if ($coursemodule->showdescription) {
00195         // Convert intro to html. Do not filter cached version, filters run at display time.
00196         $info->content = format_module_intro('lti', $lti, $coursemodule->id, false);
00197     }
00198 
00199     $info->name = $lti->name;
00200 
00201     return $info;
00202 }
00203 
00214 function lti_user_outline($course, $user, $mod, $basiclti) {
00215     return null;
00216 }
00217 
00225 function lti_user_complete($course, $user, $mod, $basiclti) {
00226     return true;
00227 }
00228 
00238 function lti_print_recent_activity($course, $isteacher, $timestart) {
00239     return false;  //  True if anything was printed, otherwise false
00240 }
00241 
00250 function lti_cron () {
00251     return true;
00252 }
00253 
00269 function lti_grades($basicltiid) {
00270     return null;
00271 }
00272 
00284 function lti_get_participants($basicltiid) {
00285     return false;
00286 }
00287 
00299 function lti_scale_used ($basicltiid, $scaleid) {
00300     $return = false;
00301 
00302     //$rec = get_record("basiclti","id","$basicltiid","scale","-$scaleid");
00303     //
00304     //if (!empty($rec)  && !empty($scaleid)) {
00305     //    $return = true;
00306     //}
00307 
00308     return $return;
00309 }
00310 
00320 function lti_scale_used_anywhere($scaleid) {
00321     global $DB;
00322 
00323     if ($scaleid and $DB->record_exists('lti', array('grade' => -$scaleid))) {
00324         return true;
00325     } else {
00326         return false;
00327     }
00328 }
00329 
00336 function lti_install() {
00337      return true;
00338 }
00339 
00346 function lti_uninstall() {
00347     return true;
00348 }
00349 
00355 function lti_get_lti_types() {
00356     global $DB;
00357 
00358     return $DB->get_records('lti_types');
00359 }
00360 
00368 function lti_grade_item_update($basiclti, $grades=null) {
00369     global $CFG;
00370     require_once($CFG->libdir.'/gradelib.php');
00371 
00372     $params = array('itemname'=>$basiclti->name, 'idnumber'=>$basiclti->cmidnumber);
00373 
00374     if ($basiclti->grade > 0) {
00375         $params['gradetype'] = GRADE_TYPE_VALUE;
00376         $params['grademax']  = $basiclti->grade;
00377         $params['grademin']  = 0;
00378 
00379     } else if ($basiclti->grade < 0) {
00380         $params['gradetype'] = GRADE_TYPE_SCALE;
00381         $params['scaleid']   = -$basiclti->grade;
00382 
00383     } else {
00384         $params['gradetype'] = GRADE_TYPE_TEXT; // allow text comments only
00385     }
00386 
00387     if ($grades  === 'reset') {
00388         $params['reset'] = true;
00389         $grades = null;
00390     }
00391 
00392     return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, $grades, $params);
00393 }
00394 
00401 function lti_grade_item_delete($basiclti) {
00402     global $CFG;
00403     require_once($CFG->libdir.'/gradelib.php');
00404 
00405     return grade_update('mod/lti', $basiclti->course, 'mod', 'lti', $basiclti->id, 0, null, array('deleted'=>1));
00406 }
00407 
00408 function lti_extend_settings_navigation($settings, $parentnode) {
00409     global $PAGE;
00410 
00411     if (has_capability('mod/lti:grade', get_context_instance(CONTEXT_MODULE, $PAGE->cm->id))) {
00412         $keys = $parentnode->get_children_key_list();
00413 
00414         $node = navigation_node::create('Submissions',
00415             new moodle_url('/mod/lti/grade.php', array('id'=>$PAGE->cm->id)),
00416             navigation_node::TYPE_SETTING, null, 'mod_lti_submissions');
00417 
00418         $parentnode->add_node($node, $keys[1]);
00419     }
00420 }
 All Data Structures Namespaces Files Functions Variables Enumerations