mirror of
https://github.com/SkillDisplay/PHPToolKit.git
synced 2024-12-22 10:46:09 +01:00
parent
4d401081e8
commit
ca56b9224c
4 changed files with 29 additions and 12 deletions
|
@ -9,8 +9,9 @@ require '../Includes/ExampleSettings.php';
|
|||
|
||||
use SkillDisplay\PHPToolKit\Verification\Issuer;
|
||||
|
||||
// Automatically grant a Business-Verification (e.g.: after completing an exam) if the SkillDisplay username is known
|
||||
// Automatically grant a Business-Verification (e.g.: after completing an exam) if the SkillDisplay username is known.
|
||||
// The number 567 is the optional campaignId the verification is attributed to.
|
||||
// In order to grant an Educational Verification you just need to exchange the constant to VERIFICATION_EDUCATIONAL
|
||||
// (your Verifier Account needs the according permissions)
|
||||
$myVerificationTool = new Issuer($mySettings);
|
||||
$myVerificationTool->outputResponse($myVerificationTool->issueVerification(193, '--skilldisplay-user-email--', VERIFICATION_BUSINESS));
|
||||
$myVerificationTool->outputResponse($myVerificationTool->issueVerification(193, '--skilldisplay-user-email--', VERIFICATION_BUSINESS, 567));
|
||||
|
|
|
@ -25,13 +25,16 @@ class Issuer
|
|||
* @param string $useremail E-Mail of the User who should receive the verification
|
||||
* @param string $vtype one of VERIFICATION_SELF, VERIFICATION_EDUCATIONAL, VERIFICATION_BUSINESS, VERIFICATION_CERTIFICATION
|
||||
* @param bool $isSkillSet
|
||||
* @param int $campaignId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function generateSignedRequestData(
|
||||
int $ID,
|
||||
string $useremail,
|
||||
string $vtype,
|
||||
bool $isSkillSet = false
|
||||
bool $isSkillSet = false,
|
||||
int $campaignId = 0
|
||||
): array {
|
||||
if ($isSkillSet) {
|
||||
$requestData['SkillSetId'] = $ID;
|
||||
|
@ -43,6 +46,9 @@ class Issuer
|
|||
$requestData['VerifierId'] = $this->settings->getVerifierID();
|
||||
$requestData['Username'] = $useremail;
|
||||
$requestData['AutoConfirm'] = true;
|
||||
if ($campaignId) {
|
||||
$requestData['CampaignId'] = $campaignId;
|
||||
}
|
||||
$requestData['Signature'] = '';
|
||||
|
||||
$json = json_encode($requestData);
|
||||
|
@ -72,15 +78,17 @@ class Issuer
|
|||
* @param string $useremail E-Mail of the SkillDisplay user for whom you want to verify the skill
|
||||
* @param string $vtype Verification type, one of the constants in /src/Constants/VerificationTypes.php
|
||||
* @param bool $isSkillSet is the passed ID that of a SkillSet (else it is a single skill, also default)
|
||||
* @param int $campaignId An optional campaign ID the verification is attributed to
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function issueVerification(
|
||||
int $skillID,
|
||||
string $useremail,
|
||||
string $vtype,
|
||||
bool $isSkillSet = false
|
||||
bool $isSkillSet = false,
|
||||
int $campaignId = 0
|
||||
): ResponseInterface {
|
||||
$requestData = $this->generateSignedRequestData($skillID, $useremail, $vtype, $isSkillSet);
|
||||
$requestData = $this->generateSignedRequestData($skillID, $useremail, $vtype, $isSkillSet, $campaignId);
|
||||
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$request = new Request(
|
||||
|
|
|
@ -81,9 +81,13 @@ class Link
|
|||
|
||||
/**
|
||||
* @param string $vtype one of VERIFICATION_SELF, VERIFICATION_EDUCATIONAL, VERIFICATION_BUSINESS, VERIFICATION_CERTIFICATION
|
||||
* @param int|null $id The ID of the skill or skillset
|
||||
* @param string $type one of SKILL or SKILL_SET
|
||||
* @param int $campaignId An optional campaign ID the verification is attributed to
|
||||
* @return string URL to a Verification that a user can click, he/she will see the Verification interface and can choose a verifier
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getVerificationLink(string $vtype, ?int $id = null, string $type = self::SKILL): string
|
||||
public function getVerificationLink(string $vtype, ?int $id = null, string $type = self::SKILL, int $campaignId = 0): string
|
||||
{
|
||||
if ($type !== static::SKILL && $type !== static::SKILL_SET) {
|
||||
throw new \Exception('$type has to be "' . static::SKILL . '" or "' . static::SKILL_SET . '" but "' . $type . '" given.', 1600774955);
|
||||
|
@ -95,7 +99,7 @@ class Link
|
|||
throw new \InvalidArgumentException('No ID provided.', 1599723825);
|
||||
}
|
||||
|
||||
$link = $this->settings->getMySkillDisplayUrl() . '/skillup/' . $type . '/' . $id . '/0/';
|
||||
$link = $this->settings->getMySkillDisplayUrl() . '/skillup/' . $type . '/' . $id . '/0/' . ($campaignId ?: '');
|
||||
switch ($vtype) {
|
||||
case VERIFICATION_EDUCATIONAL:
|
||||
$link .= '2';
|
||||
|
@ -116,9 +120,13 @@ class Link
|
|||
|
||||
/**
|
||||
* @param string $vtype one of VERIFICATION_SELF, VERIFICATION_EDUCATIONAL, VERIFICATION_BUSINESS, VERIFICATION_CERTIFICATION
|
||||
* @param int|null $id The ID of the skill or skillset
|
||||
* @param string $type one of SKILL or SKILL_SET
|
||||
* @param int $campaignId An optional campaign ID the verification is attributed to
|
||||
* @return string SVG Button to a Verification that a user can click, he/she will see the Verification interface and can choose a verifier
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getVerificationButton(string $vtype, ?int $id = null, string $type = self::SKILL): string
|
||||
public function getVerificationButton(string $vtype, ?int $id = null, string $type = self::SKILL, int $campaignId = 0): string
|
||||
{
|
||||
switch ($vtype) {
|
||||
case VERIFICATION_EDUCATIONAL:
|
||||
|
@ -135,7 +143,7 @@ class Link
|
|||
break;
|
||||
}
|
||||
return <<<BUTTON
|
||||
<a href="{$this->getVerificationLink($vtype, $id, $type)}" target="_blank">{$buttonsvg}</a>
|
||||
<a href="{$this->getVerificationLink($vtype, $id, $type, $campaignId)}" target="_blank">{$buttonsvg}</a>
|
||||
BUTTON;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class LinkTest extends TestCase
|
|||
/**
|
||||
* @test
|
||||
*/
|
||||
public function canReturnSkillVerificationLinkForEducational()
|
||||
public function canReturnSkillVerificationLinkForEducationalWithCampaign()
|
||||
{
|
||||
$settings = $this->prophesize(Settings::class);
|
||||
$settings->getMySkillDisplayUrl()->willReturn('https://my.example.com/verify');
|
||||
|
@ -50,8 +50,8 @@ class LinkTest extends TestCase
|
|||
$subject = new Link($settings->reveal(), 10);
|
||||
|
||||
static::assertSame(
|
||||
'https://my.example.com/verify/skillup/skill/10/0/2',
|
||||
$subject->getVerificationLink('education')
|
||||
'https://my.example.com/verify/skillup/skill/10/0/2/678',
|
||||
$subject->getVerificationLink('education', null, Link::SKILL, 678)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue