Completed
Push — 7.x-3.x ( d8666b...d48267 )
by Devin
03:54
created

modules/commons/commons_events/includes/commons_events.theme.inc::theme_commons_events_attending_event()   D

Complexity

Conditions 10
Paths 13

Size

Total Lines 39
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 29
nc 13
nop 1
dl 0
loc 39
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @file
4
 * Commons Events theme functions.
5
 */
6
7
/**
8
 * Theme callback to display that a user is attending an event.
9
 */
10
function theme_commons_events_attending_event($variables = array()) {
11
  global $user;
12
  $event = $variables['event'];
13
  if (!$event->nid) {
14
    return '';
15
  }
16
17
  $attendee_count = isset($variables['attendee_count']) ? $variables['attendee_count'] : 0;
18
19
  $registration_type = registration_get_entity_registration_type('node', $event);
20
  $registration = entity_get_controller('registration')->create(array(
21
    'entity_type' => 'node',
22
    'entity_id' => $event->nid,
23
    'type' => $registration_type,
24
    'author_uid' => $user->uid,
25
  ));
26
27
  if (!function_exists('commons_events_attend_event_form')
28
    || !function_exists('commons_events_cancel_event_form')) {
29
    module_load_include('inc', 'commons_events', 'includes/commons_events.forms');
30
  }
31
  if (!registration_is_registered($registration, NULL, $user->uid)
32
    && registration_access('create', $registration, $user, $registration->type)
33
    && registration_status('node', $event->nid, TRUE)) {
34
    return drupal_get_form('commons_events_attend_event_form_' . $event->nid, $event, $registration, $attendee_count);
35
  }
36
  elseif (registration_is_registered($registration, NULL, $user->uid) &&
37
    registration_access('delete', $registration, $user, $registration->type)) {
38
    $query = new EntityFieldQuery();
39
    $query->entityCondition('entity_type', 'registration')
40
      ->propertyCondition('user_uid', $user->uid)
41
      ->propertyCondition('entity_id', $event->nid)
42
      ->propertyCondition('entity_type', 'node');
43
    $result = $query->execute();
44
45
    return drupal_get_form('commons_events_cancel_event_form_' . $event->nid, $event, $result['registration']);
46
  }
47
  return "";
48
}
49
50
/**
51
 * Theme the event attendees list.
52
 */
53
function theme_commons_events_event_attendees($variables = array()) {
54
  $title = '<p class="commons-events-attendees-title">' . t('Attendees') . '</p>';
55
  $event_nid = $variables['event_nid'];
56
  if (!isset($variables['display'])
57
    || $variables['display'] != 'full') {
58
    return $title . views_embed_view('commons_events_event_attendee_list', 'default', $event_nid)
59
      . '<p class="commons-events-all-attendees"><a href="/node/' . $event_nid . '/attendees">'
60
      . t('See all attendees') . '</a></p>';
61
  }
62
  return $title . views_embed_view(
63
    'commons_events_event_attendee_list',
64
    'commons_events_full_attendee_list',
65
    $event_nid);
66
}
67