function tft_get_content in Taxonomy File Tree 7
Same name and namespace in other branches
- 7.2 tft.module \tft_get_content()
Get the folder content and return it in an array form for the theme_table call
Parameters
int $tid: The taxonomy term tid
Return value
array The folder content
1 call to tft_get_content()
- tft_content_table in ./
tft.module - Get the folder content in HTML table form
File
- ./
tft.module, line 718 - Module hooks.
Code
function tft_get_content($tid, $gid = NULL) {
$content = array();
$elements = tft_folder_content($tid, FALSE, $gid);
$setting = tft_get_file_setting();
$node_type = node_type_load($setting['type']);
$og_nid = tft_get_og_nid($tid);
$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') {
$name = db_query("SELECT name FROM {taxonomy_term_data} WHERE tid = :tid", array(
':tid' => $element['id'],
))
->fetchField();
$content[] = array(
tft_l($name, $element['id'], 'folder'),
'',
'',
t("Folder"),
tft_is_archive_folder($element['id']) ? '' : tft_operation_links('folder', $element['id'], NULL, $og_nid),
);
}
else {
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()) {
$node = node_load($element['id']);
$content[] = array(
tft_l($row['title'], $element['id'], $row['filemime']),
tft_print_username($row['uid']),
date('d/m/Y H:i', $row['changed']),
t('!type file', array(
'!type' => strtoupper(end(explode('.', $row['filename']))),
)),
tft_operation_links('file', $element['id'], $node, $og_nid),
);
}
}
}
}
return $content;
/*
// Get all child folders (terms)
$result = db_query("SELECT {taxonomy_term_data}.name, {taxonomy_term_data}.tid FROM {taxonomy_term_data}
LEFT JOIN {taxonomy_term_hierarchy} ON {taxonomy_term_hierarchy}.tid = {taxonomy_term_data}.tid
WHERE {taxonomy_term_hierarchy}.parent = %d AND {taxonomy_term_data}.vid = %d
ORDER BY {taxonomy_term_data}.name = 'Archives' ASC, {taxonomy_term_data}.weight, {taxonomy_term_data}.name", array($tid, variable_get('tft_vocabulary_vid', 0)));
while ($row = db_fetch_array($result)) {
$content[] = array(
tft_l($row['name'], $row['tid'], 'folder'),
'',
'',
t("Folder"),
tft_is_archive_folder($row['tid']) ? '' : tft_operation_links('folder', $row['tid']),
);
}
// Get all files. First deduce the db table and column
$setting = tft_get_file_setting();
$node_type = content_types($setting['type']);
if (in_array('content_' . $setting['field'], $node_type['tables'])) {
$db_table = 'content_' . $setting['field'];
}
else {
$db_table = 'content_type_' . $setting['type'];
}
$db_table = db_escape_string($db_table);
$db_field = db_escape_string($setting['field'] . '_fid');
// Get the files
if (db_table_exists($db_table)) {
$result = db_query("SELECT DISTINCT({taxonomy_index}.nid), {files}.filemime, {files}.filename, {node_revisions}.title, {node}.changed, {node}.uid FROM {taxonomy_index}
LEFT JOIN {node_revisions} ON {node_revisions}.nid = {taxonomy_index}.nid AND {node_revisions}.vid = {taxonomy_index}.vid
LEFT JOIN {node} ON {node_revisions}.nid = {node}.nid AND {node_revisions}.vid = {node}.vid
LEFT JOIN {$db_table} AS tft_table ON tft_table.vid = {node}.vid
LEFT JOIN {files} ON tft_table.$db_field = {files}.fid
WHERE {taxonomy_index}.tid = %d AND {node}.status = 1", array($tid));
while ($row = db_fetch_array($result)) {
$node = node_load($row['nid']);
if (node_access('view', $node)) {
$content[] = array(
tft_l($row['title'], $row['nid'], $row['filemime']),
tft_print_username($row['uid']),
date('d/m/Y H:i', $row['changed']),
t('!type file', array('!type' => strtoupper(end(explode('.', $row['filename']))))),
tft_operation_links('file', $row['nid'], $node),
);
}
}
}
else {
watchdog('tft', "The database table @table does not exist. Couldn't retreive the files.", array('@table' => $db_table), WATCHDOG_ERROR);
return t("Configuration error. Couldn't load the data from the database. Contact your site administrator.");
}
return $content;*/
}