function pretty_calendar_select_month_nodes in Pretty Calendar 7
Select all month nodes.
Parameters
int $date: Timestamp of selected month.
Return value
array Nids array for the given month.
1 call to pretty_calendar_select_month_nodes()
- pretty_calendar_block_content in ./
pretty_calendar.module - Rendering calendar block content.
File
- ./
pretty_calendar.module, line 578 - Simple nice calendar module that displays the materials by date.
Code
function pretty_calendar_select_month_nodes($date = 0) {
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', mktime(0, 0, 0, date('m', $date), 1, date('Y', $date)), '>=')
->condition('created', mktime(0, 0, 0, date('m', $date) + 1, 1, date('Y', $date)), '<');
}
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_FORMAT(fd.' . $field_name . '_value, \'%Y%m\') = :stamp', array(
':stamp' => date('Ym', $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
->addTag('node_access');
$result = array();
try {
foreach ($select
->execute() as $row) {
$result[] = $row;
}
} catch (Exception $e) {
$result['error'] = $e;
}
return $result;
}