function tripal_block_view
3.x tripal.module | tripal_block_view($delta = '') |
Implements hook_block_view().
File
- tripal/
tripal.module, line 1133 - The core Tripal module
Code
function tripal_block_view($delta = '') {
global $base_path;
$block = array();
// The $delta parameter tells us which block is being requested.
switch ($delta) {
case 'powered_by_tripal':
$size = variable_get('powered_by_tripal_size', 'small');
$type = variable_get('powered_by_tripal_type', 'bw');
$image = 'powered_by_tripal_bw_small.png';
if ($size == 'small' and $type == 'col') {
$image = 'powered_by_tripal_small.png';
}
if ($size == 'large' and $type == 'bw') {
$image = 'powered_by_tripal_bw.png';
}
if ($size == 'large' and $type == 'col') {
$image = 'powered_by_tripal.png';
}
$block['title'] = '';
$block['content'] = array(
'#markup' => '<a href="http://tripal.info"><img border="0" src="' . $base_path . drupal_get_path('module', 'tripal') . '/theme/images/' . $image . '"></a>',
);
break;
case 'content_type_barchart':
// The number of content types
$entity_types = db_select('tripal_bundle', 'tb')
->fields('tb')
->execute()
->fetchAll();
$entity_count_listing = array();
// The number of entities per content type.
foreach ($entity_types as $entity_types => $entity_type) {
$result = db_select('chado_' . $entity_type->name, 'et')
->fields('et')
->execute();
$number_of_entities = $result->rowCount();
$entity_count_listing[$entity_types] = array(
'name' => $entity_type->label,
'count' => $number_of_entities,
);
}
tripal_add_d3js();
drupal_add_js(drupal_get_path('module', 'tripal') . '/theme/js/tripal.dashboard.js');
drupal_add_css(drupal_get_path('module', 'tripal') . '/theme/css/tripal.dashboard.css');
drupal_add_library('system', 'drupal.collapse');
drupal_add_js("var entityCountListing = " . json_encode($entity_count_listing) . ";", array('type' => 'inline'));
$output = "<div id=\"tripal-entity-types\" class=\"tripal-entity-types-pane\">
<p>A list of the published Tripal content types and the number of each.</p>
<div id=\"tripal-entity-type-chart\"></div>
</div>";
$block['title'] = '';
$block['content'] = array(
'#markup' => $output,
);
break;
case 'notifications_block':
// Create your block content here
$block['content'] = '';
// Prepare table header
$header = array(
'title' => array('data' => t('Title')),
'details' => array('data' => t('Details')),
'type' => array('data' => t('Type'), 'field' => 'tan.type'),
'actions' => array('data' => t('Actions'))
);
$query = db_select('tripal_admin_notfications', 'tan')
->extend('TableSort');
$results = $query->fields('tan')
->condition('enabled', 1, '=')
->orderByHeader($header)
->execute()->fetchAll();
$rows = array();
foreach ($results as $result) {
$data['operation'] = ' | ';
$data['operation'] .= l(t('Dismiss Notification'), 'admin/disable/notification/' . $result->note_id);
$actions = unserialize($result->actions);
foreach ($actions as $action) {
$label = key($actions);
$link = $action;
}
$rows[] = array(
'Title' => $result->title,
'Details' => $result->details,
'Type' => $result->type,
'Actions' => l(t($label), $link) . $data['operation'],
);
}
if (!empty($rows)) {
//Number of records shown in per page
$per_page = 10;
$current_page = pager_default_initialize(count($rows), $per_page);
$chunks = array_chunk($rows, $per_page, TRUE);
// Output of table with the paging
$table = theme('table',
array(
"header" => $header,
"rows" => $chunks[$current_page],
"attributes" => array(),
"sticky" => TRUE,
"caption" => "",
"colgroups" => array(),
"empty" => t("No notifications.")
)
);
$table .= theme('pager', array('quantity', count($rows)));
$fieldset_table = array(
'#title' => t('Notifications'),
'#collapsed' => FALSE,
'#collapsible' => TRUE,
'#attributes' => array('class' => array('collapsible')),
'#children' => $table,
);
//return pager with limited number of records.
$block['content'] = theme('fieldset', array('element' => $fieldset_table));
}
else {
$block['content'] = 'There are no notifications at this time.';
}
$block['title'] = 'Tripal Administrative Notifications';
break;
}
return $block;
}