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 {
|
|
|
|
public function __construct( User $user, Language $language ) {
|
|
|
|
$this->user = $user;
|
|
|
|
$this->language = $language;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Equivalent to IContextSource::msg for the current
|
|
|
|
* language
|
|
|
|
*
|
|
|
|
* @return Message
|
|
|
|
*/
|
|
|
|
protected function msg( /* ,,, */ ) {
|
|
|
|
/**
|
|
|
|
* @var Message $msg
|
|
|
|
*/
|
|
|
|
$msg = call_user_func_array( 'wfMessage', func_get_args() );
|
|
|
|
$msg->inLanguage( $this->language );
|
|
|
|
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param EchoEvent[] $events
|
|
|
|
* @param string $distributionType 'web' or 'email'
|
|
|
|
* @return array|bool|string Output format depends on implementation, false if it cannot be formatted
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
* @return string|array
|
|
|
|
*/
|
|
|
|
abstract protected function formatModels( array $models );
|
|
|
|
}
|