function hubspot_block_view in HubSpot 7.3
Same name and namespace in other branches
- 7 hubspot.module \hubspot_block_view()
- 7.2 hubspot.module \hubspot_block_view()
Implements hook_block_view().
File
- ./
hubspot.module, line 126 - Sends Webform results to HubSpot's Forms API.
Code
function hubspot_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'hubspot_recent':
if (!user_access('see recent hubspot leads')) {
return;
}
$block['subject'] = t('HubSpot Recent Leads');
$leads = hubspot_get_recent();
// This part of the HubSpot API returns HTTP error codes on failure, with no message
if (!empty($leads['Error']) || $leads['HTTPCode'] != 200) {
$block['content'] = t('An error occurred when fetching the HubSpot leads data: @error', array(
'@error' => !empty($leads['Error']) ? $leads['Error'] : $leads['HTTPCode'],
));
return $block;
}
elseif (empty($leads['Data'])) {
$block['content'] = t('No leads to show.');
return $block;
}
$block['content'] = array(
'#theme' => 'item_list',
'#items' => array(),
'#type' => 'ul',
);
foreach ($leads['Data']->contacts as $lead) {
foreach ($leads['Data']->contacts as $lead) {
// Note that $lead->insertedAt is in ms, not seconds, since the epoch.
$block['content']['#items'][] = l($lead->properties->firstname->value . ' ' . $lead->properties->lastname->value, $lead->{'profile-url'}) . ' ' . t('(@time ago)', array(
'@time' => format_interval(time() - floor($lead->addedAt / 1000)),
));
}
}
break;
}
return $block;
}