外部のウェブサイトをmoodle-systemに接続したいです。すでに webService をセットアップし、アクセスするためのトークンを作成しました。
http://www.rumours.co.nz/manuals/using_moodle_web_services.htmのセットアップに従いましたが、対照的に、 https://github.com/moodlehq/sample-ws-のように REST 経由で接続を実現したかったのです。クライアント/検索/マスター
私のアプローチは、データ交換を処理するムードル クラスを持つことです。最初に、webService を介していくつかの新しいハードコードされたユーザーを作成しようとしただけですが、Moodle-Response で失敗します:
"invalidrecord データベース テーブル external_functions にデータ レコードが見つかりません。"
呼び出しは成功したように思えますが、moodle には「core_user_create_users」関数を見つけるのに問題があります。私はローカルのmoodleデータベースをチェックしましたが、テーブルexternal_functionsは「core_user_create_users」のエントリであるため、moodleが何をすべきかわからない場所でちょっと混乱しています。
それは私のクラスです:
require_once (DOCUMENT_ROOT.'/tcm/api/moodle/curl.php');
class Moodle {
private $token;
private $domainName; // 'local.moodle.dev';
private $serverUrl;
public function __construct($token, $domainName) {
$this->token = $token;
$this->domainName = $domainName;
$this->serverUrl = $this->domainName . '/webservice/rest/server.php' . '?wstoken=' . $this->token;
echo "initialize Service: $this->serverUrl </br>";
}
public function createUser() {
$functionName = 'core_user_create_users';
/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION
$user1 = new stdClass();
$user1->username = 'testusername1';
$user1->password = 'testpassword1';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1@moodle.com';
$user1->auth = 'manual';
$user1->idnumber = 'testidnumber1';
$user1->lang = 'en';
$user1->theme = 'standard';
$user1->timezone = '-12.5';
$user1->mailformat = 0;
$user1->description = 'Hello World!';
$user1->city = 'testcity1';
$user1->country = 'au';
$preferencename1 = 'preference1';
$preferencename2 = 'preference2';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'preferencevalue1'),
array('type' => $preferencename2, 'value' => 'preferencevalue2'));
$user2 = new stdClass();
$user2->username = 'testusername2';
$user2->password = 'testpassword2';
$user2->firstname = 'testfirstname2';
$user2->lastname = 'testlastname2';
$user2->email = 'testemail2@moodle.com';
$user2->timezone = 'Pacific/Port_Moresby';
$users = array($user1, $user2);
$params = array('users' => $users);
/// REST CALL
$serverurl = $this->serverUrl . '&wsfunction=' . $functionName;
require_once (DOCUMENT_ROOT.'/tcm/api/moodle/curl.php');
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = "json";
$resp = $curl->post($serverurl . $restformat, $params);
//print_r($resp);
echo '</br>*************Server Response*************</br>';
var_dump($resp);
}
}
上に投稿したのと同じgithub-projectのcurlクラスを使用しています-moodleはドキュメントでリンクしています.. docs.moodle.org/dev/Creating_a_web_service_client
私の呼び出しのエントリポイントは現在ハードコードされています:
<?php
include_once (DOCUMENT_ROOT.'/tcm/api/moodle/moodle.php');
//entry point of code
if (isset($_POST)){
//token and domain would be in $_POST
$bla = new Moodle('0b5a1e98061c5f7fb70fc3b42af6bfc4', 'local.moodle.dev');
$bla->createUser();
}
「invalidrecord Can not find data record in database table external_functions」エラーを解決する方法を知っている人はいますか、またはユーザーをリモートで作成する方法が異なるアプローチ/提案がありますか??
前もって感謝します