php Tsugi-Core-LTIX类(方法)实例源码

下面列出了php Tsugi-Core-LTIX 类(方法)源码代码实例,从而了解它的用法。

作者:cse    项目:tsugi-ph   
public static function gradeTable($GRADE_DETAIL_CLASS)
 {
     global $CFG, $OUTPUT, $USER, $LINK;
     // Require CONTEXT, USER, and LINK
     $LAUNCH = LTIX::requireData();
     if (!$USER->instructor) {
         die("Requires instructor role");
     }
     $p = $CFG->dbprefix;
     // Get basic grade data
     $query_parms = array(":LID" => $LINK->id);
     $orderfields = array("R.updated_at", "displayname", "email", "grade");
     $searchfields = $orderfields;
     $sql = "SELECT R.user_id AS user_id, displayname, email,\n                grade, note, R.updated_at AS updated_at\n            FROM {$p}lti_result AS R\n            JOIN {$p}lti_user AS U ON R.user_id = U.user_id\n            WHERE R.link_id = :LID";
     // View
     $OUTPUT->header();
     $OUTPUT->bodyStart();
     $OUTPUT->flashMessages();
     $OUTPUT->welcomeUserCourse();
     if (isset($GRADE_DETAIL_CLASS) && is_object($GRADE_DETAIL_CLASS)) {
         $detail = $GRADE_DETAIL_CLASS;
     } else {
         $detail = false;
     }
     Table::pagedAuto($sql, $query_parms, $searchfields, $orderfields, "grade-detail.php");
     // Since this is in a popup, put out a done button
     $OUTPUT->closeButton();
     $OUTPUT->footer();
 }

作者:shaamimahme    项目:tsug   
function gradeUpdateJson($newdata = false)
{
    global $CFG, $PDOX, $LINK;
    if ($newdata == false) {
        return;
    }
    if (is_string($newdata)) {
        $newdata = json_decode($newdata, true);
    }
    $LTI = LTIX::requireData(array(LTIX::LINK));
    $row = gradeLoad();
    $data = array();
    if ($row !== false && isset($row['json'])) {
        $data = json_decode($row['json'], true);
    }
    $changed = false;
    foreach ($newdata as $k => $v) {
        if (!isset($data[$k]) || $data[$k] != $v) {
            $data[$k] = $v;
            $changed = true;
        }
    }
    if ($changed === false) {
        return;
    }
    $jstr = json_encode($data);
    $stmt = $PDOX->queryDie("UPDATE {$CFG->dbprefix}lti_result SET json = :json, updated_at = NOW()\n            WHERE result_id = :RID", array(':json' => $jstr, ':RID' => $LINK->result_id));
}

作者:cse    项目:tsugi-ph   
public static function serveContent()
 {
     global $CFG, $CONTEXT, $PDOX;
     // Sanity checks
     $LAUNCH = LTIX::requireData(LTIX::CONTEXT);
     $id = $_REQUEST['id'];
     if (strlen($id) < 1) {
         die("File not found");
     }
     $p = $CFG->dbprefix;
     $stmt = $PDOX->prepare("SELECT contenttype, content, file_name FROM {$p}blob_file\n                    WHERE file_id = :ID AND context_id = :CID");
     $stmt->execute(array(":ID" => $id, ":CID" => $CONTEXT->id));
     $row = $stmt->fetch(\PDO::FETCH_ASSOC);
     if ($row === false) {
         error_log('File not loaded: ' . $id);
         die("File not loaded");
     }
     if (!BlobUtil::safeFileSuffix($row['file_name'])) {
         error_log('Unsafe file suffix: ' . $row['file_name']);
         die('Unsafe file suffix');
     }
     $mimetype = $row['contenttype'];
     // die($mimetype);
     if (strlen($mimetype) > 0) {
         header('Content-Type: ' . $mimetype);
     }
     // header('Content-Disposition: attachment; filename="'.$fn.'"');
     // header('Content-Type: text/data');
     echo $row['content'];
 }

