Skip to content

Commit

Permalink
MetaData: move copyright entries to KS (36692)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitz-ilias committed Oct 6, 2023
1 parent 3f548de commit 610d126
Show file tree
Hide file tree
Showing 12 changed files with 787 additions and 57 deletions.
63 changes: 63 additions & 0 deletions Services/MetaData/classes/Copyright/CopyrightData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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\MetaData\Copyright;

use ILIAS\Data\URI;

class CopyrightData implements CopyrightDataInterface
{
protected string $full_name;
protected ?URI $link;
protected ?URI $image_link;
protected string $alt_text;

public function __construct(
string $full_name,
?URI $link,
?URI $image_link,
string $alt_text
) {
$this->full_name = $full_name;
$this->link = $link;
$this->alt_text = $alt_text;
$this->image_link = $image_link;
}

public function fullName(): string
{
return $this->full_name;
}

public function link(): ?URI
{
return $this->link;
}

public function imageLink(): ?URI
{
return $this->image_link;
}

public function altText(): string
{
return $this->alt_text;
}
}
34 changes: 34 additions & 0 deletions Services/MetaData/classes/Copyright/CopyrightDataInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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\MetaData\Copyright;

use ILIAS\Data\URI;

interface CopyrightDataInterface
{
public function fullName(): string;

public function link(): ?URI;

public function imageLink(): ?URI;

public function altText(): string;
}
46 changes: 46 additions & 0 deletions Services/MetaData/classes/Copyright/NullCopyrightData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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\MetaData\Copyright;

use ILIAS\Data\URI;

class NullCopyrightData implements CopyrightDataInterface
{
public function fullName(): string
{
return '';
}

public function link(): ?URI
{
return null;
}

public function imageLink(): ?URI
{
return null;
}

public function altText(): string
{
return '';
}
}
104 changes: 104 additions & 0 deletions Services/MetaData/classes/Copyright/Renderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?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\MetaData\Copyright;

use ILIAS\UI\Factory;
use ILIAS\UI\Component\Image\Image;
use ILIAS\UI\Component\Link\Link;
use ILIAS\UI\Component\Legacy\Legacy;

class Renderer implements RendererInterface
{
protected Factory $factory;

public function __construct(
Factory $factory
) {
$this->factory = $factory;
}

/**
* @return Image[]|Link[]|Legacy[]
*/
public function toUIComponents(CopyrightDataInterface $copyright): array
{
$res = [];
$has_link = false;
if (!is_null($image = $this->buildImage($copyright))) {
$res[] = $image;
}
if (!is_null($link = $this->buildLink($copyright))) {
$res[] = $link;
$has_link = true;
}
if ($copyright->fullName() && !$has_link) {
$res[] = $this->textInLegacy($copyright->fullName());
}
return $res;
}

protected function buildImage(CopyrightDataInterface $copyright): ?Image
{
if (!$copyright->imageLink()) {
return null;
}
return $this->getImage(
(string) $copyright->imageLink(),
$copyright->altText(),
(string) $copyright->link()
);
}

protected function getImage(string $src, string $alt, string $link): Image
{
$image = $this->standardImage($src, $alt);
if ($link !== '') {
$image = $image->withAction($link);
}
return $image;
}

protected function buildLink(CopyrightDataInterface $copyright): ?Link
{
if (!$copyright->link()) {
return null;
}
return $this->standardLink(
$copyright->fullName() !== '' ? $copyright->fullName() : (string) $copyright->link(),
(string) $copyright->link()
);
}

protected function standardImage(string $src, string $alt): Image
{
return $this->factory->image()->standard($src, $alt);
}

protected function standardLink(string $label, string $action): Link
{
return $this->factory->link()->standard($label, $action);
}

protected function textInLegacy(string $text): Legacy
{
return $this->factory->legacy($text);
}
}
34 changes: 34 additions & 0 deletions Services/MetaData/classes/Copyright/RendererInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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\MetaData\Copyright;

use ILIAS\UI\Component\Image\Image;
use ILIAS\UI\Component\Link\Link;
use ILIAS\UI\Component\Legacy\Legacy;

interface RendererInterface
{
/**
* Returns a string in a legacy UI component if only a string can be returned.
* @return Image[]|Link[]|Legacy[]
*/
public function toUIComponents(CopyrightData $copyright): array;
}
Loading

0 comments on commit 610d126

Please sign in to comment.