function pretty_calendar_select_nodes in Pretty Calendar 7
Select nodes for selected date.
Parameters
int $date: Date timestamp.
bool $links_only: Boolean value. If "TRUE", returned result will be contain pager element.
Return value
array|DatabaseStatementInterface By dependency of $links_only value, result will be array or query result.
2 calls to pretty_calendar_select_nodes()
- pretty_calendar_links_loader in ./
pretty_calendar.module - AJAX response for preloading node links.
- pretty_calendar_node_list in ./
pretty_calendar.module - Display page with nodes by date.
File
- ./
pretty_calendar.module, line 509 - Simple nice calendar module that displays the materials by date.
Code
function pretty_calendar_select_nodes($date = 0, $links_only = FALSE) {
global $language;
$field_name = variable_get('pretty_calendar_field_date', '');
$node_types = explode(',', variable_get('pretty_calendar_node_type', ''));
// Check if field was deleted.
if (field_info_field($field_name) == '') {
$field_name = '';
}
// Select nodes without date field.
$select = db_select('node', 'n')
->fields('n', array(
'nid',
'title',
'created',
))
->condition('n.status', 1);
// Multilanguage condition.
if (variable_get('pretty_calendar_separate_languages', FALSE)) {
$select
->condition('n.language', $language->language);
}
// Check date.
if ($date > 0) {
if ($field_name == '') {
$select
->condition('created', $date, '>=')
->condition('created', $date + 86400, '<');
}
else {
$select
->distinct();
$select
->leftJoin('field_data_' . $field_name, 'fd', 'fd.entity_id = n.nid');
$select
->fields('fd', array(
$field_name . '_value',
));
$select
->where('DATE(' . $field_name . '_value) = :date', array(
':date' => date('Y.m.d', $date),
));
}
}
// Check types.
if ($node_types[0] != '') {
if (variable_get('pretty_calendar_node_invert', FALSE)) {
$select
->condition('n.type', $node_types, 'NOT IN');
}
else {
$select
->condition('n.type', $node_types, 'IN');
}
}
$select
->orderBy('n.sticky', 'DESC')
->orderBy('n.created', 'DESC');
if (!$links_only) {
$select
->extend('PagerDefault')
->limit(variable_get('pretty_calendar_node_per_page', '20'))
->addTag('node_access');
return $select
->execute()
->fetchCol();
}
else {
$select
->addTag('node_access');
$result = array();
foreach ($select
->execute() as $row) {
$result[] = $row;
}
return $result;
}
}