Skip to content

Commit

Permalink
Merge branch 'oc-php-lib' into issue-182_oc-php-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Aug 24, 2023
2 parents d2d4bc6 + 63f88f9 commit e03eb89
Show file tree
Hide file tree
Showing 446 changed files with 42,768 additions and 5,838 deletions.
35 changes: 21 additions & 14 deletions classes/Conf/Export/class.xoctConfExportGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,32 @@
*/
class xoctConfExportGUI extends xoctGUI
{
/**
* @var \ilToolbarGUI
*/
protected $toolbar;

public function __construct()
{
global $DIC;
parent::__construct();
$this->toolbar = $DIC->toolbar();
}

protected function index()
{
$b = ilLinkButton::getInstance();
$b->setCaption('rep_robj_xoct_admin_export');
$b->setUrl(self::dic()->ctrl()->getLinkTarget($this, 'export'));
self::dic()->toolbar()->addButtonInstance($b);
self::dic()->toolbar()->addSpacer();
self::dic()->toolbar()->addSeparator();
self::dic()->toolbar()->addSpacer();
$b->setUrl($this->ctrl->getLinkTarget($this, 'export'));
$this->toolbar->addButtonInstance($b);
$this->toolbar->addSpacer();
$this->toolbar->addSeparator();
$this->toolbar->addSpacer();

self::dic()->toolbar()->setFormAction(self::dic()->ctrl()->getLinkTarget($this, 'import'), true);
$this->toolbar->setFormAction($this->ctrl->getLinkTarget($this, 'import'), true);
$import = new ilFileInputGUI('xoct_import', 'xoct_import');
self::dic()->toolbar()->addInputItem($import);
self::dic()->toolbar()->addFormButton(self::plugin()->translate('admin_import'), 'import');
$this->toolbar->addInputItem($import);
$this->toolbar->addFormButton($this->plugin->txt('admin_import'), 'import');
}

/**
Expand All @@ -39,6 +51,7 @@ protected function import()

/**
*
* @return never
*/
protected function export()
{
Expand All @@ -48,32 +61,26 @@ protected function export()
exit;
}


protected function add()
{
}


protected function create()
{
}


protected function edit()
{
}


protected function update()
{
}


protected function confirmDelete()
{
}


protected function delete()
{
}
Expand Down
124 changes: 75 additions & 49 deletions classes/Conf/Metadata/class.xoctMetadataConfigGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use ILIAS\UI\Component\Input\Container\Form\Standard;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Renderer;
use srag\DIC\OpenCast\Exception\DICException;
use srag\Plugins\Opencast\Model\Metadata\Config\MDFieldConfigAR;
use srag\Plugins\Opencast\Model\Metadata\Config\MDFieldConfigRepository;
use srag\Plugins\Opencast\Model\Metadata\Config\MDPrefillOption;
Expand All @@ -13,9 +12,12 @@
use srag\Plugins\Opencast\Model\Metadata\Definition\MDFieldDefinition;
use srag\Plugins\Opencast\UI\Metadata\Config\MDConfigTable;
use srag\Plugins\Opencast\Model\Metadata\Definition\MDDataType;
use srag\Plugins\Opencast\LegacyHelpers\OutputTrait;

abstract class xoctMetadataConfigGUI extends xoctGUI
{
use OutputTrait;

public const CMD_STORE = 'store';
public const CMD_REORDER = 'reorder';

Expand Down Expand Up @@ -53,28 +55,42 @@ abstract class xoctMetadataConfigGUI extends xoctGUI
* @var ilPlugin
*/
protected $plugin;
/**
* @var \ilToolbarGUI
*/
private $toolbar;
/**
* @var \ILIAS\DI\UIServices
*/
private $ui;
/**
* @var \ILIAS\HTTP\Services
*/
private $http;

public function __construct(
MDFieldConfigRepository $repository,
MDCatalogueFactory $md_catalogue_factory,
Container $dic,
ilPlugin $plugin
Container $dic
) {
parent::__construct();
$this->dic = $dic;
$ui = $this->dic->ui();
$this->toolbar = $this->dic->toolbar();
$this->ui = $this->dic->ui();
$this->http = $this->dic->http();
$this->repository = $repository;
$this->ui_factory = self::dic()->ui()->factory();
$this->renderer = self::dic()->ui()->renderer();
$this->ui_factory = $ui->factory();
$this->renderer = $ui->renderer();
$this->md_catalogue_factory = $md_catalogue_factory;
$this->dic = $dic;
$this->plugin = $plugin;
}


/**
* @throws xoctException
*/
public function executeCommand()
public function executeCommand(): void
{
$cmd = self::dic()->ctrl()->getCmd(self::CMD_STANDARD);
$cmd = $this->ctrl->getCmd(self::CMD_STANDARD);
if (!in_array($cmd, self::$available_commands)) {
throw new xoctException(xoctException::INTERNAL_ERROR, "invalid command: $cmd");
}
Expand All @@ -89,30 +105,35 @@ protected function index()
{
$items = [];
foreach ($this->getAvailableMetadataFields() as $field_id) {
self::dic()->ctrl()->setParameter($this, 'field_id', $field_id);
$this->ctrl->setParameter($this, 'field_id', $field_id);
$items[] = $this->ui_factory->link()->standard(
$field_id,
self::dic()->ctrl()->getLinkTarget($this, self::CMD_ADD)
$this->ctrl->getLinkTarget($this, self::CMD_ADD)
);
}
self::dic()->ctrl()->clearParameters($this);
if (count($items)) {
self::dic()->toolbar()->addComponent(
self::dic()->ui()->factory()->dropdown()->standard(
$this->ctrl->clearParameters($this);
if ($items !== []) {
$this->toolbar->addComponent(
$this->ui->factory()->dropdown()->standard(
$items
)->withLabel(self::plugin()->translate('btn_add_new_metadata_field'))
)->withLabel($this->plugin->txt('btn_add_new_metadata_field'))
);
}

self::output()->output($this->buildTable());
$this->ui->mainTemplate()->setContent($this->buildTable()->getHTML());
}

protected function buildTable(): MDConfigTable
{
return new MDConfigTable($this, $this->getTableTitle(), $this->dic, $this->plugin, $this->repository->getArray());
return new MDConfigTable(
$this,
$this->getTableTitle(),
$this->dic,
$this->plugin,
$this->repository->getArray()
);
}


/**
* @throws ilTemplateException
* @throws xoctException
Expand All @@ -122,7 +143,7 @@ protected function add()
{
$field_id = filter_input(INPUT_GET, 'field_id', FILTER_SANITIZE_STRING);
$form = $this->buildForm($field_id);
self::output()->output($this->renderer->render($form));
$this->output($this->renderer->render($form));
}

/**
Expand All @@ -134,7 +155,7 @@ protected function edit()
{
$field_id = filter_input(INPUT_GET, 'field_id', FILTER_SANITIZE_STRING);
$form = $this->buildForm($field_id);
self::output()->output($this->renderer->render($form));
$this->output($this->renderer->render($form));
}

/**
Expand All @@ -145,15 +166,15 @@ protected function edit()
protected function store()
{
$field_id = filter_input(INPUT_GET, 'field_id', FILTER_SANITIZE_STRING);
$form = $this->buildForm($field_id)->withRequest(self::dic()->http()->request());
$form = $this->buildForm($field_id)->withRequest($this->http->request());
$data = $form->getData();
if (is_null($data)) {
$this->dic->ui()->mainTemplate()->setContent($this->renderer->render($form));
return;
}
$this->repository->storeFromArray($data['fields']);
ilUtil::sendSuccess(self::plugin()->translate('msg_success'), true);
self::dic()->ctrl()->redirect($this, self::CMD_STANDARD);
ilUtil::sendSuccess($this->plugin->txt('msg_success'), true);
$this->ctrl->redirect($this, self::CMD_STANDARD);
}

protected function confirmDelete()
Expand All @@ -170,10 +191,10 @@ protected function delete()

protected function getAvailableMetadataFields(): array
{
$already_configured = array_map(function (MDFieldConfigAR $md_config) {
$already_configured = array_map(function (MDFieldConfigAR $md_config): string {
return $md_config->getFieldId();
}, $this->repository->getAll(false));
$available_total = array_map(function (MDFieldDefinition $md_field_def) {
$available_total = array_map(function (MDFieldDefinition $md_field_def): string {
return $md_field_def->getId();
}, $this->getMetadataCatalogue()->getFieldDefinitions());
return array_diff($available_total, $already_configured);
Expand All @@ -182,51 +203,53 @@ protected function getAvailableMetadataFields(): array
abstract protected function getMetadataCatalogue(): MDCatalogue;

/**
* @param string $field_id
* @param string $cmd
* @return Standard
* @throws DICException
* @throws xoctException
*/
protected function buildForm(string $field_id): Standard
{
self::dic()->ctrl()->setParameter($this, 'field_id', $field_id);
$this->ctrl->setParameter($this, 'field_id', $field_id);
$md_field_def = $this->getMetadataCatalogue()->getFieldById($field_id);
$md_field_config = $this->repository->findByFieldId($field_id);
$fields = [
'field_id' => $this->ui_factory->input()->field()->text(
self::plugin()->translate('md_field_id')
$this->plugin->txt('md_field_id')
)
->withDisabled(true)
->withValue($field_id)
->withRequired(true),
'title_de' => $this->ui_factory->input()->field()->text(
self::plugin()->translate('md_title_de')
$this->plugin->txt('md_title_de')
)
->withRequired(true)
->withValue(
$md_field_config ? $md_field_config->getTitle('de') : ''
$md_field_config instanceof \srag\Plugins\Opencast\Model\Metadata\Config\MDFieldConfigAR ? $md_field_config->getTitle(
'de'
) : ''
),
'title_en' => $this->ui_factory->input()->field()->text(
self::plugin()->translate('md_title_en')
$this->plugin->txt('md_title_en')
)
->withRequired(true)
->withValue(
$md_field_config ? $md_field_config->getTitle('en') : ''
$md_field_config instanceof \srag\Plugins\Opencast\Model\Metadata\Config\MDFieldConfigAR ? $md_field_config->getTitle(
'en'
) : ''
),
'visible_for_permissions' => $this->ui_factory->input()->field()->select(
self::plugin()->translate('md_visible_for_permissions'),
$this->plugin->txt('md_visible_for_permissions'),
[
MDFieldConfigAR::VISIBLE_ALL => $this->plugin->txt('md_visible_all'),
MDFieldConfigAR::VISIBLE_ADMIN => $this->plugin->txt('md_visible_admin')
]
)->withRequired(true)
->withValue(
$md_field_config ? $md_field_config->getVisibleForPermissions(
$md_field_config instanceof \srag\Plugins\Opencast\Model\Metadata\Config\MDFieldConfigAR ? $md_field_config->getVisibleForPermissions(
) : null
),
'required' => $this->ui_factory->input()->field()->checkbox(
self::plugin()->translate('md_required')
$this->plugin->txt('md_required')
)
->withDisabled(
$md_field_def->isRequired() || $md_field_def->isReadOnly()
Expand All @@ -236,41 +259,44 @@ protected function buildForm(string $field_id): Standard
) || ($md_field_config && $md_field_config->isRequired())
),
'read_only' => $this->ui_factory->input()->field()->checkbox(
self::plugin()->translate('md_read_only')
$this->plugin->txt('md_read_only')
)
->withDisabled($md_field_def->isReadOnly())
->withValue(
$md_field_def->isReadOnly(
) || ($md_field_config && $md_field_config->isReadOnly())
),
'prefill' => $this->ui_factory->input()->field()->select(
self::plugin()->translate('md_prefill'),
$this->plugin->txt('md_prefill'),
$this->getPrefillOptions()
)
->withRequired(true)
->withDisabled($md_field_def->isReadOnly())
->withValue(
$md_field_config ? $md_field_config->getPrefill()->getValue(
) : MDPrefillOption::T_NONE
$md_field_config instanceof \srag\Plugins\Opencast\Model\Metadata\Config\MDFieldConfigAR ? $md_field_config->getPrefill(
)->getValue() : MDPrefillOption::T_NONE
)
];

if ($md_field_def->getType()->getTitle() === MDDataType::TYPE_TEXT_SELECTION) {
$fields['values'] = $this->ui_factory->input()->field()->textarea(
self::plugin()->translate('md_values'),
self::plugin()->translate('md_values_info', '', [MDFieldConfigAR::VALUE_SEPERATOR])
$this->plugin->txt('md_values'),
$this->plugin->txt('md_values_info')
)->withValue(
$md_field_config ? $md_field_config->getValuesAsEditableString() : ''
$md_field_config instanceof \srag\Plugins\Opencast\Model\Metadata\Config\MDFieldConfigAR ? $md_field_config->getValuesAsEditableString(
) : ''
)->withRequired(true)
->withDisabled($md_field_def->isReadOnly());
->withDisabled($md_field_def->isReadOnly());
}

return $this->ui_factory->input()->container()->form()->standard(
self::dic()->ctrl()->getFormAction($this, self::CMD_STORE),
$this->ctrl->getFormAction($this, self::CMD_STORE),
[
'fields' => $this->ui_factory->input()->field()->section(
$fields,
$this->plugin->txt('md_conf_form_' . ($md_field_config ? 'edit' : 'create'))
$this->plugin->txt(
'md_conf_form_' . ($md_field_config instanceof \srag\Plugins\Opencast\Model\Metadata\Config\MDFieldConfigAR ? 'edit' : 'create')
)
)
]
);
Expand All @@ -280,7 +306,7 @@ protected function getPrefillOptions(): array
{
$options = [];
foreach (MDPrefillOption::$allowed_values as $allowed_value) {
$options[$allowed_value] = self::plugin()->translate('md_prefill_' . $allowed_value);
$options[$allowed_value] = $this->plugin->txt('md_prefill_' . $allowed_value);
}
return $options;
}
Expand Down
Loading

0 comments on commit e03eb89

Please sign in to comment.