diff --git a/modules/registration_views/includes/registration_handler_field_entity_capacity_total.inc b/modules/registration_views/includes/registration_handler_field_entity_capacity_total.inc index c46b0ee..346cebc 100644 --- a/modules/registration_views/includes/registration_handler_field_entity_capacity_total.inc +++ b/modules/registration_views/includes/registration_handler_field_entity_capacity_total.inc @@ -1,145 +1,20 @@ tokenize_value($this->options['entity'], 0); - return registration_administer_registrations_access($this->options['entity_type'], (int)$entity, $account); - } - - function get_access_callback() { - $entity = $this->tokenize_value($this->options['entity'], 0); - return array('registration_administer_registrations_access', array($this->options['entity_type'], (int)$entity)); - } - - function summary_title() { - return t('%entity_type with ID %entity', array('%entity_type' => $this->options['entity_type'], '%entity' => $this->options['entity'])); - } - - function option_definition() { - $options = parent::option_definition(); - $options['entity_type'] = array('default' => NULL); - $options['entity'] = array('default' => NULL); - - return $options; - } - - function options_form(&$form, &$form_state) { - parent::options_form($form, $form_state); - - $form['entity_type'] = array( - '#type' => 'textfield', - '#title' => t('Entity type'), - '#default_value' => $this->options['entity_type'], - '#required' => TRUE, - '#description' => t("The type of entity who's permission needs to be checked."), - ); - $form['entity'] = array( - '#type' => 'textfield', - '#title' => t('Entity ID'), - '#default_value' => $this->options['entity'], - '#required' => TRUE, - '#description' => t("The entity ID of the entity who's permission needs to be checked."), - ); - - $count = 0; // This lets us prepare the key as we want it printed. - foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) { - $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name())); - $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name())); - } - - if (!empty($options)) { - $output = '

' . t('The following tokens are available. If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.' . '

'); - foreach (array_keys($options) as $type) { - if (!empty($options[$type])) { - $items = array(); - foreach ($options[$type] as $key => $value) { - $items[] = $key . ' == ' . $value; - } - $output .= theme('item_list', - array( - 'items' => $items, - 'type' => $type - )); - } - } +class registration_handler_field_entity_capacity_total extends views_handler_field_entity { + function render($values) { + $entity = $this->get_value($values); + list($entity_id) = entity_extract_ids($this->entity_type, $entity); - $form['token_help'] = array( - '#type' => 'fieldset', - '#title' => t('Replacement patterns'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#value' => $output, - '#id' => 'edit-options-token-help', - '#dependency' => array( - 'edit-options-tokenize' => array(1), - ), - '#prefix' => '
', - '#suffix' => '
', - ); - } - } + $settings = registration_entity_settings($this->entity_type, $entity_id); - function options_validate(&$form, &$form_state) { - // @todo - if (FALSE && !$form_state['values']['entity_type']) { - form_error($form['entity_type'], t('You must enter a valid entity type.')); + if ($settings['capacity'] != 0) { + return $settings['capacity']; } - } - - /** - * Get the 'render' tokens to use for advanced rendering. - * - * This runs through all of the fields and arguments that - * are available and gets their values. This will then be - * used in one giant str_replace(). - */ - function get_render_tokens() { - $tokens = array(); - if (!empty($this->view->build_info['substitutions'])) { - $tokens = $this->view->build_info['substitutions']; + else { + return t('unlimited'); } - - $path = explode('/', $this->view->display_handler->get_option('path')); - $count = 0; - foreach ($path as $key => $piece) { - if (strpos($piece, '%') !== FALSE) { - $token = '%' . ++$count; - if (!isset($tokens[$token])) { - $tokens[$token] = ''; - } - - // Use strip tags as there should never be HTML in the path. - // However, we need to preserve special characters like " that - // were removed by check_plain(). - $tokens['!' . $count] = $key; - } - } - - return $tokens; - } - - /** - * Replace a value with tokens from the last field. - */ - function tokenize_value($value, $row_index = NULL) { - if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) { - $tokens = $this->get_render_tokens(); - - $value = filter_xss_admin($value); - $value = strtr($value, $tokens); - $value = strip_tags($value); - } - - return $value; } } diff --git a/modules/registration_views/includes/registration_handler_field_entity_capacity_used.inc b/modules/registration_views/includes/registration_handler_field_entity_capacity_used.inc index d8657d7..47188af 100644 --- a/modules/registration_views/includes/registration_handler_field_entity_capacity_used.inc +++ b/modules/registration_views/includes/registration_handler_field_entity_capacity_used.inc @@ -1,7 +1,7 @@ display->display_options['header']['area']['table'] = 'views'; $handler->display->display_options['header']['area']['field'] = 'area'; $handler->display->display_options['header']['area']['empty'] = TRUE; - $handler->display->display_options['header']['area']['content'] = '[capacity_used] total slots used for %1. Registration is [registration_status].'; + $handler->display->display_options['header']['area']['content'] = '[capacity_used] total slots out of [capacity_total] used for %1. Registration is [registration_status].'; $handler->display->display_options['header']['area']['format'] = 'plain_text'; $handler->display->display_options['header']['area']['tokenize'] = TRUE; /* No results behavior: Global: Unfiltered text */ @@ -225,12 +225,18 @@ function registration_views_views_default_views() { $handler->display->display_options['fields']['capacity_used']['relationship'] = 'registration_related_node'; $handler->display->display_options['fields']['capacity_used']['label'] = ''; $handler->display->display_options['fields']['capacity_used']['exclude'] = TRUE; - /* Field: Registration Settings: Registration Status */ + /* Field: Registration Settings: Registration Status */ $handler->display->display_options['fields']['registration_status']['id'] = 'registration_status'; $handler->display->display_options['fields']['registration_status']['table'] = 'node'; $handler->display->display_options['fields']['registration_status']['field'] = 'registration_status'; $handler->display->display_options['fields']['registration_status']['relationship'] = 'registration_related_node'; $handler->display->display_options['fields']['registration_status']['exclude'] = TRUE; + /* Field: Registration Settings: Total spaces */ + $handler->display->display_options['fields']['capacity_total']['id'] = 'capacity_total'; + $handler->display->display_options['fields']['capacity_total']['table'] = 'node'; + $handler->display->display_options['fields']['capacity_total']['field'] = 'capacity_total'; + $handler->display->display_options['fields']['capacity_total']['relationship'] = 'registration_related_node'; + $handler->display->display_options['fields']['capacity_total']['exclude'] = TRUE; /* Contextual filter: Registration: Host entity ID */ $handler->display->display_options['arguments']['entity_id']['id'] = 'entity_id'; $handler->display->display_options['arguments']['entity_id']['table'] = 'registration'; diff --git a/modules/registration_views/registration_views.module b/modules/registration_views/registration_views.module index 867362a..cc9fffd 100644 --- a/modules/registration_views/registration_views.module +++ b/modules/registration_views/registration_views.module @@ -283,6 +283,17 @@ function registration_views_views_data_alter(&$data) { ), ); + // Host entity: total slots. + $data[$info['base table']]['capacity_total'] = array( + 'real field' => $info['entity keys']['id'], + 'group' => t('Registration Settings'), + 'title' => t('Total spaces'), + 'help' => t('Maximum number of spaces available for this entity.'), + 'field' => array( + 'handler' => 'registration_handler_field_entity_capacity_total', + ), + ); + // Host entity: used slots. $data[$info['base table']]['capacity_used'] = array( 'real field' => $info['entity keys']['id'],