aboutsummaryrefslogtreecommitdiff
path: root/lib/models/LogAction.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:07:19 +0200
committerJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:19:12 +0200
commita3da1483a9e689846179159355badfec8073dbec (patch)
tree770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /lib/models/LogAction.php
current code from svn, revision 62608
Diffstat (limited to 'lib/models/LogAction.php')
-rw-r--r--lib/models/LogAction.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/models/LogAction.php b/lib/models/LogAction.php
new file mode 100644
index 0000000..7fbf1e1
--- /dev/null
+++ b/lib/models/LogAction.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * LogAction
+ * model class for table log_actions
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * @author Peter Thienel <thienel@data-quest.de>
+ * @copyright 2013 Stud.IP Core-Group
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
+ * @category Stud.IP
+ * @since 3.0
+ * @property string action_id database column
+ * @property string id alias column for action_id
+ * @property string name database column
+ * @property string description database column
+ * @property string info_template database column
+ * @property string active database column
+ * @property string expires database column
+ * @property string filename database column
+ * @property string class database column
+ * @property string type database column
+ * @property SimpleORMapCollection events has_many LogEvent
+ */
+class LogAction extends SimpleORMap
+{
+ protected static function configure($config = [])
+ {
+ $config['db_table'] = 'log_actions';
+ $config['has_many']['events'] = [
+ 'class_name' => LogEvent::class,
+ 'on_delete' => 'delete',
+ ];
+ parent::configure($config);
+ }
+
+ /**
+ * Returns whether this action is active or not.
+ *
+ * @return boolean TRUE if action is active.
+ */
+ public function isActive()
+ {
+ return (bool) $this->active;
+ }
+
+ /**
+ * Returns an associative array of all actions with at least one event.
+ * The array contains the action_id and the description. It is ordered by
+ * the first part of the actions name and the description.
+ *
+ * @param bool $grouped Return array grouped by group name
+ * @return array Assoc array of actions.
+ */
+ public static function getUsed($grouped = false)
+ {
+ $sql = "SELECT action_id, description, SUBSTRING_INDEX(name, '_', 1) AS log_group
+ FROM log_actions WHERE EXISTS
+ (SELECT * FROM log_events WHERE log_events.action_id = log_actions.action_id)
+ ORDER BY log_group, description";
+ $result = DBManager::get()->fetchAll($sql);
+
+ if (!$grouped) {
+ return $result;
+ }
+
+ $actions = [];
+ foreach ($result as $action) {
+ extract($action);
+
+ if (!isset($actions[$log_group])) {
+ $actions[$log_group] = [];
+ }
+ $actions[$log_group][$action_id] = $description;
+ }
+ return $actions;
+ }
+}