diff --git a/classes/class.ilOneDriveActionListGUI.php b/classes/class.ilOneDriveActionListGUI.php index f3d1e4f..398145b 100644 --- a/classes/class.ilOneDriveActionListGUI.php +++ b/classes/class.ilOneDriveActionListGUI.php @@ -175,7 +175,7 @@ protected function rename() $form = $this->buildForm(); if (!$form->checkInput()) { $response->success = false; - $response->message = ilUtil::getSystemMessageHTML($this->txt('msg_invalid_input'), "failure"); + $response->message = $DIC->ui()->mainTemplate()->getMessageHTML($this->txt('msg_invalid_input'), "failure"); echo json_encode($response); exit; } @@ -192,14 +192,15 @@ protected function rename() $this->getService()->getClient()->renameItemById($id, $title); EventLogger::logObjectRenamed( $DIC->user()->getId(), - $exoItem->getPath(), + $this->getPluginObject()->getObjId(), + $exoItem->getFullPath(), $title, ObjectType::fromExodItem($exoItem) ); - $response->message = ilUtil::getSystemMessageHTML($this->txt("msg_renamed"), "success"); + $response->message = $DIC->ui()->mainTemplate()->getMessageHTML($this->txt("msg_renamed"), "success"); $response->success = true; } catch (Exception $e) { - $response->message = ilUtil::getSystemMessageHTML($e->getMessage(), "failure"); + $response->message = $DIC->ui()->mainTemplate()->getMessageHTML($e->getMessage(), "failure"); } $response->id = $id; diff --git a/classes/class.ilOneDriveDeleteGUI.php b/classes/class.ilOneDriveDeleteGUI.php index 9f3c150..43cf40a 100644 --- a/classes/class.ilOneDriveDeleteGUI.php +++ b/classes/class.ilOneDriveDeleteGUI.php @@ -30,6 +30,7 @@ public function deleteItem() $response->success = true; EventLogger::logObjectDeleted( $DIC->user()->getId(), + $this->getPluginHookObject()->getId(), $node->getPath(), ObjectType::fromExodItem(exodItemCache::get($node->getId())) ); diff --git a/classes/class.ilOneDriveSettingsGUI.php b/classes/class.ilOneDriveSettingsGUI.php index a9c29fb..e9991d3 100644 --- a/classes/class.ilOneDriveSettingsGUI.php +++ b/classes/class.ilOneDriveSettingsGUI.php @@ -104,7 +104,7 @@ protected function showLogs() $DIC->tabs()->activateTab('settings'); $this->initSubtabs(self::SUBTAB_LOGS); $DIC->ui()->mainTemplate()->setContent( - (new EventLogTableUI($DIC))->render() + (new EventLogTableUI($DIC, $this->getPluginObject()->getObjId()))->render() ); } diff --git a/classes/class.ilOneDriveUploadGUI.php b/classes/class.ilOneDriveUploadGUI.php index f2f3ec4..b47ffee 100644 --- a/classes/class.ilOneDriveUploadGUI.php +++ b/classes/class.ilOneDriveUploadGUI.php @@ -103,6 +103,7 @@ protected function afterUpload() $parent_id = $_SESSION["cld_folder_id"]; EventLogger::logUploadComplete( $DIC->user()->getId(), + $this->getPluginObject()->getObjId(), ilCloudFileTree::getFileTreeFromSession()->getNodeFromId($parent_id)->getPath() . '/' . $name ); } @@ -123,6 +124,7 @@ protected function asyncGetResumableUploadUrl() } catch (ilCloudException $e) { EventLogger::logUploadFailed( $DIC->user()->getId(), + $this->getPluginObject()->getObjId(), $file_path, $e->getMessage() ); @@ -131,6 +133,7 @@ protected function asyncGetResumableUploadUrl() } EventLogger::logUploadStarted( $DIC->user()->getId(), + $this->getPluginObject()->getObjId(), $file_path, $name_sanitized === $name ? '' : $name ); @@ -148,6 +151,7 @@ protected function uploadFailed() $file_path = ilCloudFileTree::getFileTreeFromSession()->getNodeFromId($parent_id)->getPath() . '/' . $name; EventLogger::logUploadFailed( $DIC->user()->getId(), + $this->getPluginObject()->getObjId(), $file_path, $message ?? '' ); @@ -161,6 +165,7 @@ protected function uploadAborted() $file_path = ilCloudFileTree::getFileTreeFromSession()->getNodeFromId($parent_id)->getPath() . '/' . $name; EventLogger::logUploadAborted( $DIC->user()->getId(), + $this->getPluginObject()->getObjId(), $file_path ); } diff --git a/composer.json b/composer.json index 97d873d..df8321f 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,9 @@ "issues": "https://plugins.studer-raimann.ch/goto.php?target=uihk_srsu_PLONEDRIVE" }, "require": { - "php": ">=7.0" + "php": ">=7.0", + "srag/custominputguis": ">=0.1.0", + "srag/librariesnamespacechanger": ">=0.1.0" }, "autoload": { "psr-4": { @@ -37,5 +39,8 @@ "sort-packages": true }, "scripts": { + "pre-autoload-dump": [ + "srag\\LibrariesNamespaceChanger\\LibrariesNamespaceChanger::rewriteLibrariesNamespaces" + ] } } diff --git a/src/EventLog/EventLogEntryAR.php b/src/EventLog/EventLogEntryAR.php index ff0daa8..6d542ef 100644 --- a/src/EventLog/EventLogEntryAR.php +++ b/src/EventLog/EventLogEntryAR.php @@ -23,6 +23,14 @@ class EventLogEntryAR extends ActiveRecord * @con_sequence true */ protected $id; + /** + * @var int + * @con_has_field true + * @con_fieldtype integer + * @con_is_notnull true + * @con_length 8 + */ + protected $obj_id; /** * @var string * @con_has_field true @@ -82,6 +90,22 @@ public function getId() : int return $this->id; } + /** + * @return int + */ + public function getObjId() : int + { + return $this->obj_id; + } + + /** + * @param int $obj_id + */ + public function setObjId(int $obj_id) + { + $this->obj_id = $obj_id; + } + /** * @return string */ diff --git a/src/EventLog/EventLogger.php b/src/EventLog/EventLogger.php index 3f81510..367cbcc 100644 --- a/src/EventLog/EventLogger.php +++ b/src/EventLog/EventLogger.php @@ -9,11 +9,13 @@ class EventLogger { public static function logUploadStarted( int $user_id, + int $obj_id, string $file_path, string $renamed_from = '' ) { self::log( $user_id, + $obj_id, EventType::uploadStarted(), $file_path, ObjectType::file(), @@ -23,10 +25,12 @@ public static function logUploadStarted( public static function logUploadComplete( int $user_id, + int $obj_id, string $file_path ) { self::log( $user_id, + $obj_id, EventType::uploadComplete(), $file_path, ObjectType::file(), @@ -36,10 +40,12 @@ public static function logUploadComplete( public static function logUploadAborted( int $user_id, + int $obj_id, string $file_path ) { self::log( $user_id, + $obj_id, EventType::uploadAborted(), $file_path, ObjectType::file(), @@ -49,11 +55,13 @@ public static function logUploadAborted( public static function logUploadFailed( int $user_id, + int $obj_id, string $file_path, string $message = '' ) { self::log( $user_id, + $obj_id, EventType::uploadFailed(), $file_path, ObjectType::file(), @@ -63,11 +71,13 @@ public static function logUploadFailed( public static function logObjectDeleted( int $user_id, + int $obj_id, string $object_path, ObjectType $object_type ) { self::log( $user_id, + $obj_id, EventType::objectDeleted(), $object_path, $object_type, @@ -77,12 +87,14 @@ public static function logObjectDeleted( public static function logObjectRenamed( int $user_id, + int $obj_id, string $object_path_old, string $object_name_new, ObjectType $object_type ) { self::log( $user_id, + $obj_id, EventType::objectRenamed(), $object_path_old, $object_type, @@ -92,12 +104,14 @@ public static function logObjectRenamed( protected static function log( int $user_id, + int $obj_id, EventType $event_type, string $object_path, ObjectType $object_type, array $additional_data ) { $entry = new EventLogEntryAR(); + $entry->setObjId($obj_id); $entry->setTimestamp(date('Y-m-d H:i:s', time())); $entry->setEventType($event_type); $entry->setUserId($user_id); diff --git a/src/EventLog/UI/EventLogTableUI.php b/src/EventLog/UI/EventLogTableUI.php index 6993a2b..0eaf233 100644 --- a/src/EventLog/UI/EventLogTableUI.php +++ b/src/EventLog/UI/EventLogTableUI.php @@ -12,6 +12,10 @@ */ class EventLogTableUI { + /** + * @var int + */ + private $obj_id; /** * @var Container */ @@ -20,10 +24,12 @@ class EventLogTableUI /** * EventLogTableUI constructor. * @param Container $dic + * @param int $obj_id */ - public function __construct(Container $dic) + public function __construct(Container $dic, int $obj_id) { $this->dic = $dic; + $this->obj_id = $obj_id; } public function render() : string @@ -37,7 +43,7 @@ public function render() : string : $value[1]; }); return $arrayForConnector; - }, EventLogEntryAR::get()); + }, EventLogEntryAR::where(['obj_id' => $this->obj_id])->get()); return '