summaryrefslogtreecommitdiff
blob: c4a9d436c0f9afa57825d47590ba044d89a54b1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?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 = wfMessage( ...func_get_args() );
		$msg->inLanguage( $this->language );

		return $msg;
	}

	/**
	 * @param EchoEvent[] $events
	 * @param string $distributionType 'web' or 'email'
	 * @return string[]|false Output format depends on implementation, false if it cannot be formatted
	 */
	final public function format( array $events, $distributionType ) {
		$models = [];
		foreach ( $events as $event ) {
			$model = EchoEventPresentationModel::factory( $event, $this->language, $this->user, $distributionType );
			if ( $model->canRender() ) {
				$models[] = $model;
			}
		}

		return $models ? $this->formatModels( $models ) : false;
	}

	/**
	 * @param EchoEventPresentationModel[] $models
	 * @return string[]|string
	 */
	abstract protected function formatModels( array $models );
}