2015-08-19 20:22:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A formatter for the notification flyout popup
|
|
|
|
*
|
|
|
|
* Ideally we wouldn't need this and we'd just pass the
|
|
|
|
* presentation model to the client, but we need to continue
|
|
|
|
* sending HTML for backwards compatibility.
|
|
|
|
*/
|
|
|
|
class EchoFlyoutFormatter extends EchoEventFormatter {
|
2015-10-29 21:13:10 +00:00
|
|
|
protected function formatModel( EchoEventPresentationModel $model ) {
|
2015-08-19 20:22:45 +00:00
|
|
|
$icon = Html::element(
|
|
|
|
'img',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2015-08-19 20:22:45 +00:00
|
|
|
'class' => 'mw-echo-icon',
|
|
|
|
'src' => $this->getIconURL( $model ),
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2015-08-19 20:22:45 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$html = Xml::tags(
|
|
|
|
'div',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'class' => 'mw-echo-title' ],
|
2015-08-19 20:22:45 +00:00
|
|
|
$model->getHeaderMessage()->parse()
|
|
|
|
) . "\n";
|
|
|
|
|
2015-11-04 20:41:29 +00:00
|
|
|
$body = $model->getBodyMessage();
|
|
|
|
if ( $body ) {
|
|
|
|
$html .= Xml::tags(
|
|
|
|
'div',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'class' => 'mw-echo-payload' ],
|
2015-11-04 20:41:29 +00:00
|
|
|
$body->parse()
|
|
|
|
) . "\n";
|
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
|
|
|
|
$ts = $this->language->getHumanTimestamp(
|
2015-10-29 21:13:10 +00:00
|
|
|
new MWTimestamp( $model->getTimestamp() ),
|
2015-08-19 20:22:45 +00:00
|
|
|
null,
|
|
|
|
$this->user
|
|
|
|
);
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$footerItems = [ $ts ];
|
2016-01-12 21:54:05 +00:00
|
|
|
$secondaryLinks = array_filter( $model->getSecondaryLinks() );
|
2015-11-19 15:41:18 +00:00
|
|
|
foreach ( $secondaryLinks as $link ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$footerItems[] = Html::element( 'a', [ 'href' => $link['url'] ], $link['label'] );
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
$html .= Xml::tags(
|
|
|
|
'div',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'class' => 'mw-echo-notification-footer' ],
|
2015-08-19 20:22:45 +00:00
|
|
|
$this->language->pipeList( $footerItems )
|
|
|
|
) . "\n";
|
|
|
|
|
2015-11-02 23:55:17 +00:00
|
|
|
// Add the primary link afterwards, if it has one
|
2016-05-03 01:56:13 +00:00
|
|
|
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
|
2015-11-02 23:55:17 +00:00
|
|
|
if ( $primaryLink !== false ) {
|
|
|
|
$html .= Html::element(
|
|
|
|
'a',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'class' => 'mw-echo-notification-primary-link', 'href' => $primaryLink['url'] ],
|
2015-11-19 15:41:18 +00:00
|
|
|
$primaryLink['label']
|
2015-11-02 23:55:17 +00:00
|
|
|
) . "\n";
|
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
|
|
|
|
// Wrap everything in mw-echo-content class
|
2016-12-05 18:51:07 +00:00
|
|
|
$html = Xml::tags( 'div', [ 'class' => 'mw-echo-content' ], $html );
|
2015-08-19 20:22:45 +00:00
|
|
|
|
|
|
|
// And then add the icon in front and wrap with mw-echo-state class.
|
2016-12-05 18:51:07 +00:00
|
|
|
$html = Xml::tags( 'div', [ 'class' => 'mw-echo-state' ], $icon . $html );
|
2015-08-19 20:22:45 +00:00
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getIconURL( EchoEventPresentationModel $model ) {
|
2016-07-20 14:53:36 +00:00
|
|
|
return EchoIcon::getUrl(
|
2015-08-19 20:22:45 +00:00
|
|
|
$model->getIconType(),
|
|
|
|
$this->language->getDir()
|
|
|
|
);
|
|
|
|
}
|
2015-11-19 15:41:18 +00:00
|
|
|
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|