2015-10-29 21:14:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class for formatters that process multiple events.
|
|
|
|
*
|
|
|
|
* The formatter does not maintain any state except for the
|
|
|
|
* arguments passed in the constructor (user and language)
|
|
|
|
*/
|
|
|
|
abstract class EchoEventDigestFormatter {
|
2019-01-04 14:03:05 +00:00
|
|
|
|
|
|
|
/** @var User */
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
/** @var Language */
|
|
|
|
protected $language;
|
|
|
|
|
2015-10-29 21:14:35 +00:00
|
|
|
public function __construct( User $user, Language $language ) {
|
|
|
|
$this->user = $user;
|
|
|
|
$this->language = $language;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Equivalent to IContextSource::msg for the current
|
|
|
|
* language
|
|
|
|
*
|
2019-03-10 01:54:04 +00:00
|
|
|
* @param string ...$args
|
2015-10-29 21:14:35 +00:00
|
|
|
* @return Message
|
|
|
|
*/
|
2019-03-10 01:54:04 +00:00
|
|
|
protected function msg( ...$args ) {
|
2015-10-29 21:14:35 +00:00
|
|
|
/**
|
|
|
|
* @var Message $msg
|
|
|
|
*/
|
2019-03-10 01:54:04 +00:00
|
|
|
$msg = wfMessage( ...$args );
|
2015-10-29 21:14:35 +00:00
|
|
|
$msg->inLanguage( $this->language );
|
|
|
|
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param EchoEvent[] $events
|
|
|
|
* @param string $distributionType 'web' or 'email'
|
2018-08-13 07:32:22 +00:00
|
|
|
* @return string[]|false Output format depends on implementation, false if it cannot be formatted
|
2015-10-29 21:14:35 +00:00
|
|
|
*/
|
|
|
|
final public function format( array $events, $distributionType ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$models = [];
|
2015-10-29 21:14:35 +00:00
|
|
|
foreach ( $events as $event ) {
|
|
|
|
$model = EchoEventPresentationModel::factory( $event, $this->language, $this->user, $distributionType );
|
|
|
|
if ( $model->canRender() ) {
|
|
|
|
$models[] = $model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 13:19:01 +00:00
|
|
|
return $models ? $this->formatModels( $models ) : false;
|
2015-10-29 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param EchoEventPresentationModel[] $models
|
2018-08-13 07:33:57 +00:00
|
|
|
* @return string[]|string
|
2015-10-29 21:14:35 +00:00
|
|
|
*/
|
|
|
|
abstract protected function formatModels( array $models );
|
|
|
|
}
|