You are here

function tft_get_content in Taxonomy File Tree 7.2

Same name and namespace in other branches
  1. 7 tft.module \tft_get_content()

Get the folder content and return it in an array form for the theme_table call.

Parameters

int $tid:

Return value

array

Related topics

1 call to tft_get_content()
tft_content_table in ./tft.module
Get the folder content in HTML table format.

File

./tft.module, line 477
Hook implementations and module logic for TFT.

Code

function tft_get_content($tid) {
  if (!tft_term_access($tid)) {
    drupal_access_denied();
    exit;
  }
  $content = array();
  $elements = tft_folder_content($tid, FALSE);
  $setting = tft_get_file_setting();
  $db_table = 'field_data_' . $setting['field'];
  $db_table = db_escape_field($db_table);
  $db_field = db_escape_field($setting['field'] . '_fid');
  foreach ($elements as $element) {
    if ($element['type'] == 'term') {
      if (!tft_term_access($element['id'])) {
        continue;
      }
      $term = taxonomy_term_load($element['id']);
      $content[] = array(
        tft_l($term->name, $element['id'], 'folder'),
        '',
        '',
        t("Folder"),
        tft_theme_item_operation_links(tft_item_operation_links('folder', $element['id'], $tid)),
      );
    }
    else {
      $node = node_load($element['id']);
      if (node_access('view', $node)) {
        if (db_table_exists($db_table)) {
          $result = db_query("SELECT f.filemime, f.filename, v.title, n.changed, n.uid FROM {node_revision} v\n                                  LEFT JOIN {node} n ON n.vid = v.vid\n                                    LEFT JOIN {" . $db_table . "} c ON c.revision_id = v.vid\n                                      LEFT JOIN {file_managed} f ON c.{$db_field} = f.fid\n                              WHERE n.nid = :nid AND n.status = 1", array(
            ':nid' => $element['id'],
          ));
          if ($row = $result
            ->fetchAssoc()) {
            $parts = explode('.', $row['filename']);
            $content[] = array(
              tft_l($row['title'], $element['id'], $row['filemime']),
              tft_get_username($row['uid']),
              date('d/m/Y H:i', $row['changed']),
              t('!type file', array(
                '!type' => strtoupper(array_pop($parts)),
              )),
              tft_theme_item_operation_links(tft_item_operation_links('file', $element['id'], $tid)),
            );
          }
        }
      }
    }
  }
  return $content;
}