diff --git a/include/class-Log.php b/include/class-Log.php index fccb38b..f62d505 100644 --- a/include/class-Log.php +++ b/include/class-Log.php @@ -1,141 +1,154 @@ . // make sure that this class is loaded at startup class_exists( User::class ); class_exists( Domain::class ); trait LogTrait { /** * Get the log actor name * * @return string */ public function getLogActorFirm() { return User::firm( $this->get( 'actor_uid' ) ); } /** * Get the action family * * @return string */ public function getLogFamily() { return $this->get( 'log_family' ); } /** * Get the action */ public function getLogAction() { return $this->get( 'log_action' ); } /** * Get the action */ public function getLogDate() { return $this->get( 'log_timestamp' ); } /** * Get the log message * * @param array $args Arguments * @return self */ public function getLogMessage( $args ) { $family = $this->getLogFamily(); $action = $this->getLogAction(); // trigger the right message family switch( $family ) { case 'domain': return self::domainMessage( $action, $this, $args ); } return 'misterious action'; } + /** + * Get the log message alongside the date + * + * @param array $args Arguments + * @return self + */ + public function getLogMessageWithDate( $args ) { + return sprintf( + "%s - %s", + $this->getLogDate()->format( __( "Y-m-d H:i" ) ), + $this->getLogMessage( $args ) + ); + } + protected function normalizeLog() { $this->datetimes( 'log_timestamp' ); } } /** * A generic log of an action * * Something happened. Dunno what. */ class Log extends Queried { use LogTrait; use UserTrait; use DomainTrait; public function __construct() { $this->normalizeLog(); } /** * Database table name */ const T = 'log'; /** * Generate a Domain-related message * * @param string $action The related action name * @param object $log * @param array $args Arguments * @return string Message */ public static function domainMessage( $action, $log, $args ) { /** * You can pass some objects to build the message: * * A complete 'actor' User object * A complete 'domain' Domain object */ $actor = $args['actor'] ?? $log; $domain = $args['domain'] ?? $log; $plan = $args['plan'] ?? $log; // create the Actor firm from the passed User object or from the Log $actor_firm = $actor instanceof User ? $actor->getUserFirm() : $log->getLogActorFirm(); switch( $action ) { // an administrator has changed the Plan for a Domain case 'plan.change': return sprintf( - "%s - %s changed the Plan for %s to %s", - $log->getLogDate()->format( __( "Y-m-d H:i" ) ), + __( "%s changed the Plan for %s to %s" ), $actor_firm, $domain->getDomainFirm(), esc_html( $plan->getPlanName() ) ); } return 'edited a domain (wtf?)'; } } diff --git a/template/activity-panel.php b/template/activity-panel.php index 64f1175..26424e8 100644 --- a/template/activity-panel.php +++ b/template/activity-panel.php @@ -1,36 +1,36 @@ . /* * This is the template for the activity panel * * Called from * include/class-ActivityPanel.php - the_link() function * * Available variables: * $message_args array Arguments * $query QueryLog The query log */ ?>