コード例 #1
0
ファイル: RemoteLRSTest.php プロジェクト: deltace/TinCanPHP
 public function testSaveStatementsWithAttachments()
 {
     $lrs = new RemoteLRS(self::$endpoint, self::$version, self::$username, self::$password);
     $attachment1 = ['usageType' => 'http://id.tincanapi.com/attachment/supporting_media', 'display' => ['en-US' => 'RemoteLRSTest::testSaveStatements'], 'contentType' => 'text/plain; charset=ascii', 'content' => 'Attachment 1 content created at: ' . TinCan\Util::getTimestamp()];
     $attachment2 = ['usageType' => 'http://id.tincanapi.com/attachment/supporting_media', 'display' => ['en-US' => 'RemoteLRSTest::testSaveStatements'], 'contentType' => 'text/plain; charset=ascii', 'content' => 'Attachment 2 content created at: ' . TinCan\Util::getTimestamp()];
     $statements = [['actor' => ['mbox' => COMMON_MBOX], 'verb' => ['id' => COMMON_VERB_ID], 'object' => new TinCan\Activity(['id' => COMMON_ACTIVITY_ID]), 'attachments' => [$attachment1]], ['actor' => ['mbox' => COMMON_MBOX], 'verb' => ['id' => COMMON_VERB_ID], 'object' => new TinCan\Activity(['id' => COMMON_ACTIVITY_ID . '/2']), 'attachments' => [$attachment1, $attachment2]]];
     $response = $lrs->saveStatements($statements);
     $this->assertInstanceOf('TinCan\\LRSResponse', $response);
     $this->assertTrue($response->success, 'success');
     $this->assertTrue(is_array($response->content), 'content is array');
     $this->assertSame(count($response->content), 2, 'content has 2 values');
     foreach ($response->content as $i => $st) {
         $this->assertInstanceof('TinCan\\Statement', $st, "{$i}: is statement");
         $id = $st->getId();
         $this->assertTrue(isset($id), "{$i}: id set");
     }
 }
コード例 #2
0
    $statements = array();
    foreach ($batch as $id => $logrecord) {
        $event = array('eventname' => '\\core\\event\\user_loggedin');
        $event['userid'] = $logrecord->userid;
        $event['relateduserid'] = null;
        $event['courseid'] = 1;
        // Should be $logrecord->courseid;
        $event['timecreated'] = $logrecord->time;
        if ($statement = $gen->generateStatement($event)) {
            $statements[] = $statement;
        }
    }
    $log->info("Sending statements {$start} to " . ($start + count($batch) - 1));
    $log->info("Statement count: " . count($statements));
    // Send statements as a batch
    $result = $lrs->saveStatements($statements);
    $start += count($batch);
}
// CourseViewed recipe
$log->info("Processing CourseViewed events");
$start = 0;
while ($batch = $DB->get_records('log', array('module' => 'course', 'action' => 'view'), '', '*', $start, $batchsize)) {
    $statements = array();
    foreach ($batch as $id => $logrecord) {
        try {
            // Make sure course still exists
            get_course($logrecord->course);
        } catch (Exception $e) {
            $log->warning("MISSING: Unable to get course {$logrecord->course}");
            continue;
        }