-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadef_camps.api.inc
23 lines (22 loc) · 959 Bytes
/
adef_camps.api.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
function adef_camps_registration_slots() {
$result = array();
$period_date = adef_camps_get_period_date();
$views_date_arg = $period_date['year'] . '-' . $period_date['month'] . '-' . $period_date['day'] . '--P2D';
$sessions = views_get_view_result('content_blocks', 'block_sessions', $views_date_arg);
foreach ($sessions as $timespace) {
$node = node_load($timespace->nid);
if (!empty($node->field_session)) {
$session = node_load($node->field_session[LANGUAGE_NONE][0]['target_id']);
$workshop = node_load($session->field_workshop[LANGUAGE_NONE][0]['target_id']);
$max = intval($workshop->field_max_participants[LANGUAGE_NONE][0]['value']);
$participants = 0;
if (!empty($node->field_participants)) {
$participants = count($node->field_participants[LANGUAGE_NONE]);
}
$remain = $max-$participants;
$result[$timespace->nid] = $remain;
}
}
drupal_json_output($result);
}