src/App/Entity/ActivityMonitoringEvent.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Command\DatabaseCleanups;
  4. use App\Utility\GuidUtility;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * Activity Monitoring Events: track what users do in order to decide if their behaviour is problematic and should be reported.
  9. *
  10. * While Business-, Application-, and Webrequest-Events are tracked for statistical use in the Data Warehouse, and Usage
  11. * Events used to change the platform behaviour according to a user's behaviour, Activity Monitoring Events are collected
  12. * to decide if a given user misuses or overuses the platform, which triggers an alarm.
  13. *
  14. * Usage and Activity Monitoring Events look very similar at first glance, but have some important differences and serve
  15. * very different purposes:
  16. *
  17. * - Usage Events are much leaner - instead of writing a new event entry for every relevant action the user takes, we
  18. * only store the info *that* he did something *at least* once, and merely update a counter if the action is repeated.
  19. * This is because most of the time, decisions that are based on Usage Events only need to know if a user not yet did
  20. * something, already did something, and sometimes, how often and when they did it the last time. In other words,
  21. * this is a very *qualitative* perspective
  22. *
  23. * - Activity Monitoring Events, on the other hand, provide a much more *quantitative* perspective. Because we need to
  24. * know if a user over-uses the platform, we need to know *how often* a user did something in a certain *time frame*.
  25. * For example, while writing many conversation messages is fine, writing a thousand conversation messages within the
  26. * last 24 hours would be considered over-use.
  27. *
  28. * In order to answer these "how often did user X do action Y in timeframe Z?" questions, we need to keep track of every
  29. * single occurrence of the action, while for Usage Events, it's sufficient to only increase a counter.
  30. *
  31. * Also, Activity Monitoring is more short-lived; we normally won't be interested in tracking user behaviour over more
  32. * than a couple of weeks, because alarming is based on misbehaviour during timeframes of hours or days. This is why
  33. * old Activity Monitoring Events can be wiped on a regular base via @see DatabaseCleanups, which mitigates the
  34. * disadvantage of their large data volume a bit.
  35. *
  36. * On the other hand, we generally keep Usage Events forever (or at least, until the related User is removed), because
  37. * we need the answers they provide all the time - which is no problem data volume wise, because Usage Events are very
  38. * lean.
  39. *
  40. * @ORM\Entity()
  41. *
  42. * @ORM\Table(
  43. * name="activity_monitoring_events",
  44. * indexes={
  45. *
  46. * @ORM\Index(name="timerange_search_idx", columns={"users_id", "event_type", "occurred_at"})
  47. * }
  48. * )
  49. */
  50. class ActivityMonitoringEvent
  51. {
  52. public const EVENT_TYPE_CONVERSATION_MESSAGE_SENT_BY_USER = 1;
  53. public const EVENT_TYPE_SEARCH_STARTED = 2;
  54. /**
  55. * @var string
  56. *
  57. * @ORM\GeneratedValue(strategy="CUSTOM")
  58. *
  59. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  60. *
  61. * @ORM\Column(name="id", type="guid")
  62. *
  63. * @ORM\Id
  64. */
  65. protected $id;
  66. public function getId()
  67. {
  68. return $this->id;
  69. }
  70. public function setId(string $id): void
  71. {
  72. GuidUtility::validOrThrow($id);
  73. $this->id = $id;
  74. }
  75. /**
  76. * @var User
  77. *
  78. * @ORM\ManyToOne(targetEntity="App\Entity\User", cascade={"persist"})
  79. *
  80. * @ORM\JoinColumn(name="users_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  81. */
  82. protected $user;
  83. public function getUser(): User
  84. {
  85. return $this->user;
  86. }
  87. public function setUser(User $user): void
  88. {
  89. $this->user = $user;
  90. }
  91. /**
  92. * @var int
  93. *
  94. * @ORM\Column(name="event_type", type="smallint", nullable=false)
  95. */
  96. protected $eventType;
  97. public function getEventType(): int
  98. {
  99. return $this->eventType;
  100. }
  101. public function setEventType(int $eventType): void
  102. {
  103. $this->eventType = $eventType;
  104. }
  105. /**
  106. * @var DateTime
  107. *
  108. * @ORM\Column(name="occurred_at", type="datetime", nullable=false)
  109. */
  110. protected $occurredAt;
  111. public function getOccurredAt(): DateTime
  112. {
  113. return $this->occurredAt;
  114. }
  115. public function setOccurredAt(DateTime $occurredAt): void
  116. {
  117. $this->occurredAt = $occurredAt;
  118. }
  119. }