Add default params to avoid massive if/else block

Change-Id: I966d16525220565e805fda582c5f88a7978faa37
This commit is contained in:
bsitu 2013-04-04 14:56:05 -07:00 committed by Bsitu
parent 2b420bfac8
commit cbd88322f2
2 changed files with 99 additions and 85 deletions

View file

@ -133,6 +133,7 @@ $3',
'echo-email-body-default' => 'You have a new notification at {{SITENAME}}:
$1',
'echo-email-batch-body-default' => 'You have a new notification',
'echo-email-footer-default' => '$2
To control which emails we send you, visit:
@ -455,6 +456,7 @@ The new notification count next to notification link, for example: 99+
'echo-email-subject-default' => 'Default subject for Echo e-mail notifications',
'echo-email-body-default' => 'Default message content for Echo e-mail notifications.
* $1 is a plain text description of the notification.',
'echo-email-batch-body-default' => 'Default message for Echo e-mail digest notifications',
'echo-email-footer-default' => 'Default footer content for Echo e-mail notifications. Parameters:
* $1 is the address of the organization that sent the e-mail
* $2 is "-------..." ({{msg-mw|echo-email-batch-separator}})',

View file

@ -6,14 +6,49 @@
* in all the internal method
*/
class EchoBasicFormatter extends EchoNotificationFormatter {
protected $messageKey = false;
protected $messageParams = false;
/**
* Required parameters
* @param array
*/
protected $requiredParameters = array(
'title-message',
'title-params',
'title-params'
);
protected $title, $flyoutTitle, $bundleTitle, $content, $email, $icon;
/**
* Notification title data for archive page
* @param array
*/
protected $title;
/**
* Notification title data for flyout
* @param array
*/
protected $flyoutTitle;
/**
* Notification title data for bundling ( flyout and archive page )
*/
protected $bundleTitle;
/**
* @Todo Check if this varaible can be removed
*/
protected $content;
/**
* Notification email data
* @param array
*/
protected $email;
/**
* Notification icon for each type
* @param string
*/
protected $icon;
/**
* Data for constructing bundle message, data in this array
@ -27,94 +62,71 @@ class EchoBasicFormatter extends EchoNotificationFormatter {
public function __construct( $params ) {
parent::__construct( $params );
$this->title = $this->flyoutTitle = $this->bundleTitle = array();
// Title for archive page
$this->title = array(
'message' => $params['title-message'],
'params' => $params['title-params']
);
if ( isset( $params['flyout-message'] ) && isset( $params['flyout-params'] ) ) {
$this->flyoutTitle['message'] = $params['flyout-message'];
$this->flyoutTitle['params'] = $params['flyout-params'];
} else {
$this->flyoutTitle['message'] = $params['title-message'];
$this->flyoutTitle['params'] = $params['title-params'];
}
// Set up default params if one is missing
$params += $this->getDefaultParams();
// Title for the flyout
$this->flyoutTitle = array(
'message' => $params['flyout-message'],
'params' => $params['flyout-params']
);
if ( isset( $params['bundle-message'] ) ) {
$this->bundleTitle['message'] = $params['bundle-message'];
if ( isset( $params['bundle-params'] ) ) {
$this->bundleTitle['params'] = $params['bundle-params'];
} else {
$this->bundleTitle['params'] = array();
}
}
// Bundle title for both archive page and flyout
$this->bundleTitle = array(
'message' => $params['bundle-message'],
'params' => $params['bundle-params']
);
$this->title['message'] = $params['title-message'];
$this->title['params'] = $params['title-params'];
$this->payload = array();
// Notification payload data, eg, summary
$this->payload = $params['payload'];
if ( isset( $params['payload'] ) ) {
$this->payload = $params['payload'];
}
// Notification email subject and body
$this->email = array(
'subject' => array(
'message' => $params['email-subject-message'],
'params' => $params['email-subject-params']
),
'body' => array(
'message' => $params['email-body-message'],
'params' => $params['email-body-params']
),
'batch-body' => array(
'message' => $params['email-body-batch-message'],
'params' => $params['email-body-batch-params']
)
);
$this->email = array();
if ( isset( $params['email-subject-message'] ) ) {
$this->email['subject'] = array();
$this->email['subject']['message'] = $params['email-subject-message'];
// Notification icon for the event type
$this->icon = $params['icon'];
if ( isset( $params['email-subject-params'] ) ) {
$this->email['subject']['params'] = $params['email-subject-params'];
} else {
$this->email['subject']['params'] = array();
}
} else {
$this->email = array(
'subject' => array(
'message' => 'echo-email-subject-default',
'params' => array(),
),
'body' => array(
'message' => 'echo-email-body-default',
'params' => array(
'text-notification',
),
),
);
}
if ( isset( $params['email-body-message'] ) ) {
$this->email['body'] = array();
$this->email['body']['message'] = $params['email-body-message'];
if ( isset( $params['email-body-params'] ) ) {
$this->email['body']['params'] = $params['email-body-params'];
} else {
$this->email['body']['params'] = array( 'text-notification' );
}
} else {
$this->email['body'] = array(
'message' => 'echo-email-body-default',
'params' => array(
'text-notification',
),
);
}
$this->email['batch-body'] = array();
if ( isset( $params['email-body-batch-message'] ) ) {
$this->email['batch-body']['message'] = $params['email-body-batch-message'];
if ( isset( $params['email-body-batch-params'] ) ) {
$this->email['batch-body']['params'] = $params['email-body-batch-params'];
} else {
$this->email['batch-body']['params'] = array();
}
} else {
$this->email['batch-body'] = $this->email['body'];
}
if ( isset( $params['icon'] ) ) {
$this->icon = $params['icon'];
} else {
$this->icon = 'placeholder';
}
}
/**
* Internal function that returns notification default params
*
* @return array
*/
protected function getDefaultParams() {
return array(
'flyout-message' => $this->title['message'],
'flyout-params' => $this->title['params'],
'bundle-message' => '',
'bundle-params' => array(),
'payload' => array(),
'email-subject-message' => 'echo-email-subject-default',
'email-subject-params' => array(),
'email-body-message' => 'echo-email-body-default',
'email-body-params' => array( 'text-notification' ),
'email-body-batch-message' => 'echo-email-batch-body-default',
'email-body-batch-params' => array(),
'icon' => 'placeholder'
);
}
/**