作者:cse    项目:tsugi-ph   
/**
  * Retrieve an array of all of the link level settings
  *
  * If there are no settings, return an empty array.  
  *
  * This routine also looks for legacy custom fields and treats
  * them as defaults for settings if the corresponding key is not
  * already present in settings.  This will slowly convert LTI 
  * 1.x custom parameters under the control of the LMS to LTI 2.x 
  * style settings under control of our local tools.
  */
 public static function linkGetAll()
 {
     global $CFG, $PDOX, $LINK;
     if (!isset($_SESSION['lti'])) {
         return array();
     }
     if (isset($_SESSION['lti']['link_settings_merge'])) {
         return $_SESSION['lti']['link_settings_merge'];
     }
     $legacy_fields = array('dologin', 'close', 'due', 'timezone', 'penalty_time', 'penalty_cost');
     $defaults = array();
     foreach ($legacy_fields as $k) {
         $value = LTIX::customGet($k);
         $defaults[$k] = $value;
     }
     if (isset($_SESSION['lti']['link_settings'])) {
         $json = $_SESSION['lti']['link_settings'];
         if (strlen($json) < 0) {
             return $defaults;
         }
         $retval = json_decode($json, true);
         // No objects
         $retval = array_merge($defaults, $retval);
         $_SESSION['lti']['link_settings_array'] = $retval;
         return $retval;
     }
     // Not in session - retrieve from the database
     // We cannot assume the $LINK is fully set up yet...
     if (!isset($_SESSION['lti']['link_id'])) {
         return $defaults;
     }
     $row = $PDOX->rowDie("SELECT settings FROM {$CFG->dbprefix}lti_link WHERE link_id = :LID", array(":LID" => $_SESSION['lti']['link_id']));
     if ($row === false) {
         return $defaults;
     }
     $json = $row['settings'];
     if ($json === null) {
         return $defaults;
     }
     $retval = json_decode($json, true);
     // No objects
     $retval = array_merge($defaults, $retval);
     // Store in session for later
     $_SESSION['lti']['link_settings'] = $json;
     $_SESSION['lti']['link_settings_array'] = $retval;
     return $retval;
 }

作者:ixte    项目:tsug   
function webauto_test_passed($grade, $url)
{
    global $USER, $OUTPUT;
    success_out("Test passed - congratulations");
    if ($USER->displayname === false || !isset($_SESSION['lti'])) {
        line_out('Not setup to return a grade..');
        return false;
    }
    $LTI = $_SESSION['lti'];
    $old_grade = isset($LTI['grade']) ? $LTI['grade'] : 0.0;
    if ($grade < $old_grade) {
        line_out('New grade is not higher than your previous grade=' . $old_grade);
        line_out('Sending your previous high score');
        $grade = $old_grade;
    }
    gradeUpdateJson(json_encode(array("url" => $url)));
    $debug_log = array();
    $retval = LTIX::gradeSend($grade, false, $debug_log);
    $OUTPUT->dumpDebugArray($debug_log);
    if ($retval == true) {
        $success = "Grade sent to server (" . $grade . ")";
    } else {
        if (is_string($retval)) {
            $failure = "Grade not sent: " . $retval;
        } else {
            echo "<pre>\n";
            var_dump($retval);
            echo "</pre>\n";
            $failure = "Internal error";
        }
    }
    if (strlen($success) > 0) {
        success_out($success);
        error_log($success);
    } else {
        if (strlen($failure) > 0) {
            error_out($failure);
            error_log($failure);
        } else {
            error_log("No status");
        }
    }
    return true;
}

作者:JANQLIANGTSA    项目:tsug   
count = 0
for line in fh:
    print line.strip()
    count = count + 1

print count,"Lines"';
$CHECKS = false;
$EX = false;

