Benutzeraktivitäten
From Joomla! Documentation
So verwendet man das neue Benutzeraktivitätssystem.
Mit Joomla! 3.9 führte Joomla! ein Benutzeraktivitätssystem ein.
Dieses System ist der Abschluss von "Recording Action Logs" project from GSoC 2016 (en). Dieses System bietet eine Infrastruktur zum Erstellen eines Prüfprotokolls der auf einer Website ausgeführten Aktivitäten und kann an die Präferenzen des Site-Administrators angepasst werden. Erweiterungen können sich in dieses System einbinden, um benutzerdefinierte Nachrichten hinzuzufügen oder die CRUD-Standardaktionen des Systems verarbeiten zu lassen.
Dieses Tutorial enthält Informationen, wie man das neue System einrichtet.
'Hinweis: Nur Super Benutzer haben Zugriff auf das Benutzeraktivitätssystem.'
Komponente
Benutzeraktivitäten Übersicht
Navigiere zu Benutzer → Benutzeraktivitäten um die Übersicht aufzurufen.
Über diese Ansicht hat ein Super Benutzer eine globale Übersicht zu allen Aktivitäten auf der Seite welche von Benutzern ausgeführt werden. Hier besteht auch die Möglichkeit, diese Einträge zu prüfen, zu exportieren, zu löschen und zu bereinigen.
Weiterführende Informationen:
Plugin
System - Benutzeraktivitäten
Einmal aktiviert, erlaubt das Plugin die Tage zu definieren nach dem die Aktivitäten gelöscht werden.
Aktivitäten
Einmal aktiviert, zeichnet dieses Plugin die Benutzeraktivitäten in den Joomla-Core Erweiterungen auf.
Datenschutz - Aktivitäten
Einmal aktiviert, erlaubt dieses Plugin die Aktivitäten zu Datenschutzanfragen von Benutzern zu exportieren.
Module
Aktivitäten - Neueste
Dieses Admin Modul zeigt im Kontrollzentrum eine Liste der zuletzt ausgeführten Aktivitäten auf der Seite an.
Hinweis: Das Modul wird standardmäßig bei Seiten welche auf Joomla 3.9 aktualisiert wurden, nicht angezeigt. Damit es angezeigt wird, gehe über die Kontrollnavigation zu Erweiterungen → Verwalten → Verwalten → Aktivitäten - Neueste Modul aktivieren. Danach gehe unter Erweiterungen → Module → Administrator → Neu → Aktivitäten - Neueste
Weiterführende Informationen: Aktivitäten - Neueste Admin Module.
So integriert man eine Erweiterung in das System
Bitte zögere nicht, diesen Abschnitt zu bearbeiten, zu verbessern oder zu korrigieren.
Component Installation Script
Add the extension to the table (#__action_logs_extensions) so that it will appear in the configuration of User Action Logs.
$extension = 'com_mycomponent';
$db = Factory::getDbo();
$db->setQuery(' INSERT into #__action_logs_extensions (extension) VALUES ('.$db->Quote($extension).') ' );
try {
// If it fails, it will throw a RuntimeException
$result = $db->execute();
} catch (RuntimeException $e) {
Factory::getApplication()->enqueueMessage($e->getMessage());
return false;
}
Add the extension configuration to the table (#__action_log_config) so that your actions data will be captured.
$logConf = new stdClass();
$logConf->id = 0;
$logConf->type_title = 'transaction';
$logConf->type_alias = $extension;
$logConf->id_holder = 'id';
$logConf->title_holder = 'trans_desc';
$logConf->table_name = '#__mycomponent_transaction';
$logConf->text_prefix = 'COM_MYCOMPONENT_TRANSACTION';
try {
// If it fails, it will throw a RuntimeException
// Insert the object into the table.
$result = Factory::getDbo()->insertObject('#__action_log_config', $logConf);
} catch (RuntimeException $e) {
Factory::getApplication()->enqueueMessage($e->getMessage());
return false;
}
Of course it would be best to perform some checking to ensure that the record doesn't already exist.
Component Helper
In this example, the component helper is used to perform the storing of actions.
/**
* Record transaction details in log record
* @param object $user Saves getting the current user again.
* @param int $tran_id The transaction id just created or updated
* @param int $id Passed id reference from the form to identify if new record
* @return boolean True
*/
public static function recordActionLog($user = null, $tran_id = 0, $id = 0)
{
// get the component details such as the id
$extension = MycomponentHelper::getExtensionDetails('com_mycomponent');
// get the transaction details for use in the log for easy reference
$tran = MycomponentHelper::getTransaction($tran_id);
$con_type = "transaction";
if ($id === 0) { $type = 'New '; } else { $type = 'Update '; }
$message = array();
$message['action'] = $con_type;
$message['type'] = $type . $tran->tran_type . ' - '.$tran->tran_desc . ' $' . $tran->tran_amount;
$message['id'] = $tran->id;
$message['title'] = $extension->name;
$message['extension_name'] = $extension->name;
$message['itemlink'] = "index.php?option=com_mycomponent&task=transaction.edit&id=".$tran->id;
$message['userid'] = $user->id;
$message['username'] = $user->username;
$message['accountlink'] = "index.php?option=com_users&task=user.edit&id=".$user->id;
$messages = array($message);
$messageLanguageKey = Text::_('COM_MYCOMPONENT_TRANSACTION_LINK');
$context = $extension->name.'.'.$con_type;
$fmodel = MycomponentHelper::getForeignModel('Actionlog', 'ActionlogsModel');
$fmodel->addLog($messages, $messageLanguageKey, $context, $user->id);
return true;
}
/**
* Get the Model from another component for use
* @param string $name The model name. Optional. Default to my own for safety.
* @param string $prefix The class prefix. Optional
* @param array $config Configuration array for model. Optional
* @return object The model
*/
public function getForeignModel($name = 'Transaction', $prefix = 'MycomponentModel', $config = array('ignore_request' => true))
{
\Joomla\CMS\MVC\Model\ItemModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_actionlogs/models', 'ActionlogsModelActionlog');
$fmodel = \Joomla\CMS\MVC\Model\ItemModel::getInstance($name, $prefix, $config);
return $fmodel;
}
Front End Transaction Form
Now that the foundations are set, we just need to trigger the process. We're capturing information about a transaction that is created or update and we have a model called transactionform.php. It is in the Save method that we want to capture a log.
// So the code above this point checks and does what it should do and then after the successful save of the record, we check for the parameter setting to see if logging is required, we pass key elements to recordActionLog.
$table = $this->getTable();
if ($table->save($data) === true) {
/* ---------------------------------------------------------------- */
// trigger transaction log if required
$act_log = $params->get('act_log', 0);
if ($act_log && $table->id) {
// gather information and log in a new action log record
MycomponentHelper::recordActionLog($user, $table->id, $data['id']);
}
/* ---------------------------------------------------------------- */
return $table->id;
} else {
return false;
}
Sprach Datei
Finally, to help with the Action Log Listing in the admin side of Joomla, we want to set some key elements of data to be displayed in the language file en-GB.com_mycomponent.ini.
COM_MYCOMPONENT_TRANSACTION_LINK="User <a href='{accountlink}'>{username}</a> created a transaction ( <a href='{itemlink}'>{type}</a> )"
Hope this helps.