diff --git a/culturefeed.helpers.inc b/culturefeed.helpers.inc index 0f51558d..3e48cecb 100644 --- a/culturefeed.helpers.inc +++ b/culturefeed.helpers.inc @@ -58,8 +58,10 @@ function culturefeed_create_user($cf_account, $user = NULL) { if (!$cf_account || empty($cf_account->nick)) { return FALSE; } + + $uid = db_query("SELECT uid FROM {culturefeed_user} cfu WHERE cfu.uid = :uid", array(':uid' => $user->uid))->fetchField(); - if (isset($user->uid) && $user->uid) { + if (isset($user->uid) && $user->uid && $user->uid != $uid) { // User is already Drupaluser, so map his Drupal and CultureFeed account $account = $user; } diff --git a/culturefeed.module b/culturefeed.module index f6c70b3a..2bd963da 100644 --- a/culturefeed.module +++ b/culturefeed.module @@ -218,20 +218,54 @@ function culturefeed_page_build(&$page) { $gtm_globals['search_query'] = json_encode(drupal_get_query_parameters()); } - // Check if it is an event detail page. - $gtm_globals['is_event_detail'] = (arg(0) == 'agenda' && arg(1) == 'e'); - if ($gtm_globals['is_event_detail']) { - - $event = menu_get_object('culturefeed_agenda_event', 3); - if ($event) { - $gtm_globals['event_detail_title'] = culturefeed_agenda_detail_title($event); - $gtm_globals['cdbid'] = arg(3); + // Check if it is a detail page. + $gtm_globals['is_detail'] = (arg(0) == 'agenda' && in_array(arg(1), array('e', 'a', 'p', 'g'))); + if ($gtm_globals['is_detail']) { + + // Make this backwards compatible + $gtm_globals['is_event_detail'] = TRUE; + + if (arg(1) == 'e') { + $event = menu_get_object('culturefeed_agenda_event', 3); + if ($event) { + $gtm_globals['detail_title'] = culturefeed_agenda_detail_title($event); + $gtm_globals['detail_type'] = 'event'; + $gtm_globals['cdbid'] = arg(3); + } + } + + else if (arg(1) == 'a') { + $actor = menu_get_object('culturefeed_agenda_actor', 3); + if ($actor) { + $gtm_globals['detail_title'] = culturefeed_agenda_detail_title($actor); + $gtm_globals['detail_type'] = 'actor'; + $gtm_globals['cdbid'] = arg(3); + } + } + + else if (arg(1) == 'p') { + $production = menu_get_object('culturefeed_agenda_production', 3); + if ($production) { + $gtm_globals['detail_title'] = culturefeed_agenda_detail_title($production); + $gtm_globals['detail_type'] = 'production'; + $gtm_globals['cdbid'] = arg(3); + } + } + + else if (arg(1) == 'g') { + $cfpage = menu_get_object('culturefeed_pages_page', 3); + if ($cfpage) { + $gtm_globals['detail_title'] = culturefeed_pages_detail_title($cfpage); + $gtm_globals['detail_type'] = 'page'; + $gtm_globals['cdbid'] = arg(3); + } } } // Add custom dimensions. $gtm_globals['consumer_key'] = variable_get('culturefeed_api_application_key', ''); + $gtm_globals['consumer_name'] = variable_get('site_name', ''); $gtm_globals['login_status'] = user_is_logged_in(); // Set the script code. diff --git a/culturefeed.pages.inc b/culturefeed.pages.inc index 22c56709..cdfa013f 100644 --- a/culturefeed.pages.inc +++ b/culturefeed.pages.inc @@ -108,8 +108,11 @@ function culturefeed_oauth_authorize($application_key = NULL) { $account = culturefeed_create_user($cf_account, $user); } else { - // If the drupal user already exist we update the reference in the culturefeed_user table - if ($user->uid && $user->uid != $uid) { + + $cf_uid = db_query("SELECT cf_uid FROM {culturefeed_user} cfu WHERE cfu.uid = :uid", array(':uid' => $user->uid))->fetchField(); + + // If the drupal user already exist with another cf_uid we update the reference + if (!$cf_uid && $user->uid && $user->uid != $uid) { $query = db_update('culturefeed_user') ->condition('cf_uid', $cf_account->id) ->fields(array('uid' => $user->uid)) diff --git a/culturefeed_agenda/culturefeed_agenda.module b/culturefeed_agenda/culturefeed_agenda.module index ff0ff8dc..55311465 100644 --- a/culturefeed_agenda/culturefeed_agenda.module +++ b/culturefeed_agenda/culturefeed_agenda.module @@ -90,6 +90,13 @@ function culturefeed_agenda_theme() { 'path' => $path, ); + $theme['culturefeed_agenda_actors_nearby'] = array( + 'variables' => array('items' => array()), + 'template' => 'culturefeed-agenda-actors-nearby', + 'path' => $path, + 'file' => 'theme.inc', + ); + return $theme; } @@ -172,6 +179,15 @@ function culturefeed_agenda_menu() { 'file' => 'includes/pages.inc', ); + $items['admin/config/culturefeed/agenda'] = array( + 'title' => 'CultureFeed Agenda', + 'description' => 'Change CultureFeed Agenda settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('culturefeed_agenda_admin_settings_form'), + 'access arguments' => array('administer site configuration'), + 'file' => 'includes/admin.inc', + ); + // Autocomplete for event / production suggestions $items['autocomplete/culturefeed/activity-suggestion'] = array( 'page callback' => 'culturefeed_agenda_activity_suggestion_autocomplete_page', @@ -197,6 +213,14 @@ function culturefeed_agenda_menu() { 'file' => 'includes/pages.inc', ); + $items['autocomplete/culturefeed/agenda/actor-search'] = array( + 'page callback' => 'culturefeed_agenda_actor_search_autocomplete', + 'page arguments' => array(4, TRUE), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + 'file' => 'includes/pages.inc', + ); + return $items; } @@ -284,6 +308,11 @@ function culturefeed_agenda_block_info() { 'cache' => DRUPAL_CACHE_PER_PAGE, ); + $blocks['agenda-actor-search'] = array( + 'info' => t('Culturefeed agenda: actor search'), + 'cache' => DRUPAL_CACHE_PER_PAGE, + ); + return $blocks; } @@ -358,6 +387,29 @@ function culturefeed_agenda_block_configure($delta) { '#default_value' => variable_get('agenda_search_block_domain_id'), ); + } + elseif ($delta == 'agenda-actor-search') { + + $options = culturefeed_search_get_actortype_categories(); + asort($options); + $form['agenda_actor_search'] = array( + '#title' => t('Available actortype categories.'), + '#description' => t('Select the actortype categories that will be used to filter the autocomplete.'), + '#type' => 'checkboxes', + '#options' => $options, + '#default_value' => variable_get('agenda_actor_search'), + ); + + $visibility_options = culturefeed_search_get_categories_by_domain('eventtype'); + asort($visibility_options); + $form['agenda_actor_search_visibility'] = array( + '#title' => t('Visibility settings.'), + '#description' => t('Select the eventtypes where tis block may be visible.'), + '#type' => 'checkboxes', + '#options' => $visibility_options, + '#default_value' => variable_get('agenda_actor_search_visibility'), + ); + } return $form; @@ -380,6 +432,10 @@ function culturefeed_agenda_block_save($delta, $edit) { elseif ($delta == 'agenda-search-block') { variable_set('agenda_search_block_domain_id', $edit['agenda_search_block_domain_id']); } + elseif ($delta == 'agenda-actor-search') { + variable_set('agenda_actor_search', $edit['agenda_actor_search']); + variable_set('agenda_actor_search_visibility', $edit['agenda_actor_search_visibility']); + } } @@ -406,6 +462,8 @@ function culturefeed_agenda_block_view($delta) { case 'production-program': return culturefeed_agenda_block_production_program(); + case 'agenda-actor-search': + return culturefeed_agenda_block_actor_search_facet(); } return $block; @@ -429,7 +487,7 @@ function culturefeed_agenda_culturefeed_search_ui_active_filters($culturefeedFac unset($search_query['actor']); $url = url($path, array('query' => $search_query)); $build['nearby'] = array( - '#theme' => 'culturefeed_search_active_filters_item', + '#theme' => 'cul turefeed_search_active_filters_item', '#label' => check_plain($actor->getTitle(culturefeed_search_get_preferred_language())), '#url' => $url, ); diff --git a/culturefeed_agenda/includes/admin.inc b/culturefeed_agenda/includes/admin.inc new file mode 100644 index 00000000..3b085dad --- /dev/null +++ b/culturefeed_agenda/includes/admin.inc @@ -0,0 +1,39 @@ + t('Entity types to be searched'), + '#type' => 'checkboxes', + '#options' => culturefeed_agenda_known_entity_types(), + '#default_value' => variable_get('culturefeed_agenda_active_entity_types', array('event', 'production')), + '#description' => t('Select the different entity types that can be shown on agenda/search'), + ); + + $form = system_settings_form($form); + $form['#submit'] = array('culturefeed_agenda_admin_settings_form_submit'); + + return $form; + +} + +/** + * Submit the settings form. + */ +function culturefeed_agenda_admin_settings_form_submit($form, $form_state) { + + $form_state['values']['culturefeed_agenda_active_entity_types'] = array_filter($form_state['values']['culturefeed_agenda_active_entity_types']); + system_settings_form_submit($form, $form_state); + +} + diff --git a/culturefeed_agenda/includes/blocks.inc b/culturefeed_agenda/includes/blocks.inc index 0a570f21..4a42d3ef 100644 --- a/culturefeed_agenda/includes/blocks.inc +++ b/culturefeed_agenda/includes/blocks.inc @@ -4,6 +4,8 @@ * Block callbacks for culturefeed agenda. */ +use \CultuurNet\Search\Parameter; + /** * Block to show the related events from an item. */ @@ -55,10 +57,20 @@ function culturefeed_agenda_search_block_form($form, &$form_state) { } asort($options); + if (isset($_GET['facet']['category_' . $domain_id . '_id'][0])) { + $default = $_GET['facet']['category_' . $domain_id . '_id'][0]; + } + elseif (isset($_GET['facet']['category_id'][0])) { + $default = $_GET['facet']['category_id'][0]; + } + else { + $default = NULL; + } + $form['category'] = array( '#type' => 'select', '#options' => $options, - '#default_value' => isset($_GET['facet']['category_' . $domain_id . '_id'][0]) ? $_GET['facet']['category_' . $domain_id . '_id'][0] : NULL, + '#default_value' => $default, ); $form_state['#domain_id'] = $domain_id; @@ -246,3 +258,76 @@ function culturefeed_agenda_block_production_program() { return $block; } + +function culturefeed_agenda_block_actor_search_facet() { + + // Only go if we're on an agenda search page. + if (current_path() != 'agenda/search') { + return; + } + + // Only show this block if allowed in the block settings. + if (isset($_GET['facet']['category_eventtype_id'][0])) { + $current_event = $_GET['facet']['category_eventtype_id'][0]; + } + elseif (isset($_GET['facet']['category_id'][0])) { + $current_event = $_GET['facet']['category_id'][0]; + } + else { + $current_event = ''; + } + + $saved_events = variable_get('agenda_actor_search_visibility'); + $allowed_events = array(); + + foreach ($saved_events as $saved_event) { + if ($saved_event != 0) { + $allowed_events[] = $saved_event; + } + } + + if (!in_array($current_event, $allowed_events)) { + return; + } + + // Create build array with actor search form and nearby actors. + $build = array(); + $build['form'] = drupal_get_form('culturefeed_agenda_block_actor_search_form'); + $build['actors_nearby'] = culturefeed_agenda_get_actors_nearby_for_event($current_event); + + return array( + 'subject' => t('Actor'), + 'content' => $build, + ); +} + +/** + * Form callback to show the agenda actor search block. + */ +function culturefeed_agenda_block_actor_search_form($form, &$form_state) { + $form = array(); + + $form['#attached']['js'] = array( + array('data' => CULTUREFEED_GOOGLE_MAPS_JS_API, 'type' => 'external'), + drupal_get_path('module', 'culturefeed_agenda') . '/js/autocomplete_autosubmit.js', + ); + $form['#attached']['library'] = array( + array('system', 'jquery.cookie'), + ); + + $form['search'] = array( + '#type' => 'textfield', + '#size' => 28, + '#title' => t('Search string'), + '#title_display' => 'invisible', + '#attributes' => array('class' => array('auto-submit-field'), 'placeholder' => t('Plaats of naam')), + '#autocomplete_path' => 'autocomplete/culturefeed/agenda/actor-search' + ); + + return $form; +} + + + + + diff --git a/culturefeed_agenda/includes/helpers.inc b/culturefeed_agenda/includes/helpers.inc index 4c7262bc..a11d2c5a 100644 --- a/culturefeed_agenda/includes/helpers.inc +++ b/culturefeed_agenda/includes/helpers.inc @@ -4,6 +4,19 @@ * Helper functions for the culturefeed agenda. **/ +/** + * Return all the known agenda entity types. + */ +function culturefeed_agenda_known_entity_types() { + + return array( + 'event' => t('event', array(), array('context' => 'culturefeed-facets')), + 'production' => t('production', array(), array('context' => 'culturefeed-facets')), + 'actor' => t('actor', array(), array('context' => 'culturefeed-facets')), + ); + +} + /** * Get the current active agenda object. * @param $path @@ -260,7 +273,7 @@ function culturefeed_agenda_get_production_program_data_for_item(Cultuurnet\Sear 'city' => isset($location['city']) ? $location['city'] : '', 'venue' => isset($location['title']) ? $location['title'] : '', ); - + // Extend with an url to the actor. // This can be an organiser, or a location. $organiser = $cdb_item->getOrganiser(); @@ -543,8 +556,8 @@ function culturefeed_agenda_load_events_of_production($production, $future_only function culturefeed_agenda_parse_weekscheme(CultureFeed_Cdb_Data_Calendar_Weekscheme $weekscheme) { $weekscheme_array = array(); - - foreach ($weekscheme->getDays() as $day) { + + foreach ($weekscheme->getDays() as $day) { $weekscheme_array[$day->getDayName()] = array( 'type' => $day->getOpenType(), ); @@ -602,14 +615,14 @@ function culturefeed_agenda_parse_timestamps($timestamps) { } function culturefeed_agenda_group_timestamps(&$timestamps) { - + for ($i=0; $irewind(); if ($calendar_class == 'CultureFeed_Cdb_Data_Calendar_PeriodList') { - + $calendar_array = array( 'type' => 'period', 'period_start' => $calendar->current()->getDateFrom(), 'period_end' => $calendar->current()->getDateTo(), ); - if ($calendar->current()->getWeekScheme()) { + if ($calendar->current()->getWeekScheme()) { $calendar_array['weekscheme'] = culturefeed_agenda_parse_weekscheme($calendar->current()->getWeekScheme()); } if ($calendar->current()->getExceptions()) { $calendar_array['exceptions'] = culturefeed_agenda_parse_timestamps($calendar->current()->getExceptions()); } - + } elseif ($calendar_class == 'CultureFeed_Cdb_Data_Calendar_Permanent') { $calendar_array = array( 'type' => 'permanent', ); - + if ($calendar->getWeekScheme()) { $calendar_array['weekscheme'] = culturefeed_agenda_parse_weekscheme($calendar->getWeekScheme()); } if ($calendar->getExceptions()) { $calendar_array['exceptions'] = culturefeed_agenda_parse_timestamps($calendar->getExceptions()); } - + } elseif ($calendar_class == 'CultureFeed_Cdb_Data_Calendar_TimestampList') { $calendar_array = array( @@ -669,4 +682,48 @@ function culturefeed_agenda_parse_calendar($calendar) { $calendar_array['timestamps'] = culturefeed_agenda_group_timestamps($calendar_array['timestamps']); } return $calendar_array; +} + +/** + * Function to search for 5 actors in the neighbourhood for a given eventtype. + * @param type $event + * The tid of the eventtype. + * @return string + * A string with html links. + */ +function culturefeed_agenda_get_actors_nearby_for_event($event) { + + $type = db_query('SELECT slug FROM {culturefeed_search_terms} WHERE tid = :tid AND language = :language', array(':tid' => $event, ':language' => culturefeed_search_get_preferred_language()))->fetchField(); + $coordinates = json_decode($_COOKIE['uitid_location']); + $point = new \CultuurNet\Search\Parameter\Spatial\Point($coordinates->latitude, $coordinates->longitude); + $distance = new \CultuurNet\Search\Parameter\Spatial\Distance(CULTUREFEED_SEARCH_DEFAULT_PROXIMITY_RANGE); + $field = new \CultuurNet\Search\Parameter\Spatial\SpatialField('physical_gis'); + $parameters = array(); + $parameters[] = new \CultuurNet\Search\Parameter\Spatial\GeoFilterQuery($point, $distance, $field); + $parameters[] = new \CultuurNet\Search\Parameter\Rows(5); + $parameters[] = new \CultuurNet\Search\Parameter\Query($type); + $parameters[] = new \CultuurNet\Search\Parameter\FilterQuery('type:actor'); + + try { + + $result = culturefeed_get_search_service()->search($parameters); + + if ($result->getTotalCount() == 0) { + return; + } + + $items = $result->getItems(); + + } + catch (Exception $e) { + watchdog_exception('culturefeed_agenda', $e); + return; + } + + $actors = array( + '#theme' => 'culturefeed_agenda_actors_nearby', + '#items' => $items, + ); + + return $actors; } \ No newline at end of file diff --git a/culturefeed_agenda/includes/pages.inc b/culturefeed_agenda/includes/pages.inc index 48ede33c..92ad60ee 100644 --- a/culturefeed_agenda/includes/pages.inc +++ b/culturefeed_agenda/includes/pages.inc @@ -219,3 +219,30 @@ function culturefeed_agenda_page_ajax_related_activities($cdb_id) { ajax_deliver(array('#type' => 'ajax', '#commands' => $commands)); } + +function culturefeed_agenda_actor_search_autocomplete($search, $past) { + + $matches = array(); + + if ($search) { + + try { + + // Get the list of suggestions from service. + $suggestions = culturefeed_get_search_service()->searchSuggestions($search, array('actor'), $past); + // @todo: only use suggestions for the actortypes saved in block configure. + if ($suggestions->hasSuggestions()) { + foreach ($suggestions as $suggestion) { + $path = culturefeed_search_detail_url('actor', $suggestion->getCdbid(), $suggestion->getTitle()); + $matches[$path] = check_plain($suggestion->getTitle()); + } + } + + } + catch (ClientErrorResponseException $e) { + watchdog_exception('culturefeed_agenda', $e); + } + + } + drupal_json_output($matches); +} diff --git a/culturefeed_agenda/js/autocomplete_autosubmit.js b/culturefeed_agenda/js/autocomplete_autosubmit.js new file mode 100644 index 00000000..12a96ed9 --- /dev/null +++ b/culturefeed_agenda/js/autocomplete_autosubmit.js @@ -0,0 +1,36 @@ +(function ($) { + + Drupal.jsAC.prototype.select = function (node) { + + if($(this.input).hasClass('auto-submit-field')) { + window.location.href = $(node).data('autocompleteValue'); + } + }; + + $(document).ready(function() { + if (navigator.geolocation) { + + //if the browser supports geolocations get along and execute + navigator.geolocation.getCurrentPosition( function (position) { + //build up the querie for the google api + var geocoder = new google.maps.Geocoder(); + var lat = parseFloat(position.coords.latitude); + var lng = parseFloat(position.coords.longitude); + var latlng = new google.maps.LatLng(lat, lng); + + // execute the request and send the respons to addpostalcode function + geocoder.geocode({'latLng': latlng}, function (response) { + + var location = { + latitude : response[0].geometry.location.lat(), + longitude : response[0].geometry.location.lng(), + } + + $.cookie('uitid_location', JSON.stringify(location)); + }); + }); + + } + }) + +})(jQuery); diff --git a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php index c7b61538..8ae51110 100644 --- a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php +++ b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php @@ -37,12 +37,32 @@ public function initialize() { $this->addQueryTerm(preg_replace("/\/\b|\b:/x", "", $params['search'])); } + $add_type_filter = TRUE; + if (isset($params['facet']['type'])) { + $active_types = $params['facet']['type']; + unset($params['facet']['type']); + } + else { + $active_types = variable_get('culturefeed_agenda_active_entity_types', array('event', 'production')); + // If all active types are selected, don't add filter. + if (count($active_types) == count(culturefeed_agenda_known_entity_types())) { + $add_type_filter = FALSE; + } + } + + if ($add_type_filter) { + array_walk($active_types, function(&$active_type) { + $active_type = 'type:' . $active_type; + }); + $this->parameters[] = new Parameter\FilterQuery(implode(' OR ', $active_types)); + } + $this->addFacetFilters($params); - $this->parameters[] = new Parameter\FilterQuery('type:event OR type:production'); $this->parameters[] = $this->facetComponent->facetField('category'); $this->parameters[] = $this->facetComponent->facetField('datetype'); $this->parameters[] = $this->facetComponent->facetField('city'); + $this->parameters[] = $this->facetComponent->facetField('location_category_facility_id'); $this->execute($params); @@ -181,8 +201,9 @@ private function translateFacets() { $translated_terms = array(); $facets = $this->facetComponent->getFacets(); foreach ($facets as $key => $facet) { - // The key should start with 'category_' - if (substr($key, 0, 9) == 'category_') { + // The key should start with 'category_' or 'location_' + $start = substr($key, 0, 9); + if (in_array($start, array('category_', 'location_'))) { $items = $facet->getResult()->getItems(); foreach ($items as $item) { $found_ids[$item->getValue()] = $item->getValue(); @@ -198,8 +219,9 @@ private function translateFacets() { // Translate the facets labels. foreach ($facets as $key => $facet) { - // The key should start with 'category_' - if (substr($key, 0, 9) == 'category_') { + // The key should start with 'category_' or 'location_' + $start = substr($key, 0, 9); + if (in_array($start, array('category_', 'location_'))) { $items = $facet->getResult()->getItems(); foreach ($items as $item) { // Translate if found. diff --git a/culturefeed_agenda/theme/culturefeed-actor-summary.tpl.php b/culturefeed_agenda/theme/culturefeed-actor-summary.tpl.php index 2c3c2413..3def8ae5 100644 --- a/culturefeed_agenda/theme/culturefeed-actor-summary.tpl.php +++ b/culturefeed_agenda/theme/culturefeed-actor-summary.tpl.php @@ -2,16 +2,38 @@ /** * @file * Template for the summary of an actor. + * Please don't remove the cf- prefixed id's. This is used by GTM for user behavior tracking. + * Some day your client will benefit from our aggregated insights & benchmarks too. + * See https://github.com/cultuurnet/culturefeed/wiki/Culturefeed-tracking + * Thanks! */ ?> -

- - - +
- - - +

array('id' => 'cf-title_' . $cdbid))); ?>

+ +
+ + ', array('attributes' => array('id' => 'cf-image_' . $cdbid), 'html' => TRUE)); ?> + +
+ +
+ + +
+
+ + + +
+
+ + +
+ + array('class' => 'button', 'id' => 'cf-readmore_' . $cdbid))); ?> + +
- array('class' => 'button'))); ?> diff --git a/culturefeed_agenda/theme/culturefeed-agenda-actors-nearby.tpl.php b/culturefeed_agenda/theme/culturefeed-agenda-actors-nearby.tpl.php new file mode 100644 index 00000000..8b6b28ee --- /dev/null +++ b/culturefeed_agenda/theme/culturefeed-agenda-actors-nearby.tpl.php @@ -0,0 +1,10 @@ + + + + + diff --git a/culturefeed_agenda/theme/culturefeed-production-summary.tpl.php b/culturefeed_agenda/theme/culturefeed-production-summary.tpl.php index 39e46bac..2468d5b6 100644 --- a/culturefeed_agenda/theme/culturefeed-production-summary.tpl.php +++ b/culturefeed_agenda/theme/culturefeed-production-summary.tpl.php @@ -1,4 +1,4 @@ -cf-review-readgetTitle()); - $variables['shortdescription'] = $detail->getShortDescription(); + $variables['shortdescription'] = check_plain($detail->getShortDescription()); $variables['longdescription'] = $detail->getLongDescription(); // Ad id / title to Drupal settings for easy reference in GTM. @@ -325,6 +325,10 @@ function _culturefeed_agenda_preprocess_agenda(&$variables) { $variables['keywords'] = ''; if ($keywords) { $variables['keywords'] = implode(', ', $keywords); + // check if event is suitable for kids + if (array_key_exists('ook voor kinderen', $keywords)) { + $variables['forkids'] = TRUE; + } } } @@ -351,7 +355,7 @@ function _culturefeed_agenda_preprocess_agenda_detail(&$variables) { $variables['videos'] = array(); $videos = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_VIDEO); foreach ($videos as $video) { - if ($video_embed = _culturefeed_search_ui_video_url_to_embed($video->getHLink(), 240, 180)) { + if ($video_embed = _culturefeed_search_ui_video_url_to_embed($video->getHLink())) { $variables['videos'][] = $video_embed; } } @@ -389,6 +393,9 @@ function _culturefeed_agenda_preprocess_event(&$variables) { $event_detail = $event->getDetails()->getDetailByLanguage(culturefeed_search_get_preferred_language()); $variables['agefrom'] = check_plain($event->getAgeFrom()); + if (is_numeric($event->getAgeFrom()) && ($event->getAgeFrom() <= 12)) { + $variables['forkids'] = TRUE; + } $variables['location'] = culturefeed_agenda_get_location_of_event($event); $actor = NULL; @@ -493,6 +500,9 @@ function _culturefeed_agenda_preprocess_production(&$variables) { $organiser = $production->getOrganiser(); $variables['agefrom'] = $production->getAgeFrom(); + if (is_numeric($production->getAgeFrom()) && ($production->getAgeFrom() <= 12)) { + $variables['forkids'] = TRUE; + } $relations = $production->getRelations(); $total_relations = count($relations); @@ -608,7 +618,7 @@ function _culturefeed_agenda_preprocess_actor(&$variables) { // Mails. $mails = array(); foreach ($contact_info->getMails() as $mail) { - $mails[] = l($mail->getMailAddress(), 'mailto:' . $mail->getMailAddress()); + $mails[] = l($mail->getMailAddress(), 'mailto:' . $mail->getMailAddress(), array('attributes' => array('id' => 'cf-contact'))); } $variables['contact']['mail'] = implode(', ', $mails); @@ -885,3 +895,22 @@ function culturefeed_agenda_preprocess_culturefeed_agenda_de_lijn_widget(&$varia drupal_add_js(array('delijn' => $settings), 'setting'); } + +/** + * Preprocess the agenda nearby actor search. + */ +function culturefeed_agenda_preprocess_culturefeed_agenda_actors_nearby(&$variables) { + + //Create link for each actor. + $actors = array(); + + foreach ($variables['items'] as $item) { + $title = $item->getTitle(culturefeed_search_get_preferred_language()); + $id = $item->getId(); + $url = culturefeed_search_detail_url('actor', $id, $title); + $actors[] = l($title, $GLOBALS['base_url'] . $url); + } + + $variables['links'] = implode(', ', $actors); + +} diff --git a/culturefeed_devel/culturefeed_devel.module b/culturefeed_devel/culturefeed_devel.module index 05f6e224..68d4260d 100644 --- a/culturefeed_devel/culturefeed_devel.module +++ b/culturefeed_devel/culturefeed_devel.module @@ -107,15 +107,35 @@ function culturefeed_devel_shutdown() { } // Don't add output on ajax / drush / xml requests. - $content_type = drupal_get_http_header('content-type'); - if (drupal_is_cli() || $content_type == 'text/xml' || !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { - return; + if (culturefeed_devel_show_log() && variable_get('culturefeed_devel_show_requests', TRUE) && user_access('access culturefeed devel information')) { + print culturefeed_devel_requests_table($requests, $max_time); } - if (variable_get('culturefeed_devel_show_requests', TRUE) && user_access('access culturefeed devel information')) { - print culturefeed_devel_requests_table($requests, $max_time); +} + +/** + * Check if the log should be shown. + * @return bool + */ +function culturefeed_devel_show_log() { + + $content_type = drupal_get_http_header('content-type'); + if (strpos($content_type, 'text/html') === FALSE || !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { + return FALSE; } + return !( + function_exists('drupal_is_cli') && drupal_is_cli() || + (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'ApacheBench') !== FALSE) || + !empty($_REQUEST['XDEBUG_PROFILE']) || + isset($GLOBALS['devel_shutdown']) || + strstr($_SERVER['PHP_SELF'], 'update.php') || + (isset($_GET['q']) && ( + in_array($_GET['q'], array( 'admin/content/node-settings/rebuild')) || + substr($_GET['q'], 0, strlen('system/files')) == 'system/files' || + substr($_GET['q'], 0, strlen('batch')) == 'batch' || + substr($_GET['q'], 0, strlen('file/ajax')) == 'file/ajax') + )); } /** diff --git a/culturefeed_entry_ui/css/culturefeed_entry_ui.css b/culturefeed_entry_ui/css/culturefeed_entry_ui.css index 9dcce588..8772804e 100644 --- a/culturefeed_entry_ui/css/culturefeed_entry_ui.css +++ b/culturefeed_entry_ui/css/culturefeed_entry_ui.css @@ -73,10 +73,6 @@ clear: left; } -#when-ajax-wrapper { - clear: left; -} - .link-field { float: left; } @@ -156,41 +152,6 @@ input.add-more-link:hover { float: left; } -/* dates */ - -.when-datetimes .container-inline-date .date-padding { - padding: 0; - float: none; -} - -.when-datetimes input.add-more-link { - display: inline-block; - vertical-align: middle; -} - -.when-datetimes-table { - width: auto !important; -} - -.when-datetimes-table td { - white-space: nowrap; - padding: 4px; - vertical-align: top; -} - -.when-datetimes-table td .container-inline-date .form-item .form-item { - display: inline-block; - float: none; -} - -.when-datetimes-table td .container-inline-date .form-item { - vertical-align: top; -} - -.when-datetimes-table .ui-icon { - display: inline-block; -} - /* Photo */ .photo_thumbnail { diff --git a/culturefeed_entry_ui/culturefeed_date_control/README.txt b/culturefeed_entry_ui/culturefeed_date_control/README.txt new file mode 100644 index 00000000..fbd02cef --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/README.txt @@ -0,0 +1,21 @@ +This module contains a drupal form element to enter or modify culturefeed dates. + +The dates can be of different formats: +* timestamps (date and optional time) +* period (start date and end date including opening hours) +* opening times (including culturefeed weekscheme). + +To provide flexible form elements, this module provides form elements for +each individual type and these can be used separately. The actual date control +form element uses the three above elements and a hybrid element. The hybrid +element is an element that switches to one of the other elements depending on +initial input. + +Developers: +* The form is very depending on user interaction. Therefore all manipulation of + the form is done on user input level. This because the manipulation is on + elements (adding and/or removing elements) and not data. This means working + with element value callback and form state input. This also ensures that the + final date in form state values stays clean. +* The actual manipulation is done in element validate functions, a common core + practice. \ No newline at end of file diff --git a/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control.css b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control.css new file mode 100644 index 00000000..0f7af494 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control.css @@ -0,0 +1,36 @@ +@CHARSET "UTF-8"; + +/* dates */ + +table.date-control-table { + width: auto; +} + +.date-control-table .container-inline-date .date-padding { + padding: 0; + float: none; +} + +.date-control-table .ui-icon { + display: inline-block; +} + +.date-control-table input.add-more-link { + display: inline-block; + vertical-align: middle; +} + +.date-control-table td { + white-space: nowrap; + padding: 4px; + vertical-align: top; +} + +.date-control-table td .container-inline-date .form-item .form-item { + display: inline-block; + float: none; +} + +.date-control-table td .container-inline-date .form-item { + vertical-align: top; +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_opening_times.css b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_opening_times.css new file mode 100644 index 00000000..ddccd50a --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_opening_times.css @@ -0,0 +1,7 @@ +@CHARSET "UTF-8"; + +/* dates */ + +table.date-control-opening-times-table { + width: 100% !important; +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.info b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.info new file mode 100644 index 00000000..b40b31fb --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.info @@ -0,0 +1,5 @@ +name = CultureFeed Entry UI Date control +description = Form element to manage dates in the Entry UI. +package = CultureFeed +version = VERSION +core = 7.x diff --git a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module new file mode 100644 index 00000000..c56718f5 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module @@ -0,0 +1,282 @@ + 'ajax', + '#commands' => ajax_prepare_response($output), + ); + return $result; + +} + +/** + * Checks if the triggering element is part of the element. + * + * @param array $triggering_element + * The triggering element. + * @param array $element + * The element. + * + * @return bool + * True or false. + */ +function culturefeed_date_control_check_trigger_element(array $triggering_element, array $element) { + return array_intersect($triggering_element['#parents'], $element['#parents']) == $element['#parents']; +} + +/** + * Adds a span element for a calendar icon on date popup fields. + * + * @param array $element + * The element. + * @param array $form_state + * The form state. + * + * @return array + * The element. + */ +function culturefeed_date_control_element_date_popup_after_build(array $element, array $form_state) { + if (isset($element['date']) && isset($element['#icon']) && $element['#icon']) { + $element['date']['#suffix'] = ""; + } + return $element; +} + +/** + * Implements hook_element_info(). + * + * This is a complex ajax driven form element. Several new ajax buttons are + * added based on initial interaction or default value. Most of the logic is + * taken from the core managed file field. + * + * - To ensure all buttons remain registered in the form, visibility is set + * through access in a pre render function. + * - Element validation functions are used to set the data. + * - A custom ajax callback path to ensure the form is rerenderd. + * + * @see file_managed_file_pre_render() + * @see file_managed_file_value() + */ +function culturefeed_date_control_element_info() { + return array( + 'culturefeed_date_control' => array( + '#element_validate' => array('culturefeed_date_control_date_control_validate'), + '#input' => TRUE, + '#process' => array('culturefeed_date_control_date_control_process', 'ajax_process_form'), + '#tree' => TRUE, + '#value_callback' => 'culturefeed_date_control_date_control_value_callback', + ), + 'culturefeed_date_control_hybrid' => array( + '#element_validate' => array('culturefeed_date_control_hybrid_validate'), + '#input' => TRUE, + '#pre_render' => array('culturefeed_date_control_hybrid_pre_render'), + '#process' => array('culturefeed_date_control_hybrid_process', 'ajax_process_form'), + '#theme' => 'culturefeed_date_control_hybrid_table', + '#tree' => TRUE, + '#value_callback' => 'culturefeed_date_control_hybrid_value_callback', + ), + 'culturefeed_date_control_opening_times' => array( + '#input' => TRUE, + '#process' => array('culturefeed_date_control_opening_times_process', 'ajax_process_form'), + '#tree' => TRUE, + '#value_callback' => 'culturefeed_date_control_opening_times_value_callback', + ), + 'culturefeed_date_control_period' => array( + '#element_validate' => array('culturefeed_date_control_period_validate'), + '#input' => TRUE, + '#pre_render' => array('culturefeed_date_control_period_pre_render'), + '#process' => array('culturefeed_date_control_period_process', 'ajax_process_form'), + '#theme' => 'culturefeed_date_control_period_table', + '#tree' => TRUE, + '#value_callback' => 'culturefeed_date_control_period_value_callback', + ), + 'culturefeed_date_control_timestamps' => array( + '#cell_count' => 4, + '#element_validate' => array('culturefeed_date_control_timestamps_validate'), + '#input' => TRUE, + '#pre_render' => array('culturefeed_date_control_timestamps_pre_render'), + '#process' => array('culturefeed_date_control_timestamps_process', 'ajax_process_form'), + '#theme' => 'culturefeed_date_control_timestamps_table', + '#tree' => TRUE, + '#value_callback' => 'culturefeed_date_control_timestamps_value_callback', + ), + ); +} + +/** + * Implements hook_element_info_alter(). + */ +function culturefeed_date_control_element_info_alter(&$types) { + if (isset($types['date_popup'])) { + $types['date_popup']['#after_build'][] = 'culturefeed_date_control_element_date_popup_after_build'; + } +} + +/** + * Explodes a date string into array components. + * + * @param array $element + * The element. + * @param string $date_string + * The date. + * + * @return array + * The exploded date. + */ +function culturefeed_date_control_explode_date(array $element, $date_string) { + + $date_element = array( + '#date_flexible' => 0, + '#date_format' => $element['#popup_date_format'], + '#date_increment' => $element['#popup_date_increment'], + '#date_timezone' => date_default_timezone(), + '#default_value' => $date_string, + ); + + $date = date_default_date($date_element); + $date = array( + 'date' => date_format_date($date, 'custom', $element['#popup_date_format']), + ); + + return $date; + +} + +/** + * Explodes a time string into array components. + * + * @param array $element + * The element. + * @param string $time_string + * The time. + * @param string $date_string + * The date. + * + * @return array + * The exploded time. + */ +function culturefeed_date_control_explode_time(array $element, $time_string, $date_string) { + + $time_element = array( + '#date_flexible' => 0, + '#date_format' => $element['#select_time_format'], + '#date_increment' => $element['#select_time_increment'], + '#date_timezone' => date_default_timezone(), + '#default_value' => $date_string . ' ' . $time_string, + ); + + return date_select_element_value_callback($time_element); + +} + +/** + * Implodes a date array into string. + * + * @param array $element + * The element. + * @param array $date_array + * The date array. + * + * @return string + * The imploded date. + */ +function culturefeed_date_control_implode_date(array $element, array $date_array) { + + $element = array( + '#date_flexible' => 0, + '#date_format' => $element['#popup_date_format'], + '#date_increment' => $element['#popup_date_increment'], + '#date_timezone' => date_default_timezone(), + '#default_value' => $date_array, + ); + $date = date_popup_input_date($element, $date_array); + return date_format_date($date, 'custom', 'Y-m-d'); + +} + +/** + * Implodes a time array into string. + * + * @param array $time_array + * The time array. + * @param string $date_string + * The date string. + * + * @return string + * The imploded time. + */ +function culturefeed_date_control_implode_time(array $time_array, $date_string) { + + $time = ''; + if (isset($time_array['hour']) && isset($time_array['minute']) && $date_string) { + $time = new DateObject( + array( + 'hour' => $time_array['hour'], + 'minute' => $time_array['minute'], + ), + date_default_timezone() + ); + $time = $date_string . ' ' . $time->format(DATE_FORMAT_DATETIME); + } + return $time; + +} + +/** + * Implements hook_menu(). + */ +function culturefeed_date_control_menu() { + + return array( + 'culturefeed_elements/ajax' => array( + 'title' => 'AHAH callback', + 'page callback' => 'culturefeed_date_control_ajax_callback', + 'delivery callback' => 'ajax_deliver', + 'access callback' => TRUE, + 'theme callback' => 'ajax_base_page_theme', + 'type' => MENU_CALLBACK, + ), + ); + +} + +/** + * Implements hook_theme(). + */ +function culturefeed_date_control_theme() { + + $settings = array( + 'file' => 'theme.inc', + 'path' => drupal_get_path('module', 'culturefeed_date_control') . '/theme', + 'render element' => 'form', + ); + + return array( + 'culturefeed_date_control_hybrid_table' => $settings, + 'culturefeed_date_control_opening_times_table' => $settings, + 'culturefeed_date_control_period_table' => $settings, + 'culturefeed_date_control_timestamps_table' => $settings, + ); + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc new file mode 100644 index 00000000..5676f49b --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc @@ -0,0 +1,366 @@ +"; + $element['#suffix'] = ""; + + $element['date_control'] = array( + '#type' => 'fieldset', + '#title' => (isset($element['#title'])) ? $element['#title'] : t('Dates'), + ); + + $date_control = $element['#value']['date_control']; + + // Type. + $element['date_control']['type'] = array( + '#type' => 'hidden', + '#value' => $date_control['type'], + ); + + // Hybrid. + $access = $date_control['type'] == 'hybrid'; + $element['date_control']['hybrid'] = array( + '#access' => $access, + '#date_control' => $element, + '#default_value' => $access && isset($date_control['hybrid']) ? $date_control['hybrid'] : '', + '#popup_date_format' => 'd-m-Y', + '#popup_date_increment' => 1, + '#select_time_format' => 'H:i', + '#select_time_increment' => 30, + '#type' => 'culturefeed_date_control_hybrid', + ); + + // Timestamps. + $access = $date_control['type'] == 'timestamps'; + $element['date_control']['timestamps'] = array( + '#access' => $access, + '#date_control' => $element, + '#default_value' => $access && isset($date_control['timestamps']) ? $date_control['timestamps'] : '', + '#popup_date_format' => 'd-m-Y', + '#popup_date_increment' => 1, + '#select_time_format' => 'H:i', + '#select_time_increment' => 30, + '#type' => 'culturefeed_date_control_timestamps', + ); + + // Period. + $access = $date_control['type'] == 'period'; + $element['date_control']['period'] = array( + '#access' => $access, + '#date_control' => $element, + '#default_value' => $access && isset($date_control['period']) ? $date_control['period'] : '', + '#popup_date_format' => 'd-m-Y', + '#popup_date_increment' => 1, + '#type' => 'culturefeed_date_control_period', + ); + + // Permanent. + $access = $date_control['type'] == 'permanent'; + $element['date_control']['permanent'] = array( + '#access' => $access, + '#ajax' => array( + 'effect' => 'none', + 'path' => 'culturefeed_elements/ajax/' . implode('/', $element['#array_parents']), + 'progress' => array('type' => 'throbber'), + 'wrapper' => $element['#id'] . '-ajax-wrapper', + ), + '#value' => $access && isset($date_control['permanent']) ? $date_control['permanent'] : 0, + '#title' => t('Permanent'), + '#type' => 'checkbox', + ); + + // Opening times. + $access = $date_control['type'] == 'period' || $date_control['type'] == 'permanent'; + $element['date_control']['opening_times'] = array( + '#access' => $access, + '#allowed_days' => $element['#allowed_days'], + '#date_control' => $element, + '#default_value' => $access && isset($date_control['opening_times']) ? $date_control['opening_times'] : '', + '#type' => 'culturefeed_date_control_opening_times', + ); + + $element['#attached'] = array( + 'css' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control.css', + ), + ); + + return $element; + +} + +/** + * Submit handler for the ajax buttons. + * + * @param array $form + * The form. + * @param array $form_state + * The form state. + */ +function culturefeed_date_control_date_control_submit(array $form, array &$form_state) { + + $form_state['rebuild'] = TRUE; + +} + +/** + * Validate and alter the culturefeed date control form values. + * + * This is where the element switching is set, based on values. + * + * @param array $element + * The element. + * @param array $form_state + * The form state. + */ +function culturefeed_date_control_date_control_validate(array $element, array &$form_state) { + + $triggering_element = (isset($form_state['triggering_element'])) ? $form_state['triggering_element'] : ''; + $triggering_parent = array_pop($triggering_element['#parents']); + // Use form_state instead of element as individual sub elements have changes + // that won't be reflected in element. + $values = drupal_array_get_nested_value($form_state['input'], $element['#parents']); + $date_control = $values['date_control']; + + if (culturefeed_date_control_check_trigger_element($triggering_element, $element)) { + + $type = $date_control['type']; + + // Hybrid. + if ($date_control['type'] == 'hybrid') { + + // Period. + if ($triggering_parent == 'end_date') { + + $type = 'period'; + $date_control['period'] = array('start_date' => ''); + if (isset($date_control['hybrid']['start_date'])) { + $date_control['period']['start_date'] = $date_control['hybrid']['start_date']; + } + if (isset($date_control['hybrid']['end_date'])) { + $date_control['period']['end_date'] = $date_control['hybrid']['end_date']; + } + + } + + // Permanent. + if ($triggering_parent == 'permanent') { + + $type = 'permanent'; + $date_control['permanent'] = 1; + + } + + // Timestamps. + if ($triggering_parent == 'add_date' || $triggering_parent == 'hour' || $triggering_parent == 'minute') { + + $type = 'timestamps'; + $date_control['timestamps']['stamps'] = array( + array('date' => ''), + ); + if (isset($date_control['hybrid']['start_date'])) { + $date_control['timestamps']['stamps'][0]['date'] = $date_control['hybrid']['start_date']; + } + if (isset($date_control['hybrid']['start_time'])) { + $date_control['timestamps']['stamps'][0]['start_time'] = $date_control['hybrid']['start_time']; + } + if (isset($date_control['hybrid']['end_time'])) { + $date_control['timestamps']['stamps'][0]['end_time'] = $date_control['hybrid']['end_time']; + } + if ($triggering_parent == 'add_date') { + $date_control['timestamps']['stamps'][] = array('date' => ''); + } + + } + + } + + // Period. + if ($date_control['type'] == 'period') { + + if ($triggering_parent == 'remove_end') { + + $type = 'hybrid'; + // Pass over any set values. + $date_control['hybrid'] = array( + 'start_date' => isset($date_control['period']['start_date']) ? $date_control['period']['start_date'] : '', + ); + + } + + } + + // Permanent. + if ($date_control['type'] == 'permanent') { + + if ($triggering_parent == 'permanent') { + + $type = 'hybrid'; + + } + + } + + // Timestamps. + if ($date_control['type'] == 'timestamps') { + + if ( + (($triggering_parent == 'remove_stamp' && !isset($date_control['timestamps']['stamps'][0]['end_time'])) || + $triggering_parent == 'remove_end') && count($date_control['timestamps']['stamps']) == 1 + ) { + + $type = 'hybrid'; + $date_control['hybrid'] = array('start_date' => ''); + if (isset($date_control['timestamps']['stamps'][0]['date'])) { + $date_control['hybrid']['start_date'] = $date_control['timestamps']['stamps'][0]['date']; + } + if (isset($date_control['timestamps']['stamps'][0]['start_time'])) { + $date_control['hybrid']['start_time'] = $date_control['timestamps']['stamps'][0]['start_time']; + } + + } + + } + + $date_control['type'] = $type; + $element['#parents'][] = 'date_control'; + + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $date_control); + + } + else { + + // The one exception. + if ($date_control['type'] == 'hybrid') { + + $values = drupal_array_get_nested_value($form_state['values'], $element['#parents']); + $date_control = $values['date_control']; + + $date_control['timestamps']['stamps'][0] = array( + 'date' => $date_control['hybrid']['start_date'], + ); + if (isset($date_control['hybrid']['start_time'])) { + $date_control['timestamps']['stamps'][0]['start_time'] = $date_control['hybrid']['start_time']; + } + $date_control['type'] = 'timestamps'; + + $element['#parents'][] = 'date_control'; + drupal_array_set_nested_value($form_state['values'], $element['#parents'], $date_control); + + } + + } + +} + +/** + * Value callback for the date control element. + * + * @param array $element + * The element. + * @param mixed $input + * The input. + * @param array $form_state + * The form state. + * + * @return mixed + * The value. + */ +function culturefeed_date_control_date_control_value_callback(array &$element, $input, array $form_state) { + + if ($input) { + return $input; + } + else { + + $value = array( + 'date_control' => array( + 'type' => 'hybrid', + 'hybrid' => array(), + 'opening_times' => array(), + 'period' => array(), + 'timestamps' => array(), + ), + ); + + if (isset($element['#default_value']) && $element['#default_value']) { + + $date_control = $value['date_control']; + $default_value = $element['#default_value']; + + // Timestamps / hybrid. + if (count($default_value['timestamps']) == 1 && !isset($default_value['timestamps'][0]['end_time'])) { + + $date_control['type'] = 'hybrid'; + $date_control['hybrid'] = array( + 'start_date' => $default_value['timestamps'][0]['date'], + ); + if (isset($default_value['timestamps'][0]['start_time'])) { + $date_control['hybrid']['start_time'] = $default_value['timestamps'][0]['start_time']; + } + + } + + // Timestamps. + elseif (count($default_value['timestamps'])) { + + $date_control['type'] = 'timestamps'; + $date_control['timestamps'] = $default_value['timestamps']; + + } + + // Period. + elseif ($default_value['period']['start_date'] && $default_value['period']['end_date']) { + + $date_control['type'] = 'period'; + $date_control['period'] = $default_value['period']; + + } + + // Permanent. + elseif ($default_value['permanent']) { + + $date_control['type'] = 'permanent'; + $date_control['permanent'] = $default_value['permanent']; + + } + + else { + $date_control['type'] = 'hybrid'; + } + + // Opening times don't set type, they go with period or permanent. + if ($default_value['opening_times']) { + + $date_control['opening_times'] = $default_value['opening_times']; + + } + + $value['date_control'] = $date_control; + + } + + return $value; + + } + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc new file mode 100644 index 00000000..d6a9e470 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc @@ -0,0 +1,215 @@ +"; + $element['#suffix'] = ""; + + if (isset($element['#date_control'])) { + $element_id = $element['#date_control']['#id']; + $array_parents = $element['#date_control']['#array_parents']; + } + + $hybrid = $element['#value']; + + $ajax_settings = array( + 'effect' => 'none', + 'path' => 'culturefeed_elements/ajax/' . implode('/', $array_parents), + 'progress' => array('type' => 'throbber'), + 'wrapper' => $element_id . '-ajax-wrapper', + ); + + $ajax_button = array( + '#access' => TRUE, + '#ajax' => $ajax_settings, + '#attributes' => array('class' => array('add-more-link btn-link')), + '#limit_validation_errors' => array($element['#parents']), + '#submit' => array('culturefeed_date_control_date_control_submit'), + '#type' => 'submit', + ); + + $date = isset($hybrid['start_date']) && $hybrid['start_date'] ? culturefeed_date_control_implode_date($element, $hybrid['start_date']) : ''; + $element['start_date'] = array( + '#date_format' => 'd-m-Y', + '#date_label_position' => 'none', + '#default_value' => $date, + '#icon' => TRUE, + '#required' => TRUE, + '#title' => t('Date'), + '#type' => 'date_popup', + ); + + $time = isset($hybrid['start_time']) && $hybrid['start_time'] ? culturefeed_date_control_implode_time($hybrid['start_time'], $date) : ''; + $element['start_time'] = array( + '#attributes' => array('class' => array('time-select-complete-minutes')), + '#date_format' => 'H:i', + '#date_increment' => 30, + '#default_value' => $time, + '#title' => '', + '#type' => 'date_select', + ); + + $element['add_end_date_or_time'] = $ajax_button + array( + '#value' => t('+ add end date or time'), + ); + + $element['end_date'] = array( + '#access' => TRUE, + '#ajax' => $ajax_settings, + '#date_format' => 'd-m-Y', + '#date_label_position' => 'none', + '#default_value' => '', + '#icon' => TRUE, + '#title' => t('Date'), + '#type' => 'date_popup', + ); + + $element['end_time'] = array( + '#access' => TRUE, + '#attributes' => array('class' => array('time-select-complete-minutes')), + '#ajax' => $ajax_settings, + '#date_format' => 'H:i', + '#date_increment' => 30, + '#default_value' => '', + '#title' => '', + '#type' => 'date_select', + ); + + $element['add_date'] = $ajax_button + array( + '#value' => t('+ add date'), + ); + + // Value will always be 0 as a different element is used when actually + // permanent. + $element['permanent'] = array( + '#ajax' => $ajax_settings, + '#title' => t('Permanent'), + '#type' => 'checkbox', + '#value' => 0, + ); + + $element['#attached'] = array( + 'js' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/js/culturefeed_date_control_time_select.js', + ), + ); + + return $element; + +} + +/** + * Validate and alter the culturefeed date control hybrid form values. + * + * @param array $element + * The element. + * @param array $form_state + * The form state. + */ +function culturefeed_date_control_hybrid_validate(array &$element, array &$form_state) { + + $triggering_element = (isset($form_state['triggering_element'])) ? $form_state['triggering_element'] : ''; + $triggering_parent = array_pop($triggering_element['#parents']); + $hybrid = $element['#value']; + + if (culturefeed_date_control_check_trigger_element($triggering_element, $element)) { + + switch ($triggering_parent) { + + case 'add_end_date_or_time': + + $hybrid['end_date'] = array('date' => ''); + $hybrid['end_time'] = array('hour' => '', 'minute' => ''); + + } + + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $hybrid); + + } + +} + +/** + * Value callback for the culturefeed date control hybrid element. + * + * @param array $element + * The element. + * @param mixed $input + * The input. + * @param array $form_state + * The form state. + * + * @return mixed + * The value. + */ +function culturefeed_date_control_hybrid_value_callback(array $element, $input, array $form_state) { + + if ($input) { + return $input; + } + else { + + $value = array('start_date' => '', 'start_time' => ''); + + if (isset($element['#default_value']) && $element['#default_value']) { + + $default_value = $element['#default_value']; + if (isset($default_value['start_date']) && $default_value['start_date']) { + $value['start_date'] = culturefeed_date_control_explode_date($element, $default_value['start_date']); + if (isset($element['#default_value']['start_time']) && $element['#default_value']['start_time']) { + $value['start_time'] = culturefeed_date_control_explode_time($element, $default_value['start_time'], $default_value['start_date']); + } + } + + } + + return $value; + + } + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc new file mode 100644 index 00000000..02715405 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc @@ -0,0 +1,159 @@ + t('mon'), + 'tuesday' => t('tue'), + 'wednesday' => t('wed'), + 'thursday' => t('thu'), + 'friday' => t('fri'), + 'saturday' => t('sat'), + 'sunday' => t('sun'), + ); + + $opening_times = $element['#value']; + + $element['all_day'] = array( + '#options' => array('1' => t('Yes'), '0' => t('No')), + '#title' => t('Open all day ?'), + '#type' => 'radios', + '#default_value' => $opening_times['days'] ? 0 : 1, + ); + + $element['days'] = array( + '#type' => 'container', + '#theme' => 'culturefeed_date_control_opening_times_table', + '#states' => array( + 'visible' => array(":input[name=\"" . $element['#name'] . "[all_day]\"]" => array('value' => '0')), + ), + ); + + foreach ($element['#allowed_days'] as $day) { + + $element['days'][$day] = array( + '#tree' => TRUE, + '#type' => 'fieldset', + '#title' => $day_labels[$day], + ); + + $element['days'][$day][0]['open_from'] = array( + '#default_value' => isset($opening_times['days'][$day][0]['open_from']) ? $opening_times['days'][$day][0]['open_from'] : '', + '#description' => t('Format') . ': 12:00', + '#size' => 12, + '#type' => 'textfield', + ); + + $element['days'][$day][0]['open_till'] = array( + '#default_value' => isset($opening_times['days'][$day][0]['open_till']) ? $opening_times['days'][$day][0]['open_till'] : '', + '#description' => t('Format') . ': 12:00', + '#size' => 12, + '#type' => 'textfield', + ); + + } + + $element['#attached'] = array( + 'css' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control_opening_times.css', + ), + 'js' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/js/culturefeed_date_control_opening_times.js', + ), + ); + + if (!isset($element['#date_control'])) { + $element['#attached']['css'][] = drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control.css'; + } + + return $element; + +} + +/** + * Value callback for the culturefeed date control opening times element. + * + * @param array $element + * The element. + * @param mixed $input + * The input. + * @param array $form_state + * The form state. + * + * @return mixed + * The value. + */ +function culturefeed_date_control_opening_times_value_callback(array $element, $input, array $form_state) { + + if ($input) { + + // Clean up. + $days = array(); + foreach ($input['days'] as $day => $times) { + if ($times[0]['open_from'] && $times[0]['open_till']) { + $days[$day] = $input['days'][$day]; + } + } + $input['days'] = $days; + return $input; + + } + else { + + if ( + isset($element['#default_value']) && isset($element['#default_value']['days']) && + $element['#default_value']['days'] + ) { + + // @todo This should be in the entry_ui module. + /* @var CultureFeed_Cdb_Data_Calendar_Weekscheme $week_scheme */ + $week_scheme = $element['#default_value']['days']; + $days = array(); + + foreach ($element['#allowed_days'] as $day) { + + $day_scheme = $week_scheme->getDay($day); + if ($day_scheme->isOpen()) { + + /* @var CultureFeed_Cdb_Data_Calendar_OpeningTime[] $opening_times */ + $opening_times = $day_scheme->getOpeningTimes(); + // Strip the seconds. + $days[$day] = array( + array( + 'open_from' => substr($opening_times[0]->getOpenFrom(), 0, 5), + 'open_till' => substr($opening_times[0]->getOpenTill(), 0, 5), + ), + ); + + } + + } + + return array('days' => $days); + + } + else { + return array('days' => ''); + } + + } + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc new file mode 100644 index 00000000..77eb2078 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc @@ -0,0 +1,194 @@ +"; + $element['#suffix'] = ""; + + if (isset($element['#date_control'])) { + $element_id = $element['#date_control']['#id']; + $array_parents = $element['#date_control']['#array_parents']; + } + + $period = $element['#value']; + + $ajax_button = array( + '#access' => TRUE, + '#ajax' => array( + 'effect' => 'none', + 'path' => 'culturefeed_elements/ajax/' . implode('/', $array_parents), + 'progress' => array('type' => 'throbber'), + 'wrapper' => $element_id . '-ajax-wrapper', + ), + '#attributes' => array('class' => array('add-more-link btn-link')), + '#limit_validation_errors' => array($element['#parents']), + '#submit' => array('culturefeed_date_control_date_control_submit'), + '#type' => 'submit', + ); + + $date = isset($period['start_date']) && $period['start_date'] ? culturefeed_date_control_implode_date($element, $period['start_date']) : ''; + $element['start_date'] = array( + '#date_format' => 'd-m-Y', + '#date_label_position' => 'none', + '#default_value' => $date, + '#icon' => TRUE, + '#required' => TRUE, + '#title' => t('Start date'), + '#type' => 'date_popup', + ); + + $element['add_end'] = array( + '#name' => 'add_end', + '#value' => t('+ add end date'), + ) + $ajax_button; + + $date = isset($period['end_date']) && $period['end_date'] ? culturefeed_date_control_implode_date($element, $period['end_date']) : ''; + $element['end_date'] = array( + '#access' => TRUE, + '#date_format' => 'd-m-Y', + '#date_label_position' => 'none', + '#default_value' => $date, + '#icon' => TRUE, + '#required' => TRUE, + '#title' => t('End date'), + '#type' => 'date_popup', + ); + + $element['remove_end'] = array( + '#limit_validation_errors' => array(), + '#name' => 'remove_end', + '#value' => t('- remove end date'), + ) + $ajax_button; + + if (!isset($element['#date_control'])) { + $element['#attached'] = array( + 'css' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control.css', + ), + ); + } + + return $element; + +} + +/** + * Validate and alter the culturefeed date control timestamps form values. + * + * @param array $element + * The element. + * @param array $form_state + * The form state. + */ +function culturefeed_date_control_period_validate(array $element, array &$form_state) { + + $triggering_element = (isset($form_state['triggering_element'])) ? $form_state['triggering_element'] : ''; + $triggering_parent = array_pop($triggering_element['#parents']); + $dates = $element['#value']; + + if (culturefeed_date_control_check_trigger_element($triggering_element, $element)) { + + switch ($triggering_parent) { + + case 'add_end': + $dates['end_date'] = array('date' => ''); + break; + + case 'remove_end': + unset($dates['end_date']); + break; + + } + + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $dates, TRUE); + + } + +} + +/** + * Value callback for the culturefeed date control period element. + * + * @param array $element + * The element. + * @param mixed $input + * The input. + * @param array $form_state + * The form state. + * + * @return mixed + * The value. + */ +function culturefeed_date_control_period_value_callback(array $element, $input, array $form_state) { + + if ($input) { + return $input; + } + else { + + $value = array('start_date' => '', 'end_date' => ''); + + if (isset($element['#default_value']) && $element['#default_value']) { + + $default_value = $element['#default_value']; + if ( + isset($default_value['start_date']) && $default_value['start_date'] && + isset($default_value['end_date']) && $default_value['end_date'] + ) { + $value['start_date'] = culturefeed_date_control_explode_date($element, $default_value['start_date']); + $value['end_date'] = culturefeed_date_control_explode_date($element, $default_value['end_date']); + } + + } + + return $value; + + } + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc new file mode 100644 index 00000000..27d93afb --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -0,0 +1,264 @@ + $timestamp) { + + if ( + isset($timestamps[$key]['end_time']) + && !is_null($timestamps[$key]['end_time']['hour']) + && !is_null($timestamps[$key]['end_time']['minute']) + ) { + $element['stamps'][$key]['add_end']['#access'] = FALSE; + $element['#cell_count'] = 5; + } + else { + $element['stamps'][$key]['end_time']['#access'] = FALSE; + $element['stamps'][$key]['remove_end']['#access'] = FALSE; + } + } + + return $element; + +} + +/** + * Sets the culturefeed date control timestamps form elements. + * + * @param array $element + * The element. + * @param array $form_state + * The form state. + * @param array $form + * The form. + * + * @return array + * The element. + */ +function culturefeed_date_control_timestamps_process(array $element, array &$form_state, array $form) { + + $element_id = $element['#id']; + $array_parents = $element['#array_parents']; + + $element['#prefix'] = "
"; + $element['#suffix'] = "
"; + + if (isset($element['#date_control'])) { + $element_id = $element['#date_control']['#id']; + $array_parents = $element['#date_control']['#array_parents']; + } + + $ajax_button = array( + '#access' => TRUE, + '#ajax' => array( + 'effect' => 'none', + 'path' => 'culturefeed_elements/ajax/' . implode('/', $array_parents), + 'progress' => array('type' => 'throbber'), + 'wrapper' => $element_id . '-ajax-wrapper', + ), + '#attributes' => array('class' => array('add-more-link btn-link')), + '#limit_validation_errors' => array($element['#parents']), + '#submit' => array('culturefeed_date_control_date_control_submit'), + '#type' => 'submit', + ); + + $timestamps = $element['#value']; + + foreach ($timestamps['stamps'] as $key => $timestamp) { + + $element['stamps'][$key]['remove_stamp'] = array( + '#limit_validation_errors' => array(), + '#value' => t('×'), + '#name' => 'remove_stamp_' . $key, + ) + $ajax_button; + + $date = isset($timestamp['date']) && $timestamp['date'] ? culturefeed_date_control_implode_date($element, $timestamp['date']) : ''; + $element['stamps'][$key]['date'] = array( + '#date_format' => $element['#popup_date_format'], + '#date_increment' => $element['#popup_date_increment'], + '#date_label_position' => 'none', + '#default_value' => $date, + '#icon' => TRUE, + '#required' => TRUE, + '#title' => t('Date'), + '#type' => 'date_popup', + ); + + $time = isset($timestamp['start_time']) && $timestamp['start_time'] ? culturefeed_date_control_implode_time($timestamp['start_time'], $date) : ''; + $element['stamps'][$key]['start_time'] = array( + '#attributes' => array('class' => array('time-select-complete-minutes')), + '#date_format' => $element['#select_time_format'], + '#date_increment' => $element['#select_time_increment'], + '#default_value' => $time, + '#title' => '', + '#type' => 'date_select', + ); + + $time = isset($timestamp['end_time']) && $timestamp['end_time'] ? culturefeed_date_control_implode_time($timestamp['end_time'], $date) : ''; + $element['stamps'][$key]['end_time'] = array( + '#access' => TRUE, + '#attributes' => array('class' => array('time-select-complete-minutes')), + '#date_format' => $element['#select_time_format'], + '#date_increment' => $element['#select_time_increment'], + '#default_value' => $time, + '#title' => '', + '#type' => 'date_select', + ); + + $element['stamps'][$key]['remove_end'] = array( + '#name' => 'remove_end_' . $key, + '#value' => t('- remove end time'), + ) + $ajax_button; + + $element['stamps'][$key]['add_end'] = array( + '#name' => 'add_end_' . $key, + '#value' => t('+ add end time'), + ) + $ajax_button; + + } + + $element['timestamps_add_stamp'] = array( + '#name' => 'add_stamp', + '#value' => t('+ add date'), + ) + $ajax_button; + + $element['#attached'] = array( + 'js' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/js/culturefeed_date_control_time_select.js', + ), + ); + + if (!isset($element['#date_control'])) { + $element['#attached']['css'] = array( + drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control.css', + ); + } + + return $element; + +} + +/** + * Validate and alter the culturefeed date control timestamps form values. + * + * @param array $element + * The element. + * @param array $form_state + * The form state. + */ +function culturefeed_date_control_timestamps_validate(array $element, array &$form_state) { + + $triggering_element = (isset($form_state['triggering_element'])) ? $form_state['triggering_element'] : ''; + $triggering_parent = array_pop($triggering_element['#parents']); + $timestamps = $element['#value']; + + if (culturefeed_date_control_check_trigger_element($triggering_element, $element)) { + + switch ($triggering_parent) { + + case 'timestamps_add_stamp': + $timestamps['stamps'][] = array('date' => array('date' => '')); + break; + + case 'remove_stamp': + $index = array_pop($triggering_element['#parents']); + array_splice($timestamps['stamps'], $index, 1); + break; + + case 'add_end': + $index = array_pop($triggering_element['#parents']); + $timestamps['stamps'][$index]['end_time'] = array('hour' => '', 'minute' => ''); + break; + + case 'remove_end': + $index = array_pop($triggering_element['#parents']); + unset($timestamps['stamps'][$index]['end_time']); + break; + + } + + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $timestamps); + + } + +} + +/** + * Value callback for the culturefeed date control timestamps element. + * + * @param array $element + * The element. + * @param mixed $input + * The input. + * @param array $form_state + * The form state. + * + * @return mixed + * The value. + */ +function culturefeed_date_control_timestamps_value_callback(array $element, $input, array $form_state) { + + if ($input) { + return $input; + } + else { + + $value = array( + 'stamps' => array( + array('date' => '', 'start_time' => '', 'end_time' => ''), + ), + ); + + if (isset($element['#default_value']) && $element['#default_value']) { + + $stamps = array(); + foreach ($element['#default_value'] as $default_value) { + + if (isset($default_value['date']) && $default_value['date']) { + + $stamp = array(); + $stamp['date'] = culturefeed_date_control_explode_date($element, $default_value['date']); + if (isset($default_value['start_time']) && $default_value['start_time']) { + $stamp['start_time'] = culturefeed_date_control_explode_time($element, $default_value['start_time'], $default_value['date']); + } + if (isset($default_value['end_time']) && $default_value['end_time']) { + $stamp['end_time'] = culturefeed_date_control_explode_time($element, $default_value['end_time'], $default_value['date']); + } + $stamps[] = $stamp; + + } + + } + + if (count($stamps)) { + $value['stamps'] = $stamps; + } + + } + + return $value; + + } + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/js/culturefeed_date_control_opening_times.js b/culturefeed_entry_ui/culturefeed_date_control/js/culturefeed_date_control_opening_times.js new file mode 100644 index 00000000..ab32d3f2 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/js/culturefeed_date_control_opening_times.js @@ -0,0 +1,27 @@ +/** + * @file + * Contains culturefeed date control opening times javascript. + */ + +(function ($) { + + Drupal.behaviors.culturefeed_date_control_opening_times_complete_time = { + attach: function (context, setings) { + $(".culturefeed-date-control-opening-times-complete input").blur(function () { + var string = $(this).val(); + if (string) { + var time = string.split(':'); + var has_separator = time.length - 1; + if (has_separator === 0) { + $(this).val(string + ':00'); + } + if (time[1].length === 0) { + $(this).val(string + '00'); + } + } + }); + } + } + +})(jQuery); + diff --git a/culturefeed_entry_ui/culturefeed_date_control/js/culturefeed_date_control_time_select.js b/culturefeed_entry_ui/culturefeed_date_control/js/culturefeed_date_control_time_select.js new file mode 100644 index 00000000..08420e42 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/js/culturefeed_date_control_time_select.js @@ -0,0 +1,22 @@ +/** + * @file + * Contains culturefeed date control opening times javascript. + */ + +(function ($) { + + Drupal.behaviors.culturefeed_date_control_time_select_complete_time = { + attach: function (context, setings) { + $(".date-hour > .time-select-complete-minutes").change(function () { + if ($(this).val()) { + var minute = $(this).parents(".form-type-date-select").find(".date-minute > .time-select-complete-minutes"); + if (!minute.val()) { + minute.val('00'); + } + } + }); + } + } + +})(jQuery); + diff --git a/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc b/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc new file mode 100644 index 00000000..2e7ac91d --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc @@ -0,0 +1,192 @@ + array( + 'class' => array( + 'date-control-table', + 'date-control-hybrid-table', + ), + ), + 'rows' => array(), + ); + + $cells = array(); + $cells[] = drupal_render($form['start_date']); + $cells[] = drupal_render($form['start_time']); + if (!$form['end_date']['#access'] && !$form['end_time']['#access']) { + $cells[] = drupal_render($form['add_end_date_or_time']); + } + if ($form['end_date']['#access']) { + $cells[] = drupal_render($form['end_date']); + } + if ($form['end_time']['#access']) { + $cells[] = drupal_render($form['end_time']); + } + + $table['rows'][] = $cells; + $output = theme('table', $table); + $output .= drupal_render_children($form); + return $output; + +} + +/** + * Theme the timestamps table. + * + * @param array $variables + * The variables. + * + * @return string + * The output. + */ +function theme_culturefeed_date_control_opening_times_table(array &$variables) { + + $form = $variables['form']; + + $header = array(t('open'), t('from'), t('to')); + $table = array( + 'attributes' => array( + 'class' => array( + 'date-control-table', + 'date-control-opening-times-table', + ), + ), + 'header' => $header, + 'rows' => array(), + ); + + foreach (element_children($form) as $element) { + + $cells = array(); + $cells[] = $form[$element]['#title']; + $cells[] = array( + 'data' => drupal_render($form[$element][0]['open_from']), + 'class' => 'culturefeed-date-control-opening-times-complete', + ); + $cells[] = array( + 'data' => drupal_render($form[$element][0]['open_till']), + 'class' => 'culturefeed-date-control-opening-times-complete', + ); + $table['rows'][] = $cells; + + } + + $output = theme('table', $table); + return $output; + +} + +/** + * Theme the period table. + * + * @param array $variables + * The variables. + * + * @return string + * The output. + */ +function theme_culturefeed_date_control_period_table(array &$variables) { + + $form = $variables['form']; + + $table = array( + 'attributes' => array( + 'class' => array( + 'date-control-table', + 'date-control-period-table', + ), + ), + 'rows' => array(), + ); + + $cells = array(drupal_render($form['start_date'])); + if ($form['add_end']['#access']) { + $cells[] = drupal_render($form['add_end']); + } + if ($form['end_date']['#access']) { + $cells[] = drupal_render($form['end_date']); + } + if ($form['remove_end']['#access']) { + $cells[] = drupal_render($form['remove_end']); + } + + $table['rows'][] = $cells; + $output = theme('table', $table); + return $output; + +} + +/** + * Theme the timestamps table. + * + * @param array $variables + * The variables. + * + * @return string + * The output. + */ +function theme_culturefeed_date_control_timestamps_table(array &$variables) { + + $form = $variables['form']; + + $table = array( + 'attributes' => array( + 'class' => array( + 'date-control-table', + 'date-control-timestamps-table', + ), + ), + 'rows' => array(), + ); + + foreach (element_children($form['stamps']) as $element) { + + if ($element !== 'timestamps_add_stamp') { + + $cells = array(); + if ($form['stamps'][$element]['remove_stamp']['#access']) { + $cells[] = drupal_render($form['stamps'][$element]['remove_stamp']); + } + $cells[] = drupal_render($form['stamps'][$element]['date']); + $cells[] = drupal_render($form['stamps'][$element]['start_time']); + if ($form['stamps'][$element]['end_time']['#access']) { + $cells[] = drupal_render($form['stamps'][$element]['end_time']); + } + if ($form['stamps'][$element]['add_end']['#access']) { + $cells[] = drupal_render($form['stamps'][$element]['add_end']); + } + if ($form['stamps'][$element]['remove_end']['#access']) { + $cells[] = drupal_render($form['stamps'][$element]['remove_end']); + } + elseif ($form['#cell_count'] == 5) { + $cells[] = ''; + } + $table['rows'][] = $cells; + + } + + } + + $output = theme('table', $table); + $output .= drupal_render_children($form); + return $output; + +} diff --git a/culturefeed_entry_ui/culturefeed_entry_ui.info b/culturefeed_entry_ui/culturefeed_entry_ui.info index 53a711a0..14b0a6a8 100644 --- a/culturefeed_entry_ui/culturefeed_entry_ui.info +++ b/culturefeed_entry_ui/culturefeed_entry_ui.info @@ -6,6 +6,7 @@ core = 7.x dependencies[] = culturefeed_search dependencies[] = culturefeed_search_views dependencies[] = culturefeed +dependencies[] = culturefeed_date_control dependencies[] = file dependencies[] = date dependencies[] = date_api diff --git a/culturefeed_entry_ui/culturefeed_entry_ui.module b/culturefeed_entry_ui/culturefeed_entry_ui.module index 1ca6921d..03d929b8 100644 --- a/culturefeed_entry_ui/culturefeed_entry_ui.module +++ b/culturefeed_entry_ui/culturefeed_entry_ui.module @@ -43,14 +43,6 @@ function culturefeed_entry_ui_permission() { function culturefeed_entry_ui_theme() { return array( - 'culturefeed_entry_ui_opening_times_table' => array( - 'file' => 'theme/theme.inc', - 'render element' => 'element', - ), - 'culturefeed_entry_ui_when_datetimes_table' => array( - 'file' => 'theme/theme.inc', - 'render element' => 'form', - ), 'culturefeed_entry_ui_event_form' => array( 'render element' => 'form', 'template' => 'culturefeed-entry-ui-event-form', @@ -227,42 +219,6 @@ function culturefeed_entry_ui_add_more_submit($form, &$form_state) { switch ($form_state['input']['_triggering_element_name']) { - case 'datetimes_add_child': - // No need to add as the the add more button is already counted. - $form_state['#dates_needed'] = count(element_children($form['basic']['when']['datetimes'])); - break; - - case (strpos($form_state['input']['_triggering_element_name'], 'datetimes_remove_child_') === 0): - $remove = explode('datetimes_remove_child_', $form_state['input']['_triggering_element_name']); - $remove = $remove[1]; - - // Unset and reindex. - unset($form_state['values']['datetimes'][$remove]); - $datetimes = array(); - foreach ($form_state['values']['datetimes'] as $key => $datetime) { - - if (is_numeric($key)) { - $datetimes[] = $datetime; - } - else { - $datetimes[$key] = $datetime; - } - - } - $form_state['values']['datetimes'] = $datetimes; - unset($form_state['input']['datetimes'][$remove]); - $form_state['input']['datetimes'] = array_values($form_state['input']['datetimes']); - // Don't forget to count the add more button. - $form_state['#dates_needed'] = count(element_children($form['basic']['when']['datetimes'])) - 2; - break; - - case (strpos($form_state['input']['_triggering_element_name'], 'datetimes_remove_end_') === 0): - $remove = explode('datetimes_remove_end_', $form_state['input']['_triggering_element_name']); - $remove = $remove[1]; - unset($form_state['values']['datetimes'][$remove]['end']); - unset($form_state['input']['datetimes'][$remove]['end']); - break; - case 'links_add_more': $form_state['#links_needed'] = count(element_children($form['extra']['links'])) + 1; break; @@ -312,24 +268,8 @@ function culturefeed_entry_ui_add_more_submit($form, &$form_state) { */ function culturefeed_entry_ui_add_more_js($form, $form_state) { - // Rebuild the form: - $form = drupal_rebuild_form($form['#form_id'], $form_state, $form); switch ($form_state['input']['_triggering_element_name']) { - case 'begindates_add_more': - case 'enddates_add_more': - case (strpos($form_state['input']['_triggering_element_name'], 'datetimes_add_end_') === 0): - case (strpos($form_state['input']['_triggering_element_name'], 'datetimes_remove_end_') === 0): - case (strpos($form_state['input']['_triggering_element_name'], 'datetimes_remove_child_') === 0): - case 'datetimes[0][begin][date]': - case 'datetimes[0][end][date]': - case 'datetimes_add_child': - case 'permanent': - return $form['basic']['when']; - - case 'timestamps_add_more': - return $form['basic']['timestamps']; - case 'location[new][citywrapper][country_select]': return $form['basic']['location']['new']['citywrapper']; @@ -444,25 +384,6 @@ function culturefeed_entry_ui_culturefeed_ui_profile_box_main_items() { return $items; } -/** - * Implements hook_element_info_alter(). - */ -function culturefeed_entry_ui_element_info_alter(&$types) { - if (isset($types['date_popup'])) { - $types['date_popup']['#after_build'][] = 'culturefeed_entry_ui_element_date_popup_after_build'; - } -} - -/** - * Adds a span element for a calendar icon on date popup fields. - */ -function culturefeed_entry_ui_element_date_popup_after_build($element, $form_state) { - if (isset($element['date'])) { - $element['date']['#suffix'] = ""; - } - return $element; -} - /** * Validation function for some textarea form elements. */ diff --git a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc index 915689bf..e1c10144 100644 --- a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc +++ b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc @@ -10,7 +10,6 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { $form = array(); - $triggering_element = isset($form_state['input']['_triggering_element_name']) ? $form_state['input']['_triggering_element_name'] : ''; $default_contacts = array(); $performers_info = array(); @@ -29,20 +28,11 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { $default_organiser_label = ''; $default_organiser_id = ''; $publication_date = ''; - $when = 'timestamps'; $timestamps = array(); $period_start = ''; $period_end = ''; + $permanent = FALSE; $weekscheme = NULL; - $day_labels = array( - 'monday' => t('mon'), - 'tuesday' => t('tue'), - 'wednesday' => t('wed'), - 'thursday' => t('thu'), - 'friday' => t('fri'), - 'saturday' => t('sat'), - 'sunday' => t('sun'), - ); $age = ''; $age_category = 'everyone'; $default_short_description = ''; @@ -139,18 +129,16 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { $today = strtotime(date('Y-m-d') . ' 00:00:00'); if ($calendar_class == 'CultureFeed_Cdb_Data_Calendar_PeriodList') { - $when = 'period'; $period_start = $calendar->current()->getDateFrom(); $period_end = $calendar->current()->getDateTo(); $weekscheme = $calendar->current()->getWeekScheme(); } elseif ($calendar_class == 'CultureFeed_Cdb_Data_Calendar_Permanent') { - $when = 'permanent'; + $permanent = TRUE; $weekscheme = $calendar->getWeekScheme(); } elseif ($calendar_class == 'CultureFeed_Cdb_Data_Calendar_TimestampList') { - $when = 'timestamps'; $timestamps_count = iterator_count($calendar); $calendar->rewind(); $current_timestamp = 0; @@ -162,8 +150,8 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { if (strtotime($date) >= $today) { $timestamps[$current_timestamp] = array( 'date' => $date, - 'begintime' => $timestamp->getStartTime(), - 'endtime' => $timestamp->getEndTime(), + 'start_time' => $timestamp->getStartTime(), + 'end_time' => $timestamp->getEndTime(), ); $current_timestamp++; } @@ -675,341 +663,22 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { ); } - // Date. + // Date control $form['basic']['when'] = array( - '#type' => 'fieldset', - '#prefix' => '
', - '#suffix' => '
', '#title' => t('Dates'), - ); - - $date_count = (isset($form_state['#dates_needed'])) ? $form_state['#dates_needed'] : (count($timestamps) ? count($timestamps) : 1); - - // $when can change from datetime to period and vice versa. - - // Is it a timestamp ? - if ( - ($date_count > 1) || - (isset($form_state['values']['datetimes'][0]['begin']['date']) && - (!isset($form_state['values']['datetimes'][0]['end']['date']) || $triggering_element == 'datetimes_remove_end_' . 0)) || - (isset($form_state['values']['permanent']) && !$form_state['values']['permanent']) || - (isset($form_state['values']['datetimes'][0]['begin'])) - ) { - $when = 'timestamps'; - } - // Is it a period ? - if ( - (isset($form_state['values']['datetimes'][0]['begin']['date']) && isset($form_state['values']['datetimes'][0]['end']['date']) && - $form_state['values']['datetimes'][0]['begin']['date'] != $form_state['values']['datetimes'][0]['end']['date'] && - $triggering_element != 'datetimes_remove_end_' . 0) - ) { - $when = 'period'; - } - // Is it permanent - if (isset($form_state['values']['permanent']) && $form_state['values']['permanent']) { - $when = 'permanent'; - } - - $form['basic']['when']['datetype'] = array( - '#type' => 'hidden', - '#value' => $when, - ); - - if ($when != 'permanent') { - - $form['basic']['when']['datetimes'] = array( - '#tree' => TRUE, - '#type' => 'container', - '#attributes' => array('class' => array('when-datetimes')), - '#theme' => 'culturefeed_entry_ui_when_datetimes_table', - ); - - for ($i = 0; $i < $date_count; $i++) { - - // Timestamps / Period wrapper. - $form['basic']['when']['datetimes'][$i] = array( - '#type' => 'container', - ); - - // Timestamps / Period begin wrapper. - $form['basic']['when']['datetimes'][$i]['begin'] = array( - '#type' => 'container', - ); - - // Remove timestamp. - if ($date_count > 1) { - - $form['basic']['when']['datetimes'][$i]['begin']['datetimes_remove_child'] = array( - '#type' => 'submit', - '#value' => t('×'), - '#name' => 'datetimes_remove_child_' . $i, - '#attributes' => array('class' => array('add-more-link btn-link'), 'title' => 'remove date'), - '#ajax' => array( - 'callback' => 'culturefeed_entry_ui_add_more_js', - 'wrapper' => 'when-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - ), - '#limit_validation_errors' => array(array('datetimes')), - '#submit' => array('culturefeed_entry_ui_add_more_submit'), - ); - - } - - // Timestamp / Period begin date. - $begin_date = ($when == 'timestamps') ? (isset($timestamps[$i]['date']) ? $timestamps[$i]['date'] : '') : $period_start; - - $form['basic']['when']['datetimes'][$i]['begin']['date'] = array( - '#type' => 'date_popup', - '#date_label_position' => 'none', - '#title' => t('Date'), - '#default_value' => (!$triggering_element) ? $begin_date : '', - '#date_format' => 'd-m-Y', - '#ajax' => array( - 'callback' => 'culturefeed_entry_ui_add_more_js', - 'wrapper' => 'when-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - ), - '#attributes' => array('class' => array('start-date')), - ); - - // Timestamp begin hour. - if ($when == 'timestamps') { - - $begin_time = isset($timestamps[$i]['begintime']) ? $timestamps[$i]['date'] . ' ' . $timestamps[$i]['begintime'] : ''; - - $form['basic']['when']['datetimes'][$i]['begin']['hour'] = array( - '#type' => 'date_select', - '#name' => 'begin_hour', - '#default_value' => (!$triggering_element) ? $begin_time : '', - '#date_format' => 'H:i', - '#date_increment' => 30, - ); - - } - - // Check if the date has an end. - // First check if we are dealing with a period. - // Next check if we are in the initial form build and a timestamp - // endtime exists. - // Next check if there is a submitted end. - // Next check if a new end is being added. - // Next check for any non date ajax trigger to avoid losing values. - $has_end = ( - ($when == 'period') || - (!$triggering_element && isset($timestamps[$i]['endtime'])) || - (isset($form_state['values']['datetimes'][$i]['end'])) || - ($triggering_element == 'datetimes_add_end_' . $i) || - ($triggering_element && strpos($triggering_element, 'datetimes') !== 0) - ); - - // Timestamp / Period add end date or time. - if (!$has_end) { - - $form['basic']['when']['datetimes'][$i]['begin']['datetimes_add_end'] = array( - '#type' => 'submit', - '#value' => t('+ add end date or time'), - '#name' => 'datetimes_add_end_' . $i, - '#attributes' => array('class' => array('add-more-link btn-link')), - '#ajax' => array( - 'callback' => 'culturefeed_entry_ui_add_more_js', - 'wrapper' => 'when-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - ), - '#limit_validation_errors' => array(array('datetimes')), - '#submit' => array('culturefeed_entry_ui_add_more_submit'), - ); - - } - - // Timestamp / Period end wrapper. - if ($has_end) { - - $form['basic']['when']['datetimes'][$i]['end'] = array( - '#type' => 'container', - ); - - if ($when == 'period' || ($date_count == 1 && !isset($form_state['values']['datetimes'][$i]['end']['date']))) { - - $form['basic']['when']['datetimes'][$i]['end']['date'] = array( - '#type' => 'date_popup', - '#title' => t('End date'), - '#date_label_position' => 'none', - '#default_value' => (!$triggering_element) ? $period_end : '', - '#date_format' => 'd-m-Y', - '#ajax' => array( - 'callback' => 'culturefeed_entry_ui_add_more_js', - 'wrapper' => 'when-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - ), - ); - - } - - if ($when == 'timestamps') { - - $end_time = isset($timestamps[$i]['endtime']) ? $timestamps[$i]['date'] . ' ' . $timestamps[$i]['endtime'] : ''; - - $form['basic']['when']['datetimes'][$i]['end']['hour'] = array( - '#type' => 'date_select', - '#default_value' => (!$triggering_element) ? $end_time : '', - '#date_format' => 'H:i', - '#date_increment' => 30, - ); - - } - - $form['basic']['when']['datetimes'][$i]['end']['datetimes_remove_end'] = array( - '#type' => 'submit', - '#value' => t('remove end date'), - '#name' => 'datetimes_remove_end_' . $i, - '#attributes' => array('class' => array('add-more-link btn-link')), - '#ajax' => array( - 'callback' => 'culturefeed_entry_ui_add_more_js', - 'wrapper' => 'when-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - ), - '#limit_validation_errors' => array(array('datetimes')), - '#submit' => array('culturefeed_entry_ui_add_more_submit'), - ); - - } - - } - - if ($when == 'timestamps') { - - $form['basic']['when']['datetimes']['datetimes_add_child'] = array( - '#type' => 'submit', - '#name' => 'datetimes_add_child', - '#value' => t('+ add date'), - '#attributes' => array('class' => array('add-more-link btn-link')), - '#ajax' => array( - 'callback' => 'culturefeed_entry_ui_add_more_js', - 'wrapper' => 'when-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - 'effect' => 'none', - ), - '#limit_validation_errors' => array(array('datetimes')), - '#submit' => array('culturefeed_entry_ui_add_more_submit'), - ); - - } - - } - - $form['basic']['when']['permanent'] = array( - '#type' => 'checkbox', - '#default_value' => ($when == 'permanent'), - '#title' => t('Permanent'), - '#ajax' => array( - 'callback' => 'culturefeed_entry_ui_add_more_js', - 'wrapper' => 'when-ajax-wrapper', - 'effect' => 'fade', - 'progress' => array('type' => 'throbber'), - ), - '#states' => array( - 'visible' => array( - ':input[name="datetimes[0][begin][date][date]"]' => array( - array('filled' => FALSE), - ), + '#type' => 'culturefeed_date_control', + '#default_value' => array( + 'period' => array( + 'start_date' => $period_start, + 'end_date' => $period_end, ), + 'permanent' => $permanent, + 'timestamps' => $timestamps, + 'opening_times' => array('days' => $weekscheme), ), + '#allowed_days' => CultureFeed_Cdb_Data_Calendar_SchemeDay::$allowedDays, ); - if (($when == 'period' || $when == 'permanent') || ($triggering_element && strpos($triggering_element, 'datetimes') !== 0)) { - - // TODO put in function cos we need it for permanent as well - // Period / permanent elements. - $form['basic']['when']['period_or_permanent'] = array( - '#tree' => TRUE, - '#type' => 'container', - '#states' => array( - 'visible' => array( - ':input[name=when]' => array( - array('value' => 'period'), - array('value' => 'permanent'), - ), - ), - ), - ); - - $form['basic']['when']['period_or_permanent']['all_day'] = array( - '#type' => 'radios', - '#title' => t('Open all day?'), - '#options' => array(1 => t('Yes'), 0 => t('No')), - '#default_value' => ($weekscheme == NULL) ? 1 : 0, - ); - - $form['basic']['when']['period_or_permanent']['opening_times'] = array( - '#type' => 'container', - '#states' => array( - 'visible' => array(':input[name="period_or_permanent[all_day]"]' => array('value' => '0')), - ), - '#prefix' => '
', - '#suffix' => '
', - '#theme' => 'culturefeed_entry_ui_opening_times_table', - ); - - // Add opening times information for every day. - foreach (CultureFeed_Cdb_Data_Calendar_SchemeDay::$allowedDays as $day) { - - $form['basic']['when']['period_or_permanent']['opening_times'][$day] = array( - '#tree' => TRUE, - '#type' => 'fieldset', - '#title' => $day_labels[$day], - ); - - $opening_times = array(); - if ($weekscheme && $data = $weekscheme->getDay($day)) { - $opening_times = $data->getOpeningTimes(); - } - - $opening_count = 0; - if ($opening_times) { - foreach ($opening_times as $i => $opening_time) { - culturefeed_entry_ui_attach_opening_time_elements($form, $day, $i, $opening_time); - $opening_count++; - } - } - else { - culturefeed_entry_ui_attach_opening_time_elements($form, $day, 0); - $opening_count++; - } - - } - - // Add more button was clicked. Check how many extra rows need to be added. - if (isset($form_state['#opening_times_needed'])) { - for (; $opening_count < $form_state['#opening_times_needed']; $opening_count++) { - culturefeed_entry_ui_attach_opening_time_elements($form, $day, $opening_count); - } - } - - - /*$form['basic']['when']['period_or_permanent']['add_more_opening_times'] = array( - '#type' => 'submit', - '#name' => 'opening_times_add_more', - '#value' => t('+ add another opening time'), - '#attributes' => array('class' => array('opening-times-add-more-submit add-more-link btn-link')), - '#ajax' => array( - 'callback' => 'culturefeed_entry_ui_add_more_js', - 'wrapper' => 'opening-times-ajax-wrapper', - 'effect' => 'none', - ), - '#limit_validation_errors' => array(array('period_or_permanent')), - '#submit' => array('culturefeed_entry_ui_add_more_submit'), - '#states' => array( - 'visible' => array(':input[name="period_or_permanent[all_day]"]' => array('value' => '0')), - ), - );*/ - } - // Extra. $form['extra'] = array( '#type' => 'fieldset', @@ -1710,115 +1379,6 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { } - -/** - * Attach a new datetime element. - * - */ -function culturefeed_entry_ui_attach_begindate_elements(&$form, $i, $info = NULL) { - - $date = date("Y-m-d"); - $hour = date("H:i"); - $format = 'Y-m-d'; - - $form['basic']['when']['datetimes'][$i] = array( - '#type' => 'container', - '#prefix' => '
', - '#suffix' => '
', - ); - - $form['basic']['when']['datetimes'][$i]['begin'] = array( - '#type' => 'container', - '#prefix' => '
', - '#suffix' => '
', - ); - - $form['basic']['when']['datetimes'][$i]['begin']['date'] = array( - '#type' => 'date_popup', - '#title' => t('Date'), - '#default_value' => '', - '#date_format' => 'Y-m-d', - '#attributes' => array('class' => array('start-date')), - ); - - $form['basic']['when']['datetimes'][$i]['begin']['hour'] = array( - '#type' => 'date_select', - '#name' => 'begin_hour', - '#title' => t('Start time'), - '#default_value' => '', - '#date_format' => 'H:i', - '#date_increment' => 30, - ); - - culturefeed_entry_ui_attach_enddate_elements($form, $i, $info); - - /*$enddates = array(); - $enddate_count = 0; - - if ($enddates) { - foreach ($enddates as $j => $jinfo) { - culturefeed_entry_ui_attach_enddate_elements($form, $j, $jinfo); - $enddate_count++; - } - } - else { - culturefeed_entry_ui_attach_enddate_elements($form, 0); - - $enddate_count++; - } - - // Add more button was clicked. Check how many extra rows need to be added. - if (isset($form_state['#enddates_needed'])) { - - for (; $enddate_count < $form_state['#enddates_needed']; $enddate_count++) { - culturefeed_entry_ui_attach_enddate_elements($form, $enddate_count); - } - } - - $form['basic']['when']['datetimes'][$i] = array( - '#type' => 'submit', - '#name' => 'enddates_add_more', - '#value' => t('+ add end date or time'), - '#attributes' => array('class' => array('add-more-link btn-link add-endtime-link')), - '#ajax' => array( - 'callback' => 'culturefeed_entry_ui_add_more_js', - 'wrapper' => 'datetime-child'. $i .'-ajax-wrapper', - 'effect' => 'none', - ), - '#limit_validation_errors' => array(array('datetimes')), - '#submit' => array('culturefeed_entry_ui_add_more_submit'), - );*/ - -} - -function culturefeed_entry_ui_attach_enddate_elements(&$form, $i, $info = NULL) { - - $date = date("Y-m-d"); - $hour = date("H:i"); - $format = 'Y-m-d'; - - $form['basic']['when']['datetimes'][$i]['end'] = array( - '#type' => 'container', - '#prefix' => '
', - '#suffix' => '
', - ); - - $form['basic']['when']['datetimes'][$i]['end']['date'] = array( - '#type' => 'date_popup', - '#title' => t('End date'), - '#default_value' => '', - '#date_format' => 'Y-m-d', - ); - - $form['basic']['when']['datetimes'][$i]['end']['hour'] = array( - '#type' => 'date_select', - '#title' => t('End time'), - '#default_value' => '', - '#date_format' => 'H:i', - '#date_increment' => 30, - ); -} - /** * Attach a new language element. * @@ -1985,37 +1545,6 @@ function culturefeed_entry_ui_attach_link_info_elements(&$form, $i, $info = NULL } - -/** - * Attach opening time elements for a day. - * - * @param array $form - * Form to attach to. - * @param string $day - * English name of the day to attach, for example 'monday'. - * @param int $i - * Index to set. - * @param CultureFeed_Cdb_Data_Calendar_OpeningTime $opening_time - * Openingtime information - */ -function culturefeed_entry_ui_attach_opening_time_elements(&$form, $day, $i, $opening_time = NULL) { - - $form['basic']['when']['period_or_permanent']['opening_times'][$day][$i]['open_from'] = array( - '#type' => 'textfield', - '#size' => 12, - '#default_value' => $opening_time ? $opening_time->getOpenFrom() : '', - '#description' => t('Format') . ': 12:00', - ); - - $form['basic']['when']['period_or_permanent']['opening_times'][$day][$i]['open_till'] = array( - '#type' => 'textfield', - '#size' => 12, - '#default_value' => $opening_time ? $opening_time->getOpenTill() : '', - '#description' => t('Format') . ': 12:00', - ); - -} - /** * Validate the event form. */ @@ -2028,87 +1557,78 @@ function culturefeed_entry_ui_event_save_validate($form, &$form_state) { form_set_error('age', t('Please fill in correct age')); } - // Validate datetime - // Validate timestamps. - if ($values['datetype'] == 'timestamps') { + // Validate period. + if ($values['when']['date_control']['type'] == 'period') { - // Only one timestamp saved for one day. - if (count($values['datetimes']) == 1) { + $period = $values['when']['date_control']['period']; - $form_state['values']['datetimes'] = array($values['datetimes'][0]); - $values['datetimes'] = $form_state['values']['datetimes']; - } + // Form validation hasn't processed the dates values yet, so don't validate. + if (!is_array($period['start_date']) && !is_array($period['end_date'])) { - foreach ($values['datetimes'] as $key => $timestamp) { + // The dates. try { + CultureFeed_Cdb_Data_Calendar::validateDate($period['start_date']); + CultureFeed_Cdb_Data_Calendar::validateDate($period['end_date']); + } + catch (UnexpectedValueException $e) { + form_set_error('when][date_control][period', t('Please fill in correct date and time')); + } - // Empty start dates are ignored. - if (empty($timestamp['begin']['date'])) { - continue; - } - - CultureFeed_Cdb_Data_Calendar::validateDate($timestamp['begin']['date']); - - if (!empty($timestamp['end']['date'])) { - CultureFeed_Cdb_Data_Calendar::validateDate($timestamp['end']['date']); - } - } catch (UnexpectedValueException $e) { - form_set_error('datetimes][' . $key, t('Please fill in correct date and time')); + // Order of dates. + $start_date = strtotime($period['start_date']); + $end_date = strtotime($period['end_date']); + if ($start_date > $end_date) { + form_set_error('when][date_control][period', t('Date field is invalid. The end date is earlier than the beginning date.')); } - } - // Check if this is duplicate for above CultureFeed_Cdb_Data_Calendar::validateTime. - if (empty($values['datetimes'][0]['begin']['date'])) { - form_set_error('datetimes', t('A date is required.')); } - else { - for ($i = 0; $i < count($values['datetimes']); $i++) { - $begindate = ''; - $begintime = ''; - $enddate = ''; - $endtime = ''; - if (isset($values['datetimes'][$i]['begin']['date'])) { - $begindate = strtotime($values['datetimes'][$i]['begin']['date']); - } - if (isset($values['datetimes'][$i]['begin']['hour'])) { - $begintime = strtotime($values['datetimes'][$i]['begin']['hour']); - } - if (isset($values['datetimes'][$i]['end'])) { - if (isset($values['datetimes'][$i]['end']['date'])) { - $enddate = strtotime($values['datetimes'][$i]['end']['date']); - } - if (isset($values['datetimes'][$i]['end']['hour'])) { - $endtime = strtotime($values['datetimes'][$i]['end']['hour']); - } - } + } - if ($enddate) { - if ($begindate > $enddate) { - form_set_error('datetimes', t('Date field is invalid. The end date is earlier than the beginning date.')); - } - if ($begintime > $endtime) { - form_set_error('datetimes', t('Date field is invalid. The end time is earlier than the beginning time.')); - } - } - else { - if ($endtime && $begintime > $endtime) { - form_set_error('datetimes', t('Date field is invalid. The end time is earlier than the beginning time.')); - } - } + // Validate timestamps. + if ($values['when']['date_control']['type'] == 'timestamps') { + + $timestamps = $values['when']['date_control']['timestamps']['stamps']; + + foreach ($timestamps as $key => $timestamp) { + + // Form validation hasn't processed the dates values yet, so don't validate. + if (is_array($timestamp['date'])) { + continue; } + + // The date. + try { + CultureFeed_Cdb_Data_Calendar::validateDate($timestamp['date']); + } catch (UnexpectedValueException $e) { + form_set_error('when][date_control][timestamps][stamps][' . $key, t('Please fill in correct date and time')); + } + + // The times. + $start_time = isset($timestamp['start_time']) ? strtotime($timestamp['start_time']) : ''; + $end_time = isset($timestamp['end_time']) ? strtotime($timestamp['end_time']) : ''; + if (($start_time && $end_time) && $start_time > $end_time) { + form_set_error('when][date_control][timestamps][stamps][' . $key, t('Date field is invalid. The end time is earlier than the beginning time.')); + } + } + } - if ($values['datetype'] == 'period' || $values['datetype'] == 'permanent') { + // Validate weekscheme. + if ($values['when']['date_control']['type'] == 'period' || $values['when']['date_control']['type'] == 'permanent') { + $opening_times = $values['when']['date_control']['opening_times']; // Validate the weekscheme. - if (isset($values['period_or_permanent']) && !$values['period_or_permanent']['all_day']) { - foreach ($values['period_or_permanent']['opening_times'] as $day => $opening_times) { + if (!$opening_times['all_day']) { + + foreach ($opening_times['days'] as $day => $opening_times) { + foreach ($opening_times as $key => $opening_time) { if (!empty($opening_time['open_from']) || !empty($opening_time['open_till'])) { - $parents = array('period_or_permanent', 'opening_times', $day, $key); + + $parents = array('when', 'date_control', 'opening_times', 'days', $day, $key); if (substr_count($opening_time['open_from'], ':') == 1) { $opening_time['open_from'] .= ':00'; form_set_value(array('#parents' => array_merge($parents, array('open_from'))), $opening_time['open_from'], $form_state); @@ -2120,14 +1640,24 @@ function culturefeed_entry_ui_event_save_validate($form, &$form_state) { try { CultureFeed_Cdb_Data_Calendar::validateTime($opening_time['open_from']); + } + catch (Exception $e) { + form_set_error('when][date_control][opening_times][days][' . $day . '][' . $key . '][open_from', t('Please fill in correct time.')); + } + + try { CultureFeed_Cdb_Data_Calendar::validateTime($opening_time['open_till']); - } catch (Exception $e) { - form_set_error('period_or_permanent][opening_times][' . $day . '][' . $key, t('Please fill in correct date')); } + catch (Exception $e) { + form_set_error('when][date_control][opening_times][days][' . $day . '][' . $key . '][open_till', t('Please fill in correct time.')); + } + } } + } + } } @@ -2435,19 +1965,19 @@ function _culturefeed_entry_ui_ui_event_form_save_event($form, &$form_state, Cul } } - // Datetimes as calendar. - if ($values['datetype'] == 'timestamps') { - _culturefeed_entry_ui_event_save_timestamps($event, $values); + // Timestamps. + if ($values['when']['date_control']['type'] == 'timestamps') { + _culturefeed_entry_ui_event_save_timestamps($event, $values['when']['date_control']['timestamps']['stamps']); } - // Datetimes as period. - if ($values['datetype'] == 'period') { - _culturefeed_entry_ui_event_save_period($event, $values); + // Period. + if ($values['when']['date_control']['type'] == 'period') { + _culturefeed_entry_ui_event_save_period($event, $values['when']['date_control']['period']); } - // Weekscheme for period or permanent. - if ($values['datetype'] == 'period' || $values['datetype'] == 'permanent') { - _culturefeed_entry_ui_event_save_weekscheme($event, $values); + // Weekscheme. + if ($values['when']['date_control']['type'] == 'period' || $values['when']['date_control']['type'] == 'permanent') { + _culturefeed_entry_ui_event_save_weekscheme($event, $values['when']['date_control']); } // Categories. @@ -2780,22 +2310,18 @@ function _culturefeed_entry_ui_ui_event_form_save_event($form, &$form_state, Cul /** * Save helper function that creates calendar object for timestamps. */ -function _culturefeed_entry_ui_event_save_timestamps(&$event, $values) { - $calendar = new CultureFeed_Cdb_Data_Calendar_TimestampList(); +function _culturefeed_entry_ui_event_save_timestamps(&$event, $timestamps) { - foreach ($values['datetimes'] as $timestamp) { + $calendar = new CultureFeed_Cdb_Data_Calendar_TimestampList(); - // Empty start dates are ignored. - if (empty($timestamp['begin']['date'])) { - continue; - } + foreach ($timestamps as $timestamp) { - $timestamp_object = new CultureFeed_Cdb_Data_Calendar_Timestamp($timestamp['begin']['date']); - if (!empty($timestamp['begin']['hour'])) { - $timestamp_object->setStartTime($timestamp['begin']['hour'] . ':00'); + $timestamp_object = new CultureFeed_Cdb_Data_Calendar_Timestamp($timestamp['date']); + if (!empty($timestamp['start_time'])) { + $timestamp_object->setStartTime($timestamp['start_time'] . ':00'); } - if (!empty($timestamp['end']['hour'])) { - $timestamp_object->setEndTime($timestamp['end']['hour'] . ':00'); + if (!empty($timestamp['end_time'])) { + $timestamp_object->setEndTime($timestamp['end_time'] . ':00'); } $calendar->add($timestamp_object); } @@ -2809,7 +2335,7 @@ function _culturefeed_entry_ui_event_save_timestamps(&$event, $values) { function _culturefeed_entry_ui_event_save_period(&$event, $values) { $period_list = new CultureFeed_Cdb_Data_Calendar_PeriodList(); - $period = new CultureFeed_Cdb_Data_Calendar_Period($values['datetimes']['0']['begin']['date'], $values['datetimes']['0']['end']['date']); + $period = new CultureFeed_Cdb_Data_Calendar_Period($values['start_date'], $values['end_date']); $period_list->add($period); $event->setCalendar($period_list); @@ -2818,14 +2344,14 @@ function _culturefeed_entry_ui_event_save_period(&$event, $values) { /** * Save helper function that creates calendar object for weekschemes. */ -function _culturefeed_entry_ui_event_save_weekscheme(&$event, $values) { +function _culturefeed_entry_ui_event_save_weekscheme(&$event, $date_control) { $weekscheme = NULL; // Construct the weekscheme. - if (isset($values['period_or_permanent']) && !$values['period_or_permanent']['all_day']) { + if (isset($date_control['opening_times']) && !$date_control['opening_times']['all_day']) { $weekscheme = new CultureFeed_Cdb_Data_Calendar_Weekscheme(); - foreach ($values['period_or_permanent']['opening_times'] as $day => $opening_times) { + foreach ($date_control['opening_times']['days'] as $day => $opening_times) { $opening_info = new CultureFeed_Cdb_Data_Calendar_SchemeDay($day); $open_type = CultureFeed_Cdb_Data_Calendar_SchemeDay::SCHEMEDAY_OPEN_TYPE_CLOSED; @@ -2843,9 +2369,9 @@ function _culturefeed_entry_ui_event_save_weekscheme(&$event, $values) { } - if ($values['datetype'] == 'period') { + if ($date_control['type'] == 'period') { $calendar = new CultureFeed_Cdb_Data_Calendar_PeriodList(); - $period = new CultureFeed_Cdb_Data_Calendar_Period($values['datetimes'][0]['begin']['date'], $values['datetimes'][0]['end']['date']); + $period = new CultureFeed_Cdb_Data_Calendar_Period($date_control['period']['start_date'], $date_control['period']['end_date']); if ($weekscheme) { $period->setWeekScheme($weekscheme); } @@ -2874,6 +2400,8 @@ function culturefeed_entry_ui_event_form_submit($form, &$form_state) { array($form_state), ), ), + 'init_message' => '
' . t('Initializing.') . '
', + 'progress_message' => '
' . t('Completed @current of @total.') . '
', 'finished' => 'culturefeed_entry_ui_event_form_submission_timeout_batch_finished', 'file' => drupal_get_path('module', 'culturefeed_entry_ui') . '/includes/culturefeed_entry_ui.pages.inc', ); @@ -3032,7 +2560,7 @@ function culturefeed_entry_ui_edit_tags_form_submit($form, &$form_state) { } catch (Exception $e) { - if ($e->getCode() == culturefeed_entry_uiApi::CODE_KEYWORD_PRIVATE) { + if ($e->getCode() == CultureFeed_EntryApi::CODE_KEYWORD_PRIVATE) { drupal_set_message(t('You tried to add a tag that should not be added by anyone. If you still wish to add this or have other questions about this, please email to "vragen@uitdatabank.be".')); } else { @@ -3073,7 +2601,7 @@ function culturefeed_entry_ui_photo_after_build($element) { */ function culturefeed_entry_ui_event_form_submission_timeout_batch($form_state, &$context) { // Use the same function to get the event as used on the event page. - $event_search = culturefeed_search_item_load($form_state['#event_id'], 'event'); + $event_search = culturefeed_search_item_load($form_state['#event_id'], 'event', FALSE); $event_updated = FALSE; if ($event_search) { diff --git a/culturefeed_entry_ui/js/culturefeed_entry_ui.js b/culturefeed_entry_ui/js/culturefeed_entry_ui.js index f66e65ac..34ccccc4 100644 --- a/culturefeed_entry_ui/js/culturefeed_entry_ui.js +++ b/culturefeed_entry_ui/js/culturefeed_entry_ui.js @@ -68,21 +68,6 @@ Drupal.Culturefeed_entry_ui = Drupal.Culturefeed_entry_ui || {}; }; - Drupal.behaviors.culturefeed_entry_ui_complete_time = { - attach: function(context, setings) { - $( "input[name^='period_or_permanent[opening_times]']").blur(function() { - var string = $(this).val(); - if (string) { - var seperator = string.split(':').length - 1; - if (seperator == 0) { - $(this).val(string + ':00'); - } - } - }); - } - }; - - /** * Hides the autocomplete suggestions. */ diff --git a/culturefeed_entry_ui/theme/theme.inc b/culturefeed_entry_ui/theme/theme.inc index 7f2f4297..a9a52d8b 100644 --- a/culturefeed_entry_ui/theme/theme.inc +++ b/culturefeed_entry_ui/theme/theme.inc @@ -4,135 +4,6 @@ * Theming functions for entry api ui. */ -/** - * Theme the opening times table. - */ -function theme_culturefeed_entry_ui_opening_times_table($variables) { - - $container = $variables['element']; - - $total_opening_times = 1; - $rows = array(); - foreach (element_children($container) as $key) { - - $day_element = $container[$key]; - $row = array($day_element['#title']); - $opening_times = element_children($day_element); - $total_opening_times = count($opening_times); - - foreach ($opening_times as $opening_time) { - $row[] = render($day_element[$opening_time]['open_from']); - $row[] = render($day_element[$opening_time]['open_till']); - } - - $rows[] = $row; - - } - - $table_variables = array( - 'header' => array( - t('open'), - ), - 'rows' => $rows, - ); - - while ($total_opening_times > 0) { - $table_variables['header'][] = t('from'); - $table_variables['header'][] = t('to'); - $total_opening_times--; - } - - return theme('table', $table_variables); - -} - -/** - * Theme the datetimes table. - */ -function theme_culturefeed_entry_ui_when_datetimes_table(&$variables) { - - $form = $variables['form']; - $table = array('rows' => array(), 'attributes' => array('class' => 'when-datetimes-table')); - - // First loop to check how many cells we need. - $cell_dates_remove_child = FALSE; - $cell_begin_date = FALSE; - $cell_begin_hour = FALSE; - $cell_datetimes_add_end = FALSE; - $cell_end_date = FALSE; - $cell_end_hour = FALSE; - $cell_datetimes_remove_end = FALSE; - foreach (element_children($form) as $element) { - if (isset($form[$element]['begin']['datetimes_remove_child'])) { - $cell_dates_remove_child = TRUE; - } - if (isset($form[$element]['begin']['date'])) { - $cell_begin_date = TRUE; - } - if (isset($form[$element]['begin']['hour'])) { - $cell_begin_hour = TRUE; - } - if (isset($form[$element]['begin']['datetimes_add_end'])) { - $cell_datetimes_add_end = TRUE; - } - if (isset($form[$element]['end']['date'])) { - $cell_end_date = TRUE; - } - if (isset($form[$element]['end']['hour'])) { - $cell_end_hour = TRUE; - } - if (isset($form[$element]['end']['datetimes_remove_end'])) { - $cell_datetimes_remove_end = TRUE; - } - } - - // Second loop to set the cells. - foreach (element_children($form) as $element) { - if ($element !== 'datetimes_add_child') { - - $begin = isset($form[$element]['begin']) ? $form[$element]['begin'] : array(); - $end = isset($form[$element]['end']) ? $form[$element]['end'] : array(); - - $cells = array(); - if ($cell_dates_remove_child) { - $cells[] = isset($begin['datetimes_remove_child']) ? drupal_render($begin['datetimes_remove_child']) : ''; - } - if ($cell_begin_date) { - $cells[] = isset($begin['date']) ? drupal_render($begin['date']) : ''; - } - if ($cell_begin_hour) { - $cells[] = isset($begin['hour']) ? drupal_render($begin['hour']) : ''; - } - if ($cell_datetimes_add_end) { - $cells[] = isset($begin['datetimes_add_end']) ? drupal_render($begin['datetimes_add_end']) : ''; - } - if ($cell_end_date) { - $add = $cells; - $add[] = array(); - $cells = array(); - $cells[] = isset($end['date']) ? drupal_render($end['date']) : ''; - } - if ($cell_end_hour) { - $cells[] = isset($end['hour']) ? drupal_render($end['hour']) : ''; - } - if ($cell_datetimes_remove_end) { - $cells[] = isset($end['datetimes_remove_end']) ? drupal_render($end['datetimes_remove_end']) : ''; - } - - if (isset($add)) { - $table['rows'][] = $add; - } - $table['rows'][] = $cells; - - } - } - - $output = theme('table', $table); - $output .= drupal_render($form['datetimes_add_child']); - return $output; - -} - /** * Preprocess function for the culturefeed_entry_ui_event_form. */ diff --git a/culturefeed_mailing/culturefeed_mailing.module b/culturefeed_mailing/culturefeed_mailing.module index 99819589..395bf2fc 100644 --- a/culturefeed_mailing/culturefeed_mailing.module +++ b/culturefeed_mailing/culturefeed_mailing.module @@ -30,8 +30,7 @@ function culturefeed_mailing_menu() { $items = array(); $items['culturefeed/toggle/newsletter-optin/%/%/%'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Newsletter opt-in'), + 'title' => 'Newsletter opt-in', 'page callback' => 'culturefeed_mailing_toggle_optin', 'page arguments' => array(3, 4), 'access callback' => 'culturefeed_is_culturefeed_user', @@ -75,8 +74,7 @@ function culturefeed_mailing_menu() { // Content management pages. $items['admin/content/mailing-lists'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array(t('Mailing lists')), + 'title' => 'Mailing lists', 'page callback' => 'culturefeed_mailing_lists_overview', 'access arguments' => array('manage mailing lists'), 'type' => MENU_LOCAL_TASK, @@ -84,8 +82,7 @@ function culturefeed_mailing_menu() { ); $items['admin/content/mailing-lists/add'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array(t('Add mailing list')), + 'title' => 'Add mailing list', 'page callback' => 'drupal_get_form', 'page arguments' => array('culturefeed_mailing_lists_form'), 'access arguments' => array('manage mailing lists'), @@ -94,8 +91,7 @@ function culturefeed_mailing_menu() { ); $items['admin/content/mailing-lists/edit/%culturefeed_mailing'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array(t('Add mailing list')), + 'title' => 'Add mailing list', 'page callback' => 'drupal_get_form', 'page arguments' => array('culturefeed_mailing_lists_form', 4), 'access arguments' => array('manage mailing lists'), @@ -103,8 +99,7 @@ function culturefeed_mailing_menu() { ); $items['admin/content/mailing-lists/test/%culturefeed_mailing'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array(t('Test mailing list')), + 'title' => 'Test mailing list', 'page callback' => 'drupal_get_form', 'page arguments' => array('culturefeed_mailing_test_list_form', 4), 'access arguments' => array('manage mailing lists'), @@ -112,8 +107,7 @@ function culturefeed_mailing_menu() { ); $items['admin/content/mailing-lists/send/%culturefeed_mailing'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array(t('Activate mailing list')), + 'title' => 'Activate mailing list', 'page callback' => 'drupal_get_form', 'page arguments' => array('culturefeed_mailing_send_list_form', 4), 'access arguments' => array('manage mailing lists'), @@ -121,8 +115,7 @@ function culturefeed_mailing_menu() { ); $items['admin/content/mailing-lists/disable/%culturefeed_mailing'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array(t('Disable scheduled sending')), + 'title' => 'Disable scheduled sending', 'page callback' => 'drupal_get_form', 'page arguments' => array('culturefeed_mailing_disable_list_form', 4), 'access arguments' => array('manage mailing lists'), @@ -130,8 +123,7 @@ function culturefeed_mailing_menu() { ); $items['admin/content/mailing-lists/delete/%culturefeed_mailing'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array(t('Add mailing list')), + 'title' => 'Add mailing list', 'page callback' => 'drupal_get_form', 'page arguments' => array('culturefeed_mailing_delete_form', 4), 'access arguments' => array('manage mailing lists'), diff --git a/culturefeed_messages/includes/pages.inc b/culturefeed_messages/includes/pages.inc index 46371c74..04e13d90 100644 --- a/culturefeed_messages/includes/pages.inc +++ b/culturefeed_messages/includes/pages.inc @@ -134,7 +134,7 @@ function culturefeed_messages_new_message_form($form, &$form_state, $object = NU } // Always use recipientPage as senderPage in replies - if ($object instanceof CultureFeed_Messages_Message && !empty($object->recipientPage)) { + if ($object instanceof CultureFeed_Messages_Message && $object->recipientPage instanceof CultureFeed_Cdb_Item_Page) { $form['send_as'] = array( '#type' => 'hidden', '#default_value' => $object->recipientPage->getId(), diff --git a/culturefeed_pages/culturefeed_pages.module b/culturefeed_pages/culturefeed_pages.module index 13f97e50..9ffb36ae 100644 --- a/culturefeed_pages/culturefeed_pages.module +++ b/culturefeed_pages/culturefeed_pages.module @@ -425,6 +425,15 @@ function culturefeed_pages_menu() { 'file' => 'includes/members.inc', ); + $items['pages/%culturefeed_pages_page/membership/request-validated-admin/%'] = array( + 'title' => 'Request to become validated admin', + 'page callback' => 'culturefeed_pages_page_request_validated_admin', + 'page arguments' => array(1, 4), + 'access callback' => 'culturefeed_is_culturefeed_user', + 'type' => MENU_CALLBACK, + 'file' => 'includes/members.inc', + ); + $items['pages/switch/%culturefeed_pages_page'] = array( 'title' => 'Change active page', 'page callback' => 'culturefeed_pages_switch_page', @@ -442,6 +451,14 @@ function culturefeed_pages_menu() { 'file' => 'includes/pages.inc', ); + $items['ajax/culturefeed/pages/page-suggestion/ids'] = array( + 'page callback' => 'culturefeed_pages_page_suggestion_autocomplete_page', + 'page arguments' => array(5, TRUE), + 'access callback' => 'culturefeed_is_culturefeed_user', + 'type' => MENU_CALLBACK, + 'file' => 'includes/pages.inc', + ); + $items['culturefeed/pages/join/%/%culturefeed_pages_page'] = array( 'page callback' => 'culturefeed_pages_page_join', 'page arguments' => array(3, 4), diff --git a/culturefeed_pages/includes/helpers.inc b/culturefeed_pages/includes/helpers.inc index fc0dd2be..49b9eab0 100644 --- a/culturefeed_pages/includes/helpers.inc +++ b/culturefeed_pages/includes/helpers.inc @@ -129,6 +129,34 @@ function culturefeed_pages_is_user_admin_of_page($page_id, $cf_account = NULL) { } +/** + * Is the given user validated admin of a given page. + * @return bool + */ +function culturefeed_pages_is_user_validated_admin_of_page($page_id, $cf_account = NULL) { + + try { + + if (empty($cf_account)) { + $cf_account = DrupalCultureFeed::getLoggedInUser(); + } + + if (!empty($cf_account->pageMemberships)) { + foreach ($cf_account->pageMemberships as $membership) { + if ($membership->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN && $membership->page->getId() == $page_id && $membership->validated) { + return TRUE; + } + } + } + } + catch (Exception $e) { + watchdog_exception('culturefeed_pages', $e); + } + + return FALSE; + +} + /** * Is the current user following a given page id. * @param string $page_id @@ -157,6 +185,18 @@ function culturefeed_pages_is_user_following_page($page_id) { } +/** + * Check if current page is a validated page. + * + * @param CultureFeed_Cdb_Item_Page $page + * Page to check + * @return bool + */ +function culturefeed_pages_page_is_validated_page(CultureFeed_Cdb_Item_Page $page) { + $validated_admins = culturefeed_pages_get_validated_admins_of_page($page); + return count($validated_admins) > 0; +} + /** * Get the page that currently is beïng viewed. This can be via a news item, or via the page itself. */ @@ -357,30 +397,18 @@ function culturefeed_pages_block_request_admin_membership(CultureFeed_Cdb_Item_P // Only for pages if the current user is already member of the page AND // if the page does not have a default admin yet. - $is_member = FALSE; - $is_admin = FALSE; - $number_of_admins = 0; - $account = DrupalCultureFeed::getLoggedInAccount(); if (!$account) { return; } - $cf_pages = DrupalCultureFeed::getConsumerInstance()->pages(); - $user_list = $cf_pages->getUserList($page->getId(), array(CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN, CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_MEMBER), FALSE); - if (!empty($user_list->memberships)) { - foreach ($user_list->memberships as $user_list_membership) { - if ($user_list_membership->user->id == $account->culturefeed_uid) { - $is_member = TRUE; - if ($user_list_membership->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN) { - $is_admin = TRUE; - } - } - if ($user_list_membership->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN) { - $number_of_admins++; - } - } + $is_admin = culturefeed_pages_is_user_admin_of_page($page->getId()); + if ($is_admin) { + $is_member = TRUE; + } + else { + $is_member = culturefeed_pages_is_user_member_of_page($page->getId()); } // Skip if the user is not even member. @@ -443,7 +471,7 @@ function culturefeed_pages_get_admins_of_page(CultureFeed_Cdb_Item_Page $page) { } catch (Exception $e) { watchdog_exception('culturefeed_pages', $e); - $admin_list = new CultureFeed_Pages_UserList(); + return array(); } foreach ($admin_list->memberships as $admin) { @@ -453,6 +481,47 @@ function culturefeed_pages_get_admins_of_page(CultureFeed_Cdb_Item_Page $page) { return $admins_of_page; } +/** + * Get all the validated admins of a given page. + * @param CultureFeed_Cdb_Item_Page $page + * @param bool $skip_cache + * Skip the cache. + */ +function culturefeed_pages_get_validated_admins_of_page(CultureFeed_Cdb_Item_Page $page, $skip_cache = FALSE) { + + try { + + if (!$skip_cache) { + $cf_pages = DrupalCultureFeed::getLoggedInUserInstance()->pages(); + } + else { + $cf = DrupalCultureFeed::getLoggedInUserInstance(); + if ($cf instanceof DrupalCultureFeed_Cache) { + $cf_pages = $cf->getRealCultureFeed()->pages(); + } + else { + $cf_pages = $cf->pages(); + } + } + + + $admin_list = $cf_pages->getUserList($page->getId(), array(CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN), FALSE); + } + catch (Exception $e) { + watchdog_exception('culturefeed_pages', $e); + return array(); + } + + $admins_of_page = array(); + foreach ($admin_list->memberships as $admin) { + if ($admin->validated) { + $admins_of_page[$admin->user->id] = $admin->user->id; + } + } + + return $admins_of_page; +} + /** * Get the themed list of page suggestions. */ @@ -513,3 +582,4 @@ function culturefeed_pages_get_page_suggestions_list() { return theme('culturefeed_pages_page_suggestion_list', array('suggestions' => $result->getItems())); } + diff --git a/culturefeed_pages/includes/members.inc b/culturefeed_pages/includes/members.inc index f7fe8d0a..887e7624 100644 --- a/culturefeed_pages/includes/members.inc +++ b/culturefeed_pages/includes/members.inc @@ -288,12 +288,12 @@ function culturefeed_pages_edit_membership_form_submit(&$form, &$form_state) { function culturefeed_pages_search_user_form() { $form = array(); - + $form['title'] = array( '#markup' => t('Add new members'), '#weight' => -999, ); - + $form['search'] = array( '#title' => t('Keyword'), '#type' => 'textfield', @@ -407,7 +407,7 @@ function culturefeed_pages_add_member_form_submit($form, &$form_state) { try { $params = array('activityPrivate' => FALSE); DrupalCultureFeed::getLoggedInUserInstance()->pages()->addMember($form_state['page']->getId(), $form_state['user']->id, $params); - $message = format_string(t('@nick is member of @page now.'), array('@nick' => $form_state['user']->nick, '@page' => $page->getName())); + $message = t('@nick is member of @page now.', array('@nick' => $form_state['user']->nick, '@page' => $page->getName())); drupal_set_message($message); } catch (Exception $e) { @@ -529,13 +529,13 @@ function culturefeed_pages_delete_member_form_submit($form, &$form_state) { if ($form_state['my_pages']) { $form_state['redirect'] = 'culturefeed/pages'; - $message = format_string(t('You are not longer a member of @page.'), array( + $message = t('You are not longer a member of @page.', array( '@page' => $form_state['page']->getName()) ); } else { $form_state['redirect'] = 'pages/' . $form_state['page']->getId() . '/members/nojs'; - $message = format_string(t('User @nick is removed as member of page @page.'), array( + $message = t('User @nick is removed as member of page @page.', array( '@nick' => $form_state['user']->nick, '@page' => $form_state['page']->getName()) ); @@ -608,7 +608,7 @@ function culturefeed_pages_page_request_admin_membership_approved($form, &$form_ $drupal_uid = culturefeed_get_uid_for_cf_uid($cf_user->id, $cf_user->nick); $page_title = $page->getName(); - $message = format_string(t('!username wants to be an administrator of !page.'), array( + $message = t('!username wants to be an administrator of !page.', array( '!username' => l($cf_user->nick, 'user/' . $drupal_uid), '!page' => l($page_title, culturefeed_search_detail_path('page', $page->getId(), $page_title)), )); @@ -640,7 +640,7 @@ function culturefeed_pages_page_request_admin_membership_approved_submit($form, $page_title = $page->getName(); $page_path = culturefeed_search_detail_path('page', $page->getId(), $page_title); - $message = format_string(t('!username successfully added as administrator of page !page.'), array( + $message = t('!username successfully added as administrator of page !page.', array( '!username' => l($cf_user->nick, 'user/' . $drupal_uid), '!page' => l($page_title, $page_path), )); @@ -663,3 +663,39 @@ function culturefeed_pages_page_request_admin_membership_approved_submit($form, drupal_goto($page_path); } + +/** + * Sent a request to become validated admin. + */ +function culturefeed_pages_page_request_validated_admin($page, $request_type) { + + // Send request to become a validated admin. + $success = FALSE; + try { + + $cf_pages = DrupalCultureFeed::getLoggedInUserInstance()->pages(); + $cf_pages->addValidatedadmin($page->getId()); + $message = t('Your request to become a validated administrator of this page is sent'); + $success = TRUE; + + } + catch (Exception $e) { + watchdog_exception('culturefeed_pages', $e); + $message = t('The request could not be sent.'); + } + + if ($request_type == 'ajax') { + $commands = array(); + + if ($success) { + $commands[] = ajax_command_html('#request_validated_adminship_link_' . $page->getId() . '_wrapper', $message); + } + + ajax_deliver(array('#type' => 'ajax', '#commands' => $commands)); + } + else { + drupal_set_message($message, $success ? 'status': 'error'); + drupal_goto(); + } + +} \ No newline at end of file diff --git a/culturefeed_pages/includes/pages.inc b/culturefeed_pages/includes/pages.inc index d38936b3..ac0bb602 100644 --- a/culturefeed_pages/includes/pages.inc +++ b/culturefeed_pages/includes/pages.inc @@ -227,7 +227,7 @@ function culturefeed_pages_page_follow($request_type, $page, $follow = TRUE) { /** * Page callback for the page suggestions autocomplete. */ -function culturefeed_pages_page_suggestion_autocomplete_page($search_string) { +function culturefeed_pages_page_suggestion_autocomplete_page($search_string, $return_ids = FALSE) { $matches = array(); if ($search_string) { @@ -244,7 +244,11 @@ function culturefeed_pages_page_suggestion_autocomplete_page($search_string) { if ($suggestions->hasSuggestions()) { foreach ($suggestions as $suggestion) { $page = culturefeed_pages_page_load($suggestion->getCdbid()); - $matches[$suggestion->getTitle()] = check_plain($suggestion->getTitle()); + if ($return_ids) { + $matches[$suggestion->getCdbid()] = check_plain($suggestion->getTitle()); + } else { + $matches[$suggestion->getTitle()] = check_plain($suggestion->getTitle()); + } } } diff --git a/culturefeed_pages/theme/theme.inc b/culturefeed_pages/theme/theme.inc index 2b8a82f2..6578b1f8 100644 --- a/culturefeed_pages/theme/theme.inc +++ b/culturefeed_pages/theme/theme.inc @@ -179,6 +179,7 @@ function _culturefeed_pages_preprocess_culturefeed_page(&$variables) { $variables['description'] = check_markup($page->getDescription(), 'filtered_html'); $variables['links'] = $page->getLinks(); $variables['image'] = $page->getImage(); + $variables['thumbnail'] = $page->getImage(); $variables['baseline'] = $page->getTagline(); $variables['cover'] = $page->getCover(); @@ -193,6 +194,12 @@ function _culturefeed_pages_preprocess_culturefeed_page(&$variables) { $query = array('destination' => culturefeed_search_detail_path('page', $page->getId(), $page->getName()), '/'); $variables['become_member_link'] = l(t('Become a member'), 'culturefeed/pages/join/nojs/' . $page->getId(), array('query' => $query)); } + else { + if (culturefeed_pages_is_user_member_of_page($page->getId()) && !culturefeed_pages_is_user_validated_admin_of_page($page->getId())) { + $query = array('destination' => culturefeed_search_detail_path('page', $page->getId(), $page->getName()), '/'); + $variables['become_validated_admin_url'] = url('pages/' . $page->getId() . '/membership/request-validated-admin/nojs', array('query' => $query)); + } + } // Address information $address = $page->getAddress(); diff --git a/culturefeed_search/includes/helpers.inc b/culturefeed_search/includes/helpers.inc index e6177263..5702523f 100644 --- a/culturefeed_search/includes/helpers.inc +++ b/culturefeed_search/includes/helpers.inc @@ -35,7 +35,7 @@ function culturefeed_get_search_service() { * @return mixed * FALSE if not found, otherwise CultuurNet\Search\ActivityStatsExtendedEntity. */ -function culturefeed_search_item_load($cdb_id, $type = '') { +function culturefeed_search_item_load($cdb_id, $type = '', $watchdog = TRUE) { $items = &drupal_static(__FUNCTION__, array()); @@ -66,7 +66,9 @@ function culturefeed_search_item_load($cdb_id, $type = '') { return $items[$cdb_id]; } catch (Exception $e) { - watchdog_exception('culturefeed_search', $e); + if ($watchdog) { + watchdog_exception('culturefeed_search', $e); + } } } diff --git a/culturefeed_search/lib/Drupal/Import/CultureFeedDomainImport.php b/culturefeed_search/lib/Drupal/Import/CultureFeedDomainImport.php index 29f4e787..633f2c89 100644 --- a/culturefeed_search/lib/Drupal/Import/CultureFeedDomainImport.php +++ b/culturefeed_search/lib/Drupal/Import/CultureFeedDomainImport.php @@ -87,6 +87,12 @@ private function importTerms($TermsElement, $pids = array()) { $termAttributes = $term->attributes(); + // Do not import disabled terms + if ($termAttributes['enabled'] == 'false') { + drush_log('skipped disabled term: ' . $termAttributes['id'], 'warning'); + continue; + } + // If it has children, also import them. if (isset($term->term)) { $child_pids = $pids; diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 5bf38f1b..396f9688 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -17,7 +17,7 @@ define("CULTUREFEED_SEARCH_UI_PAGER_ITEMS_PER_PAGE", 10); define('CULTUREFEED_SEARCH_SORT_ALPHABETICALLY', 'alphabetically'); define('CULTUREFEED_SEARCH_SORT_TOTAL_RESULTS', 'total_results'); -use Cultuurnet\Search\Parameter; +use CultuurNet\Search\Parameter; /** * Implements hook_init(). @@ -59,7 +59,12 @@ function culturefeed_search_ui_init() { * Implements hook_cron(). */ function culturefeed_search_ui_cron() { - culturefeed_search_ui_register_deletions(); + + // Only register deletions on production api (otherwise to slow) + if (strpos(variable_get('culturefeed_search_api_location', CULTUREFEED_SEARCH_API_LOCATION) ,'www') !== false) { + culturefeed_search_ui_register_deletions(); + } + } /** @@ -109,13 +114,30 @@ function culturefeed_search_ui_menu() { $items['admin/config/culturefeed/search-ui'] = array( 'title' => 'CultureFeed Search UI', - 'description' => t('Change CultureFeed Search UI settings like display, filters, …'), + 'description' => t('CultureFeed Search UI settings'), 'page callback' => 'drupal_get_form', 'page arguments' => array('culturefeed_search_ui_admin_settings'), 'access arguments' => array('administer site configuration'), 'file' => 'includes/admin.inc', ); + $items['admin/config/culturefeed/search-ui/general'] = array( + 'title' => 'General settings', + 'description' => t('Change CultureFeed Search UI settings like display, filters, …'), + 'access arguments' => array('administer site configuration'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + ); + + $items['admin/config/culturefeed/search-ui/sort'] = array( + 'title' => 'Sort settings', + 'description' => t('Change CultureFeed Search UI sort settings.'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('culturefeed_search_ui_admin_sort_order_settings_form'), + 'access arguments' => array('administer site configuration'), + 'file' => 'includes/admin.inc', + 'type' => MENU_LOCAL_TASK, + ); + $items['autocomplete/culturefeed_ui/city-region-suggestion'] = array( 'page callback' => 'culturefeed_search_ui_city_suggestion_autocomplete_page', 'page arguments' => array(3, TRUE), @@ -297,6 +319,11 @@ function culturefeed_search_ui_block_info() { 'cache' => DRUPAL_NO_CACHE, ); + $blocks['facet-type'] = array( + 'info' => t('Culturefeed search: facet entity type'), + 'cache' => DRUPAL_NO_CACHE, + ); + $blocks['facet-datetype'] = array( 'info' => t('Culturefeed search: facet when'), 'cache' => DRUPAL_NO_CACHE, @@ -374,6 +401,21 @@ function culturefeed_search_ui_block_configure($delta) { ); } + // Disable possible facet options. + // In fact this facility is named "location_category_facility_id" on events. + if ($delta == 'facet-facility') { + + $options = culturefeed_search_get_categories_by_domain($delta_parts[1]); + $enabled_options = variable_get('culturefeed_facet_enabled_options', NULL); + + $form['culturefeed-facet-enabled-options'] = array( + '#type' => 'checkboxes', + '#title' => t('Show only selected options'), + '#options' => $options, + '#default_value' => $enabled_options !== NULL && isset($enabled_options[$delta_parts[1]]) ? $enabled_options[$delta_parts[1]] : array_keys($options), + ); + } + if ($delta == 'facet-theme') { $form['culturefeed-facet-theme-hide'] = array( '#type' => 'checkbox', @@ -482,79 +524,6 @@ function culturefeed_search_ui_block_configure($delta) { } - elseif ($delta == 'culturefeed-search-sortorder') { - - $form['description'] = array( - '#markup' => t('

- Define the different sorting options you want.
- When a sorting option is not exposed. It won\'t be shown as option, but is applicable through the url. - Example: