Skip to content

Commit

Permalink
Component: add Activities
Browse files Browse the repository at this point in the history
  • Loading branch information
klees committed Dec 19, 2024
1 parent bdd49f1 commit 07fa263
Show file tree
Hide file tree
Showing 14 changed files with 831 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cli/entry_point.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

$info = <<<INFO
Hello there.
This calls an arbitrary entrypoint of ILIAS for testing purpose. For more informations
about entrypoints, have a look into `components/ILIAS/Component/src/EntryPoint.php`.
INFO;

if (count($argv) !== 3) {
echo $info;
die("php cli/entry_point.php \$bootstrap \$name\n");
}

$bootstrap = $argv[1];
$entry_point = $argv[2];

require_once(__DIR__ . "/../artifacts/bootstrap_$bootstrap.php");

exit(entry_point($entry_point));
11 changes: 11 additions & 0 deletions components/ILIAS/Component/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
$define[] = Component\Activities\Repository::class;

$implement[Component\Activities\Repository::class] = static fn() =>
new Component\Activities\StaticRepository(
$seek[Component\Activities\Activity::class]
);

$contribute[Component\EntryPoint::class] = static fn() => new Component\EntryPoint\HelloWorld("Component/HelloWorld");
$contribute[Component\EntryPoint::class] = static fn() =>
new Component\Activities\ListActivitiesEntryPoint(
$use[Component\Activities\Repository::class]
);

$contribute[\ILIAS\Setup\Agent::class] = static fn() =>
new \ilComponentsSetupAgent(
Expand Down
74 changes: 74 additions & 0 deletions components/ILIAS/Component/src/Activities/Activity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Component\Activities;

use ILIAS\Component\Dependencies\Name;
use ILIAS\UI\Component\Input\Control\Form\FormInput;
use ILIAS\Data\Result;

/**
* An Activity is an action on the domain layer action of a component.
*
* This defines the interface to any activity. When implementing Activities,
* you should use one of these base classes:
*
*
*
*/
interface Activity
{
/**
* Shall return classname of the Activity, wrapped in Name.
*/
public function getName(): Name;

public function getType(): ActivityType;

public function getDescription(): string; // shall be TextHandling/Markdown some day

public function getInputDescription(): FormInput; // might better be ILIAS/UI/Input/Input, but we would need to promote many properties there before.

/**
* This shall check if the given user is allowed to perform the activity based
* on business rules of this component. This shall, for example, check if the
* given user may add this other user to a course based on RBAC and position
* permissions, but this shall not check overall business rules such as: root
* may do everything. This shall not cause any observable side effects.
*
* @param mixed $parameters whatever the `FormInput` from `getInputDescription` produces.
*/
public function isAllowedToPerform(int $usr_id, mixed $parameters): bool;

/**
* This shall perform the activity. This shall not check if a user is allowed to perform the activity.
*
* @throws any SPL Exception (https://www.php.net/manual/en/spl.exceptions.php)
* @param mixed $parameters whatever the `FormInput` from `getInputDescription` produces.
*/
public function perform(mixed $parameters): mixed;

/**
* Grinds the $raw_parameters through the input description, checks if the users
* is allowed to perform the action as requested and, if so, then attempts to
* performs it. Wraps the result and possible errors in the `Result` type.
*/
public function maybePerformAs(int $usr_id, array $raw_parameters): Result;
}
33 changes: 33 additions & 0 deletions components/ILIAS/Component/src/Activities/ActivityImpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Component\Activities;

/**
* Basic Implementation for Activities. Use Command or Query for more speficism
* instead.
*/
abstract class ActivityImpl implements Activity
{
public function getName(): \ILIAS\Component\Dependencies\Name
{
return new \ILIAS\Component\Dependencies\Name(static::class);
}
}
27 changes: 27 additions & 0 deletions components/ILIAS/Component/src/Activities/ActivityType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Component\Activities;

enum ActivityType: string
{
case Command = "command";
case Query = "query";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Component\Activities;

use ILIAS\Component\EntryPoint;
use ILIAS\Component\Component;

/**
* A simple entrypoint that just says hello, for testing and documentation
* purpose.
*/
class ListActivitiesEntryPoint extends EntryPoint\Base
{
public function __construct(
protected Repository $repository
) {
parent::__construct(self::class);
}

public function enter(): int
{
echo join("\n", array_keys(iterator_to_array($this->repository->getActivitiesByName("/.*/"))));
echo "\n";
return 0;
}
}
58 changes: 58 additions & 0 deletions components/ILIAS/Component/src/Activities/ObjectActivity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Component\Activities;

use ILIAS\UI\Component\Input\Control\Form\FormInput;

/**
* An Activity that refers to a certain object in the system. This also is a
* generic interface but a subset of inputs is fixed.
*
* This does not necessarily need to refer to an ilObject, but can also be used
* to refer to any objects internal to a given component, such as questions,
* memberships or certain results.
*/
interface ObjectActivity extends Activity
{
/**
* @inheritdocs
*
* For an ObjectActivity, this needs to return an input with one field named
* "id" that can accept a string value.
*/
public function getInputDescription(): FormInput;

/**
* Works just like `getInputDescription` but checks if that description
* matches the spec.
*
* @throws \LogicException if there is no "id" field in the Input.
*/
public function getCheckedInputDescription(): FormInput;

/**
* To allow consumers to build an understanding of internal object structure of
* a component, an ObjectActivity needs to tell a "type" of object it touches.
*
* The type should be a short alphanumeric string.
*/
public function getTargetType(): string;
}
32 changes: 32 additions & 0 deletions components/ILIAS/Component/src/Activities/Query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Component\Activities;

/**
* Basic class for Queries.
*/
abstract class Query extends ActivityImpl
{
public function getType(): \ILIAS\Component\Activities\ActivityType
{
return ActivityType::Query;
}
}
Loading

0 comments on commit 07fa263

Please sign in to comment.