Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Open badges (#5231)
Browse files Browse the repository at this point in the history
* Create branch

* Model (draft)

* Migrations

* draft

* wip

* First form (draft)

* New organization form.

* Organization: from multiple to single.

* Badge creation

* Badge edition

* Add/remove assertion.

* my badges tool

* OpenBadges custom routes

* wip

* Goes through the mozailla validator fine now.

* Tags & durations

* workspace tool

* badge in workspace upgrade

* Workspace badge creation

* Much cleaner

* Assertion page.

* Merging all tools into one (that was easy after all)

* Adding some conditions

* Wip (badge card)

* Reorganize some code

* Badge field for form (no picker yet but display is ok)

* user field type (no picker yet)

* Evidences (draft)

* single group field + issuing mode (no backend save change yet)

* Migrations reset & test.

* Fixing user creation

* IssuingModes saved

* add user modal for badges refactored

* Evidence resources

* wip

* Fixing forms & display

* Proper invalidation

* security

* enable/disable

* readytotest

* merge

* Refactoring user actions.

* Modely

* wip

* wtf

* crypto (basic)

* badge input is now valid with crypto (probably should disable it right now)

* merge fix

* quick broken fix

* absolute urls

* grant access ?

* next try

* oops

* restore

* Mozilla backpack

* wip

* wip

* done badge migrations

* [CoreBundle] wip

* Something broken with an update.

* some fixes.

* Badge validation ?

* small update

* Copying constraints from JVal

* assignation

* Update composer.json

* composer.

* nope

* tant pis

* increase memory limit

* test

* test

* /shrug

* just a test

* restore yml file.

* bump php versionX

* Try composer install

* restore

* .

* Create database.

* oops

* ça devrait alelr pourtant.

* Fixing install

* Travis 01

* might work

* .

* Routing

* wip
  • Loading branch information
ngodfraind authored and LaurentGruber committed Feb 1, 2019
1 parent 0679327 commit 36d83a4
Show file tree
Hide file tree
Showing 177 changed files with 8,711 additions and 379 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php

php:
- "7.1"
- "7.2"

addons:
apt:
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"Claroline\\DropZoneBundle\\": "plugin/drop-zone",
"Claroline\\PlannedNotificationBundle\\": "plugin/planned-notification",
"Claroline\\LinkBundle\\": "plugin/link",
"Claroline\\OpenBadgeBundle\\": "plugin/open-badge",
"Claroline\\SlideshowBundle\\": "plugin/slideshow"
}
},
Expand All @@ -184,6 +185,7 @@
"Claroline\\InstallationBundle\\ClarolineInstallationBundle",
"Claroline\\MigrationBundle\\ClarolineMigrationBundle",
"Claroline\\KernelBundle\\ClarolineKernelBundle",
"Claroline\\OpenBadgeBundle\\ClarolineOpenBadgeBundle",
"Claroline\\CoreBundle\\ClarolineCoreBundle",
"Claroline\\AppBundle\\ClarolineAppBundle",
"Claroline\\AuthenticationBundle\\ClarolineAuthenticationBundle",
Expand Down
43 changes: 43 additions & 0 deletions main/app/JVal/Constraint/AbstractCountConstraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the JVal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\AppBundle\JVal\Constraint;

use JVal\Constraint;
use JVal\Context;
use JVal\Exception\Constraint\InvalidTypeException;
use JVal\Exception\Constraint\LessThanZeroException;
use JVal\Types;
use JVal\Walker;
use stdClass;

/**
* Base class for constraints based on a specific number of elements.
*/
abstract class AbstractCountConstraint implements Constraint
{
/**
* {@inheritdoc}
*/
public function normalize(stdClass $schema, Context $context, Walker $walker)
{
$keyword = $this->keywords()[0];
$context->enterNode($keyword);

if (!is_int($schema->{$keyword})) {
throw new InvalidTypeException($context, Types::TYPE_INTEGER);
}

if ($schema->{$keyword} < 0) {
throw new LessThanZeroException($context);
}

$context->leaveNode();
}
}
62 changes: 62 additions & 0 deletions main/app/JVal/Constraint/AbstractOfConstraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of the JVal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\AppBundle\JVal\Constraint;

use JVal\Constraint;
use JVal\Context;
use JVal\Exception\Constraint\EmptyArrayException;
use JVal\Exception\Constraint\InvalidTypeException;
use JVal\Types;
use JVal\Walker;
use stdClass;

