You are here

function event_admin_events in Event Calendar 7

Form builder: Builds the event administration overview.

See also

event_available_terms()

event_build_filter_query()

event_calendar_dates()

event_calendar_status()

1 call to event_admin_events()
event_calendar_content in ./event_calendar.list.inc
Menu callback: Events administration.

File

./event_calendar.list.inc, line 16
Event administration UI.

Code

function event_admin_events() {
  $admin_access = user_access('administer event status');
  $node_type = variable_get('event_calendar_node_type', 'event_calendar');

  // Build the 'Update options' form.
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update Status'),
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
    '#access' => $admin_access,
  );
  $options = event_available_terms();

  // Unset 'any' option.
  unset($options['0']);

  // Sort options array.
  asort($options);
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Operation'),
    '#title_display' => 'invisible',
    '#options' => $options,
    '#default_value' => 'approve',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
    '#validate' => array(
      'event_admin_events_validate',
    ),
    '#submit' => array(
      'event_admin_events_submit',
    ),
  );

  // Build the sortable table header.
  $header = array(
    'title' => array(
      'data' => t('Title'),
      'field' => 'n.title',
    ),
    'start-date' => array(
      'data' => t('Start Date (y-m-d)'),
      'field' => 'n.changed',
      'sort' => 'desc',
    ),
    'end-date' => array(
      'data' => t('End Date (y-m-d)'),
      'field' => 'n.changed',
      'sort' => 'desc',
    ),
    'status' => array(
      'data' => t('Status'),
      'field' => 'n.status',
    ),
  );
  $query = db_select('node', 'n')
    ->extend('PagerDefault')
    ->extend('TableSort');
  event_build_filter_query($query);
  $nids = $query
    ->fields('n', array(
    'nid',
  ))
    ->condition('type', $node_type)
    ->limit(50)
    ->orderByHeader($header)
    ->addTag('node_access')
    ->execute()
    ->fetchCol();
  $nodes = node_load_multiple($nids);

  // Prepare the list of event nodes.
  $languages = language_list();
  $destination = drupal_get_destination();
  $options = array();
  foreach ($nodes as $node) {

    // Collect events Dates.
    $dates = event_calendar_dates($node);

    // Collect events status/
    $status = event_calendar_status($node);

    // Set flag for expired events.
    if (is_event_expired($node, 'load')) {
      $flag1 = t("<i>**");
      $flag2 = t("</i>");
    }
    else {
      $flag1 = "";
      $flag2 = "";
    }
    $langcode = '';
    if (function_exists('entity_language')) {
      $langcode = entity_language('node', $node);
    }
    $l_options = $langcode != LANGUAGE_NONE && isset($languages[$langcode]) ? array(
      'language' => $languages[$langcode],
    ) : array();
    $options[$node->nid] = array(
      'title' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => $node->title,
          '#href' => 'node/' . $node->nid,
          '#options' => $l_options,
          '#suffix' => ' ' . theme('mark', array(
            'type' => node_mark($node->nid, $node->changed),
          )),
        ),
      ),
      'start-date' => $dates['start_date'],
      'end-date' => $dates['end_date'],
      'status' => $flag1 . $status . $flag2,
    );
  }
  $form['events'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No content available.'),
  );
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  return $form;
}