From ccbcffa58133dec1fbab4388be8a561f3f9ecf1a Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Fri, 6 May 2011 21:11:03 +0200 Subject: add origin table to apk template --- apk_browser.module | 57 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 9 deletions(-) (limited to 'apk_browser.module') diff --git a/apk_browser.module b/apk_browser.module index a28320e..f30e451 100644 --- a/apk_browser.module +++ b/apk_browser.module @@ -99,7 +99,7 @@ function apk_browser_settings($form) { if (module_exists('aggregator')) { $feeds += db_query("SELECT fid,title FROM {aggregator_feed}")->fetchAllKeyed(); $disabled = FALSE; - $description = t('When enabled, commit title will be searched in this aggregator feed.'); + $description = t('When enabled, commit title will be searched in this aggregator feed.'); } else { $disabled = TRUE; $description = t('You need to have aggregator enabled and configured to enable this.'); @@ -108,7 +108,7 @@ function apk_browser_settings($form) { '#type' => 'select', '#title' => t('RSS commit lookup'), '#description' => $description, - '#default_value' => variable_get('apk_import_aggregator','0'), + '#default_value' => variable_get('apk_import_aggregator', '0'), '#options' => $feeds, '#disabled' => $disabled, ); @@ -493,19 +493,19 @@ function apk_browser_cleanup() { //create an url from the commit, and if we find it in aggregator we add a title function apk_browser_commit_url($commit) { - $fid = variable_get('apk_import_aggregator','0'); + $fid = variable_get('apk_import_aggregator', '0'); $attributes = array(); $href = str_replace('%commit%', $commit, variable_get('apk_import_commit_url', '')); if (module_exists('aggregator') && $fid) { - if (!empty($commit)) { + if (!empty($commit)) { $search = '%' . $commit . '%'; } $title = db_query("SELECT title FROM {aggregator_item} WHERE link LIKE :commit AND fid = :fid", array(':commit' => $search, ':fid' => $fid))->fetchField(); - if ($title) { - $attributes = array('title' => check_plain($title), 'class' => 'with-tooltip'); - $path = drupal_get_path('module', 'apk_browser'); - drupal_add_js($path . '/tooltip/tooltip.js'); - drupal_add_js('jQuery().ready(function(){jQuery(".with-tooltip").simpletooltip();});', 'inline'); + if ($title) { + $attributes = array('title' => check_plain($title), 'class' => 'with-tooltip'); + $path = drupal_get_path('module', 'apk_browser'); + drupal_add_js($path . '/tooltip/tooltip.js'); + drupal_add_js('jQuery().ready(function(){jQuery(".with-tooltip").simpletooltip();});', 'inline'); } } return l($commit, $href, array('attributes' => $attributes)); @@ -584,6 +584,7 @@ function apk_browser_package_table($vars) { function apk_browser_preprocess_node(&$vars) { if ($vars['node']->type == 'apk') { $vars['apk_table'] = apk_browser_package_table($vars); + $vars['origin_table'] = apk_browser_origin_table($vars); } } @@ -653,3 +654,41 @@ function apk_browser_batch_delete_all_apk_finished($success, $results, $operatio } drupal_set_message($message); } + +function apk_browser_origin_table($vars) { + $rows = db_query(" + SELECT node.title + FROM {node} + LEFT JOIN {field_data_apk_origin} as origin ON (node.nid = origin.entity_id) + LEFT JOIN {field_data_taxonomy_apk_arch} as arch ON (node.nid = arch.entity_id) + LEFT JOIN {field_data_taxonomy_apk_repo} as repo ON (node.nid = repo.entity_id) + WHERE origin.apk_origin_value = :origin + AND arch.taxonomy_apk_arch_tid = :arch + AND repo.taxonomy_apk_repo_tid = :repo + AND node.status = '1' + LIMIT 10", array( + ':origin' => $vars['apk_origin']['0']['value'], + ':arch' => $vars['taxonomy_apk_arch']['0']['tid'], + ':repo' => $vars['taxonomy_apk_repo']['0']['tid'] + ) + )->fetchCol(); + if ($rows) { + $table['header'] = array(t('Same origin')); + foreach ($rows as $key => $row) { + $value = trim($row, '!'); + $value = preg_split("/[<>=]/", $value); + $link = l($row, 'apk/' . + $vars['taxonomy_apk_repo']['0']['taxonomy_term']->name . '/' . + $vars['taxonomy_apk_arch']['0']['taxonomy_term']->name . '/' . + $value[0] + ); + $table['rows'][$key]['data'] = array($link); + } + $table['attributes']['id'] = 'origin-table'; + return theme('table', $table); + } else { + return FALSE; + } +} + +?> -- cgit v1.2.3