/**
* Base class for constraints based on a set of sub-schemas.
*/
abstract class AbstractOfConstraint implements Constraint
{
/**
* {@inheritdoc}
*/
public function supports($type)
{
return true;
}

/**
* {@inheritdoc}
*/
public function normalize(stdClass $schema, Context $context, Walker $walker)
{
$keyword = $this->keywords()[0];
$context->enterNode($keyword);

if (!is_array($schema->{$keyword})) {
throw new InvalidTypeException($context, Types::TYPE_ARRAY);
}

if (0 === count($schema->{$keyword})) {
throw new EmptyArrayException($context);
}

foreach ($schema->{$keyword} as $index => $subSchema) {
$context->enterNode($index);

if (!is_object($subSchema)) {
throw new InvalidTypeException($context, Types::TYPE_OBJECT);
}

$walker->parseSchema($subSchema, $context);
$context->leaveNode();
}

$context->leaveNode();
}
}
62 changes: 62 additions & 0 deletions main/app/JVal/Constraint/AbstractRangeConstraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of the JVal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\AppBundle\JVal\Constraint;

use JVal\Constraint;
use JVal\Context;
use JVal\Exception\Constraint\InvalidTypeException;
use JVal\Exception\Constraint\MissingKeywordException;
use JVal\Types;
use JVal\Walker;
use stdClass;

/**
* Base class for constraints based on a numeric limit.
*/
abstract class AbstractRangeConstraint implements Constraint
{
/**
* {@inheritdoc}
*/
public function supports($type)
{
return Types::TYPE_INTEGER === $type
|| Types::TYPE_NUMBER === $type;
}

/**
* {@inheritdoc}
*/
public function normalize(stdClass $schema, Context $context, Walker $walker)
{
$property = $this->keywords()[0];
$secondaryProperty = $this->keywords()[1];

if (!property_exists($schema, $property)) {
throw new MissingKeywordException($context, $property);
}

if (!property_exists($schema, $secondaryProperty)) {
$schema->{$secondaryProperty} = false;
}

if (!Types::isA($schema->{$property}, Types::TYPE_NUMBER)) {
$context->enterNode($property);

throw new InvalidTypeException($context, Types::TYPE_NUMBER);
}

if (!is_bool($schema->{$secondaryProperty})) {
$context->enterNode($secondaryProperty);

throw new InvalidTypeException($context, Types::TYPE_BOOLEAN);
}
}
}
44 changes: 44 additions & 0 deletions main/app/JVal/Constraint/AllOfConstraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the JVal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\AppBundle\JVal\Constraint;

use JVal\Context;
use JVal\Walker;
use stdClass;

/**
* Constraint for the "allOf" keyword.
*/
class AllOfConstraint extends AbstractOfConstraint
{
/**
* {@inheritdoc}
*/
public function keywords()
{
return ['allOf'];
}

/**
* {@inheritdoc}
*/
public function apply($instance, stdClass $schema, Context $context, Walker $walker)
{
$originalCount = $context->countViolations();

foreach ($schema->allOf as $subSchema) {
$walker->applyConstraints($instance, $subSchema, $context);
}

if ($context->countViolations() > $originalCount) {
$context->addViolation('instance must match all the schemas listed in allOf');
}
}
}
52 changes: 52 additions & 0 deletions main/app/JVal/Constraint/AnyOfConstraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the JVal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\AppBundle\JVal\Constraint;

use JVal\Context;
use JVal\Walker;
use stdClass;

/**
* Constraint for the "anyOf" keyword.
*/
class AnyOfConstraint extends AbstractOfConstraint
{
/**
* {@inheritdoc}
*/
public function keywords()
{
return ['anyOf'];
}

/**
* {@inheritdoc}
*/
public function apply($instance, stdClass $schema, Context $context, Walker $walker)
{
$accumulatingContext = $context->duplicate();
$hasMatch = false;

foreach ($schema->anyOf as $subSchema) {
$originalCount = $accumulatingContext->countViolations();
$walker->applyConstraints($instance, $subSchema, $accumulatingContext);

if ($accumulatingContext->countViolations() === $originalCount) {
$hasMatch = true;
break;
}
}

if (!$hasMatch) {
$context->mergeViolations($accumulatingContext);
$context->addViolation('instance must match at least one of the schemas listed in anyOf');
}
}
}
2 changes: 1 addition & 1 deletion main/app/JVal/Constraint/ClarolineConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function applyRequired($instance, stdClass $schema, Context $context, Wa
{
foreach ($schema->requiredAtCreation as $property) {
if (in_array('create', $options) && !property_exists($instance, $property)) {
$context->addViolation('property "%s" is missing', [$property]);
$context->addViolation('property "%s" is missing', [$property], $property);
}
}
}
Expand Down
Loading

0 comments on commit 36d83a4

Please sign in to comment.