prayno/moveon

MoveON API 包装器

2.1 2022-04-08 09:54 UTC

This package is auto-updated.

Last update: 2024-09-04 14:21:33 UTC


README

MoveOn (https://www.qs-unisolution.com/moveon/) 是一款用于管理大学和学校之间国际流动性(例如Erasmus项目)的应用程序。此包是MoveOn API的PHP包装器。

安装

通过运行以下命令使用Composer安装库

composer require prayno/moveon

使用方法

先决条件

在开始使用之前,您必须联系您的MoveON技术代表,以在您的MoveON实例中激活API。

然后,您必须为您的API客户端生成一个自签名的X509证书(.pem),并将序列号绑定到一个MoveON用户(有关技术文档请参阅)

类的实例化

现在MoveOn类需要使用symfony/http-client组件。

private $client;

public function __construct(HttpClientInterface $client)
{
    $this->client = $client->withOptions([
        'local_cert' => '/location/to/my/certificate/mycertificate.crt',
        'local_pk' => '/location/to/my/certificate/mycertificate.key',
        'passphrase' => 'myOptionalPassphraseToReadTheCertificate',
        'base_uri' => 'https://myUniversityInstance-api.moveonfr.com/restService/index.php?version=3.0'
    ]);
}

public function myFunction()
{
    $moveon = new MoveOn($this->client);
    ...
}

检索信息

要收集信息,您需要查找的实体和您想要搜索的准则。

$data = $moveon->findBy("person",["surname"=>"Foo","first_name"=>"Bar"]);

您可以使用数组作为搜索多个值的准则。例如

$data = $moveon->findBy("person",["surname"=>"Doe","first_name"=>["John","Jane"]]);

这将返回一个SimpleXMLElement对象(页面、记录、总数和行)。

您也可以为此方法添加更多选项

  • sort : 字段/顺序数组
  • rows : 每页行数
  • page : 结果页
  • columns : 返回的筛选字段
  • locale : eng/fra/deu/ita/spa

例如

$data = $moveon->findBy("person",["surname"=>"Foo","first_name"=>"Bar"],["surname"=>"asc","first_name"=>"asc"],20,1,["email","surname","last_name"],"fra");

由于QS设置了限制,您不能请求超过250行。但是,此库允许您请求更多行,它将发送多个请求并将响应合并为一个。此功能仅在您不请求特定页的情况下可用。

保存数据

创建和更新使用相同的方法;如果您想更新,只需提供条目的ID。

$data = $moveon->save("person",["id"=>"1","surname"=>"Foo","first_name"=>"Bar"]);

将附加参数$retrieveData设置为false允许该方法仅返回API提供的queueId,以便稍后使用(当您有许多查询时很有用)

注意

以下字段由于它们会导致请求失败而被从其实体中排除

person : address.type_eng,address.type_fra,address.type_deu,address.type_ita,address.type_spa

relation : parent,created_on,created_by,last_modified_by,last_modified_on

academic-year : is_active

subject-area : isced

institution : sector_id,size_id,organization_type_id

自定义查询

您还可以创建自己的自定义查询,并使用sendQuery方法将其发送到API。

$data = $moveon->sendQuery("person","list",YOUR_QUERY_STRING);