function hubspot_block in HubSpot 6.2
Same name and namespace in other branches
- 6 hubspot.module \hubspot_block()
Implements hook_block() to provide a HubSpot recent leads block.
File
- ./
hubspot.module, line 328 - Sends Webform results to HubSpot's Leads API by using Webform's provided hooks.
Code
function hubspot_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks = array();
$blocks[0] = array(
'info' => t('HubSpot Recent Leads'),
'status' => 0,
);
return $blocks;
break;
case 'view':
if ($delta == 0 && user_access('see recent hubspot leads')) {
$block = array();
$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;
}
$items = array();
foreach ($leads['Data'] as $lead) {
// Note that $lead->insertedAt comes in milliseconds, not seconds, since the epoch
$items[] = l($lead->firstName . ' ' . $lead->lastName, $lead->leadLink) . ' ' . t('(@time ago)', array(
'@time' => format_interval(time() - intval($lead->insertedAt / 1000)),
));
}
$block['content'] = theme('item_list', $items);
return $block;
}
break;
default:
// ignore 'configure' and 'save'
break;
}
}