MandrillActivityController.php in Mandrill 8
File
modules/mandrill_activity/src/Controller/MandrillActivityController.php
View source
<?php
namespace Drupal\mandrill_activity\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\user\Entity\User;
class MandrillActivityController extends ControllerBase {
public function overview(User $user) {
$content = array();
$api = \Drupal::service('mandrill.api');
$activity = $api
->getMessages($user
->getEmail());
$content['activity'] = array(
'#markup' => t('The 100 most recent Emails sent to %email via Mandrill.', array(
'%email' => $email,
)),
);
$content['activity_table'] = array(
'#type' => 'table',
'#header' => array(
t('Subject'),
t('Timestamp'),
t('State'),
t('Opens'),
t('Clicks'),
t('Tags'),
),
'#empty' => 'No activity yet.',
);
foreach ($activity as $index => $message) {
$content['activity_table'][$index]['subject'] = array(
'#markup' => $message['subject'],
);
$content['activity_table'][$index]['timestamp'] = array(
'#markup' => \Drupal::service('date.formatter')
->format($message['ts'], 'short'),
);
$content['activity_table'][$index]['state'] = array(
'#markup' => $message['state'],
);
$content['activity_table'][$index]['opens'] = array(
'#markup' => $message['opens'],
);
$content['activity_table'][$index]['clicks'] = array(
'#markup' => $message['clicks'],
);
$content['activity_table'][$index]['tags'] = array(
'#markup' => implode(', ', $message['tags']),
);
}
return $content;
}
}