Skip to content

Commit

Permalink
Chatroom: Simplify creation code
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Aug 23, 2024
1 parent cb7186b commit d4cd03f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 153 deletions.
121 changes: 22 additions & 99 deletions components/ILIAS/Chatroom/classes/class.ilObjChatroomGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@
use ILIAS\Chatroom\AccessBridge;

/**
* Class ilObjChatroomGUI
* GUI class for chatroom objects.
* @author Jan Posselt <jposselt at databay.de>
* @version $Id$
* @ilCtrl_Calls ilObjChatroomGUI: ilMDEditorGUI, ilInfoScreenGUI, ilPermissionGUI, ilObjectCopyGUI
* @ilCtrl_Calls ilObjChatroomGUI: ilExportGUI, ilCommonActionDispatcherGUI, ilPropertyFormGUI, ilExportGUI
* @ingroup components\ILIASChatroom
*/
class ilObjChatroomGUI extends ilChatroomObjectGUI implements ilCtrlSecurityInterface
{
Expand All @@ -41,9 +36,6 @@ public function __construct($data = null, ?int $id = 0, bool $call_by_reference
$this->lng->loadLanguageModule('chatroom_adm');
}

/**
* @ineritdoc
*/
public static function _goto($params): void
{
global $DIC;
Expand Down Expand Up @@ -98,17 +90,6 @@ protected function getObjectDefinition(): ilChatroomObjectDefinition
return ilChatroomObjectDefinition::getDefaultDefinition('Chatroom');
}

protected function initCreationForms(string $new_type): array
{
$forms = parent::initCreationForms($new_type);

$forms[self::CFORM_NEW]->clearCommandButtons();
$forms[self::CFORM_NEW]->addCommandButton('create-save', $this->lng->txt($new_type . '_add'));
$forms[self::CFORM_NEW]->addCommandButton('cancel', $this->lng->txt('cancel'));

return $forms;
}

protected function addLocatorItems(): void
{
if (is_object($this->object)) {
Expand All @@ -126,17 +107,11 @@ public function getRefId(): int
return $this->object->getRefId();
}

/**
* @inheritDoc
*/
public function getUnsafeGetCommands(): array
{
return [];
}

/**
* @inheritDoc
*/
public function getSafePostCommands(): array
{
return [
Expand Down Expand Up @@ -168,13 +143,13 @@ public function executeCommand(): void
if (!$this->getCreationMode()) {
$tabFactory = new ilChatroomTabGUIFactory($this);

$baseClass = '';
if ($this->http->wrapper()->query()->has('baseClass')) {
$baseClass = $this->http->wrapper()->query()->retrieve(
'baseClass',
$this->refinery->kindlyTo()->string()
);
}
$baseClass = $this->http->wrapper()->query()->retrieve(
'baseClass',
$this->refinery->byTrying([
$this->refinery->kindlyTo()->string(),
$this->refinery->always('')
])
);
if (strtolower($baseClass) === strtolower(ilAdministrationGUI::class)) {
$tabFactory->getAdminTabsForCommand($this->ctrl->getCmd());
} else {
Expand Down Expand Up @@ -304,94 +279,42 @@ public function getConnector(): ilChatroomServerConnector
return new ilChatroomServerConnector(ilChatroomAdmin::getDefaultConfiguration()->getServerSettings());
}

/**
* Calls $this->prepareOutput method and sets template variable.
*/
public function fallback(): void
{
$this->prepareOutput();
$this->tpl->setVariable('ADM_CONTENT', $this->lng->txt('invalid_operation'));
}

/**
* Calls prepareOutput method.
*/
public function settings(): void
{
$this->prepareOutput();
}

public function insertObject(): ilObjChatroom
protected function afterImport(ilObject $new_object): void
{
$new_type = $this->type;
$refId = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
$title = '';
if ($this->http->wrapper()->post()->has('title')) {
$title = ilUtil::stripSlashes(
$this->http->wrapper()->post()->retrieve(
'title',
$this->refinery->kindlyTo()->string()
)
);
}
$desc = '';
if ($this->http->wrapper()->post()->has('desc')) {
$desc = ilUtil::stripSlashes(
$this->http->wrapper()->post()->retrieve(
'desc',
$this->refinery->kindlyTo()->string()
)
);
}

// create permission is already checked in createObject.
// This check here is done to prevent hacking attempts
if (!$this->rbac_system->checkAccess('create', $refId, $new_type)) {
$this->ilias->raiseError(
$this->lng->txt('no_create_permission'),
$this->ilias->error_obj->MESSAGE
);
}

// create and insert object in objecttree
$class_name = 'ilObj' . $this->obj_definition->getClassName($new_type);

$newObj = new $class_name();
$newObj->setType($new_type);
$newObj->setTitle($title);
$newObj->setDescription($desc);
$newObj->create();
$newObj->createReference();
$newObj->putInTree($refId);
$newObj->setPermissions($refId);
$room = ilChatroom::byObjectId($new_object->getId());
$connector = $this->getConnector();
$response = $connector->sendCreatePrivateRoom($room->getRoomId(), $new_object->getOwner(), $new_object->getTitle());

$objId = $newObj->getId();
parent::afterImport($new_object);
}

protected function afterSave(ilObject $new_object): void
{
$room = new ilChatroom();
$room->saveSettings([
'object_id' => $objId,
'object_id' => $new_object->getId(),
'autogen_usernames' => 'Autogen #',
'display_past_msgs' => 20,
]);

$rbac_log_roles = $this->rbac_review->getParentRoleIds($newObj->getRefId());
$rbac_log = ilRbacLog::gatherFaPa($newObj->getRefId(), array_keys($rbac_log_roles), true);
ilRbacLog::add(ilRbacLog::CREATE_OBJECT, $newObj->getRefId(), $rbac_log);

$this->object = $newObj;

return $newObj;
}

/**
* @param ilObjChatroom $new_object
*/
protected function afterImport(ilObject $new_object): void
{
$room = ilChatroom::byObjectId($new_object->getId());
$connector = $this->getConnector();
$response = $connector->sendCreatePrivateRoom($room->getRoomId(), $new_object->getOwner(), $new_object->getTitle());
$response = $connector->sendCreatePrivateRoom(
$room->getRoomId(), $new_object->getOwner(), $new_object->getTitle()
);

parent::afterImport($new_object);
$this->tpl->setOnScreenMessage('success', $this->lng->txt('object_added'), true);
$this->ctrl->setParameter($this, 'ref_id', $this->getRefId());
$this->ctrl->redirect($this, 'settings-general');
}
}

This file was deleted.

0 comments on commit d4cd03f

Please sign in to comment.