// Check which exercise we are supposed to do - settings, then custom, then 
// GET
if ( isset($oldsettings['exercise']) && $oldsettings['exercise'] != '0' ) {
    $ex = $oldsettings['exercise'];
} else {
    $ex = LTIX::customGet('exercise');
}
if ( $ex === false && isset($_REQUEST["exercise"]) ) {
    $ex = $_REQUEST["exercise"];
}
if ( $ex !== false && $ex != "code" ) {
    if ( isset($EXERCISES[$ex]) ) $EX = $EXERCISES[$ex];
    if ( $EX !== false ) {
        $CODE = '';
        $QTEXT = $EX["qtext"];
        $DESIRED = $EX["desired"];
        $DESIRED2 = isset($EX["desired2"]) ? $EX["desired2"] : '';
        $DESIRED = rtrim($DESIRED);
        $DESIRED2 = rtrim($DESIRED2);
        if ( isset($EX["code"]) ) $CODE = $EX["code"];
        if ( isset($EX["checks"]) ) $CHECKS = json_encode($EX["checks"]);

作者:shaamimahme    项目:tsug   
require_once "names.php";
require_once "locations.php";
use Tsugi\Core\LTIX;
use Tsugi\Util\LTI;
use Tsugi\Util\Net;
$LTI = LTIX::requireData();
$p = $CFG->dbprefix;
if (!$USER->instructor) {
    die('Must be instructor');
}
$sanity = array('urllib' => 'You should use urllib to retrieve the data from the API', 'urlencode' => 'You should use urlencode add parameters to the API url', 'json' => 'You should use the json library to parse the API data');
echo "<pre>\n";
echo "Running test...\n";
// Run though all the locations
// var_dump($LOCATIONS);
$url = LTIX::curPageUrlScript();
$i = 500;
foreach ($LOCATIONS as $key => $location) {
    // echo(htmlentities($location)."\n");
    $api_url = str_replace('geo_test.php', 'data/geojson', $url);
    $sample_url = $api_url . '?sensor=false&address=' . urlencode($location);
    $sample_data = Net::doGet($sample_url);
    $sample_count = strlen($sample_data);
    $response = Net::getLastHttpResponse();
    $sample_json = json_decode($sample_data);
    if ($response != 200 || $sample_json == null || !isset($sample_json->results[0])) {
        echo "*** Bad response={$response} url={$sample_url} json_error=" . json_last_error_msg() . "\n";
        echo jsonIndent($sample_data);
        continue;
    }
    // echo("<pre>\n");echo(jsonIndent(json_encode($sample_json)));echo("</pre>\n");

作者:shaamimahme    项目:tsug   
}
    unset($_SESSION['peer_submit_id']);
    $submit_id = $_POST['submit_id'] + 0;
    $stmt = $PDOX->queryReturnError("INSERT INTO {$p}peer_grade\n            (submit_id, user_id, points, note, created_at, updated_at)\n            VALUES ( :SID, :UID, :POINTS, :NOTE, NOW(), NOW())\n            ON DUPLICATE KEY UPDATE points = :POINTS, note = :NOTE, updated_at = NOW()", array(':SID' => $submit_id, ':UID' => $USER->id, ':POINTS' => $points, ':NOTE' => $_POST['note']));
    Cache::clear('peer_grade');
    if (!$stmt->success) {
        $_SESSION['error'] = $stmt->errorImplode;
        header('Location: ' . addSession($url_goback));
        return;
    }
    // Attempt to update the user's grade, may take a second..
    $grade = computeGrade($assn_id, $assn_json, $user_id);
    $_SESSION['success'] = 'Grade submitted';
    if ($grade > 0) {
        $result = lookupResult($LTI, $user_id);
        $status = LTIX::gradeSend($grade, $result);
        // This is the slow bit
        if ($status === true) {
            $_SESSION['success'] = 'Grade submitted to server';
        } else {
            error_log("Problem sending grade " . $status);
        }
    }
    header('Location: ' . addSession($url_goback));
    return;
}
unset($_SESSION['peer_submit_id']);
$submit_id = false;
$submit_json = null;
if ($user_id === false) {
    // Load the the 10 oldest ungraded submissions

作者:ixte    项目:tsug   
if ($status === true) {
     echo 'Grade submitted to server' . "<br/>\n";
     $success++;
 } else {
     echo '<pre class="alert alert-danger">' . "\n";
     $msg = "result_id=" . $row['result_id'] . "\n" . "grade=" . $row['grade'] . " server_grade=" . $row['server_grade'] . "\n" . "error=" . $status;
     echo_log("Problem Sending Grade: " . session_id() . "\n" . $msg . "\n" . "result_url=" . $row['reult_url'] . " service_key=" . $row['service_key'] . " sourcedid=" . $row['sourcedid']);
     echo "</pre>\n";
     $OUTPUT->togglePre("Error retrieving new grade at " . $count, $LastPOXGradeResponse);
     flush();
     echo "Problem sending grade " . $status . "<br/>\n";
     $fail++;
     continue;
 }
 // Check to see if the grade we sent is really there - Also updates our local table
 $server_grade = LTIX::gradeGet($row);
 if (is_string($server_grade)) {
     echo '<pre class="alert alert-danger">' . "\n";
     $msg = "result_id=" . $row['result_id'] . "\n" . "grade=" . $row['grade'] . " updated=" . $row['updated_at'] . "\n" . "server_grade=" . $row['server_grade'] . " retrieved=" . $row['retrieved_at'] . "\n" . "error=" . $server_grade;
     echo_log("Problem Updating Grade: " . session_id() . "\n" . $msg . "\n" . "result_url=" . $row['reult_url'] . " service_key=" . $row['service_key'] . " sourcedid=" . $row['sourcedid']);
     echo "</pre>\n";
     error_log("Error re-retrieving grade: " . session_id() . ' result_id=' . $row['result_id'] . "result_url=" . $row['reult_url'] . ' sourcedid=' + $row['sourcedid'] + ' service_key=' + $row['service_key']);
     $OUTPUT->togglePre("Error retrieving new grade at " . $count, $LastPOXGradeResponse);
     flush();
     $fail++;
     continue;
 } else {
     if ($server_grade != $row['grade']) {
     } else {
     }
 }

作者:shaamimahme    项目:tsug   
headerJson();
// Nothing for us to do
if (!isset($_GET[session_name()])) {
    echo json_encode(array("error" => "No session"));
    return;
}
if (isset($_COOKIE[session_name()])) {
    echo json_encode(array("status" => 'done'));
    return;
}
if (!isset($_GET['top'])) {
    echo json_encode(array("error" => "Need top= parameter"));
    return;
}
// Grab the session
$LTI = LTIX::requireData(LTIX::USER);
// This has already been set by someone so nothing to do
if (isset($_COOKIE['TSUGI_TOP_SESSION'])) {
    unset($_SESSION['TOP_CHECK']);
    // No point in further checks
    echo json_encode(array("top_session" => $_COOKIE['TSUGI_TOP_SESSION']));
    return;
}
// We are not the top frame
if ($_GET['top'] != 'true') {
    unset($_SESSION['TOP_CHECK']);
}
// No more checks are needed
if (!isset($_SESSION['TOP_CHECK']) || $_SESSION['TOP_CHECK'] < 1) {
    echo json_encode(array("status" => 'done'));
    return;

作者:shaamimahme    项目:tsug   
// Sanity checks
$LTI = LTIX::requireData();
$p = $CFG->dbprefix;
$OUTPUT->header();
$OUTPUT->bodyStart();
$OUTPUT->flashMessages();
$OUTPUT->welcomeUserCourse();
if (!$USER->instructor) {
    echo "<p>This tool must be launched by the instructor</p>";
    $OUTPUT->footer();
    exit;
}
// See https://canvas.instructure.com/doc/api/file.link_selection_tools.html
// Needed return values
$content_return_types = LTIX::postGet("ext_content_return_types", false);
$content_return_url = LTIX::postGet("ext_content_return_url", false);
if (strlen($content_return_url) < 1) {
    lmsDie("Missing ext_content_return_url");
}
if (strpos($content_return_types, "lti_launch_url") === false) {
    lmsDie("This tool requires ext_content_return_types=lti_launch_url");
}
// Scan the tools folders for registration settings
$tools = findFiles("register.php", "../");
if (count($tools) < 1) {
    lmsDie("No register.php files found...<br/>\n");
}
echo "<ul>\n";
$toolcount = 0;
foreach ($tools as $tool) {
    $path = str_replace("../", "", $tool);

作者:shaamimahme    项目:tsug   
$assn_json = json_decode($row['json']);
    $assn_id = $row['assn_id'];
}
if ($assn_id == false) {
    jsonError('This assignment is not yet set up');
    return;
}
// Compute the user's grade
$grade = computeGrade($assn_id, $assn_json, $user_id);
if ($grade <= 0) {
    jsonError('Nothing to grade for this user', $row);
    return;
}
// Lookup the result row if we are grading the non-current user
$result = false;
if ($user_id != $USER->id) {
    $result = lookupResult($LTI, $user_id);
}
// Send the grade
$debug_log = array();
$status = LTIX::gradeSend($grade, $result, $debug_log);
// This is the slow bit
if ($status === true) {
    if ($user_id != $USER->id) {
        jsonOutput(array("status" => $status, "debug" => $debug_log));
    } else {
        jsonOutput(array("status" => $status, "grade" => $grade, "debug" => $debug_log));
    }
} else {
    jsonError($status, $debug_log);
}

作者:shaamimahme    项目:tsug   
echo "<h1>" . htmlent_utf8($title) . "</h1>\n";
     echo "<p>" . htmlent_utf8($text) . "</p>\n";
     $script = isset($REGISTER_LTI2['script']) ? $REGISTER_LTI2['script'] : "index.php";
     $path = $CFG->wwwroot . '/' . str_replace("register.php", $script, $path);
     // Title is for the href and text is for display
     $json = LTI::getLtiLinkJSON($path, $title, $title, false, $fa_icon);
     $retval = json_encode($json);
     $parms = array();
     $parms["lti_message_type"] = "ContentItemSelection";
     $parms["lti_version"] = "LTI-1p0";
     $parms["content_items"] = $retval;
     $data = LTIX::postGet('data');
     if ($data) {
         $parms['data'] = $data;
     }
     $parms = LTIX::signParameters($parms, $result_url, "POST", "Install Tool");
     $endform = '<a href="index.php" class="btn btn-warning">Back to Store</a>';
     $content = LTI::postLaunchHTML($parms, $result_url, true, false, $endform);
     echo $content;
 } else {
     echo '<div style="border: 2px, solid, red;" class="card">';
     if ($fa_icon) {
         echo '<a href="index.php?install=' . urlencode($tool) . '">';
         echo '<i class="fa ' . $fa_icon . ' fa-2x" style="color: #1894C7; float:right; margin: 2px"></i>';
         echo '</a>';
     }
     echo '<p><strong>' . htmlent_utf8($title) . "</strong></p>";
     echo '<p>' . htmlent_utf8($text) . "</p>\n";
     echo '<center><a href="index.php?install=' . urlencode($tool) . '" class="btn btn-default" role="button">Details</a></center>';
     echo "</div>\n";
 }

作者:shaamimahme    项目:tsug   
function dataUrl($file)
{
    global $GLOBAL_PYTHON_DATA_URL;
    if (is_string($GLOBAL_PYTHON_DATA_URL)) {
        return $GLOBAL_PYTHON_DATA_URL . $file;
    }
    $url = LTIX::curPageUrlScript();
    $retval = str_replace('index.php', 'data/' . $file, $url);
    return $retval;
}

作者:shaamimahme    项目:tsug   
header('Location: ' . addSession('student.php?user_id=' . $user_id));
    }
    return;
}
// Compute grade
$computed_grade = computeGrade($assn_id, $assn_json, $user_id);
// Does not cache
if (isset($_POST['resendSubmit'])) {
    $result = lookupResult($LTI, $user_id);
    // Does not cache
    // Force a resend
    $_SESSION['lti']['grade'] = -1;
    // Force a resend
    $result['grade'] = -1;
    $debug_log = array();
    $status = LTIX::gradeSend($computed_grade, $result, $debug_log);
    // This is the slow bit
    if ($status === true) {
        $_SESSION['success'] = 'Grade submitted to server';
    } else {
        error_log("Problem sending grade " . $status);
        $_SESSION['error'] = 'Error: ' . $status;
    }
    $_SESSION['debug_log'] = $debug_log;
    header('Location: ' . addSession('student.php?user_id=' . $user_id));
    return;
}
// Retrieve our grades...
$grades_received = retrieveSubmissionGrades($submit_id);
// Handle incoming post to delete a grade entry
if (isset($_POST['grade_id']) && isset($_POST['deleteGrade'])) {

作者:ixte    项目:tsug   
function doAnalytics()
    {
        global $CFG;
        if ($CFG->analytics_key) {
            ?>
    <script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '<?php 
            echo $CFG->analytics_key;
            ?>
']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        // ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';

        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    <?php 
            if (LTIX::sessionGet('key_key')) {
                echo "_gaq.push(['_setCustomVar', 1, 'consumer_key', '" . $_SESSION['lti']['key_key'] . "', 2]);\n";
            }
            if (LTIX::sessionGet('context_id')) {
                echo "_gaq.push(['_setCustomVar', 2, 'context_id', '" . $_SESSION['lti']['context_id'] . "', 2]);\n";
            }
            if (LTIX::sessionGet('context_title')) {
                echo "_gaq.push(['_setCustomVar', 3, 'context_title', '" . $_SESSION['lti']['context_title'] . "', 2]);\n";
            }
            echo "</script>\n";
        }
        // if analytics is on...
    }

作者:cse    项目:tsugi-ph   
/**
  * Send a grade and update our local copy
  *
  * Call the right LTI service to send a new grade up to the server.
  * update our local cached copy of the server_grade and the date
  * retrieved. This routine pulls the key and secret from the LTIX
  * session to avoid crossing cross tennant boundaries.
  *
  * @param $grade A new grade - floating point number between 0.0 and 1.0
  * @param $row An optional array with the data that has the result_id, sourcedid,
  * and service (url) if this is not present, the data is pulled from the LTI
  * session for the current user/link combination.
  * @param $debug_log An (optional) array (by reference) that returns the
  * steps that were taken.
  * Each entry is an array with the [0] element a message and an optional [1]
  * element as some detail (i.e. like a POST body)
  *
  * @return mixed If this works it returns true.  If not, you get
  * a string with an error.
  *
  */
 public function gradeSend($grade, $row = false, &$debug_log = false)
 {
     global $CFG, $USER;
     global $LastPOXGradeResponse;
     $LastPOXGradeResponse = false;
     $PDOX = LTIX::getConnection();
     // Secret and key from session to avoid crossing tenant boundaries
     $key_key = LTIX::sessionGet('key_key');
     $secret = LTIX::sessionGet('secret');
     if ($row !== false) {
         $result_url = isset($row['result_url']) ? $row['result_url'] : false;
         $sourcedid = isset($row['sourcedid']) ? $row['sourcedid'] : false;
         $service = isset($row['service']) ? $row['service'] : false;
         // Fall back to session if it is missing
         if ($service === false) {
             $service = LTIX::sessionGet('service');
         }
         $result_id = isset($row['result_id']) ? $row['result_id'] : false;
     } else {
         $result_url = LTIX::sessionGet('result_url');
         $sourcedid = LTIX::sessionGet('sourcedid');
         $service = LTIX::sessionGet('service');
         $result_id = LTIX::sessionGet('result_id');
     }
     // Update result in the database and in the LTI session area and
     // our local copy
     $_SESSION['lti']['grade'] = $grade;
     $this->grade = $grade;
     // Update the local copy of the grade in the lti_result table
     if ($PDOX !== false && $result_id !== false) {
         $stmt = $PDOX->queryReturnError("UPDATE {$CFG->dbprefix}lti_result SET grade = :grade,\n                    updated_at = NOW() WHERE result_id = :RID", array(':grade' => $grade, ':RID' => $result_id));
         if ($stmt->success) {
             $msg = "Grade updated result_id=" . $result_id . " grade={$grade}";
         } else {
             $msg = "Grade NOT updated result_id=" . $result_id . " grade={$grade}";
         }
         error_log($msg);
         if (is_array($debug_log)) {
             $debug_log[] = array($msg);
         }
     }
     if ($key_key == false || $secret === false || $sourcedid === false || $service === false || !isset($USER)) {
         error_log("Result::gradeSend stored data locally");
         return false;
     }
     // TODO: Fix this
     $comment = "";
     if (strlen($result_url) > 0) {
         $status = LTI::sendJSONGrade($grade, $comment, $result_url, $key_key, $secret, $debug_log);
     } else {
         $status = LTI::sendPOXGrade($grade, $sourcedid, $service, $key_key, $secret, $debug_log);
     }
     if ($status === true) {
         $msg = 'Grade sent ' . $grade . ' to ' . $sourcedid . ' by ' . $USER->id;
         if (is_array($debug_log)) {
             $debug_log[] = array($msg);
         }
         error_log($msg);
     } else {
         $msg = 'Grade failure ' . $grade . ' to ' . $sourcedid . ' by ' . $USER->id;
         if (is_array($debug_log)) {
             $debug_log[] = array($msg);
         }
         error_log($msg);
         return $status;
     }
     return $status;
 }

作者:shaamimahme    项目:tsug   
require_once "../../config.php";
require_once $CFG->dirroot . "/pdo.php";
require_once $CFG->dirroot . "/lib/lms_lib.php";
require_once $CFG->dirroot . "/core/gradebook/lib.php";
use Tsugi\Core\LTIX;
use Tsugi\Util\LTI;
use Tsugi\Util\Caliper;
// Retrieve the launch data if present
$LTI = LTIX::requireData();
$p = $CFG->dbprefix;
$displayname = $USER->displayname;
if (isset($_POST['caliper'])) {
    $caliper = Caliper::sensorCanvasPageView(LTIX::sessionGet('user_key'), $CFG->wwwroot, "samples/grade/index.php");
    $_SESSION['caliper'] = $caliper;
    $debug_log = array();
    $retval = LTIX::caliperSend($caliper, 'application/json', $debug_log);
    /*
    echo("<pre>\n");
    var_dump($caliper);
    echo("</pre>\n");
    die();
    */
    if ($retval) {
        $_SESSION['success'] = "Caliper sent.";
    } else {
        $_SESSION['error'] = "Caliper attempt failed.";
    }
    $_SESSION['debuglog'] = $debug_log;
    header('Location: ' . addSession('index.php'));
    return;
}

作者:na1i    项目:tsug   
/**
  * Send a Caliper Body to the correct URL using the key and secret
  *
  * This is not yet a standard or production - it uses the Canvas 
  * extension only.
  * 
  */
 public static function caliperSend($caliperBody, $content_type = 'application/json', &$debug_log = false)
 {
     $caliperURL = LTIX::postGet('custom_sub_canvas_caliper_url');
     if (strlen($caliperURL) == 0) {
         if (is_array($debug_log)) {
             $debug_log[] = array('custom_sub_canvas_caliper_url not found in launch data');
         }
         return false;
     }
     $key_key = self::sessionGet('key_key');
     $secret = self::sessionGet('secret');
     $retval = LTI::sendJSONBody("POST", $caliperBody, $content_type, $caliperURL, $key_key, $secret, $debug_log);
     return $retval;
 }

作者:shaamimahme    项目:tsug   
<?php

require_once "../../config.php";
require_once $CFG->dirroot . "/pdo.php";
require_once $CFG->dirroot . "/lib/lms_lib.php";
require_once "blob_util.php";
use Tsugi\Core\LTIX;
// Sanity checks
$LTI = LTIX::requireData(array(LTIX::CONTEXT, LTIX::LINK));
// Model
$p = $CFG->dbprefix;
if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == 1) {
    $_SESSION['error'] = 'Error: Maximum size of ' . maxUpload() . 'MB exceeded.';
    header('Location: ' . addSession('index.php'));
    return;
}
if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == 0) {
    $filename = basename($_FILES['uploaded_file']['name']);
    if (strpos($filename, '.php') !== false) {
        $_SESSION['error'] = 'Error: Wrong file type.';
        header('Location: ' . addSession('index.php'));
        return;
    }
    $fp = fopen($_FILES['uploaded_file']['tmp_name'], "rb");
    $stmt = $PDOX->prepare("INSERT INTO {$p}sample_blob\n        (context_id, file_name, contenttype, content, created_at)\n        VALUES (?, ?, ?, ?, NOW())");
    $stmt->bindParam(1, $CONTEXT->id);
    $stmt->bindParam(2, $filename);
    $stmt->bindParam(3, $_FILES['uploaded_file']['type']);
    $stmt->bindParam(4, $fp, PDO::PARAM_LOB);
    $PDOX->beginTransaction();
    $stmt->execute();


问题


面经


文章

微信
公众号

扫码关注公众号