From d218b452255c26a9f6cd02654f394c24772d17b8 Mon Sep 17 00:00:00 2001 From: Hans Langouche Date: Wed, 20 Aug 2014 10:31:38 +0200 Subject: [PATCH 01/67] MSS-26 --- culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc index 915689bf..a17b25ce 100644 --- a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc +++ b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc @@ -2874,6 +2874,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', ); From 5d40691cc7594910d2d51c2666c72b52e5fb6ab6 Mon Sep 17 00:00:00 2001 From: Hans Langouche Date: Wed, 10 Sep 2014 14:36:47 +0200 Subject: [PATCH 02/67] MSS-26 watchdog fix --- .../includes/culturefeed_entry_ui.pages.inc | 2 +- culturefeed_search/includes/helpers.inc | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc index a17b25ce..ff4e8eb0 100644 --- a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc +++ b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc @@ -3075,7 +3075,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_search/includes/helpers.inc b/culturefeed_search/includes/helpers.inc index 5aa684cb..8ce086a3 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); + } } } From ebf51848593e5e59d864adac80fa2ae549e50877 Mon Sep 17 00:00:00 2001 From: Lieven Goudeseune Date: Thu, 23 Oct 2014 17:14:02 +0200 Subject: [PATCH 03/67] Added autocomplete. --- culturefeed_pages/culturefeed_pages.module | 8 ++++++++ culturefeed_pages/includes/pages.inc | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/culturefeed_pages/culturefeed_pages.module b/culturefeed_pages/culturefeed_pages.module index 4ef3133e..08501c99 100644 --- a/culturefeed_pages/culturefeed_pages.module +++ b/culturefeed_pages/culturefeed_pages.module @@ -455,6 +455,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/pages.inc b/culturefeed_pages/includes/pages.inc index ec65ef71..5bc06a85 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()); + } } } From 731c09c240ec27dda68d66a5ab32690187ca1f9a Mon Sep 17 00:00:00 2001 From: zuuperman Date: Fri, 24 Oct 2014 10:15:08 +0200 Subject: [PATCH 04/67] Only show the log on text/html requests --- culturefeed_devel/culturefeed_devel.module | 30 ++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) 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') + )); } /** From f35be9764aed504d0237d9b2869a21b0e6f66257 Mon Sep 17 00:00:00 2001 From: zuuperman Date: Tue, 28 Oct 2014 17:11:15 +0100 Subject: [PATCH 05/67] Added functions for validated admin requests --- culturefeed_pages/culturefeed_pages.module | 9 +++ culturefeed_pages/includes/helpers.inc | 56 ++++++++++++++++++- culturefeed_pages/includes/members.inc | 48 +++++++++++++--- culturefeed_pages/theme/theme.inc | 6 ++ lib/CultureFeed/CultureFeed/Pages.php | 9 +++ lib/CultureFeed/CultureFeed/Pages/Default.php | 11 +++- .../CultureFeed/Pages/Membership.php | 6 ++ lib/Drupal/DrupalCultureFeedPages_Cache.php | 7 +++ 8 files changed, 142 insertions(+), 10 deletions(-) diff --git a/culturefeed_pages/culturefeed_pages.module b/culturefeed_pages/culturefeed_pages.module index 08501c99..5a4710a7 100644 --- a/culturefeed_pages/culturefeed_pages.module +++ b/culturefeed_pages/culturefeed_pages.module @@ -437,6 +437,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 callback' => FALSE, 'title' => t('Change active page'), diff --git a/culturefeed_pages/includes/helpers.inc b/culturefeed_pages/includes/helpers.inc index 07941372..c17655af 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 @@ -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,30 @@ 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 + */ +function culturefeed_pages_get_validated_admins_of_page(CultureFeed_Cdb_Item_Page $page) { + + try { + $cf_pages = DrupalCultureFeed::getLoggedInUserInstance()->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(); + } + + 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. */ @@ -481,7 +533,7 @@ function culturefeed_pages_get_page_suggestions_list() { $parameters[] = new CultuurNet\Search\Parameter\Query($query); } else { - $parameters[] = new CultuurNet\Search\Parameter\Query('*:*'); + $parameters[] = new CultuurNet\Search\Parameter\Query('*:*'); } // Search on postal / city. diff --git a/culturefeed_pages/includes/members.inc b/culturefeed_pages/includes/members.inc index f7fe8d0a..5f9cfe53 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,37 @@ 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. + 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'); + + } + catch (Exception $e) { + watchdog_exception('culturefeed_pages', $e); + $message = t('The request could not be sent.'); + } + + if ($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); + drupal_goto(); + } + +} \ No newline at end of file diff --git a/culturefeed_pages/theme/theme.inc b/culturefeed_pages/theme/theme.inc index 2b8a82f2..f3372b04 100644 --- a/culturefeed_pages/theme/theme.inc +++ b/culturefeed_pages/theme/theme.inc @@ -193,6 +193,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_link'] = l(t('Become a validated admin'), 'culturefeed/pages/validated-admin/nojs/' . $page->getId(), array('query' => $query)); + } + } // Address information $address = $page->getAddress(); diff --git a/lib/CultureFeed/CultureFeed/Pages.php b/lib/CultureFeed/CultureFeed/Pages.php index cc41feca..f0a3e5a2 100644 --- a/lib/CultureFeed/CultureFeed/Pages.php +++ b/lib/CultureFeed/CultureFeed/Pages.php @@ -168,6 +168,15 @@ public function addAdmin($id, $userId, $params = array()); */ public function removeAdmin($id, $userId); + /** + * Send a request for current user to become validated admin. + * @param string $id + * The page ID to add to. + * @return string + * Message returned by the service. + */ + public function addValidatedAdmin($id); + /** * Get the timeline of a page. * @param string $id diff --git a/lib/CultureFeed/CultureFeed/Pages/Default.php b/lib/CultureFeed/CultureFeed/Pages/Default.php index b85dea12..b0f3069f 100644 --- a/lib/CultureFeed/CultureFeed/Pages/Default.php +++ b/lib/CultureFeed/CultureFeed/Pages/Default.php @@ -96,7 +96,6 @@ public function getConsumer() { public function getPage($id) { $result = $this->oauth_client->consumerGetAsXml('page/' . $id); - try { $xml = new CultureFeed_SimpleXMLElement($result); } @@ -242,6 +241,7 @@ public function getUserList($id, $roles = array(), $use_auth = TRUE) { $membership->role = $object->xpath_str('pageRole'); $membership->relation = $object->xpath_str('relation'); $membership->creationDate = $object->xpath_time('creationDate'); + $membership->validated = $object->xpath_bool('validated'); $userList->memberships[] = $membership; @@ -361,6 +361,15 @@ public function removeAdmin($id, $userId) { } + /** + * @see CultureFeed_Pages::addValidatedAdmin() + */ + public function addValidatedAdmin($id) { + $result = $this->oauth_client->authenticatedPostAsXml('page/' . $id . '/validatedadmin/add'); + $xmlElement = $this->validateResult($result, CultureFeed_Pages_Default::CODE_ACTION_SUCCEEDED); + return $xmlElement->xpath_str('message'); + } + /** * @see CultureFeed_Pages::getTimeline() */ diff --git a/lib/CultureFeed/CultureFeed/Pages/Membership.php b/lib/CultureFeed/CultureFeed/Pages/Membership.php index 971cc3fc..8b42de38 100644 --- a/lib/CultureFeed/CultureFeed/Pages/Membership.php +++ b/lib/CultureFeed/CultureFeed/Pages/Membership.php @@ -37,4 +37,10 @@ class CultureFeed_Pages_Membership { */ public $relation; + /** + * A validated membership or not. + * @var bool + */ + public $validated; + } \ No newline at end of file diff --git a/lib/Drupal/DrupalCultureFeedPages_Cache.php b/lib/Drupal/DrupalCultureFeedPages_Cache.php index 0dad0384..7e02628f 100644 --- a/lib/Drupal/DrupalCultureFeedPages_Cache.php +++ b/lib/Drupal/DrupalCultureFeedPages_Cache.php @@ -258,6 +258,13 @@ public function removeAdmin($id, $userId) { $this->clearUserListCache($id, CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN); } + /** + * @see CultureFeed_Pages::addValidatedAdmin() + */ + public function addValidatedAdmin($id) { + return $this->realCultureFeedPages->addValidatedAdmin($id); + } + /** * @see CultureFeed_Pages::getTimeline() */ From e06a021504af0ccfe4ab2aa532e4571a01408a1b Mon Sep 17 00:00:00 2001 From: zuuperman Date: Tue, 28 Oct 2014 17:29:51 +0100 Subject: [PATCH 06/67] Check if recipientPage is instance of CultureFeed_Cdb_Item_Page --- culturefeed_messages/includes/pages.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(), From d0afd8b749a205174395a62b44bd3a4124ff4c1b Mon Sep 17 00:00:00 2001 From: zuuperman Date: Tue, 28 Oct 2014 17:39:10 +0100 Subject: [PATCH 07/67] Added helper function to check if page is a validated page --- culturefeed_pages/includes/helpers.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/culturefeed_pages/includes/helpers.inc b/culturefeed_pages/includes/helpers.inc index c0b43a52..0f9a7c93 100644 --- a/culturefeed_pages/includes/helpers.inc +++ b/culturefeed_pages/includes/helpers.inc @@ -185,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. */ @@ -565,3 +577,4 @@ function culturefeed_pages_get_page_suggestions_list() { return theme('culturefeed_pages_page_suggestion_list', array('suggestions' => $result->getItems())); } + From 6b5942e403f5632e429aee9fc372298a21dcb303 Mon Sep 17 00:00:00 2001 From: zuuperman Date: Wed, 29 Oct 2014 12:25:15 +0100 Subject: [PATCH 08/67] Added functionality to remove validated admins: TBC --- culturefeed_pages/includes/members.inc | 64 +++++++++++++++---- culturefeed_pages/theme/theme.inc | 2 +- lib/CultureFeed/CultureFeed/Pages/Default.php | 8 +++ 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/culturefeed_pages/includes/members.inc b/culturefeed_pages/includes/members.inc index 5f9cfe53..f511720e 100644 --- a/culturefeed_pages/includes/members.inc +++ b/culturefeed_pages/includes/members.inc @@ -101,7 +101,14 @@ function culturefeed_pages_manage_members_list(CultureFeed_Cdb_Item_Page $page, $row['function'] = $member->relation; switch ($member->role) { case CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN: - $role = t('administrator'); + + if ($member->validated) { + $role = t('validated administrator'); + } + else { + $role = t('administrator'); + } + break; case CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_MEMBER: default: @@ -112,11 +119,17 @@ function culturefeed_pages_manage_members_list(CultureFeed_Cdb_Item_Page $page, $row['member_since'] = date('d/m/Y H:i', $member->creationDate); $row['edit'] = l(t('Edit'), 'pages/' . $page->getId() . '/membership/' . $member->user->id . '/edit/nojs', array('attributes' => array('class' => 'use-ajax'))); - if ($total_admins == 1 && $member->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN) { + if ($total_admins == 1 && !$member->validated && $member->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN) { $row['delete'] = theme('culturefeed_pages_membership_delete_not_possible', array('page' => $page)); } else { - $row['delete'] = l(t('Remove as member'), 'pages/' . $page->getId() . '/membership/' . $member->user->id . '/delete/nojs'); + if ($member->validated) { + $delete_label = t('Remove as validated administrator'); + } + else { + $delete_label = t('Remove as member'); + } + $row['delete'] = l($delete_label, 'pages/' . $page->getId() . '/membership/' . $member->user->id . '/delete/nojs'); } } // Show the edit form. @@ -198,10 +211,18 @@ function culturefeed_pages_edit_membership_form($form, &$form_state, CultureFeed // Only show toggle when user is not an admin, or he is not the only admin. if ($membership->role != CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN || $total_admins != 1) { + + if ($membership->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_MEMBER) { + $toggle_label = t('Make administrator'); + } + else { + $toggle_label = $membership->validated ? t('Remove administrator') : t('Remove validated administrator'); + } + $form['role'] = array( '#type' => 'button', '#name' => 'toggle_role', - '#value' => $membership->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN ? t('Remove administrator') : t('Make administrator'), + '#value' => $toggle_label, '#ajax' => array( 'callback' => 'culturefeed_pages_edit_membership_ajax_form_submit', 'wrapper' => 'membership-ajax-wrapper', @@ -230,16 +251,25 @@ function culturefeed_pages_edit_membership_form_validate($form, &$form_state) { $cf_pages = DrupalCultureFeed::getLoggedInUserInstance()->pages(); if ($form['#membership']->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN) { - $cf_pages->removeAdmin($form['#membership']->page->getId(), $form['#membership']->user->id); + // If he is a validated admin. Remove him as validated admin. He becomes a normal admin. + if ($form['#membership']->validated) { + $cf_pages->removeValidatedAdmin($form['#membership']->page->getId()); + $form_state['new_role'] = CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN; + } + else { - // If he was removed as admin, he is also removed as member. Re-add him as member. - $params = array( - 'relation' => $form['#membership']->relation, - 'activityPrivate' => FALSE, - ); + $cf_pages->removeAdmin($form['#membership']->page->getId(), $form['#membership']->user->id); - $cf_pages->addMember($form['#membership']->page->getId(), $form['#membership']->user->id, $params); - $form_state['new_role'] = CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_MEMBER; + // If he was removed as admin, he is also removed as member. Re-add him as member. + $params = array( + 'relation' => $form['#membership']->relation, + 'activityPrivate' => FALSE, + ); + + $cf_pages->addMember($form['#membership']->page->getId(), $form['#membership']->user->id, $params); + $form_state['new_role'] = CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_MEMBER; + + } } else { @@ -508,7 +538,15 @@ function culturefeed_pages_delete_member_form_validate($form, &$form_state) { // Check if the user is admin or member. if (culturefeed_pages_is_user_admin_of_page($form_state['page']->getId(), $form_state['user'])) { - DrupalCultureFeed::getLoggedInUserInstance()->pages()->removeAdmin($form_state['page']->getId(), $form_state['user']->id); + + // If a validated admin is removed, he becomes a normal admin. + if (culturefeed_pages_is_user_validated_admin_of_page($form_state['page']->getId(), $form_state['user'])) { + DrupalCultureFeed::getLoggedInUserInstance()->pages()->removeValidatedAdmin($form_state['page']->getId()); + } + else { + DrupalCultureFeed::getLoggedInUserInstance()->pages()->removeAdmin($form_state['page']->getId(), $form_state['user']->id); + } + } else { DrupalCultureFeed::getLoggedInUserInstance()->pages()->removeMember($form_state['page']->getId(), $form_state['user']->id); diff --git a/culturefeed_pages/theme/theme.inc b/culturefeed_pages/theme/theme.inc index f3372b04..e9e58dd2 100644 --- a/culturefeed_pages/theme/theme.inc +++ b/culturefeed_pages/theme/theme.inc @@ -196,7 +196,7 @@ function _culturefeed_pages_preprocess_culturefeed_page(&$variables) { 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_link'] = l(t('Become a validated admin'), 'culturefeed/pages/validated-admin/nojs/' . $page->getId(), array('query' => $query)); + $variables['become_validated_admin_url'] = url('culturefeed/pages/validated-admin/nojs/' . $page->getId(), array('query' => $query)); } } diff --git a/lib/CultureFeed/CultureFeed/Pages/Default.php b/lib/CultureFeed/CultureFeed/Pages/Default.php index b0f3069f..8ef4102d 100644 --- a/lib/CultureFeed/CultureFeed/Pages/Default.php +++ b/lib/CultureFeed/CultureFeed/Pages/Default.php @@ -370,6 +370,14 @@ public function addValidatedAdmin($id) { return $xmlElement->xpath_str('message'); } + /** + * @see CultureFeed_Pages::removeValidatedAdmin() + */ + public function removeValidatedAdmin($id) { + $result = $this->oauth_client->authenticatedPostAsXml('page/' . $id . '/validatedadmin/remove'); + $this->validateResult($result, CultureFeed_Pages_Default::CODE_ACTION_SUCCEEDED); + } + /** * @see CultureFeed_Pages::getTimeline() */ From 5e5e6dfe52dd775d0d18269b684aaedea861849f Mon Sep 17 00:00:00 2001 From: zuuperman Date: Wed, 29 Oct 2014 15:27:10 +0100 Subject: [PATCH 09/67] Use correct url for validated admin request --- culturefeed_pages/includes/helpers.inc | 2 +- culturefeed_pages/includes/members.inc | 2 +- culturefeed_pages/theme/theme.inc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/culturefeed_pages/includes/helpers.inc b/culturefeed_pages/includes/helpers.inc index 0f9a7c93..2e56ddeb 100644 --- a/culturefeed_pages/includes/helpers.inc +++ b/culturefeed_pages/includes/helpers.inc @@ -432,7 +432,7 @@ function culturefeed_pages_block_request_admin_membership(CultureFeed_Cdb_Item_P if ($is_admin) { return; } - +return; $build = array( '#theme' => 'culturefeed_pages_request_admin_membership_block', '#page' => $page, diff --git a/culturefeed_pages/includes/members.inc b/culturefeed_pages/includes/members.inc index f511720e..ab78c668 100644 --- a/culturefeed_pages/includes/members.inc +++ b/culturefeed_pages/includes/members.inc @@ -720,7 +720,7 @@ function culturefeed_pages_page_request_validated_admin($page, $request_type) { $message = t('The request could not be sent.'); } - if ($type == 'ajax') { + if ($request_type == 'ajax') { $commands = array(); if ($success) { diff --git a/culturefeed_pages/theme/theme.inc b/culturefeed_pages/theme/theme.inc index e9e58dd2..0a09b871 100644 --- a/culturefeed_pages/theme/theme.inc +++ b/culturefeed_pages/theme/theme.inc @@ -196,7 +196,7 @@ function _culturefeed_pages_preprocess_culturefeed_page(&$variables) { 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('culturefeed/pages/validated-admin/nojs/' . $page->getId(), array('query' => $query)); + $variables['become_validated_admin_url'] = url('pages/' . $page->getId() . '/membership/request-validated-admin/nojs', array('query' => $query)); } } From 2cc4cd15977df7e7e484aa76f04013721b88d319 Mon Sep 17 00:00:00 2001 From: zuuperman Date: Wed, 29 Oct 2014 15:27:25 +0100 Subject: [PATCH 10/67] Remove the return --- culturefeed_pages/includes/helpers.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/culturefeed_pages/includes/helpers.inc b/culturefeed_pages/includes/helpers.inc index 2e56ddeb..0f9a7c93 100644 --- a/culturefeed_pages/includes/helpers.inc +++ b/culturefeed_pages/includes/helpers.inc @@ -432,7 +432,7 @@ function culturefeed_pages_block_request_admin_membership(CultureFeed_Cdb_Item_P if ($is_admin) { return; } -return; + $build = array( '#theme' => 'culturefeed_pages_request_admin_membership_block', '#page' => $page, From 9ba7fcb7d00eb1d281b9d6232f7cd8d834362f6d Mon Sep 17 00:00:00 2001 From: zuuperman Date: Mon, 10 Nov 2014 16:53:37 +0100 Subject: [PATCH 11/67] Added setting for filtering the options --- .../culturefeed_search_ui.module | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 5bf38f1b..f237e069 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -374,6 +374,20 @@ function culturefeed_search_ui_block_configure($delta) { ); } + // Disable possible facet options. + 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', @@ -590,6 +604,14 @@ function culturefeed_search_ui_block_save($delta, $edit = array()) { variable_set('culturefeed_facet_show_subitems_' . $delta, $edit['culturefeed-facet-show-subitems']); } + // Save enabled facet options. + if (isset($edit['culturefeed-facet-enabled-options'])) { + $delta_parts = explode('-', $delta); + $options = variable_get('culturefeed_facet_enabled_options', array()); + $options[$delta_parts[1]] = array_filter($edit['culturefeed-facet-enabled-options']); + variable_set('culturefeed_facet_enabled_options', $options); + } + if ($delta == 'culturefeed-search-sortorder') { if (!empty($edit['sort_options'])) { From 0ddfb64ae598ed1f49b7afa0bc9c16977466430a Mon Sep 17 00:00:00 2001 From: HnLn Date: Thu, 13 Nov 2014 15:21:11 +0100 Subject: [PATCH 12/67] MSS-91 --- culturefeed_search_ui/culturefeed_search_ui.module | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 5bf38f1b..39f8307b 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -900,6 +900,7 @@ function culturefeed_search_ui_culturefeed_search_ui_active_filters($culturefeed unset($query['min_age']); $url = url($path, array('query' => $query)); + $current_age = t('All ages'); $age_facets = culturefeed_search_ui_get_age_range_facet_options(); foreach ($age_facets as $key => $data) { if ($key === $min_age) { @@ -907,16 +908,9 @@ function culturefeed_search_ui_culturefeed_search_ui_active_filters($culturefeed } } - if ($min_age == 0) { - $label = t('All ages'); - } - else { - $label = isset($current_age) ? $current_age : check_plain($min_age); - } - $build['min-age'] = array( '#theme' => 'culturefeed_search_active_filters_item', - '#label' => $min_age == 0 ? t('All ages') : $current_age, + '#label' => $current_age, '#url' => $url ); } From dff30df9ad41b309400714bd1f4ad1fe14b0a2ea Mon Sep 17 00:00:00 2001 From: zuuperman Date: Thu, 13 Nov 2014 15:52:33 +0100 Subject: [PATCH 13/67] Added setting for listing actors on the search page --- culturefeed_agenda/culturefeed_agenda.module | 9 ++++ culturefeed_agenda/includes/admin.inc | 43 +++++++++++++++++++ .../lib/Drupal/AgendaSearchPage.php | 6 ++- .../culturefeed_search_ui.module | 12 +++++- culturefeed_search_ui/includes/blocks.inc | 18 ++++++++ 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 culturefeed_agenda/includes/admin.inc diff --git a/culturefeed_agenda/culturefeed_agenda.module b/culturefeed_agenda/culturefeed_agenda.module index ff0ff8dc..5a9f34d8 100644 --- a/culturefeed_agenda/culturefeed_agenda.module +++ b/culturefeed_agenda/culturefeed_agenda.module @@ -172,6 +172,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', diff --git a/culturefeed_agenda/includes/admin.inc b/culturefeed_agenda/includes/admin.inc new file mode 100644 index 00000000..b9206736 --- /dev/null +++ b/culturefeed_agenda/includes/admin.inc @@ -0,0 +1,43 @@ + t('Entity types to be searched'), + '#type' => 'checkboxes', + '#options' => array( + 'event' => t('Events'), + 'production' => t('Productions'), + 'actor' => t('Actors'), + ), + '#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/lib/Drupal/AgendaSearchPage.php b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php index c7b61538..41e43ef8 100644 --- a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php +++ b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php @@ -39,7 +39,11 @@ public function initialize() { $this->addFacetFilters($params); - $this->parameters[] = new Parameter\FilterQuery('type:event OR type:production'); + $active_types = variable_get('culturefeed_agenda_active_entity_types', array('event', 'production')); + array_walk($active_types, function(&$active_type) { + $active_type = 'type:' . $active_type; + }); + $this->parameters[] = new Parameter\FilterQuery(implode(' OR ', $active_types)); $this->parameters[] = $this->facetComponent->facetField('category'); $this->parameters[] = $this->facetComponent->facetField('datetype'); $this->parameters[] = $this->facetComponent->facetField('city'); diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 5bf38f1b..82e6775b 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -297,6 +297,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, @@ -666,6 +671,10 @@ function culturefeed_search_ui_block_view($delta) { $block = culturefeed_search_ui_block_age_range_facet(); break; + case 'facet-type': + $block = culturefeed_search_ui_block_entity_type_facet(); + break; + case 'filter-form': $search_result = culturefeed_get_search_result(); @@ -721,10 +730,11 @@ function culturefeed_search_ui_culturefeed_search_page_query_alter(CultureFeedSe } } - // Add facet on agefrom. + // Add facet on agefrom and type. $facet_component = culturefeed_get_facet_component(); if ($facet_component) { $culturefeedSearchPage->addParameter($facet_component->facetField('agefrom')); + $culturefeedSearchPage->addParameter($facet_component->facetField('type')); } // Add min age filter. This is always the requested age and count till 12. diff --git a/culturefeed_search_ui/includes/blocks.inc b/culturefeed_search_ui/includes/blocks.inc index 6141fe3c..791ef9a5 100644 --- a/culturefeed_search_ui/includes/blocks.inc +++ b/culturefeed_search_ui/includes/blocks.inc @@ -593,6 +593,24 @@ function culturefeed_search_ui_city_only_facet_form_submit($form, &$form_state) } +/** + * Show the entity type facet. + */ +function culturefeed_search_ui_block_entity_type_facet() { + + $block_settings = array( + 'sort' => variable_get('culturefeed_search_sort_facet-type', CULTUREFEED_SEARCH_SORT_ALPHABETICALLY), + 'highest_level' => variable_get('culturefeed_facet_highest_level_facet-type', 1), + 'show_subitems' => variable_get('culturefeed_facet_show_subitems_facet-type', FALSE), + ); + + $block = culturefeed_search_ui_search_facets_block('type', '', array(), $block_settings); + $block['subject'] = t('Type'); + + return $block; + +} + /** * Block callback for the active filters during search. */ From f6e8292dd5a99535c0a330331311afa23ce4d861 Mon Sep 17 00:00:00 2001 From: zuuperman Date: Fri, 14 Nov 2014 10:05:41 +0100 Subject: [PATCH 14/67] Make titles translatable --- culturefeed_ui/culturefeed_ui.module | 37 +++++++++------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/culturefeed_ui/culturefeed_ui.module b/culturefeed_ui/culturefeed_ui.module index 76a7ae8f..85bacd5e 100644 --- a/culturefeed_ui/culturefeed_ui.module +++ b/culturefeed_ui/culturefeed_ui.module @@ -22,8 +22,7 @@ function culturefeed_ui_menu() { 'file' => 'culturefeed_ui.admin.inc', ); $items['culturefeed/profile/edit'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Edit profile'), + 'title' => 'Edit profile', 'page callback' => 'drupal_get_form', 'page arguments' => array('culturefeed_ui_page_profile_edit_form'), 'access callback' => 'culturefeed_is_culturefeed_user', @@ -31,24 +30,21 @@ function culturefeed_ui_menu() { 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/account/edit'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Edit account'), + 'title' => 'Edit account', 'page callback' => 'culturefeed_ui_page_account_edit', 'access callback' => 'culturefeed_is_culturefeed_user', 'type' => MENU_CALLBACK, 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/mboxverify/resend'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Resend email confirmation'), + 'title' => 'Resend email confirmation', 'page callback' => 'culturefeed_ui_page_mboxverify_resend', 'access callback' => 'culturefeed_is_culturefeed_user', 'type' => MENU_CALLBACK, 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/users/search'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Search users'), + 'title' => 'Search users', 'page callback' => 'culturefeed_ui_page_users_search', 'page arguments' => array(3), 'access arguments' => array('access content'), @@ -56,16 +52,14 @@ function culturefeed_ui_menu() { 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/serviceconsumers'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Connected channels'), + 'title' => 'Connected channels', 'page callback' => 'culturefeed_ui_page_serviceconsumers', 'access callback' => 'culturefeed_is_culturefeed_user', 'type' => MENU_CALLBACK, 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/serviceconsumers/revoke/%/%'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Remove UiTiD channel'), + 'title' => 'Remove UiTiD channel', 'page callback' => 'culturefeed_ui_page_serviceconsumer_revoke', 'page arguments' => array(3, 4), 'access callback' => 'culturefeed_is_culturefeed_user', @@ -73,8 +67,7 @@ function culturefeed_ui_menu() { 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/onlineaccounts/delete/%/%/%'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Remove social account'), + 'title' => 'Remove social account', 'page callback' => 'culturefeed_ui_page_online_account_delete', 'page arguments' => array(3, 4, 5), 'access callback' => 'culturefeed_is_culturefeed_user', @@ -82,8 +75,7 @@ function culturefeed_ui_menu() { 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/onlineaccounts/privacy/%/%/%/%'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Configure privacy social account'), + 'title' => 'Configure privacy social account', 'page callback' => 'culturefeed_ui_page_online_account_update_privacy', 'page arguments' => array(3, 4, 5, 6), 'access callback' => 'culturefeed_is_culturefeed_user', @@ -91,8 +83,7 @@ function culturefeed_ui_menu() { 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/toggle/privacy/facebook/%/%/%'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Configure privacy social account'), + 'title' => 'Configure privacy social account', 'page callback' => 'culturefeed_ui_page_online_account_toggle_facebook_privacy', 'page arguments' => array(3, 4, 5, 6), 'access callback' => 'culturefeed_is_culturefeed_user', @@ -100,8 +91,7 @@ function culturefeed_ui_menu() { 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/users/mostactive'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Most active user'), + 'title' => 'Most active user', 'page callback' => 'culturefeed_ui_page_users_most_active', 'page arguments' => array(3), 'access arguments' => array('access content'), @@ -109,8 +99,7 @@ function culturefeed_ui_menu() { 'file' => 'culturefeed_ui.pages.inc', ); $items['culturefeed/removeaccount'] = array( - 'title callback' => 'culturefeed_ui_default_title_callback', - 'title arguments' => array('Delete account'), + 'title' => 'Delete account', 'page callback' => 'drupal_get_form', 'page arguments' => array('culturefeed_ui_page_remove_account_form'), 'access callback' => 'culturefeed_is_culturefeed_user', @@ -149,10 +138,6 @@ function culturefeed_ui_init() { } } -function culturefeed_ui_default_title_callback($title = '') { - return $title; -} - /** * Implements hook_theme(). */ From 3770fe3237c367d56eec5263d3c17c01a5aa2c97 Mon Sep 17 00:00:00 2001 From: zuuperman Date: Fri, 14 Nov 2014 10:11:51 +0100 Subject: [PATCH 15/67] Also change culturefeed_mailing to use correct way of translating --- .../culturefeed_mailing.module | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) 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'), From 38d282d2f841ad12363b632337d1c78c699748a1 Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Fri, 14 Nov 2014 13:58:46 +0100 Subject: [PATCH 16/67] make embedded videos responsive --- culturefeed_agenda/theme/theme.inc | 2 +- culturefeed_search_ui/includes/helpers.inc | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/culturefeed_agenda/theme/theme.inc b/culturefeed_agenda/theme/theme.inc index 29523089..ae77f7b3 100644 --- a/culturefeed_agenda/theme/theme.inc +++ b/culturefeed_agenda/theme/theme.inc @@ -351,7 +351,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; } } diff --git a/culturefeed_search_ui/includes/helpers.inc b/culturefeed_search_ui/includes/helpers.inc index dc79eeb6..051cfdd0 100644 --- a/culturefeed_search_ui/includes/helpers.inc +++ b/culturefeed_search_ui/includes/helpers.inc @@ -7,7 +7,7 @@ /** * Convert a given url to a youtube embed. */ -function _culturefeed_search_ui_video_url_to_embed($url, $width, $height) { +function _culturefeed_search_ui_video_url_to_embed($url) { // Construct embed url. $embed_url = str_replace('watch', 'v', $url); @@ -21,14 +21,9 @@ function _culturefeed_search_ui_video_url_to_embed($url, $width, $height) { $embed_url .= '?fs=1&showinfo=0'; $embed = ''; - $embed .= ''; - $embed .= ''; - $embed .= ''; - $embed .= ''; - $embed .= ''; - $embed .= ''; - $embed .= ''; + $embed .= '
'; + $embed .= ''; + $embed .= '
'; return $embed; From 3a14dd2bc57dbd4215c5b2baf96f5d0cf120c42e Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Fri, 14 Nov 2014 14:58:26 +0100 Subject: [PATCH 17/67] remove 12 to 17 from default age range facet --- culturefeed_search_ui/includes/blocks.inc | 6 ------ culturefeed_search_ui/includes/helpers.inc | 8 -------- 2 files changed, 14 deletions(-) diff --git a/culturefeed_search_ui/includes/blocks.inc b/culturefeed_search_ui/includes/blocks.inc index 6141fe3c..01778169 100644 --- a/culturefeed_search_ui/includes/blocks.inc +++ b/culturefeed_search_ui/includes/blocks.inc @@ -470,12 +470,6 @@ function culturefeed_search_ui_block_age_range_facet() { elseif ($age >= 9 && $age <= 11) { $counts[9] += $item->getTotalResults(); } - elseif ($age >= 12 && $age <= 14) { - $counts[12] += $item->getTotalResults(); - } - elseif ($age >= 15 && $age <= 17) { - $counts[15] += $item->getTotalResults(); - } } // Create facet item for every count. diff --git a/culturefeed_search_ui/includes/helpers.inc b/culturefeed_search_ui/includes/helpers.inc index dc79eeb6..df7f791e 100644 --- a/culturefeed_search_ui/includes/helpers.inc +++ b/culturefeed_search_ui/includes/helpers.inc @@ -117,14 +117,6 @@ function culturefeed_search_ui_get_age_range_facet_options() { 'name' => '9-11 ' . t('year'), 'query' => '(agefrom:[9 TO 11])', ), - 12 => array( - 'name' => '12-14 ' . t('year'), - 'query' => '(agefrom:[12 TO 14])', - ), - 15 => array( - 'name' => '15-17 ' . t('year'), - 'query' => '(agefrom:[15 TO 17])', - ), ); } From 588fb810f54028e187282fee956a9b6f70479d76 Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Fri, 14 Nov 2014 15:00:04 +0100 Subject: [PATCH 18/67] add children events without specific min age to age range filters --- culturefeed_search_ui/includes/helpers.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/culturefeed_search_ui/includes/helpers.inc b/culturefeed_search_ui/includes/helpers.inc index df7f791e..e9bc9584 100644 --- a/culturefeed_search_ui/includes/helpers.inc +++ b/culturefeed_search_ui/includes/helpers.inc @@ -103,19 +103,19 @@ function culturefeed_search_ui_get_age_range_facet_options() { return array( 0 => array( 'name' => '0-2 ' . t('year'), - 'query' => '(agefrom:[0 TO 2])', + 'query' => '(agefrom:[0 TO 2] OR keywords:"ook voor kinderen")', ), 3 => array( 'name' => '3-5 ' . t('year'), - 'query' => '(agefrom:[3 TO 5])', + 'query' => '(agefrom:[3 TO 5] OR keywords:"ook voor kinderen")', ), 6 => array( 'name' => '6-8 ' . t('year'), - 'query' => '(agefrom:[6 TO 8])', + 'query' => '(agefrom:[6 TO 8] OR keywords:"ook voor kinderen")', ), 9 => array( 'name' => '9-11 ' . t('year'), - 'query' => '(agefrom:[9 TO 11])', + 'query' => '(agefrom:[9 TO 11] OR keywords:"ook voor kinderen")', ), ); } From 7a45f868fae987d5f79399f51e12625e99b2c575 Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Fri, 14 Nov 2014 19:57:41 +0100 Subject: [PATCH 19/67] add variable if event is suitable for kids --- culturefeed_agenda/theme/theme.inc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/culturefeed_agenda/theme/theme.inc b/culturefeed_agenda/theme/theme.inc index ae77f7b3..df215715 100644 --- a/culturefeed_agenda/theme/theme.inc +++ b/culturefeed_agenda/theme/theme.inc @@ -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; + } } } @@ -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 ($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 ($event->getAgeFrom() && ($event->getAgeFrom() <= 12)) { + $variables['forkids'] = TRUE; + } $relations = $production->getRelations(); $total_relations = count($relations); From ade3f384119be8a8fff051b34d0920950a22c21e Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Fri, 14 Nov 2014 20:09:54 +0100 Subject: [PATCH 20/67] variable forkids is true when agefrom = 0 --- culturefeed_agenda/theme/theme.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/culturefeed_agenda/theme/theme.inc b/culturefeed_agenda/theme/theme.inc index df215715..2c3070ed 100644 --- a/culturefeed_agenda/theme/theme.inc +++ b/culturefeed_agenda/theme/theme.inc @@ -393,7 +393,7 @@ function _culturefeed_agenda_preprocess_event(&$variables) { $event_detail = $event->getDetails()->getDetailByLanguage(culturefeed_search_get_preferred_language()); $variables['agefrom'] = check_plain($event->getAgeFrom()); - if ($event->getAgeFrom() && ($event->getAgeFrom() <= 12)) { + if (is_numeric($event->getAgeFrom()) && ($event->getAgeFrom() <= 12)) { $variables['forkids'] = TRUE; } $variables['location'] = culturefeed_agenda_get_location_of_event($event); @@ -500,7 +500,7 @@ function _culturefeed_agenda_preprocess_production(&$variables) { $organiser = $production->getOrganiser(); $variables['agefrom'] = $production->getAgeFrom(); - if ($event->getAgeFrom() && ($event->getAgeFrom() <= 12)) { + if (is_numeric($event->getAgeFrom()) && ($event->getAgeFrom() <= 12)) { $variables['forkids'] = TRUE; } From 274e2b266b1a9f9d7e85eaf8427272203ca8548c Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Fri, 14 Nov 2014 20:40:04 +0100 Subject: [PATCH 21/67] UIV-951 fix typo --- culturefeed_agenda/theme/theme.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/culturefeed_agenda/theme/theme.inc b/culturefeed_agenda/theme/theme.inc index 2c3070ed..95584953 100644 --- a/culturefeed_agenda/theme/theme.inc +++ b/culturefeed_agenda/theme/theme.inc @@ -500,7 +500,7 @@ function _culturefeed_agenda_preprocess_production(&$variables) { $organiser = $production->getOrganiser(); $variables['agefrom'] = $production->getAgeFrom(); - if (is_numeric($event->getAgeFrom()) && ($event->getAgeFrom() <= 12)) { + if (is_numeric($production->getAgeFrom()) && ($production->getAgeFrom() <= 12)) { $variables['forkids'] = TRUE; } From fd5f46f673a7a3f826ab897034d22864f1b9f3fe Mon Sep 17 00:00:00 2001 From: zuuperman Date: Mon, 17 Nov 2014 10:26:04 +0100 Subject: [PATCH 22/67] Revert commit 6b5942e403f5632e429aee9fc372298a21dcb303 (functionality removing validated admins) --- culturefeed_pages/includes/members.inc | 64 ++++++-------------------- 1 file changed, 13 insertions(+), 51 deletions(-) diff --git a/culturefeed_pages/includes/members.inc b/culturefeed_pages/includes/members.inc index ab78c668..c1e5338e 100644 --- a/culturefeed_pages/includes/members.inc +++ b/culturefeed_pages/includes/members.inc @@ -101,14 +101,7 @@ function culturefeed_pages_manage_members_list(CultureFeed_Cdb_Item_Page $page, $row['function'] = $member->relation; switch ($member->role) { case CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN: - - if ($member->validated) { - $role = t('validated administrator'); - } - else { - $role = t('administrator'); - } - + $role = t('administrator'); break; case CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_MEMBER: default: @@ -119,17 +112,11 @@ function culturefeed_pages_manage_members_list(CultureFeed_Cdb_Item_Page $page, $row['member_since'] = date('d/m/Y H:i', $member->creationDate); $row['edit'] = l(t('Edit'), 'pages/' . $page->getId() . '/membership/' . $member->user->id . '/edit/nojs', array('attributes' => array('class' => 'use-ajax'))); - if ($total_admins == 1 && !$member->validated && $member->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN) { + if ($total_admins == 1 && $member->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN) { $row['delete'] = theme('culturefeed_pages_membership_delete_not_possible', array('page' => $page)); } else { - if ($member->validated) { - $delete_label = t('Remove as validated administrator'); - } - else { - $delete_label = t('Remove as member'); - } - $row['delete'] = l($delete_label, 'pages/' . $page->getId() . '/membership/' . $member->user->id . '/delete/nojs'); + $row['delete'] = l(t('Remove as member'), 'pages/' . $page->getId() . '/membership/' . $member->user->id . '/delete/nojs'); } } // Show the edit form. @@ -211,18 +198,10 @@ function culturefeed_pages_edit_membership_form($form, &$form_state, CultureFeed // Only show toggle when user is not an admin, or he is not the only admin. if ($membership->role != CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN || $total_admins != 1) { - - if ($membership->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_MEMBER) { - $toggle_label = t('Make administrator'); - } - else { - $toggle_label = $membership->validated ? t('Remove administrator') : t('Remove validated administrator'); - } - $form['role'] = array( '#type' => 'button', '#name' => 'toggle_role', - '#value' => $toggle_label, + '#value' => $membership->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN ? t('Remove administrator') : t('Make administrator'), '#ajax' => array( 'callback' => 'culturefeed_pages_edit_membership_ajax_form_submit', 'wrapper' => 'membership-ajax-wrapper', @@ -251,25 +230,16 @@ function culturefeed_pages_edit_membership_form_validate($form, &$form_state) { $cf_pages = DrupalCultureFeed::getLoggedInUserInstance()->pages(); if ($form['#membership']->role == CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN) { - // If he is a validated admin. Remove him as validated admin. He becomes a normal admin. - if ($form['#membership']->validated) { - $cf_pages->removeValidatedAdmin($form['#membership']->page->getId()); - $form_state['new_role'] = CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_ADMIN; - } - else { + $cf_pages->removeAdmin($form['#membership']->page->getId(), $form['#membership']->user->id); - $cf_pages->removeAdmin($form['#membership']->page->getId(), $form['#membership']->user->id); + // If he was removed as admin, he is also removed as member. Re-add him as member. + $params = array( + 'relation' => $form['#membership']->relation, + 'activityPrivate' => FALSE, + ); - // If he was removed as admin, he is also removed as member. Re-add him as member. - $params = array( - 'relation' => $form['#membership']->relation, - 'activityPrivate' => FALSE, - ); - - $cf_pages->addMember($form['#membership']->page->getId(), $form['#membership']->user->id, $params); - $form_state['new_role'] = CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_MEMBER; - - } + $cf_pages->addMember($form['#membership']->page->getId(), $form['#membership']->user->id, $params); + $form_state['new_role'] = CultureFeed_Pages_Membership::MEMBERSHIP_ROLE_MEMBER; } else { @@ -538,15 +508,7 @@ function culturefeed_pages_delete_member_form_validate($form, &$form_state) { // Check if the user is admin or member. if (culturefeed_pages_is_user_admin_of_page($form_state['page']->getId(), $form_state['user'])) { - - // If a validated admin is removed, he becomes a normal admin. - if (culturefeed_pages_is_user_validated_admin_of_page($form_state['page']->getId(), $form_state['user'])) { - DrupalCultureFeed::getLoggedInUserInstance()->pages()->removeValidatedAdmin($form_state['page']->getId()); - } - else { - DrupalCultureFeed::getLoggedInUserInstance()->pages()->removeAdmin($form_state['page']->getId(), $form_state['user']->id); - } - + DrupalCultureFeed::getLoggedInUserInstance()->pages()->removeAdmin($form_state['page']->getId(), $form_state['user']->id); } else { DrupalCultureFeed::getLoggedInUserInstance()->pages()->removeMember($form_state['page']->getId(), $form_state['user']->id); From feafab0d6aae5cedeb42775532477972c1cd6f0a Mon Sep 17 00:00:00 2001 From: zuuperman Date: Mon, 17 Nov 2014 17:44:22 +0100 Subject: [PATCH 23/67] Use correct status code for messages --- culturefeed_pages/includes/members.inc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/culturefeed_pages/includes/members.inc b/culturefeed_pages/includes/members.inc index c1e5338e..887e7624 100644 --- a/culturefeed_pages/includes/members.inc +++ b/culturefeed_pages/includes/members.inc @@ -670,12 +670,14 @@ function culturefeed_pages_page_request_admin_membership_approved_submit($form, 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); @@ -692,7 +694,7 @@ function culturefeed_pages_page_request_validated_admin($page, $request_type) { ajax_deliver(array('#type' => 'ajax', '#commands' => $commands)); } else { - drupal_set_message($message); + drupal_set_message($message, $success ? 'status': 'error'); drupal_goto(); } From a55566131681221d7a6e813904ac48c0ef8c4b01 Mon Sep 17 00:00:00 2001 From: zuuperman Date: Tue, 18 Nov 2014 14:26:05 +0100 Subject: [PATCH 24/67] Translate the entity type facet items --- culturefeed_agenda/includes/admin.inc | 6 +++--- culturefeed_search_ui/includes/blocks.inc | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/culturefeed_agenda/includes/admin.inc b/culturefeed_agenda/includes/admin.inc index b9206736..064f402b 100644 --- a/culturefeed_agenda/includes/admin.inc +++ b/culturefeed_agenda/includes/admin.inc @@ -16,9 +16,9 @@ function culturefeed_agenda_admin_settings_form() { '#title' => t('Entity types to be searched'), '#type' => 'checkboxes', '#options' => array( - 'event' => t('Events'), - 'production' => t('Productions'), - 'actor' => t('Actors'), + 'event' => t('event', array(), array('context' => 'culturefeed-facets')), + 'production' => t('production', array(), array('context' => 'culturefeed-facets')), + 'actor' => t('actor', array(), array('context' => 'culturefeed-facets')), ), '#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'), diff --git a/culturefeed_search_ui/includes/blocks.inc b/culturefeed_search_ui/includes/blocks.inc index 791ef9a5..dcf930d4 100644 --- a/culturefeed_search_ui/includes/blocks.inc +++ b/culturefeed_search_ui/includes/blocks.inc @@ -119,10 +119,17 @@ function culturefeed_search_ui_search_facets_block($facet_name, $domain_id = '', else { $items = $facet->getResult()->getItems(); + // type facet should go through t() + if ($facet_name == 'type') { + foreach ($items as $item) { + $item->setLabel(t($item->getLabel(), array(), array('context' => 'culturefeed-facets'))); + } + } // If the facet is one of the category facets. Translate the items. - if (substr($facet_name, strlen($facet_name) - 3) == '_id') { + elseif (substr($facet_name, strlen($facet_name) - 3) == '_id') { culturefeed_search_translate_facet($items); } + } if (!empty($items)) { From 76e8844fef68339fd6dcd79f197dbb7601b4b0f9 Mon Sep 17 00:00:00 2001 From: zuuperman Date: Tue, 18 Nov 2014 17:51:36 +0100 Subject: [PATCH 25/67] Make sure type is not becoming category_id filter --- culturefeed_agenda/lib/Drupal/AgendaSearchPage.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php index 41e43ef8..fe230e1a 100644 --- a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php +++ b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php @@ -37,13 +37,21 @@ public function initialize() { $this->addQueryTerm(preg_replace("/\/\b|\b:/x", "", $params['search'])); } - $this->addFacetFilters($params); + 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')); + } - $active_types = variable_get('culturefeed_agenda_active_entity_types', array('event', 'production')); 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[] = $this->facetComponent->facetField('category'); $this->parameters[] = $this->facetComponent->facetField('datetype'); $this->parameters[] = $this->facetComponent->facetField('city'); From 7733e210f35b2e908063a92cd435f2ce71efeb7d Mon Sep 17 00:00:00 2001 From: zuuperman Date: Wed, 19 Nov 2014 11:57:31 +0100 Subject: [PATCH 26/67] Make sure no notice occurs --- culturefeed_pages/includes/helpers.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/culturefeed_pages/includes/helpers.inc b/culturefeed_pages/includes/helpers.inc index 0f9a7c93..3d46b3f0 100644 --- a/culturefeed_pages/includes/helpers.inc +++ b/culturefeed_pages/includes/helpers.inc @@ -508,6 +508,7 @@ function culturefeed_pages_get_validated_admins_of_page(CultureFeed_Cdb_Item_Pag return array(); } + $admins_of_page = array(); foreach ($admin_list->memberships as $admin) { if ($admin->validated) { $admins_of_page[$admin->user->id] = $admin->user->id; From 1990f9eeb6bf0baf1bc441edf4bee6b4671c56f7 Mon Sep 17 00:00:00 2001 From: Jochen Stals Date: Wed, 19 Nov 2014 13:01:01 +0100 Subject: [PATCH 27/67] initial work for the location category id. --- .../lib/Drupal/AgendaSearchPage.php | 14 +++++++++---- .../culturefeed_search_ui.module | 21 ++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php index c7b61538..bb923d05 100644 --- a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php +++ b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php @@ -43,6 +43,7 @@ public function initialize() { $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 +182,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,12 +200,16 @@ 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. if (!empty($translations[$item->getValue()][$preferred_language])) { + if ($start == 'location_') { + dsm($translations[$item->getValue()][$preferred_language], $item->getLabel()); + } $item->setLabel($translations[$item->getValue()][$preferred_language]); } } diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index f237e069..7eb804cf 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -375,6 +375,7 @@ 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]); @@ -716,12 +717,30 @@ function culturefeed_search_ui_block_view($delta) { } } + $facet_name = 'category_' . $delta_parts[1] . '_id'; + $domain_id = $delta_parts[1]; + $allowed_values = array(); + + // Hande "location_category_facility_id" as "facility". + if ($delta_parts[1] == 'facility') { + $delta = 'facility'; + $facet_name = 'location_category_facility_id'; + $domain_id = 'location_category_facility_id'; + $enabled_options = variable_get('culturefeed_facet_enabled_options', NULL); + $allowed_values = culturefeed_search_get_categories_by_domain($delta_parts[1]); + foreach ($allowed_values as $key => $value) { + if (!isset($enabled_options[$delta][$key])) { + unset($allowed_values[$key]); + } + } + } + $block_settings = array( 'sort' => variable_get('culturefeed_search_sort_' . $delta, CULTUREFEED_SEARCH_SORT_ALPHABETICALLY), 'highest_level' => variable_get('culturefeed_facet_highest_level_' . $delta, 1), 'show_subitems' => variable_get('culturefeed_facet_show_subitems_' . $delta, FALSE), ); - $block = culturefeed_search_ui_search_facets_block('category_' . $delta_parts[1] . '_id', $delta_parts[1], array(), $block_settings); + $block = culturefeed_search_ui_search_facets_block($facet_name, $domain_id, $allowed_values, $block_settings); } } From 5d5f2810c71f174d254486f55cdf6ba36626955d Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Wed, 19 Nov 2014 15:08:11 +0100 Subject: [PATCH 28/67] UIV-965 show shortdescription as plain text --- culturefeed_agenda/theme/theme.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/culturefeed_agenda/theme/theme.inc b/culturefeed_agenda/theme/theme.inc index 95584953..7e9668d0 100644 --- a/culturefeed_agenda/theme/theme.inc +++ b/culturefeed_agenda/theme/theme.inc @@ -151,7 +151,7 @@ function _culturefeed_agenda_preprocess_agenda(&$variables) { if ($detail) { $variables['title'] = check_plain($detail->getTitle()); - $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. From c72073dc0c3e500f27acc2f4b362c7964ba6ef26 Mon Sep 17 00:00:00 2001 From: Sven Houtmeyers Date: Wed, 19 Nov 2014 17:15:39 +0100 Subject: [PATCH 29/67] fix typo in class name for adding tags --- culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc index 915689bf..04e0c843 100644 --- a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc +++ b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc @@ -3032,7 +3032,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 { From f9d60a68f53368a1c1109721d62b29c988ca0767 Mon Sep 17 00:00:00 2001 From: Sven Houtmeyers Date: Wed, 19 Nov 2014 17:30:32 +0100 Subject: [PATCH 30/67] replace NULL as default for culturefeed_search_ui_last_deletion_registration var - mail E2E --- culturefeed_search_ui/culturefeed_search_ui.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 39f8307b..641162a0 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -938,7 +938,7 @@ function culturefeed_search_ui_culturefeed_search_ui_active_filters($culturefeed */ function culturefeed_search_ui_register_deletions() { - $last_registration_timestamp = variable_get('culturefeed_search_ui_last_deletion_registration', NULL); + $last_registration_timestamp = variable_get('culturefeed_search_ui_last_deletion_registration', REQUEST_TIME - (2629743 * 3)); if ($last_registration_timestamp) { $last_registration = date('Y-m-d', $last_registration_timestamp); } From 44171f44c7cb8d95b67a6fc6c35b3550987ca6ba Mon Sep 17 00:00:00 2001 From: Jochen Stals Date: Thu, 20 Nov 2014 11:29:27 +0100 Subject: [PATCH 31/67] Fixed the translateFacet --- culturefeed_agenda/lib/Drupal/AgendaSearchPage.php | 3 --- culturefeed_search_ui/culturefeed_search_ui.module | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php index bb923d05..6c996fd4 100644 --- a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php +++ b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php @@ -207,9 +207,6 @@ private function translateFacets() { foreach ($items as $item) { // Translate if found. if (!empty($translations[$item->getValue()][$preferred_language])) { - if ($start == 'location_') { - dsm($translations[$item->getValue()][$preferred_language], $item->getLabel()); - } $item->setLabel($translations[$item->getValue()][$preferred_language]); } } diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 7eb804cf..6520225a 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -733,6 +733,7 @@ function culturefeed_search_ui_block_view($delta) { unset($allowed_values[$key]); } } + $allowed_values = drupal_map_assoc($allowed_values); } $block_settings = array( From d6d702884d5b27c152e49456d5dbdb21b595d82a Mon Sep 17 00:00:00 2001 From: Jochen Stals Date: Thu, 20 Nov 2014 14:49:31 +0100 Subject: [PATCH 32/67] finished UIT-3: created a way to have the allowed options filtered. --- .../culturefeed_search_ui.module | 20 ++++++---------- culturefeed_search_ui/includes/blocks.inc | 24 +++++++++++++++---- .../lib/Drupal/CultureFeedSearchPage.php | 3 +++ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 6520225a..9ab893c5 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -720,6 +720,11 @@ function culturefeed_search_ui_block_view($delta) { $facet_name = 'category_' . $delta_parts[1] . '_id'; $domain_id = $delta_parts[1]; $allowed_values = array(); + $block_settings = array( + 'sort' => variable_get('culturefeed_search_sort_' . $delta, CULTUREFEED_SEARCH_SORT_ALPHABETICALLY), + 'highest_level' => variable_get('culturefeed_facet_highest_level_' . $delta, 1), + 'show_subitems' => variable_get('culturefeed_facet_show_subitems_' . $delta, FALSE), + ); // Hande "location_category_facility_id" as "facility". if ($delta_parts[1] == 'facility') { @@ -727,20 +732,9 @@ function culturefeed_search_ui_block_view($delta) { $facet_name = 'location_category_facility_id'; $domain_id = 'location_category_facility_id'; $enabled_options = variable_get('culturefeed_facet_enabled_options', NULL); - $allowed_values = culturefeed_search_get_categories_by_domain($delta_parts[1]); - foreach ($allowed_values as $key => $value) { - if (!isset($enabled_options[$delta][$key])) { - unset($allowed_values[$key]); - } - } - $allowed_values = drupal_map_assoc($allowed_values); + $allowed_values = $enabled_options['facility']; + $block_settings['intersect'] = TRUE; } - - $block_settings = array( - 'sort' => variable_get('culturefeed_search_sort_' . $delta, CULTUREFEED_SEARCH_SORT_ALPHABETICALLY), - 'highest_level' => variable_get('culturefeed_facet_highest_level_' . $delta, 1), - 'show_subitems' => variable_get('culturefeed_facet_show_subitems_' . $delta, FALSE), - ); $block = culturefeed_search_ui_search_facets_block($facet_name, $domain_id, $allowed_values, $block_settings); } diff --git a/culturefeed_search_ui/includes/blocks.inc b/culturefeed_search_ui/includes/blocks.inc index 6141fe3c..53448b9d 100644 --- a/culturefeed_search_ui/includes/blocks.inc +++ b/culturefeed_search_ui/includes/blocks.inc @@ -89,6 +89,10 @@ function culturefeed_search_ui_search_block_form_submit($form, & $form_state) { * List of allowed items, and the label that should be shown for every item. * @param array $settings * Array containing setting information (sort, highest level and subitems). + * $settings['intersect'] only works when $allowed_items is set. Intersect + * enabled will only use the options which were given. + * Intersect disabled will override the filter term labels. If you use this, + * make sure the given allowed items have the label as key as well. */ function culturefeed_search_ui_search_facets_block($facet_name, $domain_id = '', $allowed_items = array(), $settings = array()) { @@ -105,14 +109,24 @@ function culturefeed_search_ui_search_facets_block($facet_name, $domain_id = '', $facet = $facets[$facet_name]; - // Show only the allowed values, and set the requested label. if (!empty($allowed_items)) { $all_items = $facet->getResult()->getItems(); $items = array(); - foreach ($all_items as $item) { - if (isset($allowed_items[$item->getLabel()]) && $item->getTotalResults() > 0) { - $item->setLabel($allowed_items[$item->getLabel()]); - $items[] = $item; + // Show only the allowed values, and set the requested label. + if (!isset($settings['intersect']) || !$settings['intersect']) { + foreach ($all_items as $item) { + if (isset($allowed_items[$item->getLabel()]) && $item->getTotalResults() > 0) { + $item->setLabel($allowed_items[$item->getLabel()]); + $items[] = $item; + } + } + } + // Show only the filtered allowed values. + else { + foreach ($all_items as $item) { + if (isset($allowed_items[$item->getValue()]) && $item->getTotalResults() > 0) { + $items[] = $item; + } } } } diff --git a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php index 720d8c0a..1707e994 100644 --- a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php +++ b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php @@ -458,6 +458,9 @@ protected function addFacetFilters($params) { if ($facetFieldName == 'datetype') { $facetFilterQuery = new Parameter\DateTypeQuery(implode(' OR ', $facetFilter)); } + elseif ($facetFieldName == 'location_category_facility_id') { + $facetFilterQuery = new Parameter\FilterQuery('location_category_facility_id:(' . implode(' OR ', $facetFilter) . ')'); + } else { // If wreg we need to add reg (same id's, example 3000 Leuven wreg.638 reg.638) From 5f20c008ea91a5d62ca86ed58f184e656077000b Mon Sep 17 00:00:00 2001 From: zuuperman Date: Thu, 20 Nov 2014 16:16:53 +0100 Subject: [PATCH 33/67] Use domain id for title --- culturefeed_search_ui/culturefeed_search_ui.module | 1 - 1 file changed, 1 deletion(-) diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 9ab893c5..427db48a 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -730,7 +730,6 @@ function culturefeed_search_ui_block_view($delta) { if ($delta_parts[1] == 'facility') { $delta = 'facility'; $facet_name = 'location_category_facility_id'; - $domain_id = 'location_category_facility_id'; $enabled_options = variable_get('culturefeed_facet_enabled_options', NULL); $allowed_values = $enabled_options['facility']; $block_settings['intersect'] = TRUE; From 5a7a71e807325f2f846b36e3afe9ea252a1d349e Mon Sep 17 00:00:00 2001 From: zuuperman Date: Thu, 20 Nov 2014 17:29:24 +0100 Subject: [PATCH 34/67] Only add type when not all known types are selected --- culturefeed_agenda/includes/admin.inc | 6 +--- culturefeed_agenda/includes/helpers.inc | 33 +++++++++++++------ .../lib/Drupal/AgendaSearchPage.php | 15 ++++++--- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/culturefeed_agenda/includes/admin.inc b/culturefeed_agenda/includes/admin.inc index 064f402b..3b085dad 100644 --- a/culturefeed_agenda/includes/admin.inc +++ b/culturefeed_agenda/includes/admin.inc @@ -15,11 +15,7 @@ function culturefeed_agenda_admin_settings_form() { $form['culturefeed_agenda_active_entity_types'] = array( '#title' => t('Entity types to be searched'), '#type' => 'checkboxes', - '#options' => 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')), - ), + '#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'), ); diff --git a/culturefeed_agenda/includes/helpers.inc b/culturefeed_agenda/includes/helpers.inc index 4c7262bc..32a636e6 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( diff --git a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php index fe230e1a..6e523903 100644 --- a/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php +++ b/culturefeed_agenda/lib/Drupal/AgendaSearchPage.php @@ -37,18 +37,25 @@ 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; + } } - array_walk($active_types, function(&$active_type) { - $active_type = 'type:' . $active_type; - }); - $this->parameters[] = new Parameter\FilterQuery(implode(' OR ', $active_types)); + 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); From 5f18f70b27bf8914362b48752ecbbdc7f30272bc Mon Sep 17 00:00:00 2001 From: Sven Houtmeyers Date: Fri, 21 Nov 2014 11:23:51 +0100 Subject: [PATCH 35/67] CF-368 only register deletions in cron op production api --- culturefeed_search_ui/culturefeed_search_ui.module | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 641162a0..b358367d 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -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(); + } + } /** From bee8a2babc15292376908b39a4071768286c0dc8 Mon Sep 17 00:00:00 2001 From: Sven Houtmeyers Date: Fri, 21 Nov 2014 12:08:41 +0100 Subject: [PATCH 36/67] UIV-957 fixing to many films --- culturefeed_search_ui/culturefeed_search_ui.module | 5 +++++ culturefeed_search_ui/includes/helpers.inc | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index b358367d..1172200c 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -725,6 +725,11 @@ function culturefeed_search_ui_culturefeed_search_page_query_alter(CultureFeedSe $culturefeedSearchPage->addParameter(new Parameter\FilterQuery($option['api-filter-query'])); } } + + // If group = event_production exclude productions (already included in group) + if ($culturefeedSearchPage->getGroup() == 'event_production') { + $culturefeedSearchPage->addParameter(new \Cultuurnet\Search\Parameter\FilterQuery('!type:production')); + } // Add facet on agefrom. $facet_component = culturefeed_get_facet_component(); diff --git a/culturefeed_search_ui/includes/helpers.inc b/culturefeed_search_ui/includes/helpers.inc index 4eaae9ca..a6badcdb 100644 --- a/culturefeed_search_ui/includes/helpers.inc +++ b/culturefeed_search_ui/includes/helpers.inc @@ -304,7 +304,7 @@ function culturefeed_get_search_page($search_type) { $pages[$class_name] = new $search_type['class_name'](); $pages[$class_name]->setResultsPerPage(variable_get('culturefeed_search_ui_pager_items_per_page', CULTUREFEED_SEARCH_UI_PAGER_ITEMS_PER_PAGE)); $pages[$class_name]->setDefaultSort($search_type['sort_default']); - $pages[$class_name]->setGroup(variable_get('culturefeed_search_group', TRUE)); + $pages[$class_name]->setGroup(variable_get('culturefeed_search_group', 'event_production')); $pages[$class_name]->initialize(); } return $pages[$class_name]; From 043b961c1521c1f8254acaaca1f06568f04708f2 Mon Sep 17 00:00:00 2001 From: zuuperman Date: Mon, 24 Nov 2014 13:53:48 +0100 Subject: [PATCH 37/67] Don't show on nodes --- culturefeed_social/culturefeed_social.module | 3 +++ 1 file changed, 3 insertions(+) diff --git a/culturefeed_social/culturefeed_social.module b/culturefeed_social/culturefeed_social.module index 4a82b596..ffa8a526 100644 --- a/culturefeed_social/culturefeed_social.module +++ b/culturefeed_social/culturefeed_social.module @@ -517,6 +517,9 @@ function culturefeed_social_block_view($delta) { case 'attended-by': $object = culturefeed_search_get_active_object(); + if (!$object || !method_exists($object, 'getType') || $object->getType() == 'node') { + return; + } return culturefeed_social_user_list_block_for_activity($object, CultureFeed_Activity::TYPE_IK_GA); case 'comments': From 81ba717278388441acf47dada410cbbef565ea56 Mon Sep 17 00:00:00 2001 From: Lieven Goudeseune Date: Wed, 26 Nov 2014 15:46:20 +0100 Subject: [PATCH 38/67] UIT-5: Actor search block. --- culturefeed_agenda/culturefeed_agenda.module | 51 +++++++++++++- culturefeed_agenda/includes/blocks.inc | 66 +++++++++++++++++++ culturefeed_agenda/includes/helpers.inc | 64 +++++++++++++++--- culturefeed_agenda/includes/pages.inc | 27 ++++++++ .../js/autocomplete_autosubmit.js | 36 ++++++++++ .../culturefeed-agenda-actors-nearby.tpl.php | 10 +++ culturefeed_agenda/theme/theme.inc | 19 ++++++ 7 files changed, 262 insertions(+), 11 deletions(-) create mode 100644 culturefeed_agenda/js/autocomplete_autosubmit.js create mode 100644 culturefeed_agenda/theme/culturefeed-agenda-actors-nearby.tpl.php diff --git a/culturefeed_agenda/culturefeed_agenda.module b/culturefeed_agenda/culturefeed_agenda.module index ff0ff8dc..7ef9517a 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; } @@ -197,6 +204,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 +299,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 +378,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 +423,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 +453,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 +478,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/blocks.inc b/culturefeed_agenda/includes/blocks.inc index 0a570f21..9ce76637 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. */ @@ -246,3 +248,67 @@ 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. + $current_event = $_GET['facet']['category_eventtype_id'][0]; + $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..fb57c6d8 100644 --- a/culturefeed_agenda/includes/helpers.inc +++ b/culturefeed_agenda/includes/helpers.inc @@ -260,7 +260,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 +543,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 +602,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 +669,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/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/theme.inc b/culturefeed_agenda/theme/theme.inc index 7e9668d0..55d3176a 100644 --- a/culturefeed_agenda/theme/theme.inc +++ b/culturefeed_agenda/theme/theme.inc @@ -895,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); + +} From 8344095876a3f3434662ac49b3fdd474fdf80c9f Mon Sep 17 00:00:00 2001 From: Lieven Goudeseune Date: Wed, 26 Nov 2014 17:11:03 +0100 Subject: [PATCH 39/67] UIT-11: Skip disabled terms in termImport(). --- .../lib/Drupal/Import/CultureFeedDomainImport.php | 6 ++++++ 1 file changed, 6 insertions(+) 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; From d47f8abe7a04c0051c17dbf1bdf69f3c8d0ca846 Mon Sep 17 00:00:00 2001 From: Lieven Goudeseune Date: Thu, 27 Nov 2014 13:42:43 +0100 Subject: [PATCH 40/67] UIT-18: Move sort settings from block settings to admin settings, Make sure default sorting is visible in sorting block. --- culturefeed_agenda/includes/blocks.inc | 2 +- .../culturefeed_search_ui.module | 126 +++--------------- culturefeed_search_ui/includes/admin.inc | 112 ++++++++++++++++ culturefeed_search_ui/theme/theme.inc | 5 +- 4 files changed, 137 insertions(+), 108 deletions(-) diff --git a/culturefeed_agenda/includes/blocks.inc b/culturefeed_agenda/includes/blocks.inc index 9ce76637..f4e9c859 100644 --- a/culturefeed_agenda/includes/blocks.inc +++ b/culturefeed_agenda/includes/blocks.inc @@ -257,7 +257,7 @@ function culturefeed_agenda_block_actor_search_facet() { } // Only show this block if allowed in the block settings. - $current_event = $_GET['facet']['category_eventtype_id'][0]; + $current_event = isset($_GET['facet']['category_eventtype_id'][0]) ? $_GET['facet']['category_eventtype_id'][0] : ''; $saved_events = variable_get('agenda_actor_search_visibility'); $allowed_events = array(); diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index bb0ee210..70f60529 100644 --- a/culturefeed_search_ui/culturefeed_search_ui.module +++ b/culturefeed_search_ui/culturefeed_search_ui.module @@ -59,12 +59,12 @@ function culturefeed_search_ui_init() { * Implements hook_cron(). */ function culturefeed_search_ui_cron() { - + // 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(); } - + } /** @@ -114,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), @@ -502,79 +519,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:

    -
  • Label: Date
  • -
  • Value: date
  • -
  • Sort query for API: startdateday asc
  • -

    ' - )); - - $form['sort_options'] = array( - '#type' => 'container', - '#tree' => TRUE, - ); - - $search_pages = culturefeed_get_searchable_types(); - foreach ($search_pages as $search_page) { - - $type = $search_page['id']; - $sort_options = culturefeed_search_ui_get_sort_options_for_page($search_page); - - $form['sort_options'][$type] = array( - '#type' => 'fieldset', - '#title' => check_plain($search_page['page_title']), - '#tree' => TRUE, - '#theme' => 'culturefeed_search_ui_admin_sort_order_options', - ); - - for ($i = 0; $i < 10; $i++) { - - $value = isset($sort_options[$i]['value']) ? $sort_options[$i]['value'] : ''; - - $form['sort_options'][$type][$i]['default'] = array( - '#title' => t('Default'), - '#type' => 'radio', - '#parents' => array('sort_options', $type, 'default'), - '#default_value' => (isset($sort_options['default']) && $i == $sort_options['default']) ? $i : FALSE, - '#return_value' => $i, - ); - - $form['sort_options'][$type][$i]['exposed'] = array( - '#title' => t('Exposed'), - '#type' => 'checkbox', - '#default_value' => isset($sort_options[$i]['exposed']) ? $sort_options[$i]['exposed'] : $i - ); - - $form['sort_options'][$type][$i]['label'] = array( - '#title' => t('Label'), - '#type' => 'textfield', - '#default_value' => isset($sort_options[$i]['label']) ? $sort_options[$i]['label'] : '', - ); - - $form['sort_options'][$type][$i]['value'] = array( - '#title' => t('Value used in url'), - '#type' => 'textfield', - '#default_value' => $value, - ); - - $form['sort_options'][$type][$i]['query'] = array( - '#title' => t('Sortquery for api'), - '#type' => 'textfield', - '#default_value' => isset($sort_options[$i]['query']) ? $sort_options[$i]['query'] : '', - ); - - } - - } - - } - return $form; } @@ -617,34 +561,6 @@ function culturefeed_search_ui_block_save($delta, $edit = array()) { $options[$delta_parts[1]] = array_filter($edit['culturefeed-facet-enabled-options']); variable_set('culturefeed_facet_enabled_options', $options); } - - if ($delta == 'culturefeed-search-sortorder') { - - if (!empty($edit['sort_options'])) { - - // Don't save empty options. - foreach ($edit['sort_options'] as $type => $options) { - - $default_sort = $edit['sort_options'][$type]['default']; - foreach ($options as $key => &$option) { - - if ($key == 'default') { - continue; - } - - if (empty($option['value'])) { - unset($options[$key]); - } - } - - variable_set('culturefeed_search_sortoptions_' . $type, $options); - - } - - } - - } - } /** @@ -760,7 +676,7 @@ function culturefeed_search_ui_culturefeed_search_page_query_alter(CultureFeedSe $culturefeedSearchPage->addParameter(new Parameter\FilterQuery($option['api-filter-query'])); } } - + // If group = event_production exclude productions (already included in group) if ($culturefeedSearchPage->getGroup() == 'event_production') { $culturefeedSearchPage->addParameter(new \Cultuurnet\Search\Parameter\FilterQuery('!type:production')); diff --git a/culturefeed_search_ui/includes/admin.inc b/culturefeed_search_ui/includes/admin.inc index 5e4434e0..30056c23 100644 --- a/culturefeed_search_ui/includes/admin.inc +++ b/culturefeed_search_ui/includes/admin.inc @@ -51,3 +51,115 @@ function culturefeed_search_ui_admin_settings() { return system_settings_form($form); } + +/** + * Admin form for sort order settings. + */ +function culturefeed_search_ui_admin_sort_order_settings_form() { + + $form = array(); + + $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:

      +
    • Label: Date
    • +
    • Value: date
    • +
    • Sort query for API: startdateday asc
    • +

      ' + )); + + $form['sort_options'] = array( + '#type' => 'container', + '#tree' => TRUE, + ); + + $search_pages = culturefeed_get_searchable_types(); + foreach ($search_pages as $search_page) { + + $type = $search_page['id']; + $sort_options = culturefeed_search_ui_get_sort_options_for_page($search_page); + + $form['sort_options'][$type] = array( + '#type' => 'fieldset', + '#title' => check_plain($search_page['page_title']), + '#tree' => TRUE, + '#theme' => 'culturefeed_search_ui_admin_sort_order_options', + ); + + for ($i = 0; $i < 10; $i++) { + + $value = isset($sort_options[$i]['value']) ? $sort_options[$i]['value'] : ''; + + $form['sort_options'][$type][$i]['default'] = array( + '#title' => t('Default'), + '#type' => 'radio', + '#parents' => array('sort_options', $type, 'default'), + '#default_value' => (isset($sort_options['default']) && $i == $sort_options['default']) ? $i : FALSE, + '#return_value' => $i, + ); + + $form['sort_options'][$type][$i]['exposed'] = array( + '#title' => t('Exposed'), + '#type' => 'checkbox', + '#default_value' => isset($sort_options[$i]['exposed']) ? $sort_options[$i]['exposed'] : $i + ); + + $form['sort_options'][$type][$i]['label'] = array( + '#title' => t('Label'), + '#type' => 'textfield', + '#default_value' => isset($sort_options[$i]['label']) ? $sort_options[$i]['label'] : '', + ); + + $form['sort_options'][$type][$i]['value'] = array( + '#title' => t('Value used in url'), + '#type' => 'textfield', + '#default_value' => $value, + ); + + $form['sort_options'][$type][$i]['query'] = array( + '#title' => t('Sortquery for api'), + '#type' => 'textfield', + '#default_value' => isset($sort_options[$i]['query']) ? $sort_options[$i]['query'] : '', + ); + + } + + } + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save settings'), + '#submit' => array('culturefeed_search_ui_admin_sort_order_settings_form_submit'), + ); + + return $form; +} + + +/** + * Submit the admin sort order settings form. + */ +function culturefeed_search_ui_admin_sort_order_settings_form_submit(&$form, &$form_state) { + + if (!empty($form_state['values']['sort_options'])) { + + // Don't save empty options. + foreach ($form_state['values']['sort_options'] as $type => $options) { + + $default_sort = $form_state['values']['sort_options'][$type]['default']; + foreach ($options as $key => &$option) { + + if ($key == 'default') { + continue; + } + + if (empty($option['value'])) { + unset($options[$key]); + } + } + + variable_set('culturefeed_search_sortoptions_' . $type, $options); + } + } +} diff --git a/culturefeed_search_ui/theme/theme.inc b/culturefeed_search_ui/theme/theme.inc index 1d49f008..e99d517e 100644 --- a/culturefeed_search_ui/theme/theme.inc +++ b/culturefeed_search_ui/theme/theme.inc @@ -429,7 +429,7 @@ function culturefeed_search_ui_preprocess_culturefeed_search_sort_links(&$variab } $sort_options = culturefeed_search_ui_get_sort_options_for_page($search_page); - $current_sort = isset($_GET['sort']) ? $_GET['sort'] : $sort_options['default']; + $current_sort = isset($_GET['sort']) ? $_GET['sort'] : $sort_options[$sort_options['default']]['value']; $query = drupal_get_query_parameters(NULL, array('q', 'page')); @@ -443,7 +443,8 @@ function culturefeed_search_ui_preprocess_culturefeed_search_sort_links(&$variab $query['sort'] = $option['value']; $attributes = array(); - if ($key === $current_sort || $option['value'] == $current_sort) { + + if ($option['value'] == $current_sort) { $attributes = array( 'class' => array('active'), ); From 500573d20cf58060df8d9c2641d2a14040db52bd Mon Sep 17 00:00:00 2001 From: HnLn Date: Thu, 27 Nov 2014 16:12:53 +0100 Subject: [PATCH 41/67] MSS94 initial commit --- .../css/culturefeed_entry_ui.css | 35 -- .../css/culturefeed_date_control.css | 51 ++ .../culturefeed_date_control.info | 5 + .../culturefeed_date_control.module | 74 +++ .../form_element/date_control.inc | 232 +++++++++ .../culturefeed_date_control/old_form.bak | 383 ++++++++++++++ .../culturefeed_date_control/theme/theme.inc | 45 ++ .../culturefeed_entry_ui.info | 1 + .../culturefeed_entry_ui.module | 79 --- .../includes/culturefeed_entry_ui.pages.inc | 487 +----------------- culturefeed_entry_ui/theme/theme.inc | 129 ----- 11 files changed, 799 insertions(+), 722 deletions(-) create mode 100644 culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control.css create mode 100644 culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.info create mode 100644 culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module create mode 100644 culturefeed_entry_ui/culturefeed_date_control/form_element/date_control.inc create mode 100644 culturefeed_entry_ui/culturefeed_date_control/old_form.bak create mode 100644 culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc diff --git a/culturefeed_entry_ui/css/culturefeed_entry_ui.css b/culturefeed_entry_ui/css/culturefeed_entry_ui.css index 9dcce588..46d67966 100644 --- a/culturefeed_entry_ui/css/culturefeed_entry_ui.css +++ b/culturefeed_entry_ui/css/culturefeed_entry_ui.css @@ -156,41 +156,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/css/culturefeed_date_control.css b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control.css new file mode 100644 index 00000000..228bd5cf --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control.css @@ -0,0 +1,51 @@ +@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; +} + + + +/*.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; +}*/ 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..b685b880 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module @@ -0,0 +1,74 @@ + array( + '#input' => TRUE, + '#process' => array('culturefeed_date_control_process_element'), + ), + ); +} + +/** + * 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'; + } +} + +/** + * Adds a span element for a calendar icon on date popup fields. + */ +function culturefeed_date_control_element_date_popup_after_build($element, $form_state) { + if (isset($element['date']) && isset($element['#icon']) && $element['#icon']) { + $element['date']['#suffix'] = ""; + } + return $element; +} + +/** + * Implements hook_theme(). + */ +function culturefeed_date_control_theme() { + + return array( + 'culturefeed_date_control_timestamps_table' => array( + 'file' => 'theme.inc', + 'path' => drupal_get_path('module', 'culturefeed_date_control') . '/theme', + 'render element' => 'form', + ), + ); + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form_element/date_control.inc b/culturefeed_entry_ui/culturefeed_date_control/form_element/date_control.inc new file mode 100644 index 00000000..928475a3 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form_element/date_control.inc @@ -0,0 +1,232 @@ + 'container', + '#prefix' => "
      ", + '#suffix' => "
      ", + ); + + $element['container']['date_control'] = array( + '#type' => 'fieldset', + '#title' => $element['#title'], + '#tree' => TRUE, + ); + + // Timestamps. + if ($type == 'timestamps') { + culturefeed_date_control_get_timestamps( + $element['container']['date_control'], + $form_state, + $triggering_parent, + isset($values['timestamps']) ? $values['timestamps'] : array() + ); + } + + $element['#attached'] = array( + 'css' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control.css', + ), + ); + + return $element; +} + +/** + * Returns the date control type based on the values. + * + * @param array $values + * The element values. + * + * @return string + * The type. + */ +function culturefeed_date_control_get_type(array $values) { + + if (isset($values['period']['start']) && $values['period']['end']) { + return 'period'; + } + if (isset($values['permanent'])) { + return 'permanent'; + } + else { + // Default setting. + return 'timestamps'; + } + +} + +/** + * Sets the date control timestamps form elements. + * + * @param array $element + * The element. + * @param array $form_state + * The form state. + * @param string $triggering_parent + * The triggering parent. + * @param array $timestamps + * The timestamps. + */ +function culturefeed_date_control_get_timestamps(array &$element, array &$form_state, $triggering_parent, array $timestamps) { + + if (empty($form_state['timestamp_count'])) { + $form_state['timestamp_count'] = 1; + } + + $element['timestamps'] = array( + '#type' => 'container', + '#theme' => 'culturefeed_date_control_timestamps_table', + ); + + for ($i = 0; $i < $form_state['timestamp_count']; $i++) { + + if ($form_state['timestamp_count'] > 1) { + $element['timestamps'][$i]['timestamps_remove_stamp'] = array( + '#type' => 'submit', + '#value' => t('×'), + '#name' => 'remove_stamp_' . $i, + '#submit' => array('culturefeed_date_control_ajax_submit'), + '#attributes' => array('class' => array('add-more-link btn-link'), 'title' => 'remove date'), + '#ajax' => array( + 'callback' => 'culturefeed_date_control_ajax_callback', + 'wrapper' => 'date-control-ajax-wrapper', + 'effect' => 'none', + 'progress' => array('type' => 'throbber'), + ), + ); + } + + $element['timestamps'][$i]['date'] = array( + '#type' => 'date_popup', + '#default_value' => isset($timestamps[$i]['date']) ? $timestamps[$i]['date'] : '', + '#title' => t('Date'), + '#date_label_position' => 'none', + '#date_format' => 'd-m-Y', + '#icon' => TRUE, + ); + + $element['timestamps'][$i]['start_time'] = array( + '#type' => 'date_select', + '#default_value' => isset($timestamps[$i]['start_time']) ? $timestamps[$i]['date'] . ' ' . $timestamps[$i]['start_time'] : '', + '#title' => '', + '#date_format' => 'H:i', + '#date_increment' => 30, + ); + + $element['timestamps'][$i]['end_time'] = array( + '#type' => 'date_select', + '#default_value' => isset($timestamps[$i]['end_time']) ? $timestamps[$i]['date'] . ' ' . $timestamps[$i]['end_time'] : '', + '#title' => '', + '#date_format' => 'H:i', + '#date_increment' => 30, + '#access' => isset($timestamps[$i]['end_time']), + ); + + $element['timestamps'][$i]['remove_end_' . $i] = array( + '#type' => 'submit', + '#value' => t('- remove end time'), + '#submit' => array('culturefeed_date_control_ajax_submit'), + '#attributes' => array('class' => array('add-more-link btn-link')), + '#ajax' => array( + 'callback' => 'culturefeed_date_control_ajax_callback', + 'wrapper' => 'date-control-ajax-wrapper', + 'effect' => 'none', + 'progress' => array('type' => 'throbber'), + ), + '#access' => isset($timestamps[$i]['end_time']), + ); + + $element['timestamps'][$i]['add_end_' . $i] = array( + '#type' => 'submit', + '#value' => t('+ add end time'), + '#submit' => array('culturefeed_date_control_ajax_submit'), + '#attributes' => array('class' => array('add-more-link btn-link')), + '#ajax' => array( + 'callback' => 'culturefeed_date_control_ajax_callback', + 'wrapper' => 'date-control-ajax-wrapper', + 'effect' => 'none', + 'progress' => array('type' => 'throbber'), + ), + '#access' => !isset($timestamps[$i]['end_time']), + ); + + } + + $element['timestamps_add_stamp'] = array( + '#type' => 'submit', + '#value' => t('+ add date'), + '#submit' => array('culturefeed_date_control_ajax_submit'), + '#attributes' => array('class' => array('add-more-link btn-link')), + '#ajax' => array( + 'callback' => 'culturefeed_date_control_ajax_callback', + 'wrapper' => 'date-control-ajax-wrapper', + 'effect' => 'none', + 'progress' => array('type' => 'throbber'), + ), + ); + +} + +/** + * Submit handler for the ajax buttons. + * + * @param array $form + * The form. + * @param array $form_state + * The form state. + */ +function culturefeed_date_control_ajax_submit(array $form, array &$form_state) { + + $triggering_parent = array_pop($form_state['triggering_element']['#parents']); + $timestamps = $form_state['values']['date_control']['timestamps']; + + switch ($triggering_parent) { + case 'add_stamp': + $form_state['timestamp_count']++; + break; + + case 'remove_stamp': + array_splice($timestamps, array_pop($form_state['triggering_element']['#parents']), 1); + $form_state['timestamp_count']--; + break; + + case strpos($triggering_parent, 'add_end_') === 0: + $timestamps[array_pop($form_state['triggering_element']['#parents'])]['end_time'] = ''; + break; + + case strpos($triggering_parent, 'remove_end_') === 0: + unset($timestamps[array_pop($form_state['triggering_element']['#parents'])]['end_time']); + break; + } + + drupal_array_set_nested_value($form_state['input'], array('date_control', 'timestamps'), $timestamps, TRUE); + drupal_array_set_nested_value($form_state['values'], array('date_control', 'timestamps'), $timestamps, TRUE); + + $form_state['rebuild'] = TRUE; + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/old_form.bak b/culturefeed_entry_ui/culturefeed_date_control/old_form.bak new file mode 100644 index 00000000..7ff627f7 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/old_form.bak @@ -0,0 +1,383 @@ + 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 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), + ), + ), + ), + ); + + 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')), + ), + ); + + 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 '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; + + + $day_labels = array( + 'monday' => t('mon'), + 'tuesday' => t('tue'), + 'wednesday' => t('wed'), + 'thursday' => t('thu'), + 'friday' => t('fri'), + 'saturday' => t('sat'), + 'sunday' => t('sun'), + ); + + + + */ + } + +} \ No newline at end of file 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..61b007b5 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc @@ -0,0 +1,45 @@ + array(), 'attributes' => array('class' => 'date-control-table')); + + foreach (element_children($form) as $element) { + + $cells = array(); + if (isset($form[$element]['timestamps_remove_child'])) { + $cells[] = drupal_render($form[$element]['timestamps_remove_stamp']); + } + $cells[] = drupal_render($form[$element]['date']); + $cells[] = drupal_render($form[$element]['start_time']); + if (isset($form[$element]['end_time'])) { + $cells[] = drupal_render($form[$element]['end_time']); + } + if (isset($form[$element]['add_end_' . $element])) { + $cells[] = drupal_render($form[$element]['add_end_' . $element]); + } + if (isset($form[$element]['remove_end_' . $element])) { + $cells[] = drupal_render($form[$element]['remove_end_' . $element]); + } + else { + $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 04e0c843..e882f638 100644 --- a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc +++ b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc @@ -29,20 +29,10 @@ 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 = ''; $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 = ''; @@ -675,341 +665,20 @@ 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' => $period_start, + 'end' => $period_end, ), + 'timestamps' => $timestamps, + 'permanent' => $weekscheme, ), ); - 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. */ 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. */ From 66197fb0064a188e9c28a3686cbf86ad63d6b6f7 Mon Sep 17 00:00:00 2001 From: Lieven Goudeseune Date: Thu, 27 Nov 2014 16:38:03 +0100 Subject: [PATCH 42/67] UIT-19: Make correct facets active when entering pages from non-clean url. --- culturefeed_agenda/includes/blocks.inc | 23 +++++++++++++++++++++-- culturefeed_search_ui/theme/theme.inc | 12 ++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/culturefeed_agenda/includes/blocks.inc b/culturefeed_agenda/includes/blocks.inc index f4e9c859..fc7cf2c0 100644 --- a/culturefeed_agenda/includes/blocks.inc +++ b/culturefeed_agenda/includes/blocks.inc @@ -57,10 +57,20 @@ function culturefeed_agenda_search_block_form($form, &$form_state) { } asort($options); + if (isset($_GET['facet']['category_id'][0])) { + $default = $_GET['facet']['category_id'][0]; + } + elseif (isset($_GET['facet']['category_' . $domain_id . '_id'][0])) { + $default = $_GET['facet']['category_' . $domain_id . '_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; @@ -257,7 +267,16 @@ function culturefeed_agenda_block_actor_search_facet() { } // Only show this block if allowed in the block settings. - $current_event = isset($_GET['facet']['category_eventtype_id'][0]) ? $_GET['facet']['category_eventtype_id'][0] : ''; + if (isset($_GET['facet']['category_id'][0])) { + $current_event = $_GET['facet']['category_id'][0]; + } + elseif (isset($_GET['facet']['category_eventtype_id'][0])) { + $current_event = $_GET['facet']['category_eventtype_id'][0]; + } + else { + $current_event = ''; + } + $saved_events = variable_get('agenda_actor_search_visibility'); $allowed_events = array(); diff --git a/culturefeed_search_ui/theme/theme.inc b/culturefeed_search_ui/theme/theme.inc index e99d517e..82dd0fa8 100644 --- a/culturefeed_search_ui/theme/theme.inc +++ b/culturefeed_search_ui/theme/theme.inc @@ -237,7 +237,15 @@ function culturefeed_search_ui_preprocess_culturefeed_search_facet(&$variables) 'facet' => array() ); - $active_options = isset($query['facet'][$facet->getKey()]) ? $query['facet'][$facet->getKey()] : array(); + if (isset($query['facet'][$facet->getKey()])) { + $active_options = $query['facet'][$facet->getKey()]; + } + elseif (isset($query['facet']['category_id'])) { + $active_options = $query['facet']['category_id']; + } + else { + $active_options = array(); + } $items = array(); $facets = $variables['items']; @@ -443,7 +451,7 @@ function culturefeed_search_ui_preprocess_culturefeed_search_sort_links(&$variab $query['sort'] = $option['value']; $attributes = array(); - + if ($option['value'] == $current_sort) { $attributes = array( 'class' => array('active'), From 868dc00d89b2aea9f7fc6ab457e3a64bd8151c89 Mon Sep 17 00:00:00 2001 From: Lieven Goudeseune Date: Thu, 27 Nov 2014 16:46:43 +0100 Subject: [PATCH 43/67] UIT-19: Change if else order. --- culturefeed_agenda/includes/blocks.inc | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/culturefeed_agenda/includes/blocks.inc b/culturefeed_agenda/includes/blocks.inc index fc7cf2c0..4a42d3ef 100644 --- a/culturefeed_agenda/includes/blocks.inc +++ b/culturefeed_agenda/includes/blocks.inc @@ -57,12 +57,12 @@ function culturefeed_agenda_search_block_form($form, &$form_state) { } asort($options); - if (isset($_GET['facet']['category_id'][0])) { - $default = $_GET['facet']['category_id'][0]; - } - elseif (isset($_GET['facet']['category_' . $domain_id . '_id'][0])) { + 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; } @@ -267,16 +267,16 @@ function culturefeed_agenda_block_actor_search_facet() { } // Only show this block if allowed in the block settings. - if (isset($_GET['facet']['category_id'][0])) { - $current_event = $_GET['facet']['category_id'][0]; - } - elseif (isset($_GET['facet']['category_eventtype_id'][0])) { - $current_event = $_GET['facet']['category_eventtype_id'][0]; - } - else { - $current_event = ''; - } - + 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(); From d95dd1b76156e091682470e71bee2fcf3370cff1 Mon Sep 17 00:00:00 2001 From: HnLn Date: Mon, 1 Dec 2014 13:02:02 +0100 Subject: [PATCH 44/67] MSS-94 timestamps --- .../culturefeed_date_control_timestamps.css | 51 ++++ .../culturefeed_date_control.module | 96 ++++++-- .../form/date_control.inc | 102 ++++++++ .../form/timestamps.inc | 210 ++++++++++++++++ .../form_element/date_control.inc | 232 ------------------ .../culturefeed_date_control/theme/theme.inc | 54 ++-- .../includes/culturefeed_entry_ui.pages.inc | 1 - 7 files changed, 470 insertions(+), 276 deletions(-) create mode 100644 culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_timestamps.css create mode 100644 culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc create mode 100644 culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc delete mode 100644 culturefeed_entry_ui/culturefeed_date_control/form_element/date_control.inc diff --git a/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_timestamps.css b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_timestamps.css new file mode 100644 index 00000000..9b0d891a --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_timestamps.css @@ -0,0 +1,51 @@ +@CHARSET "UTF-8"; + +/* dates */ + +table.date-control-timestamps-table { + width: auto; +} + +.date-control-timestamps-table .container-inline-date .date-padding { + padding: 0; + float: none; +} + +.date-control-timestamps-table .ui-icon { + display: inline-block; +} + + + +/*.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; +}*/ diff --git a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module index b685b880..ad704794 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module @@ -5,36 +5,82 @@ * Contains the culturefeed date control module. */ -// Includes. -require_once 'form_element/date_control.inc'; +require_once 'form/date_control.inc'; +require_once 'form/timestamps.inc'; /** * Ajax callback for the date control element. */ -function culturefeed_date_control_ajax_callback($form, $form_state) { +function culturefeed_date_control_ajax_callback() { - // Buttons are on different levels inside the element. Find the correct - // parent by starting from the deepest element. - $parents = array_reverse($form_state['triggering_element']['#array_parents']); - foreach ($parents as $element) { - array_shift($parents); - if ($element == 'date_control') { - break; - } - } - $parents = array_reverse($parents); - return drupal_array_get_nested_value($form, $parents); + list($form, $form_state, $form_id, $form_build_id, $commands) = ajax_get_form(); + drupal_process_form($form['#form_id'], $form, $form_state); + $parents = func_get_args(); + + $form = drupal_array_get_nested_value($form, $parents); + $output = drupal_render($form); + $result = array( + '#type' => 'ajax', + '#commands' => ajax_prepare_response($output), + ); + $result['#commands'] = array_merge($commands, $result['#commands']); + return $result; } +/** + * 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. + * - A custom value callback is used so the pre render function has all the data + * needed. + * - A custom ajax callback path to ensure the form is rerenderd. + * + * @see file_managed_file_pre_render() + * @see file_managed_file_submit() + * @see file_managed_file_value() */ function culturefeed_date_control_element_info() { return array( 'culturefeed_date_control' => array( '#input' => TRUE, - '#process' => array('culturefeed_date_control_process_element'), + '#pre_render' => array('culturefeed_date_control_pre_render_element'), + '#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_timestamps' => array( + '#cell_count' => 4, + '#input' => TRUE, + '#element_validate' => array('culturefeed_date_control_timestamps_validate'), + '#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', ), ); } @@ -49,13 +95,21 @@ function culturefeed_date_control_element_info_alter(&$types) { } /** - * Adds a span element for a calendar icon on date popup fields. + * Implements hook_menu(). */ -function culturefeed_date_control_element_date_popup_after_build($element, $form_state) { - if (isset($element['date']) && isset($element['#icon']) && $element['#icon']) { - $element['date']['#suffix'] = ""; - } - return $element; +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, + ), + ); + } /** 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..48046736 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc @@ -0,0 +1,102 @@ +"; + $element['#suffix'] = ""; + + $element['date_control'] = array( + '#type' => 'fieldset', + '#title' => (isset($element['#title'])) ? $element['#title'] : t('Dates'), + ); + + // Timestamps. + $element['date_control']['timestamps'] = array( + '#type' => 'culturefeed_date_control_timestamps', + ); + + $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; + +} + +/** + * 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; + } + +} + +/** + * Returns the date control type based on the values. + * + * @param array $values + * The element values. + * + * @return string + * The type. + */ +function culturefeed_date_control_get_type(array $values) { + + if (isset($values['period']['start']) && $values['period']['end']) { + return 'period'; + } + if (isset($values['permanent'])) { + return 'permanent'; + } + else { + // Default setting. + return 'timestamps'; + } + +} 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..7353a63a --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -0,0 +1,210 @@ + $timestamp) { + + if (isset($timestamps[$key]['end_time'])) { + $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 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['#prefix'] = "
      "; + $element['#suffix'] = "
      "; + + $ajax_button = array( + '#access' => TRUE, + '#ajax' => array( + 'effect' => 'none', + 'path' => 'culturefeed_elements/ajax/' . implode('/', $element['#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', + + ); + + // Get the timestamps. + $timestamps = $element['#value']['stamps']; + + foreach ($timestamps as $key => $timestamp) { + + if ($key !== 'timestamps_add_stamp') { + + $element['stamps'][$key]['remove_stamp'] = $ajax_button + array( + '#value' => t('×'), + '#name' => 'remove_stamp_' . $key, + ); + + $element['stamps'][$key]['date'] = array( + '#type' => 'date_popup', + '#default_value' => '', + '#title' => t('Date'), + '#date_label_position' => 'none', + '#date_format' => 'd-m-Y', + '#icon' => TRUE, + ); + + $element['stamps'][$key]['start_time'] = array( + '#type' => 'date_select', + '#default_value' => '', + '#title' => '', + '#date_format' => 'H:i', + '#date_increment' => 30, + ); + + $element['stamps'][$key]['end_time'] = array( + '#type' => 'date_select', + '#default_value' => '', + '#title' => '', + '#date_format' => 'H:i', + '#date_increment' => 30, + '#access' => TRUE, + ); + + $element['stamps'][$key]['remove_end'] = $ajax_button + array( + '#name' => 'remove_end_' . $key, + '#value' => t('- remove end time'), + ); + + $element['stamps'][$key]['add_end'] = $ajax_button + array( + '#name' => 'add_end_' . $key, + '#value' => t('+ add end time'), + ); + + } + + } + + $element['timestamps_add_stamp'] = $ajax_button + array( + '#name' => 'add_stamp', + '#value' => t('+ add date'), + ); + + $element['#attached'] = array( + 'css' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control_timestamps.css', + ), + ); + + return $element; + +} + +/** + * Validate and alter the timestamp 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'] : ''; + + if ($triggering_element) { + + $timestamps = $element['#value']['stamps']; + $triggering_parent = array_pop($triggering_element['#parents']); + + switch ($triggering_parent) { + + case 'timestamps_add_stamp': + $timestamps[] = array('date' => ''); + $triggering_element['#parents'][] = 'stamps'; + break; + + case 'remove_stamp': + array_splice($timestamps, array_pop($triggering_element['#parents']), 1); + break; + + case 'add_end': + $timestamps[array_pop($triggering_element['#parents'])]['end_time'] = ''; + break; + + case 'remove_end': + unset($timestamps[array_pop($triggering_element['#parents'])]['end_time']); + break; + + } + + drupal_array_set_nested_value($form_state['values'], $triggering_element['#parents'], $timestamps); + drupal_array_set_nested_value($form_state['input'], $triggering_element['#parents'], $timestamps); + + } + +} + +/** + * 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_timestamps_value_callback(array &$element, $input, array $form_state) { + + if ($input) { + return $input; + } + else { + // Default value or an empty stamp. + return array('stamps' => array(array('date' => ''))); + } + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form_element/date_control.inc b/culturefeed_entry_ui/culturefeed_date_control/form_element/date_control.inc deleted file mode 100644 index 928475a3..00000000 --- a/culturefeed_entry_ui/culturefeed_date_control/form_element/date_control.inc +++ /dev/null @@ -1,232 +0,0 @@ - 'container', - '#prefix' => "
      ", - '#suffix' => "
      ", - ); - - $element['container']['date_control'] = array( - '#type' => 'fieldset', - '#title' => $element['#title'], - '#tree' => TRUE, - ); - - // Timestamps. - if ($type == 'timestamps') { - culturefeed_date_control_get_timestamps( - $element['container']['date_control'], - $form_state, - $triggering_parent, - isset($values['timestamps']) ? $values['timestamps'] : array() - ); - } - - $element['#attached'] = array( - 'css' => array( - drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control.css', - ), - ); - - return $element; -} - -/** - * Returns the date control type based on the values. - * - * @param array $values - * The element values. - * - * @return string - * The type. - */ -function culturefeed_date_control_get_type(array $values) { - - if (isset($values['period']['start']) && $values['period']['end']) { - return 'period'; - } - if (isset($values['permanent'])) { - return 'permanent'; - } - else { - // Default setting. - return 'timestamps'; - } - -} - -/** - * Sets the date control timestamps form elements. - * - * @param array $element - * The element. - * @param array $form_state - * The form state. - * @param string $triggering_parent - * The triggering parent. - * @param array $timestamps - * The timestamps. - */ -function culturefeed_date_control_get_timestamps(array &$element, array &$form_state, $triggering_parent, array $timestamps) { - - if (empty($form_state['timestamp_count'])) { - $form_state['timestamp_count'] = 1; - } - - $element['timestamps'] = array( - '#type' => 'container', - '#theme' => 'culturefeed_date_control_timestamps_table', - ); - - for ($i = 0; $i < $form_state['timestamp_count']; $i++) { - - if ($form_state['timestamp_count'] > 1) { - $element['timestamps'][$i]['timestamps_remove_stamp'] = array( - '#type' => 'submit', - '#value' => t('×'), - '#name' => 'remove_stamp_' . $i, - '#submit' => array('culturefeed_date_control_ajax_submit'), - '#attributes' => array('class' => array('add-more-link btn-link'), 'title' => 'remove date'), - '#ajax' => array( - 'callback' => 'culturefeed_date_control_ajax_callback', - 'wrapper' => 'date-control-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - ), - ); - } - - $element['timestamps'][$i]['date'] = array( - '#type' => 'date_popup', - '#default_value' => isset($timestamps[$i]['date']) ? $timestamps[$i]['date'] : '', - '#title' => t('Date'), - '#date_label_position' => 'none', - '#date_format' => 'd-m-Y', - '#icon' => TRUE, - ); - - $element['timestamps'][$i]['start_time'] = array( - '#type' => 'date_select', - '#default_value' => isset($timestamps[$i]['start_time']) ? $timestamps[$i]['date'] . ' ' . $timestamps[$i]['start_time'] : '', - '#title' => '', - '#date_format' => 'H:i', - '#date_increment' => 30, - ); - - $element['timestamps'][$i]['end_time'] = array( - '#type' => 'date_select', - '#default_value' => isset($timestamps[$i]['end_time']) ? $timestamps[$i]['date'] . ' ' . $timestamps[$i]['end_time'] : '', - '#title' => '', - '#date_format' => 'H:i', - '#date_increment' => 30, - '#access' => isset($timestamps[$i]['end_time']), - ); - - $element['timestamps'][$i]['remove_end_' . $i] = array( - '#type' => 'submit', - '#value' => t('- remove end time'), - '#submit' => array('culturefeed_date_control_ajax_submit'), - '#attributes' => array('class' => array('add-more-link btn-link')), - '#ajax' => array( - 'callback' => 'culturefeed_date_control_ajax_callback', - 'wrapper' => 'date-control-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - ), - '#access' => isset($timestamps[$i]['end_time']), - ); - - $element['timestamps'][$i]['add_end_' . $i] = array( - '#type' => 'submit', - '#value' => t('+ add end time'), - '#submit' => array('culturefeed_date_control_ajax_submit'), - '#attributes' => array('class' => array('add-more-link btn-link')), - '#ajax' => array( - 'callback' => 'culturefeed_date_control_ajax_callback', - 'wrapper' => 'date-control-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - ), - '#access' => !isset($timestamps[$i]['end_time']), - ); - - } - - $element['timestamps_add_stamp'] = array( - '#type' => 'submit', - '#value' => t('+ add date'), - '#submit' => array('culturefeed_date_control_ajax_submit'), - '#attributes' => array('class' => array('add-more-link btn-link')), - '#ajax' => array( - 'callback' => 'culturefeed_date_control_ajax_callback', - 'wrapper' => 'date-control-ajax-wrapper', - 'effect' => 'none', - 'progress' => array('type' => 'throbber'), - ), - ); - -} - -/** - * Submit handler for the ajax buttons. - * - * @param array $form - * The form. - * @param array $form_state - * The form state. - */ -function culturefeed_date_control_ajax_submit(array $form, array &$form_state) { - - $triggering_parent = array_pop($form_state['triggering_element']['#parents']); - $timestamps = $form_state['values']['date_control']['timestamps']; - - switch ($triggering_parent) { - case 'add_stamp': - $form_state['timestamp_count']++; - break; - - case 'remove_stamp': - array_splice($timestamps, array_pop($form_state['triggering_element']['#parents']), 1); - $form_state['timestamp_count']--; - break; - - case strpos($triggering_parent, 'add_end_') === 0: - $timestamps[array_pop($form_state['triggering_element']['#parents'])]['end_time'] = ''; - break; - - case strpos($triggering_parent, 'remove_end_') === 0: - unset($timestamps[array_pop($form_state['triggering_element']['#parents'])]['end_time']); - break; - } - - drupal_array_set_nested_value($form_state['input'], array('date_control', 'timestamps'), $timestamps, TRUE); - drupal_array_set_nested_value($form_state['values'], array('date_control', 'timestamps'), $timestamps, TRUE); - - $form_state['rebuild'] = TRUE; - -} diff --git a/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc b/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc index 61b007b5..3f5c8d23 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc @@ -7,34 +7,44 @@ /** * Theme the timestamps table. + * + * @param array $variables + * The variables. + * + * @return string + * The output. */ -function theme_culturefeed_date_control_timestamps_table(&$variables) { +function theme_culturefeed_date_control_timestamps_table(array &$variables) { $form = $variables['form']; - $table = array('rows' => array(), 'attributes' => array('class' => 'date-control-table')); + $table = array('rows' => array(), 'attributes' => array('class' => 'date-control-timestamps-table')); + + 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; - foreach (element_children($form) as $element) { - - $cells = array(); - if (isset($form[$element]['timestamps_remove_child'])) { - $cells[] = drupal_render($form[$element]['timestamps_remove_stamp']); - } - $cells[] = drupal_render($form[$element]['date']); - $cells[] = drupal_render($form[$element]['start_time']); - if (isset($form[$element]['end_time'])) { - $cells[] = drupal_render($form[$element]['end_time']); - } - if (isset($form[$element]['add_end_' . $element])) { - $cells[] = drupal_render($form[$element]['add_end_' . $element]); - } - if (isset($form[$element]['remove_end_' . $element])) { - $cells[] = drupal_render($form[$element]['remove_end_' . $element]); - } - else { - $cells[] = ''; } - $table['rows'][] = $cells; } diff --git a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc index e882f638..12356194 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(); From 7647f6174a7635fbecbccc575962db9e97c4a555 Mon Sep 17 00:00:00 2001 From: HnLn Date: Mon, 1 Dec 2014 16:24:40 +0100 Subject: [PATCH 45/67] MSS-94 period and opening times --- .../css/culturefeed_entry_ui.css | 4 - .../css/culturefeed_date_control.css | 23 +-- .../culturefeed_date_control_timestamps.css | 51 ------- .../culturefeed_date_control.module | 44 +++++- .../form/date_control.inc | 11 ++ .../form/opening_times.inc | 80 +++++++++++ .../culturefeed_date_control/form/period.inc | 132 ++++++++++++++++++ .../form/timestamps.inc | 39 +++--- .../culturefeed_date_control_opening_times.js | 27 ++++ .../culturefeed_date_control/theme/theme.inc | 85 ++++++++++- .../includes/culturefeed_entry_ui.pages.inc | 1 + .../js/culturefeed_entry_ui.js | 15 -- 12 files changed, 394 insertions(+), 118 deletions(-) delete mode 100644 culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_timestamps.css create mode 100644 culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc create mode 100644 culturefeed_entry_ui/culturefeed_date_control/form/period.inc create mode 100644 culturefeed_entry_ui/culturefeed_date_control/js/culturefeed_date_control_opening_times.js diff --git a/culturefeed_entry_ui/css/culturefeed_entry_ui.css b/culturefeed_entry_ui/css/culturefeed_entry_ui.css index 46d67966..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; } 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 index 228bd5cf..0f7af494 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control.css +++ b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control.css @@ -15,37 +15,22 @@ table.date-control-table { display: inline-block; } - - -/*.when-datetimes .container-inline-date .date-padding { - padding: 0; - float: none; -} - -.when-datetimes input.add-more-link { +.date-control-table input.add-more-link { display: inline-block; vertical-align: middle; } -.when-datetimes-table { - width: auto !important; -} - -.when-datetimes-table td { +.date-control-table td { white-space: nowrap; padding: 4px; vertical-align: top; } -.when-datetimes-table td .container-inline-date .form-item .form-item { +.date-control-table td .container-inline-date .form-item .form-item { display: inline-block; float: none; } -.when-datetimes-table td .container-inline-date .form-item { +.date-control-table td .container-inline-date .form-item { vertical-align: top; } - -.when-datetimes-table .ui-icon { - display: inline-block; -}*/ diff --git a/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_timestamps.css b/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_timestamps.css deleted file mode 100644 index 9b0d891a..00000000 --- a/culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_timestamps.css +++ /dev/null @@ -1,51 +0,0 @@ -@CHARSET "UTF-8"; - -/* dates */ - -table.date-control-timestamps-table { - width: auto; -} - -.date-control-timestamps-table .container-inline-date .date-padding { - padding: 0; - float: none; -} - -.date-control-timestamps-table .ui-icon { - display: inline-block; -} - - - -/*.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; -}*/ diff --git a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module index ad704794..22ea670e 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module @@ -6,6 +6,8 @@ */ require_once 'form/date_control.inc'; +require_once 'form/opening_times.inc'; +require_once 'form/period.inc'; require_once 'form/timestamps.inc'; /** @@ -28,6 +30,21 @@ function culturefeed_date_control_ajax_callback() { } +/** + * 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. * @@ -72,6 +89,19 @@ function culturefeed_date_control_element_info() { '#tree' => TRUE, '#value_callback' => 'culturefeed_date_control_date_control_value_callback', ), + 'culturefeed_date_control_opening_times' => array( + '#input' => TRUE, + '#process' => array('culturefeed_date_control_opening_times_process', 'ajax_process_form'), + '#tree' => TRUE, + ), + 'culturefeed_date_control_period' => array( + '#element_validate' => array('culturefeed_date_control_period_validate'), + '#pre_render' => array('culturefeed_date_control_period_pre_render'), + '#input' => TRUE, + '#process' => array('culturefeed_date_control_period_process', 'ajax_process_form'), + '#theme' => 'culturefeed_date_control_period_table', + '#tree' => TRUE, + ), 'culturefeed_date_control_timestamps' => array( '#cell_count' => 4, '#input' => TRUE, @@ -117,12 +147,16 @@ function culturefeed_date_control_menu() { */ 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_timestamps_table' => array( - 'file' => 'theme.inc', - 'path' => drupal_get_path('module', 'culturefeed_date_control') . '/theme', - 'render element' => 'form', - ), + '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 index 48046736..cb72b9e6 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc @@ -33,6 +33,17 @@ function culturefeed_date_control_date_control_process(array $element, array &$f '#type' => 'culturefeed_date_control_timestamps', ); + // Period. + $element['date_control']['period'] = array( + '#type' => 'culturefeed_date_control_period', + ); + + // Opening times. + $element['date_control']['opening_times'] = array( + '#type' => 'culturefeed_date_control_opening_times', + '#allowed_days' => $element['#allowed_days'], + ); + $element['#attached'] = array( 'css' => array( drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control.css', 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..059a2ecc --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc @@ -0,0 +1,80 @@ + t('mon'), + 'tuesday' => t('tue'), + 'wednesday' => t('wed'), + 'thursday' => t('thu'), + 'friday' => t('fri'), + 'saturday' => t('sat'), + 'sunday' => t('sun'), + ); + + $element['all_day'] = array( + '#options' => array('1' => t('Yes'), '0' => t('No')), + '#title' => t('Open all day ?'), + '#type' => 'radios', + '#default_value' => 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( + '#type' => 'textfield', + '#size' => 12, + '#default_value' => '', + '#description' => t('Format') . ': 12:00', + ); + + $element['days'][$day][0]['open_till'] = array( + '#type' => 'textfield', + '#size' => 12, + '#default_value' => '', + '#description' => t('Format') . ': 12:00', + ); + + } + + $element['#attached'] = array( + 'js' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/js/culturefeed_date_control_opening_times.js', + ), + ); + + return $element; + +} 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..8c9a1c61 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc @@ -0,0 +1,132 @@ +"; + $element['#suffix'] = ""; + + $ajax_button = array( + '#access' => TRUE, + '#ajax' => array( + 'effect' => 'none', + 'path' => 'culturefeed_elements/ajax/' . implode('/', $element['#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', + ); + + $element['start_date'] = array( + '#date_format' => 'd-m-Y', + '#date_label_position' => 'none', + '#default_value' => '', + '#icon' => TRUE, + '#title' => t('Start date'), + '#type' => 'date_popup', + ); + + $element['add_end'] = $ajax_button + array( + '#value' => t('+ add end date'), + '#name' => 'add_end', + ); + + $element['end_date'] = array( + '#access' => TRUE, + '#date_format' => 'd-m-Y', + '#date_label_position' => 'none', + '#default_value' => '', + '#icon' => TRUE, + '#title' => t('End date'), + '#type' => 'date_popup', + ); + + $element['remove_end'] = $ajax_button + array( + '#value' => t('- remove end date'), + '#name' => 'remove_end', + ); + + 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'] : ''; + + if ($triggering_element && culturefeed_date_control_check_trigger_element($triggering_element, $element)) { + + $dates = $element['#value']; + $triggering_parent = array_pop($triggering_element['#parents']); + + switch ($triggering_parent) { + + case 'add_end': + $dates['end_date'] = ''; + break; + + case 'remove_end': + unset($dates['end_date']); + break; + + } + + drupal_array_set_nested_value($form_state['values'], $triggering_element['#parents'], $dates); + drupal_array_set_nested_value($form_state['input'], $triggering_element['#parents'], $dates); + + } + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc index 7353a63a..b3980d3d 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -14,7 +14,7 @@ * @return array $element * The element. */ -function culturefeed_date_control_timestamps_pre_render(array &$element) { +function culturefeed_date_control_timestamps_pre_render(array $element) { $timestamps = $element['#value']['stamps']; @@ -40,7 +40,7 @@ function culturefeed_date_control_timestamps_pre_render(array &$element) { } /** - * Sets the date control timestamps form elements. + * Sets the culturefeed date control timestamps form elements. * * @param array $element * The element. @@ -69,7 +69,6 @@ function culturefeed_date_control_timestamps_process(array $element, array &$for // '#limit_validation_errors' => array($element['#parents']), '#submit' => array('culturefeed_date_control_date_control_submit'), '#type' => 'submit', - ); // Get the timestamps. @@ -85,29 +84,29 @@ function culturefeed_date_control_timestamps_process(array $element, array &$for ); $element['stamps'][$key]['date'] = array( - '#type' => 'date_popup', - '#default_value' => '', - '#title' => t('Date'), - '#date_label_position' => 'none', '#date_format' => 'd-m-Y', + '#date_label_position' => 'none', + '#default_value' => '', '#icon' => TRUE, + '#title' => t('Date'), + '#type' => 'date_popup', ); $element['stamps'][$key]['start_time'] = array( - '#type' => 'date_select', - '#default_value' => '', - '#title' => '', '#date_format' => 'H:i', '#date_increment' => 30, + '#default_value' => '', + '#title' => '', + '#type' => 'date_select', ); $element['stamps'][$key]['end_time'] = array( - '#type' => 'date_select', - '#default_value' => '', - '#title' => '', + '#access' => TRUE, '#date_format' => 'H:i', '#date_increment' => 30, - '#access' => TRUE, + '#default_value' => '', + '#title' => '', + '#type' => 'date_select', ); $element['stamps'][$key]['remove_end'] = $ajax_button + array( @@ -129,18 +128,12 @@ function culturefeed_date_control_timestamps_process(array $element, array &$for '#value' => t('+ add date'), ); - $element['#attached'] = array( - 'css' => array( - drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control_timestamps.css', - ), - ); - return $element; } /** - * Validate and alter the timestamp form values. + * Validate and alter the culturefeed date control timestamps form values. * * @param array $element * The element. @@ -151,7 +144,7 @@ function culturefeed_date_control_timestamps_validate(array $element, array &$fo $triggering_element = (isset($form_state['triggering_element'])) ? $form_state['triggering_element'] : ''; - if ($triggering_element) { + if ($triggering_element && culturefeed_date_control_check_trigger_element($triggering_element, $element)) { $timestamps = $element['#value']['stamps']; $triggering_parent = array_pop($triggering_element['#parents']); @@ -185,7 +178,7 @@ function culturefeed_date_control_timestamps_validate(array $element, array &$fo } /** - * Value callback for the date control element. + * Value callback for the culturefeed date control timestamps element. * * @param array $element * The element. 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/theme/theme.inc b/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc index 3f5c8d23..d62dc414 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc @@ -5,6 +5,84 @@ * Contains the theming functions for the culturefeed date control. */ +/** + * 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( + 'header' => $header, + 'rows' => array(), + 'attributes' => array('class' => 'date-control-opening-times-table'), + ); + + 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. * @@ -18,7 +96,12 @@ function theme_culturefeed_date_control_timestamps_table(array &$variables) { $form = $variables['form']; - $table = array('rows' => array(), 'attributes' => array('class' => 'date-control-timestamps-table')); + $table = array( + 'rows' => array(), + 'attributes' => array( + 'class' => array('date-control-table', 'date-control-timestamps-table'), + ), + ); foreach (element_children($form['stamps']) as $element) { diff --git a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc index 12356194..7cdbc75a 100644 --- a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc +++ b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc @@ -676,6 +676,7 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { 'timestamps' => $timestamps, 'permanent' => $weekscheme, ), + '#allowed_days' => CultureFeed_Cdb_Data_Calendar_SchemeDay::$allowedDays, ); // Extra. 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. */ From f0ab86d5d238f35f423e90f58064c89bccb645fc Mon Sep 17 00:00:00 2001 From: zuuperman Date: Tue, 2 Dec 2014 15:00:38 +0100 Subject: [PATCH 46/67] Also fix the delete link --- culturefeed_search_ui/theme/theme.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/culturefeed_search_ui/theme/theme.inc b/culturefeed_search_ui/theme/theme.inc index 82dd0fa8..79bb64af 100644 --- a/culturefeed_search_ui/theme/theme.inc +++ b/culturefeed_search_ui/theme/theme.inc @@ -380,6 +380,19 @@ function culturefeed_search_ui_preprocess_culturefeed_search_facet_item(&$variab // Every filter will reset the current facet. // Remove this facet from URL, URL will function as removal URL. unset($query['facet'][$facet_key]); + + if (isset($query['facet']['category_id'])) { + $key = array_search($facet_item->getValue(), $query['facet']['category_id']); + if ($key !== FALSE) { + unset($query['facet']['category_id'][$key]); + if (empty($query['facet']['category_id'])) { + unset($query['facet']['category_id']); + } + } + + } + + if ($is_age_facet) { unset($query['min_age']); } From 5cb56497ba966fa385e3adac76f9663f306bf6f3 Mon Sep 17 00:00:00 2001 From: zuuperman Date: Tue, 2 Dec 2014 15:35:34 +0100 Subject: [PATCH 47/67] Also support for depth settings --- culturefeed_search_ui/theme/theme.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/culturefeed_search_ui/theme/theme.inc b/culturefeed_search_ui/theme/theme.inc index 79bb64af..1cd8e9ee 100644 --- a/culturefeed_search_ui/theme/theme.inc +++ b/culturefeed_search_ui/theme/theme.inc @@ -64,7 +64,15 @@ function theme_culturefeed_search_facet_with_depth_settings($variables) { 'facet' => array() ); - $active_options = isset($query['facet'][$facet_key]) ? $query['facet'][$facet_key] : array(); + if (isset($query['facet'][$facet_key])) { + $active_options = $query['facet'][$facet_key]; + } + elseif (isset($query['facet']['category_id'])) { + $active_options = $query['facet']['category_id']; + } + else { + $active_options = array(); + } $facet_links = _culturefeed_search_ui_get_nested_facet_links($facet_items, $facet_key, $path, $query, $active_options, $variables['sort'], $variables['show_subitems']); $facet_links = $facet_links['facet_links']; From 836f149ea35cdb24ae308e775b7f8bac4e55e80c Mon Sep 17 00:00:00 2001 From: HnLn Date: Wed, 3 Dec 2014 12:20:11 +0100 Subject: [PATCH 48/67] MSS-94 date control element --- .../culturefeed_date_control/README.txt | 12 + ...culturefeed_date_control_opening_times.css | 7 + .../culturefeed_date_control.module | 22 +- .../form/date_control.inc | 273 ++++++++++++++++-- .../culturefeed_date_control/form/hybrid.inc | 163 +++++++++++ .../form/opening_times.inc | 3 + .../culturefeed_date_control/form/period.inc | 27 +- .../form/timestamps.inc | 43 ++- .../culturefeed_date_control/theme/theme.inc | 62 +++- .../includes/culturefeed_entry_ui.pages.inc | 8 +- 10 files changed, 559 insertions(+), 61 deletions(-) create mode 100644 culturefeed_entry_ui/culturefeed_date_control/README.txt create mode 100644 culturefeed_entry_ui/culturefeed_date_control/css/culturefeed_date_control_opening_times.css create mode 100644 culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc 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..89b81bf7 --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/README.txt @@ -0,0 +1,12 @@ +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) +* permanent (including opening hours). + +To provide sufficient 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. \ No newline at end of file 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.module b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module index 22ea670e..89bbfad7 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module @@ -6,6 +6,7 @@ */ require_once 'form/date_control.inc'; +require_once 'form/hybrid.inc'; require_once 'form/opening_times.inc'; require_once 'form/period.inc'; require_once 'form/timestamps.inc'; @@ -25,7 +26,6 @@ function culturefeed_date_control_ajax_callback() { '#type' => 'ajax', '#commands' => ajax_prepare_response($output), ); - $result['#commands'] = array_merge($commands, $result['#commands']); return $result; } @@ -72,23 +72,30 @@ function culturefeed_date_control_element_date_popup_after_build(array $element, * * - To ensure all buttons remain registered in the form, visibility is set * through access in a pre render function. - * - A custom value callback is used so the pre render function has all the data - * needed. + * - 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_submit() * @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, - '#pre_render' => array('culturefeed_date_control_pre_render_element'), + '#pre_render' => array('culturefeed_date_control_date_control_pre_render'), '#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, + ), 'culturefeed_date_control_opening_times' => array( '#input' => TRUE, '#process' => array('culturefeed_date_control_opening_times_process', 'ajax_process_form'), @@ -96,16 +103,16 @@ function culturefeed_date_control_element_info() { ), 'culturefeed_date_control_period' => array( '#element_validate' => array('culturefeed_date_control_period_validate'), - '#pre_render' => array('culturefeed_date_control_period_pre_render'), '#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, ), 'culturefeed_date_control_timestamps' => array( '#cell_count' => 4, - '#input' => TRUE, '#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', @@ -154,6 +161,7 @@ function culturefeed_date_control_theme() { ); 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 index cb72b9e6..b4d91d2f 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc @@ -5,6 +5,57 @@ * Contains the functions for the culturefeed date control form element. */ +/** + * Pre renders the culturefeed date control. + * + * @param array $element + * The element. + * + * @return array $element + * The element. + */ +function culturefeed_date_control_date_control_pre_render(array $element) { + + $value = $element['#value']; + + if ($value['date_control']['type'] == 'hybrid') { + + $element['date_control']['opening_times']['#access'] = FALSE; + $element['date_control']['period']['#access'] = FALSE; + $element['date_control']['permanent']['#access'] = FALSE; + $element['date_control']['timestamps']['#access'] = FALSE; + + } + + elseif ($value['date_control']['type'] == 'period') { + + $element['date_control']['hybrid']['#access'] = FALSE; + $element['date_control']['permanent']['#access'] = FALSE; + $element['date_control']['timestamps']['#access'] = FALSE; + + } + + elseif ($value['date_control']['type'] == 'permanent') { + + $element['date_control']['hybrid']['#access'] = FALSE; + $element['date_control']['period']['#access'] = FALSE; + $element['date_control']['timestamps']['#access'] = FALSE; + + } + + elseif ($value['date_control']['type'] == 'timestamps') { + + $element['date_control']['hybrid']['#access'] = FALSE; + $element['date_control']['opening_times']['#access'] = FALSE; + $element['date_control']['period']['#access'] = FALSE; + $element['date_control']['permanent']['#access'] = FALSE; + + } + + return $element; + +} + /** * Returns the culturefeed date control element. * @@ -28,20 +79,53 @@ function culturefeed_date_control_date_control_process(array $element, array &$f '#title' => (isset($element['#title'])) ? $element['#title'] : t('Dates'), ); + // Type. + $element['date_control']['type'] = array( + '#type' => 'hidden', + '#value' => $element['#value']['date_control']['type'], + ); + + // Hybrid. + $element['date_control']['hybrid'] = array( + '#access' => TRUE, + '#date_control' => $element, + '#type' => 'culturefeed_date_control_hybrid', + ); + // Timestamps. $element['date_control']['timestamps'] = array( + '#access' => TRUE, + '#date_control' => $element, '#type' => 'culturefeed_date_control_timestamps', ); // Period. $element['date_control']['period'] = array( + '#access' => TRUE, + '#date_control' => $element, '#type' => 'culturefeed_date_control_period', ); + // Permanent. + $element['date_control']['permanent'] = array( + '#access' => TRUE, + '#ajax' => array( + 'effect' => 'none', + 'path' => 'culturefeed_elements/ajax/' . implode('/', $element['#array_parents']), + 'progress' => array('type' => 'throbber'), + 'wrapper' => $element['#id'] . '-ajax-wrapper', + ), + '#value' => isset($element['#value']['date_control']['permanent']) ? $element['#value']['date_control']['permanent'] : 0, + '#title' => t('Permanent'), + '#type' => 'checkbox', + ); + // Opening times. $element['date_control']['opening_times'] = array( - '#type' => 'culturefeed_date_control_opening_times', + '#access' => TRUE, '#allowed_days' => $element['#allowed_days'], + '#date_control' => $element, + '#type' => 'culturefeed_date_control_opening_times', ); $element['#attached'] = array( @@ -51,6 +135,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f ); return $element; + } /** @@ -67,6 +152,132 @@ function culturefeed_date_control_date_control_submit(array $form, array &$form_ } +/** + * 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['values'], $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' || $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['values'], $element['#parents'], $date_control); + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $date_control); + +} + /** * Value callback for the date control element. * @@ -85,29 +296,49 @@ function culturefeed_date_control_date_control_value_callback(array &$element, $ if ($input) { return $input; } + else { -} + // Default value or an empty value. + if (!isset($element['#default_value'])) { -/** - * Returns the date control type based on the values. - * - * @param array $values - * The element values. - * - * @return string - * The type. - */ -function culturefeed_date_control_get_type(array $values) { + return array( + 'date_control' => array( + 'type' => 'hybrid', + 'hybrid' => array(), + 'opening_times' => array(), + 'period' => array(), + 'timestamps' => array(), + ), + ); + + } + + else { + + $default_value = $element['#default_value']; + + if (count($default_value['timestamps'])) { + $stamps = $default_value['timestamps']; + $default_value['timestamps'] = array('stamps' => $stamps); + $default_value['type'] = 'timestamps'; + } + + if ($default_value['period']['start']) { + $default_value['type'] = 'period'; + } + + if ($default_value['permanent']) { + $default_value['type'] = 'permanent'; + } + + else { + $default_value['type'] = 'hybrid'; + } + + return array('date_control' => $default_value); + + } - if (isset($values['period']['start']) && $values['period']['end']) { - return 'period'; - } - if (isset($values['permanent'])) { - return 'permanent'; - } - else { - // Default setting. - return 'timestamps'; } } 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..2a04ecbf --- /dev/null +++ b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc @@ -0,0 +1,163 @@ +"; + $element['#suffix'] = ""; + + if (isset($element['#date_control'])) { + $element_id = $element['#date_control']['#id']; + $array_parents = $element['#date_control']['#array_parents']; + } + + $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', + ); + + $element['start_date'] = array( + '#date_format' => 'd-m-Y', + '#date_label_position' => 'none', + '#default_value' => '', + '#icon' => TRUE, + '#title' => t('Date'), + '#type' => 'date_popup', + ); + + $element['start_time'] = array( + '#date_format' => 'H:i', + '#date_increment' => 30, + '#default_value' => '', + '#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, + '#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 acctualy + // permanent. + $element['permanent'] = array( + '#ajax' => $ajax_settings, + '#title' => t('Permanent'), + '#type' => 'checkbox', + '#value' => 0, + ); + + 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['values'], $element['#parents'], $hybrid); + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $hybrid); + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc index 059a2ecc..449915e8 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc @@ -70,6 +70,9 @@ function culturefeed_date_control_opening_times_process(array $element, array &$ } $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', ), diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc index 8c9a1c61..2cce2bd9 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc @@ -45,16 +45,24 @@ function culturefeed_date_control_period_pre_render(array $element) { */ function culturefeed_date_control_period_process(array $element, array &$form_state, array $form) { - $element['#prefix'] = "
      "; + $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('/', $element['#array_parents']), + 'path' => 'culturefeed_elements/ajax/' . implode('/', $array_parents), 'progress' => array('type' => 'throbber'), - 'wrapper' => $element['#id'] . '-ajax-wrapper', + 'wrapper' => $element_id . '-ajax-wrapper', ), '#attributes' => array('class' => array('add-more-link btn-link')), // '#limit_validation_errors' => array($element['#parents']), @@ -106,11 +114,10 @@ function culturefeed_date_control_period_process(array $element, array &$form_st 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 ($triggering_element && culturefeed_date_control_check_trigger_element($triggering_element, $element)) { - - $dates = $element['#value']; - $triggering_parent = array_pop($triggering_element['#parents']); + if (culturefeed_date_control_check_trigger_element($triggering_element, $element)) { switch ($triggering_parent) { @@ -124,9 +131,9 @@ function culturefeed_date_control_period_validate(array $element, array &$form_s } - drupal_array_set_nested_value($form_state['values'], $triggering_element['#parents'], $dates); - drupal_array_set_nested_value($form_state['input'], $triggering_element['#parents'], $dates); - } + drupal_array_set_nested_value($form_state['values'], $element['#parents'], $dates, TRUE); + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $dates, TRUE); + } diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc index b3980d3d..6307ab5c 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -54,16 +54,24 @@ function culturefeed_date_control_timestamps_pre_render(array $element) { */ function culturefeed_date_control_timestamps_process(array $element, array &$form_state, array $form) { - $element['#prefix'] = "
      "; + $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('/', $element['#array_parents']), + 'path' => 'culturefeed_elements/ajax/' . implode('/', $array_parents), 'progress' => array('type' => 'throbber'), - 'wrapper' => $element['#id'] . '-ajax-wrapper', + 'wrapper' => $element_id . '-ajax-wrapper', ), '#attributes' => array('class' => array('add-more-link btn-link')), // '#limit_validation_errors' => array($element['#parents']), @@ -143,38 +151,37 @@ function culturefeed_date_control_timestamps_process(array $element, array &$for 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 ($triggering_element && culturefeed_date_control_check_trigger_element($triggering_element, $element)) { - - $timestamps = $element['#value']['stamps']; - $triggering_parent = array_pop($triggering_element['#parents']); + if (culturefeed_date_control_check_trigger_element($triggering_element, $element)) { switch ($triggering_parent) { case 'timestamps_add_stamp': - $timestamps[] = array('date' => ''); + $timestamps['stamps'][] = array('date' => ''); $triggering_element['#parents'][] = 'stamps'; break; case 'remove_stamp': - array_splice($timestamps, array_pop($triggering_element['#parents']), 1); + array_splice($timestamps['stamps'], array_pop($triggering_element['#parents']), 1); break; case 'add_end': - $timestamps[array_pop($triggering_element['#parents'])]['end_time'] = ''; + $timestamps['stamps'][array_pop($triggering_element['#parents'])]['end_time'] = ''; break; case 'remove_end': - unset($timestamps[array_pop($triggering_element['#parents'])]['end_time']); + unset($timestamps['stamps'][array_pop($triggering_element['#parents'])]['end_time']); break; } - drupal_array_set_nested_value($form_state['values'], $triggering_element['#parents'], $timestamps); - drupal_array_set_nested_value($form_state['input'], $triggering_element['#parents'], $timestamps); - } + drupal_array_set_nested_value($form_state['values'], $element['#parents'], $timestamps, TRUE); + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $timestamps, TRUE); + } /** @@ -196,8 +203,14 @@ function culturefeed_date_control_timestamps_value_callback(array &$element, $in return $input; } else { + // Default value or an empty stamp. - return array('stamps' => array(array('date' => ''))); + if (!isset($element['#default_value'])) { + return array('stamps' => array(array('date' => ''))); + } + else { + return array('stamps' => $element['#default_value']); + } } } diff --git a/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc b/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc index d62dc414..2e7ac91d 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/theme/theme.inc @@ -5,6 +5,49 @@ * Contains the theming functions for the culturefeed date control. */ +/** + * Theme the hybrid table. + * + * @param array $variables + * The variables. + * + * @return string + * The output. + */ +function theme_culturefeed_date_control_hybrid_table(array &$variables) { + + $form = $variables['form']; + + $table = array( + 'attributes' => 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. * @@ -20,9 +63,14 @@ function theme_culturefeed_date_control_opening_times_table(array &$variables) { $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(), - 'attributes' => array('class' => 'date-control-opening-times-table'), ); foreach (element_children($form) as $element) { @@ -61,7 +109,10 @@ function theme_culturefeed_date_control_period_table(array &$variables) { $table = array( 'attributes' => array( - 'class' => array('date-control-table', 'date-control-period-table'), + 'class' => array( + 'date-control-table', + 'date-control-period-table', + ), ), 'rows' => array(), ); @@ -97,10 +148,13 @@ function theme_culturefeed_date_control_timestamps_table(array &$variables) { $form = $variables['form']; $table = array( - 'rows' => array(), 'attributes' => array( - 'class' => array('date-control-table', 'date-control-timestamps-table'), + 'class' => array( + 'date-control-table', + 'date-control-timestamps-table', + ), ), + 'rows' => array(), ); foreach (element_children($form['stamps']) as $element) { diff --git a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc index 7cdbc75a..05f9534e 100644 --- a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc +++ b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc @@ -31,6 +31,7 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { $timestamps = array(); $period_start = ''; $period_end = ''; + $permanent = FALSE; $weekscheme = NULL; $age = ''; $age_category = 'everyone'; @@ -128,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; @@ -673,8 +672,9 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { 'start' => $period_start, 'end' => $period_end, ), + 'permanent' => $permanent, 'timestamps' => $timestamps, - 'permanent' => $weekscheme, + 'weekscheme' => $weekscheme, ), '#allowed_days' => CultureFeed_Cdb_Data_Calendar_SchemeDay::$allowedDays, ); From 6cd70db4fde35444b01048013b69517343a6eb9e Mon Sep 17 00:00:00 2001 From: zuuperman Date: Wed, 3 Dec 2014 18:59:10 +0100 Subject: [PATCH 49/67] Camelcase sensitive --- culturefeed_search_ui/culturefeed_search_ui.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/culturefeed_search_ui/culturefeed_search_ui.module b/culturefeed_search_ui/culturefeed_search_ui.module index 82e6775b..170dc737 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(). From cc42b4e028f532289d5ee5d00ccba5f72fe4e833 Mon Sep 17 00:00:00 2001 From: HnLn Date: Thu, 4 Dec 2014 10:32:24 +0100 Subject: [PATCH 50/67] MSS-94 validation and submit --- .../culturefeed_date_control/README.txt | 11 +- .../culturefeed_date_control.module | 1 + .../form/date_control.inc | 12 +- .../culturefeed_date_control/form/hybrid.inc | 4 + .../form/opening_times.inc | 33 +++- .../culturefeed_date_control/form/period.inc | 34 +++- .../form/timestamps.inc | 102 +++++----- .../includes/culturefeed_entry_ui.pages.inc | 178 ++++++++---------- 8 files changed, 212 insertions(+), 163 deletions(-) diff --git a/culturefeed_entry_ui/culturefeed_date_control/README.txt b/culturefeed_entry_ui/culturefeed_date_control/README.txt index 89b81bf7..b0e918e6 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/README.txt +++ b/culturefeed_entry_ui/culturefeed_date_control/README.txt @@ -9,4 +9,13 @@ To provide sufficient 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. \ No newline at end of file +initial input. + +Developer info: +* Data handling happens in element validate functions. The use the date_popup + element. Date fields taken from element aren't flattened. To ensure + flattened data for the form validation, the trigger element is checked and + form state instead of element values are set. +* To ensure default values don't creep back in the elements after user + operations, value callbacks reset the default value. Default values are set + in the process functions and only if the form is initialised. \ No newline at end of file diff --git a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module index 89bbfad7..f1174ba7 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module @@ -108,6 +108,7 @@ function culturefeed_date_control_element_info() { '#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, diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc index b4d91d2f..2c345b30 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc @@ -96,6 +96,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f $element['date_control']['timestamps'] = array( '#access' => TRUE, '#date_control' => $element, + '#default_value' => $element['#default_value']['timestamps'], '#type' => 'culturefeed_date_control_timestamps', ); @@ -103,6 +104,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f $element['date_control']['period'] = array( '#access' => TRUE, '#date_control' => $element, + '#default_value' => $element['#default_value']['period'], '#type' => 'culturefeed_date_control_period', ); @@ -125,6 +127,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f '#access' => TRUE, '#allowed_days' => $element['#allowed_days'], '#date_control' => $element, + '#default_value' => $element['#default_value']['opening_times'], '#type' => 'culturefeed_date_control_opening_times', ); @@ -253,7 +256,10 @@ function culturefeed_date_control_date_control_validate(array $element, array &$ // Timestamps. if ($date_control['type'] == 'timestamps') { - if (($triggering_parent == 'remove_stamp' || $triggering_parent == 'remove_end') && count($date_control['timestamps']['stamps']) == 1) { + 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' => ''); @@ -323,11 +329,11 @@ function culturefeed_date_control_date_control_value_callback(array &$element, $ $default_value['type'] = 'timestamps'; } - if ($default_value['period']['start']) { + elseif ($default_value['period']['start_date']) { $default_value['type'] = 'period'; } - if ($default_value['permanent']) { + elseif ($default_value['permanent']) { $default_value['type'] = 'permanent'; } diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc index 2a04ecbf..c76fb4be 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc @@ -157,6 +157,10 @@ function culturefeed_date_control_hybrid_validate(array $element, array &$form_s } + elseif (!isset($element['#date_control']) || !culturefeed_date_control_check_trigger_element($triggering_element, $element['#date_control'])) { + $hybrid = drupal_array_get_nested_value($form_state['values'], $element['#parents']); + } + drupal_array_set_nested_value($form_state['values'], $element['#parents'], $hybrid); drupal_array_set_nested_value($form_state['input'], $element['#parents'], $hybrid); diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc index 449915e8..0ad61ab5 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc @@ -30,11 +30,15 @@ function culturefeed_date_control_opening_times_process(array $element, array &$ 'sunday' => t('sun'), ); + /* @var CultureFeed_Cdb_Data_Calendar_Weekscheme $week_scheme */ + // @todo This should be in the entry_ui module. + $week_scheme = !count($form_state['input']) && isset($element['#default_value']['days']) ? $element['#default_value']['days'] : ''; + $element['all_day'] = array( '#options' => array('1' => t('Yes'), '0' => t('No')), '#title' => t('Open all day ?'), '#type' => 'radios', - '#default_value' => 1, + '#default_value' => $week_scheme ? 0 : 1, ); $element['days'] = array( @@ -47,6 +51,21 @@ function culturefeed_date_control_opening_times_process(array $element, array &$ foreach ($element['#allowed_days'] as $day) { + $default_value = ''; + if ($week_scheme) { + + $day_scheme = $week_scheme->getDay($day); + if ($day_scheme->isOpen()) { + $opening_times = $day_scheme->getOpeningTimes(); + // Strip the seconds. + $default_value = array( + 'open_from' => substr($opening_times[0]->getOpenFrom(), 0, 5), + 'open_till' => substr($opening_times[0]->getOpenTill(), 0, 5), + ); + } + + } + $element['days'][$day] = array( '#tree' => TRUE, '#type' => 'fieldset', @@ -54,17 +73,17 @@ function culturefeed_date_control_opening_times_process(array $element, array &$ ); $element['days'][$day][0]['open_from'] = array( - '#type' => 'textfield', - '#size' => 12, - '#default_value' => '', + '#default_value' => $default_value && isset($default_value['open_from']) ? $default_value['open_from'] : '', '#description' => t('Format') . ': 12:00', + '#size' => 12, + '#type' => 'textfield', ); $element['days'][$day][0]['open_till'] = array( - '#type' => 'textfield', - '#size' => 12, - '#default_value' => '', + '#default_value' => $default_value && isset($default_value['open_till']) ? $default_value['open_till'] : '', '#description' => t('Format') . ': 12:00', + '#size' => 12, + '#type' => 'textfield', ); } diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc index 2cce2bd9..72686a3c 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc @@ -70,10 +70,12 @@ function culturefeed_date_control_period_process(array $element, array &$form_st '#type' => 'submit', ); + $default_value = !count($form_state['input']) && isset($element['#default_value']) ? $element['#default_value'] : array(); + $element['start_date'] = array( '#date_format' => 'd-m-Y', '#date_label_position' => 'none', - '#default_value' => '', + '#default_value' => isset($default_value['start_date']) ? $default_value['start_date'] : '', '#icon' => TRUE, '#title' => t('Start date'), '#type' => 'date_popup', @@ -88,7 +90,7 @@ function culturefeed_date_control_period_process(array $element, array &$form_st '#access' => TRUE, '#date_format' => 'd-m-Y', '#date_label_position' => 'none', - '#default_value' => '', + '#default_value' => isset($default_value['end_date']) ? $default_value['end_date'] : '', '#icon' => TRUE, '#title' => t('End date'), '#type' => 'date_popup', @@ -133,7 +135,35 @@ function culturefeed_date_control_period_validate(array $element, array &$form_s } + elseif (!isset($element['#date_control']) || !culturefeed_date_control_check_trigger_element($triggering_element, $element['#date_control'])) { + $dates = drupal_array_get_nested_value($form_state['values'], $element['#parents']); + } + drupal_array_set_nested_value($form_state['values'], $element['#parents'], $dates, TRUE); 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 { + return array('start_date' => '', 'end_date' => ''); + } + +} diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc index 6307ab5c..ef11b310 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -84,50 +84,48 @@ function culturefeed_date_control_timestamps_process(array $element, array &$for foreach ($timestamps as $key => $timestamp) { - if ($key !== 'timestamps_add_stamp') { - - $element['stamps'][$key]['remove_stamp'] = $ajax_button + array( - '#value' => t('×'), - '#name' => 'remove_stamp_' . $key, - ); - - $element['stamps'][$key]['date'] = array( - '#date_format' => 'd-m-Y', - '#date_label_position' => 'none', - '#default_value' => '', - '#icon' => TRUE, - '#title' => t('Date'), - '#type' => 'date_popup', - ); - - $element['stamps'][$key]['start_time'] = array( - '#date_format' => 'H:i', - '#date_increment' => 30, - '#default_value' => '', - '#title' => '', - '#type' => 'date_select', - ); - - $element['stamps'][$key]['end_time'] = array( - '#access' => TRUE, - '#date_format' => 'H:i', - '#date_increment' => 30, - '#default_value' => '', - '#title' => '', - '#type' => 'date_select', - ); - - $element['stamps'][$key]['remove_end'] = $ajax_button + array( - '#name' => 'remove_end_' . $key, - '#value' => t('- remove end time'), - ); - - $element['stamps'][$key]['add_end'] = $ajax_button + array( - '#name' => 'add_end_' . $key, - '#value' => t('+ add end time'), - ); - - } + $default_value = !count($form_state['input']) && isset($element['#default_value'][$key]) ? $element['#default_value'][$key] : array(); + + $element['stamps'][$key]['remove_stamp'] = $ajax_button + array( + '#value' => t('×'), + '#name' => 'remove_stamp_' . $key, + ); + + $element['stamps'][$key]['date'] = array( + '#date_format' => 'd-m-Y', + '#date_label_position' => 'none', + '#default_value' => isset($default_value['date']) ? $default_value['date'] : '', + '#icon' => TRUE, + '#title' => t('Date'), + '#type' => 'date_popup', + ); + + $element['stamps'][$key]['start_time'] = array( + '#date_format' => 'H:i', + '#date_increment' => 30, + '#default_value' => isset($default_value['start_time']) ? $default_value['date'] . ' ' . $default_value['start_time'] : '', + '#title' => '', + '#type' => 'date_select', + ); + + $element['stamps'][$key]['end_time'] = array( + '#access' => TRUE, + '#date_format' => 'H:i', + '#date_increment' => 30, + '#default_value' => isset($default_value['end_time']) ? $default_value['date'] . ' ' . $default_value['end_time'] : '', + '#title' => '', + '#type' => 'date_select', + ); + + $element['stamps'][$key]['remove_end'] = $ajax_button + array( + '#name' => 'remove_end_' . $key, + '#value' => t('- remove end time'), + ); + + $element['stamps'][$key]['add_end'] = $ajax_button + array( + '#name' => 'add_end_' . $key, + '#value' => t('+ add end time'), + ); } @@ -160,7 +158,6 @@ function culturefeed_date_control_timestamps_validate(array $element, array &$fo case 'timestamps_add_stamp': $timestamps['stamps'][] = array('date' => ''); - $triggering_element['#parents'][] = 'stamps'; break; case 'remove_stamp': @@ -179,6 +176,10 @@ function culturefeed_date_control_timestamps_validate(array $element, array &$fo } + elseif (!isset($element['#date_control']) || !culturefeed_date_control_check_trigger_element($triggering_element, $element['#date_control'])) { + $timestamps = drupal_array_get_nested_value($form_state['values'], $element['#parents']); + } + drupal_array_set_nested_value($form_state['values'], $element['#parents'], $timestamps, TRUE); drupal_array_set_nested_value($form_state['input'], $element['#parents'], $timestamps, TRUE); @@ -197,20 +198,13 @@ function culturefeed_date_control_timestamps_validate(array $element, array &$fo * @return mixed * The value. */ -function culturefeed_date_control_timestamps_value_callback(array &$element, $input, array $form_state) { +function culturefeed_date_control_timestamps_value_callback(array $element, $input, array $form_state) { if ($input) { return $input; } else { - - // Default value or an empty stamp. - if (!isset($element['#default_value'])) { - return array('stamps' => array(array('date' => ''))); - } - else { - return array('stamps' => $element['#default_value']); - } + return array('stamps' => array(array('date' => ''))); } } diff --git a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc index 05f9534e..3594888c 100644 --- a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc +++ b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc @@ -150,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++; } @@ -669,12 +669,12 @@ function culturefeed_entry_ui_event_form($form, $form_state, $event = NULL) { '#type' => 'culturefeed_date_control', '#default_value' => array( 'period' => array( - 'start' => $period_start, - 'end' => $period_end, + 'start_date' => $period_start, + 'end_date' => $period_end, ), 'permanent' => $permanent, 'timestamps' => $timestamps, - 'weekscheme' => $weekscheme, + 'opening_times' => array('days' => $weekscheme), ), '#allowed_days' => CultureFeed_Cdb_Data_Calendar_SchemeDay::$allowedDays, ); @@ -1557,87 +1557,67 @@ 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']; + // 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')); } - foreach ($values['datetimes'] as $key => $timestamp) { - try { + // 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.')); + } - // Empty start dates are ignored. - if (empty($timestamp['begin']['date'])) { - continue; - } + } - CultureFeed_Cdb_Data_Calendar::validateDate($timestamp['begin']['date']); + // Validate timestamps. + if ($values['when']['date_control']['type'] == 'timestamps') { - 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')); - } - } + $timestamps = $values['when']['date_control']['timestamps']['stamps']; - // 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 { + foreach ($timestamps as $key => $timestamp) { - 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']); - } - } + // 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')); + } - 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.')); - } - } + // 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); @@ -1649,14 +1629,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.')); + } + } } + } + } } @@ -1964,19 +1954,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. @@ -2309,22 +2299,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); } @@ -2338,7 +2324,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); @@ -2347,14 +2333,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; @@ -2372,9 +2358,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); } From ae0145fc3041b90cdfe7b2c5daccbca267419e87 Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Thu, 4 Dec 2014 16:42:01 +0100 Subject: [PATCH 51/67] theme actor summary --- .../theme/culturefeed-actor-summary.tpl.php | 38 +++++++++++++++---- .../culturefeed-production-summary.tpl.php | 2 +- 2 files changed, 31 insertions(+), 9 deletions(-) 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-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-read Date: Fri, 5 Dec 2014 10:52:52 +0100 Subject: [PATCH 52/67] MSS-94 play well with input --- .../culturefeed_date_control/README.txt | 11 +- .../culturefeed_date_control.module | 110 +++++ .../form/date_control.inc | 87 ++-- .../culturefeed_date_control/form/hybrid.inc | 43 +- .../form/opening_times.inc | 96 ++++- .../culturefeed_date_control/form/period.inc | 58 ++- .../form/timestamps.inc | 113 ++++-- .../culturefeed_date_control/old_form.bak | 383 ------------------ 8 files changed, 396 insertions(+), 505 deletions(-) delete mode 100644 culturefeed_entry_ui/culturefeed_date_control/old_form.bak diff --git a/culturefeed_entry_ui/culturefeed_date_control/README.txt b/culturefeed_entry_ui/culturefeed_date_control/README.txt index b0e918e6..7a1255ac 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/README.txt +++ b/culturefeed_entry_ui/culturefeed_date_control/README.txt @@ -3,19 +3,10 @@ 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) -* permanent (including opening hours). +* opening times (including culturefeed weekscheme). To provide sufficient 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. - -Developer info: -* Data handling happens in element validate functions. The use the date_popup - element. Date fields taken from element aren't flattened. To ensure - flattened data for the form validation, the trigger element is checked and - form state instead of element values are set. -* To ensure default values don't creep back in the elements after user - operations, value callbacks reset the default value. Default values are set - in the process functions and only if the form is initialised. \ No newline at end of file diff --git a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module index f1174ba7..abcede12 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module @@ -95,11 +95,13 @@ function culturefeed_date_control_element_info() { '#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'), @@ -132,6 +134,114 @@ function culturefeed_date_control_element_info_alter(&$types) { } } +/** + * 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. + * + * @return array + * The exploded time. + */ +function culturefeed_date_control_explode_time(array $element, $time_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' => $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(). */ diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc index 2c345b30..9eeab424 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc @@ -89,6 +89,10 @@ function culturefeed_date_control_date_control_process(array $element, array &$f $element['date_control']['hybrid'] = array( '#access' => TRUE, '#date_control' => $element, + '#popup_date_format' => 'd-m-Y', + '#popup_date_increment' => 1, + '#select_time_format' => 'H:i', + '#select_time_increment' => 30, '#type' => 'culturefeed_date_control_hybrid', ); @@ -97,6 +101,10 @@ function culturefeed_date_control_date_control_process(array $element, array &$f '#access' => TRUE, '#date_control' => $element, '#default_value' => $element['#default_value']['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', ); @@ -105,6 +113,8 @@ function culturefeed_date_control_date_control_process(array $element, array &$f '#access' => TRUE, '#date_control' => $element, '#default_value' => $element['#default_value']['period'], + '#popup_date_format' => 'd-m-Y', + '#popup_date_increment' => 1, '#type' => 'culturefeed_date_control_period', ); @@ -171,7 +181,7 @@ function culturefeed_date_control_date_control_validate(array $element, array &$ $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['values'], $element['#parents']); + $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)) { @@ -275,12 +285,11 @@ function culturefeed_date_control_date_control_validate(array $element, array &$ } $date_control['type'] = $type; + $element['#parents'][] = 'date_control'; - } + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $date_control); - $element['#parents'][] = 'date_control'; - drupal_array_set_nested_value($form_state['values'], $element['#parents'], $date_control); - drupal_array_set_nested_value($form_state['input'], $element['#parents'], $date_control); + } } @@ -305,43 +314,65 @@ function culturefeed_date_control_date_control_value_callback(array &$element, $ else { // Default value or an empty value. - if (!isset($element['#default_value'])) { + if (isset($element['#default_value'])) { - return array( - 'date_control' => array( - 'type' => 'hybrid', - 'hybrid' => array(), - 'opening_times' => array(), - 'period' => array(), - 'timestamps' => array(), - ), + $date_control = array( + 'hybrid' => array(), + 'opening_times' => array(), + 'period' => array(), + 'timestamps' => array(), ); - } - - else { + // Timestamps. + if (count($element['#default_value']['timestamps'])) { - $default_value = $element['#default_value']; + $date_control['type'] = 'timestamps'; + $date_control['timestamps'] = $element['#default_value']['timestamps']; - if (count($default_value['timestamps'])) { - $stamps = $default_value['timestamps']; - $default_value['timestamps'] = array('stamps' => $stamps); - $default_value['type'] = 'timestamps'; } - elseif ($default_value['period']['start_date']) { - $default_value['type'] = 'period'; + // Period. + elseif ($element['#default_value']['period']['start_date'] && $element['#default_value']['period']['end_date']) { + + $date_control['type'] = 'period'; + $date_control['period'] = $element['#default_value']['period']; + } - elseif ($default_value['permanent']) { - $default_value['type'] = 'permanent'; + // Permanent. + elseif ($element['#default_value']['permanent']) { + + $date_control['type'] = 'permanent'; + $date_control['permanent'] = $element['#default_value']['permanent']; + } else { - $default_value['type'] = 'hybrid'; + $date_control['type'] = 'hybrid'; + } + + // Opening times don't set type, they go with period or permanent. + if ($element['#default_value']['opening_times']) { + + $date_control['opening_times'] = $element['#default_value']['opening_times']; + } - return array('date_control' => $default_value); + return array('date_control' => $date_control); + + } + + else { + + return array( + 'date_control' => array( + 'type' => 'hybrid', + 'hybrid' => array(), + 'opening_times' => array(), + 'period' => array(), + 'timestamps' => array(), + ), + ); } diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc index c76fb4be..2fd7f767 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc @@ -55,6 +55,8 @@ function culturefeed_date_control_hybrid_process(array $element, array &$form_st $array_parents = $element['#date_control']['#array_parents']; } + $hybrid = $element['#value']; + $ajax_settings = array( 'effect' => 'none', 'path' => 'culturefeed_elements/ajax/' . implode('/', $array_parents), @@ -66,24 +68,26 @@ function culturefeed_date_control_hybrid_process(array $element, array &$form_st '#access' => TRUE, '#ajax' => $ajax_settings, '#attributes' => array('class' => array('add-more-link btn-link')), - // '#limit_validation_errors' => array($element['#parents']), + '#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' => '', + '#default_value' => $date, '#icon' => 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( '#date_format' => 'H:i', '#date_increment' => 30, - '#default_value' => '', + '#default_value' => $time, '#title' => '', '#type' => 'date_select', ); @@ -117,7 +121,7 @@ function culturefeed_date_control_hybrid_process(array $element, array &$form_st '#value' => t('+ add date'), ); - // Value will always be 0 as a different element is used when acctualy + // Value will always be 0 as a different element is used when actually // permanent. $element['permanent'] = array( '#ajax' => $ajax_settings, @@ -138,7 +142,7 @@ function culturefeed_date_control_hybrid_process(array $element, array &$form_st * @param array $form_state * The form state. */ -function culturefeed_date_control_hybrid_validate(array $element, array &$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']); @@ -155,13 +159,32 @@ function culturefeed_date_control_hybrid_validate(array $element, array &$form_s } - } + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $hybrid); - elseif (!isset($element['#date_control']) || !culturefeed_date_control_check_trigger_element($triggering_element, $element['#date_control'])) { - $hybrid = drupal_array_get_nested_value($form_state['values'], $element['#parents']); } - drupal_array_set_nested_value($form_state['values'], $element['#parents'], $hybrid); - 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 { + return array('start_date' => '', 'start_time' => ''); + } } diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc index 0ad61ab5..838a2aa1 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc @@ -30,15 +30,13 @@ function culturefeed_date_control_opening_times_process(array $element, array &$ 'sunday' => t('sun'), ); - /* @var CultureFeed_Cdb_Data_Calendar_Weekscheme $week_scheme */ - // @todo This should be in the entry_ui module. - $week_scheme = !count($form_state['input']) && isset($element['#default_value']['days']) ? $element['#default_value']['days'] : ''; + $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' => $week_scheme ? 0 : 1, + '#default_value' => $opening_times['days'] ? 0 : 1, ); $element['days'] = array( @@ -51,21 +49,6 @@ function culturefeed_date_control_opening_times_process(array $element, array &$ foreach ($element['#allowed_days'] as $day) { - $default_value = ''; - if ($week_scheme) { - - $day_scheme = $week_scheme->getDay($day); - if ($day_scheme->isOpen()) { - $opening_times = $day_scheme->getOpeningTimes(); - // Strip the seconds. - $default_value = array( - 'open_from' => substr($opening_times[0]->getOpenFrom(), 0, 5), - 'open_till' => substr($opening_times[0]->getOpenTill(), 0, 5), - ); - } - - } - $element['days'][$day] = array( '#tree' => TRUE, '#type' => 'fieldset', @@ -73,14 +56,14 @@ function culturefeed_date_control_opening_times_process(array $element, array &$ ); $element['days'][$day][0]['open_from'] = array( - '#default_value' => $default_value && isset($default_value['open_from']) ? $default_value['open_from'] : '', + '#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' => $default_value && isset($default_value['open_till']) ? $default_value['open_till'] : '', + '#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', @@ -97,6 +80,77 @@ function culturefeed_date_control_opening_times_process(array $element, array &$ ), ); + 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 index 72686a3c..33d75004 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc @@ -56,6 +56,8 @@ function culturefeed_date_control_period_process(array $element, array &$form_st $array_parents = $element['#date_control']['#array_parents']; } + $period = $element['#value']; + $ajax_button = array( '#access' => TRUE, '#ajax' => array( @@ -65,41 +67,52 @@ function culturefeed_date_control_period_process(array $element, array &$form_st 'wrapper' => $element_id . '-ajax-wrapper', ), '#attributes' => array('class' => array('add-more-link btn-link')), - // '#limit_validation_errors' => array($element['#parents']), + '#limit_validation_errors' => array($element['#parents']), '#submit' => array('culturefeed_date_control_date_control_submit'), '#type' => 'submit', ); - $default_value = !count($form_state['input']) && isset($element['#default_value']) ? $element['#default_value'] : array(); - + $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' => isset($default_value['start_date']) ? $default_value['start_date'] : '', + '#default_value' => $date, '#icon' => TRUE, + '#required' => TRUE, '#title' => t('Start date'), '#type' => 'date_popup', ); - $element['add_end'] = $ajax_button + array( - '#value' => t('+ add end date'), + $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' => isset($default_value['end_date']) ? $default_value['end_date'] : '', + '#default_value' => $date, '#icon' => TRUE, + '#required' => TRUE, '#title' => t('End date'), '#type' => 'date_popup', ); - $element['remove_end'] = $ajax_button + array( - '#value' => t('- remove end date'), + $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; @@ -124,7 +137,7 @@ function culturefeed_date_control_period_validate(array $element, array &$form_s switch ($triggering_parent) { case 'add_end': - $dates['end_date'] = ''; + $dates['end_date'] = array('date' => ''); break; case 'remove_end': @@ -133,15 +146,10 @@ function culturefeed_date_control_period_validate(array $element, array &$form_s } - } + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $dates, TRUE); - elseif (!isset($element['#date_control']) || !culturefeed_date_control_check_trigger_element($triggering_element, $element['#date_control'])) { - $dates = drupal_array_get_nested_value($form_state['values'], $element['#parents']); } - drupal_array_set_nested_value($form_state['values'], $element['#parents'], $dates, TRUE); - drupal_array_set_nested_value($form_state['input'], $element['#parents'], $dates, TRUE); - } /** @@ -163,7 +171,19 @@ function culturefeed_date_control_period_value_callback(array $element, $input, return $input; } else { - return array('start_date' => '', 'end_date' => ''); + + if (isset($element['#default_value'])) { + + $exploded = array(); + $exploded['start_date'] = culturefeed_date_control_explode_date($element, $element['#default_value']['start_date']); + $exploded['end_date'] = culturefeed_date_control_explode_date($element, $element['#default_value']['end_date']); + return $exploded; + + } + else { + return array('start_date' => '', 'end_date' => ''); + } + } } diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc index ef11b310..aa90fd93 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -25,7 +25,11 @@ function culturefeed_date_control_timestamps_pre_render(array $element) { foreach ($timestamps as $key => $timestamp) { - if (isset($timestamps[$key]['end_time'])) { + 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; } @@ -74,65 +78,76 @@ function culturefeed_date_control_timestamps_process(array $element, array &$for 'wrapper' => $element_id . '-ajax-wrapper', ), '#attributes' => array('class' => array('add-more-link btn-link')), - // '#limit_validation_errors' => array($element['#parents']), + '#limit_validation_errors' => array($element['#parents']), '#submit' => array('culturefeed_date_control_date_control_submit'), '#type' => 'submit', ); - // Get the timestamps. - $timestamps = $element['#value']['stamps']; - - foreach ($timestamps as $key => $timestamp) { + $timestamps = $element['#value']; - $default_value = !count($form_state['input']) && isset($element['#default_value'][$key]) ? $element['#default_value'][$key] : array(); + foreach ($timestamps['stamps'] as $key => $timestamp) { - $element['stamps'][$key]['remove_stamp'] = $ajax_button + array( + $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' => 'd-m-Y', + '#date_format' => $element['#popup_date_format'], + '#date_increment' => $element['#popup_date_increment'], '#date_label_position' => 'none', - '#default_value' => isset($default_value['date']) ? $default_value['date'] : '', + '#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( - '#date_format' => 'H:i', - '#date_increment' => 30, - '#default_value' => isset($default_value['start_time']) ? $default_value['date'] . ' ' . $default_value['start_time'] : '', + '#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, - '#date_format' => 'H:i', - '#date_increment' => 30, - '#default_value' => isset($default_value['end_time']) ? $default_value['date'] . ' ' . $default_value['end_time'] : '', + '#date_format' => $element['#select_time_format'], + '#date_increment' => $element['#select_time_increment'], + '#default_value' => $time, '#title' => '', '#type' => 'date_select', ); - $element['stamps'][$key]['remove_end'] = $ajax_button + array( + $element['stamps'][$key]['remove_end'] = array( '#name' => 'remove_end_' . $key, '#value' => t('- remove end time'), - ); + ) + $ajax_button; - $element['stamps'][$key]['add_end'] = $ajax_button + array( + $element['stamps'][$key]['add_end'] = array( '#name' => 'add_end_' . $key, '#value' => t('+ add end time'), - ); + ) + $ajax_button; } - $element['timestamps_add_stamp'] = $ajax_button + array( + $element['timestamps_add_stamp'] = array( '#name' => 'add_stamp', '#value' => t('+ add 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; @@ -157,32 +172,30 @@ function culturefeed_date_control_timestamps_validate(array $element, array &$fo switch ($triggering_parent) { case 'timestamps_add_stamp': - $timestamps['stamps'][] = array('date' => ''); + $timestamps['stamps'][] = array('date' => array('date' => '')); break; case 'remove_stamp': - array_splice($timestamps['stamps'], array_pop($triggering_element['#parents']), 1); + $index = array_pop($triggering_element['#parents']); + array_splice($timestamps['stamps'], $index, 1); break; case 'add_end': - $timestamps['stamps'][array_pop($triggering_element['#parents'])]['end_time'] = ''; + $index = array_pop($triggering_element['#parents']); + $timestamps['stamps'][$index]['end_time'] = array('hour' => '', 'minute' => ''); break; case 'remove_end': - unset($timestamps['stamps'][array_pop($triggering_element['#parents'])]['end_time']); + $index = array_pop($triggering_element['#parents']); + unset($timestamps['stamps'][$index]['end_time']); break; } - } + drupal_array_set_nested_value($form_state['input'], $element['#parents'], $timestamps); - elseif (!isset($element['#date_control']) || !culturefeed_date_control_check_trigger_element($triggering_element, $element['#date_control'])) { - $timestamps = drupal_array_get_nested_value($form_state['values'], $element['#parents']); } - drupal_array_set_nested_value($form_state['values'], $element['#parents'], $timestamps, TRUE); - drupal_array_set_nested_value($form_state['input'], $element['#parents'], $timestamps, TRUE); - } /** @@ -204,7 +217,39 @@ function culturefeed_date_control_timestamps_value_callback(array $element, $inp return $input; } else { - return array('stamps' => array(array('date' => ''))); + + if (isset($element['#default_value'])) { + + foreach ($element['#default_value'] as &$stamp) { + + $exploded = array(); + $exploded['date'] = culturefeed_date_control_explode_date($element, $stamp['date']); + if (isset($stamp['start_time'])) { + $exploded['start_time'] = culturefeed_date_control_explode_time($element, $stamp['date'] . ' ' . $stamp['start_time']); + } + if (isset($stamp['end_time'])) { + $exploded['end_time'] = culturefeed_date_control_explode_time($element, $stamp['date'] . ' ' . $stamp['end_time']); + } + $stamp = $exploded; + + } + + return array( + 'stamps' => $element['#default_value'], + ); + + } + + else { + + return array( + 'stamps' => array( + array('date' => '', 'start_time' => NULL, 'end_time' => NULL), + ), + ); + + } + } } diff --git a/culturefeed_entry_ui/culturefeed_date_control/old_form.bak b/culturefeed_entry_ui/culturefeed_date_control/old_form.bak deleted file mode 100644 index 7ff627f7..00000000 --- a/culturefeed_entry_ui/culturefeed_date_control/old_form.bak +++ /dev/null @@ -1,383 +0,0 @@ - 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 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), - ), - ), - ), - ); - - 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')), - ), - ); - - 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 '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; - - - $day_labels = array( - 'monday' => t('mon'), - 'tuesday' => t('tue'), - 'wednesday' => t('wed'), - 'thursday' => t('thu'), - 'friday' => t('fri'), - 'saturday' => t('sat'), - 'sunday' => t('sun'), - ); - - - - */ - } - -} \ No newline at end of file From 5c3c3bfd3dbcc2176ccb9be085187fac4665ea37 Mon Sep 17 00:00:00 2001 From: HnLn Date: Fri, 5 Dec 2014 13:36:12 +0100 Subject: [PATCH 53/67] MSS-94 The single date and start_time hybrid / timestamps exception --- .../culturefeed_date_control/README.txt | 11 ++- .../culturefeed_date_control.module | 6 +- .../form/date_control.inc | 95 ++++++++++++------- .../culturefeed_date_control/form/hybrid.inc | 18 +++- .../culturefeed_date_control/form/period.inc | 21 ++-- .../form/timestamps.inc | 47 ++++----- 6 files changed, 132 insertions(+), 66 deletions(-) diff --git a/culturefeed_entry_ui/culturefeed_date_control/README.txt b/culturefeed_entry_ui/culturefeed_date_control/README.txt index 7a1255ac..fbd02cef 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/README.txt +++ b/culturefeed_entry_ui/culturefeed_date_control/README.txt @@ -5,8 +5,17 @@ The dates can be of different formats: * period (start date and end date including opening hours) * opening times (including culturefeed weekscheme). -To provide sufficient form elements, this module provides form elements for +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/culturefeed_date_control.module b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module index abcede12..a2b73776 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module @@ -171,18 +171,20 @@ function culturefeed_date_control_explode_date(array $element, $date_string) { * 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) { +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' => $time_string, + '#default_value' => $date_string . ' ' . $time_string, ); return date_select_element_value_callback($time_element); diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc index 9eeab424..a67249f6 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc @@ -79,16 +79,19 @@ function culturefeed_date_control_date_control_process(array $element, array &$f '#title' => (isset($element['#title'])) ? $element['#title'] : t('Dates'), ); + $date_control = $element['#value']['date_control']; + // Type. $element['date_control']['type'] = array( '#type' => 'hidden', - '#value' => $element['#value']['date_control']['type'], + '#value' => $date_control['type'], ); // Hybrid. $element['date_control']['hybrid'] = array( '#access' => TRUE, '#date_control' => $element, + '#default_value' => isset($date_control['hybrid']) ? $date_control['hybrid'] : '', '#popup_date_format' => 'd-m-Y', '#popup_date_increment' => 1, '#select_time_format' => 'H:i', @@ -100,7 +103,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f $element['date_control']['timestamps'] = array( '#access' => TRUE, '#date_control' => $element, - '#default_value' => $element['#default_value']['timestamps'], + '#default_value' => isset($date_control['timestamps']) ? $date_control['timestamps'] : '', '#popup_date_format' => 'd-m-Y', '#popup_date_increment' => 1, '#select_time_format' => 'H:i', @@ -112,7 +115,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f $element['date_control']['period'] = array( '#access' => TRUE, '#date_control' => $element, - '#default_value' => $element['#default_value']['period'], + '#default_value' => isset($date_control['period']) ? $date_control['period'] : '', '#popup_date_format' => 'd-m-Y', '#popup_date_increment' => 1, '#type' => 'culturefeed_date_control_period', @@ -127,7 +130,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f 'progress' => array('type' => 'throbber'), 'wrapper' => $element['#id'] . '-ajax-wrapper', ), - '#value' => isset($element['#value']['date_control']['permanent']) ? $element['#value']['date_control']['permanent'] : 0, + '#value' => isset($date_control['permanent']) ? $date_control['permanent'] : 0, '#title' => t('Permanent'), '#type' => 'checkbox', ); @@ -137,7 +140,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f '#access' => TRUE, '#allowed_days' => $element['#allowed_days'], '#date_control' => $element, - '#default_value' => $element['#default_value']['opening_times'], + '#default_value' => isset($date_control['opening_times']) ? $date_control['opening_times'] : '', '#type' => 'culturefeed_date_control_opening_times', ); @@ -290,6 +293,28 @@ function culturefeed_date_control_date_control_validate(array $element, array &$ 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); + + } + + } } @@ -313,37 +338,55 @@ function culturefeed_date_control_date_control_value_callback(array &$element, $ } else { - // Default value or an empty value. - if (isset($element['#default_value'])) { - - $date_control = array( + $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. - if (count($element['#default_value']['timestamps'])) { + elseif (count($default_value['timestamps'])) { $date_control['type'] = 'timestamps'; - $date_control['timestamps'] = $element['#default_value']['timestamps']; + $date_control['timestamps'] = $default_value['timestamps']; } // Period. - elseif ($element['#default_value']['period']['start_date'] && $element['#default_value']['period']['end_date']) { + elseif ($default_value['period']['start_date'] && $default_value['period']['end_date']) { $date_control['type'] = 'period'; - $date_control['period'] = $element['#default_value']['period']; + $date_control['period'] = $default_value['period']; } // Permanent. - elseif ($element['#default_value']['permanent']) { + elseif ($default_value['permanent']) { $date_control['type'] = 'permanent'; - $date_control['permanent'] = $element['#default_value']['permanent']; + $date_control['permanent'] = $default_value['permanent']; } @@ -352,29 +395,17 @@ function culturefeed_date_control_date_control_value_callback(array &$element, $ } // Opening times don't set type, they go with period or permanent. - if ($element['#default_value']['opening_times']) { + if ($default_value['opening_times']) { - $date_control['opening_times'] = $element['#default_value']['opening_times']; + $date_control['opening_times'] = $default_value['opening_times']; } - return array('date_control' => $date_control); + $value['date_control'] = $date_control; } - else { - - return array( - 'date_control' => array( - 'type' => 'hybrid', - 'hybrid' => array(), - 'opening_times' => array(), - 'period' => array(), - 'timestamps' => array(), - ), - ); - - } + return $value; } diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc index 2fd7f767..12b4d5ab 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc @@ -184,7 +184,23 @@ function culturefeed_date_control_hybrid_value_callback(array $element, $input, return $input; } else { - return array('start_date' => '', 'start_time' => ''); + + $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/period.inc b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc index 33d75004..77eb2078 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc @@ -172,17 +172,22 @@ function culturefeed_date_control_period_value_callback(array $element, $input, } else { - if (isset($element['#default_value'])) { + $value = array('start_date' => '', 'end_date' => ''); - $exploded = array(); - $exploded['start_date'] = culturefeed_date_control_explode_date($element, $element['#default_value']['start_date']); - $exploded['end_date'] = culturefeed_date_control_explode_date($element, $element['#default_value']['end_date']); - return $exploded; + 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']); + } } - else { - return array('start_date' => '', '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 index aa90fd93..185a9119 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -218,38 +218,41 @@ function culturefeed_date_control_timestamps_value_callback(array $element, $inp } else { - if (isset($element['#default_value'])) { + $value = array( + 'stamps' => array( + array('date' => '', 'start_time' => '', 'end_time' => ''), + ), + ); - foreach ($element['#default_value'] as &$stamp) { + if (isset($element['#default_value']) && $element['#default_value']) { - $exploded = array(); - $exploded['date'] = culturefeed_date_control_explode_date($element, $stamp['date']); - if (isset($stamp['start_time'])) { - $exploded['start_time'] = culturefeed_date_control_explode_time($element, $stamp['date'] . ' ' . $stamp['start_time']); - } - if (isset($stamp['end_time'])) { - $exploded['end_time'] = culturefeed_date_control_explode_time($element, $stamp['date'] . ' ' . $stamp['end_time']); - } - $stamp = $exploded; + $stamps = array(); + foreach ($element['#default_value'] as $default_value) { - } + if (isset($default_value['date']) && $default_value['date']) { - return array( - 'stamps' => $element['#default_value'], - ); + $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; - } + } - else { + } - return array( - 'stamps' => array( - array('date' => '', 'start_time' => NULL, 'end_time' => NULL), - ), - ); + if (count($stamps)) { + $value['stamps'] = $stamps; + } } + return $value; + } } From 01f99525ef986b8630c4c40b2c508087fec9cfea Mon Sep 17 00:00:00 2001 From: HnLn Date: Fri, 5 Dec 2014 14:51:02 +0100 Subject: [PATCH 54/67] MSS-94 required fields --- .../form/date_control.inc | 61 ++----------------- .../culturefeed_date_control/form/hybrid.inc | 3 +- .../form/opening_times.inc | 5 +- .../culturefeed_date_control/form/period.inc | 2 +- .../form/timestamps.inc | 2 +- 5 files changed, 13 insertions(+), 60 deletions(-) diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc index a67249f6..ef454dbf 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc @@ -5,57 +5,6 @@ * Contains the functions for the culturefeed date control form element. */ -/** - * Pre renders the culturefeed date control. - * - * @param array $element - * The element. - * - * @return array $element - * The element. - */ -function culturefeed_date_control_date_control_pre_render(array $element) { - - $value = $element['#value']; - - if ($value['date_control']['type'] == 'hybrid') { - - $element['date_control']['opening_times']['#access'] = FALSE; - $element['date_control']['period']['#access'] = FALSE; - $element['date_control']['permanent']['#access'] = FALSE; - $element['date_control']['timestamps']['#access'] = FALSE; - - } - - elseif ($value['date_control']['type'] == 'period') { - - $element['date_control']['hybrid']['#access'] = FALSE; - $element['date_control']['permanent']['#access'] = FALSE; - $element['date_control']['timestamps']['#access'] = FALSE; - - } - - elseif ($value['date_control']['type'] == 'permanent') { - - $element['date_control']['hybrid']['#access'] = FALSE; - $element['date_control']['period']['#access'] = FALSE; - $element['date_control']['timestamps']['#access'] = FALSE; - - } - - elseif ($value['date_control']['type'] == 'timestamps') { - - $element['date_control']['hybrid']['#access'] = FALSE; - $element['date_control']['opening_times']['#access'] = FALSE; - $element['date_control']['period']['#access'] = FALSE; - $element['date_control']['permanent']['#access'] = FALSE; - - } - - return $element; - -} - /** * Returns the culturefeed date control element. * @@ -89,7 +38,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f // Hybrid. $element['date_control']['hybrid'] = array( - '#access' => TRUE, + '#access' => $date_control['type'] == 'hybrid', '#date_control' => $element, '#default_value' => isset($date_control['hybrid']) ? $date_control['hybrid'] : '', '#popup_date_format' => 'd-m-Y', @@ -101,7 +50,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f // Timestamps. $element['date_control']['timestamps'] = array( - '#access' => TRUE, + '#access' => $date_control['type'] == 'timestamps', '#date_control' => $element, '#default_value' => isset($date_control['timestamps']) ? $date_control['timestamps'] : '', '#popup_date_format' => 'd-m-Y', @@ -113,7 +62,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f // Period. $element['date_control']['period'] = array( - '#access' => TRUE, + '#access' => $date_control['type'] == 'period', '#date_control' => $element, '#default_value' => isset($date_control['period']) ? $date_control['period'] : '', '#popup_date_format' => 'd-m-Y', @@ -123,7 +72,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f // Permanent. $element['date_control']['permanent'] = array( - '#access' => TRUE, + '#access' => $date_control['type'] == 'permanent', '#ajax' => array( 'effect' => 'none', 'path' => 'culturefeed_elements/ajax/' . implode('/', $element['#array_parents']), @@ -137,7 +86,7 @@ function culturefeed_date_control_date_control_process(array $element, array &$f // Opening times. $element['date_control']['opening_times'] = array( - '#access' => TRUE, + '#access' => $date_control['type'] == 'period' || $date_control['type'] == 'permanent', '#allowed_days' => $element['#allowed_days'], '#date_control' => $element, '#default_value' => isset($date_control['opening_times']) ? $date_control['opening_times'] : '', diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc index 12b4d5ab..8be0e499 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc @@ -79,6 +79,7 @@ function culturefeed_date_control_hybrid_process(array $element, array &$form_st '#date_label_position' => 'none', '#default_value' => $date, '#icon' => TRUE, + '#required' => TRUE, '#title' => t('Date'), '#type' => 'date_popup', ); @@ -187,7 +188,7 @@ function culturefeed_date_control_hybrid_value_callback(array $element, $input, $value = array('start_date' => '', 'start_time' => ''); - if (isset($element['#default_value']) && $element['#default_value']) { + if (isset($element['#default_value']) && $element['#default_value'] && $element['#access']) { $default_value = $element['#default_value']; if (isset($default_value['start_date']) && $default_value['start_date']) { diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc index 838a2aa1..ee11b42a 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc @@ -118,7 +118,10 @@ function culturefeed_date_control_opening_times_value_callback(array $element, $ } else { - if (isset($element['#default_value']) && isset($element['#default_value']['days']) && $element['#default_value']['days']) { + if ( + isset($element['#default_value']) && isset($element['#default_value']['days']) && + $element['#default_value']['days'] && $element['#access'] + ) { // @todo This should be in the entry_ui module. /* @var CultureFeed_Cdb_Data_Calendar_Weekscheme $week_scheme */ diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc index 77eb2078..cdfa2d94 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc @@ -174,7 +174,7 @@ function culturefeed_date_control_period_value_callback(array $element, $input, $value = array('start_date' => '', 'end_date' => ''); - if (isset($element['#default_value']) && $element['#default_value']) { + if (isset($element['#default_value']) && $element['#default_value'] && $element['#access']) { $default_value = $element['#default_value']; if ( diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc index 185a9119..2f291b3a 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -224,7 +224,7 @@ function culturefeed_date_control_timestamps_value_callback(array $element, $inp ), ); - if (isset($element['#default_value']) && $element['#default_value']) { + if (isset($element['#default_value']) && $element['#default_value'] && $element['#access']) { $stamps = array(); foreach ($element['#default_value'] as $default_value) { From 7f8590b461ca4665ff88729234848af665ce0ced Mon Sep 17 00:00:00 2001 From: HnLn Date: Sat, 6 Dec 2014 21:53:39 +0100 Subject: [PATCH 55/67] MSS-94 minor cleanup --- .../culturefeed_date_control.module | 1 - .../form/date_control.inc | 25 +++++++++++-------- .../culturefeed_date_control/form/hybrid.inc | 2 +- .../form/opening_times.inc | 2 +- .../culturefeed_date_control/form/period.inc | 2 +- .../form/timestamps.inc | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module index a2b73776..c56718f5 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module +++ b/culturefeed_entry_ui/culturefeed_date_control/culturefeed_date_control.module @@ -83,7 +83,6 @@ function culturefeed_date_control_element_info() { 'culturefeed_date_control' => array( '#element_validate' => array('culturefeed_date_control_date_control_validate'), '#input' => TRUE, - '#pre_render' => array('culturefeed_date_control_date_control_pre_render'), '#process' => array('culturefeed_date_control_date_control_process', 'ajax_process_form'), '#tree' => TRUE, '#value_callback' => 'culturefeed_date_control_date_control_value_callback', diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc index ef454dbf..5676f49b 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/date_control.inc @@ -37,10 +37,11 @@ function culturefeed_date_control_date_control_process(array $element, array &$f ); // Hybrid. + $access = $date_control['type'] == 'hybrid'; $element['date_control']['hybrid'] = array( - '#access' => $date_control['type'] == 'hybrid', + '#access' => $access, '#date_control' => $element, - '#default_value' => isset($date_control['hybrid']) ? $date_control['hybrid'] : '', + '#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', @@ -49,10 +50,11 @@ function culturefeed_date_control_date_control_process(array $element, array &$f ); // Timestamps. + $access = $date_control['type'] == 'timestamps'; $element['date_control']['timestamps'] = array( - '#access' => $date_control['type'] == 'timestamps', + '#access' => $access, '#date_control' => $element, - '#default_value' => isset($date_control['timestamps']) ? $date_control['timestamps'] : '', + '#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', @@ -61,35 +63,38 @@ function culturefeed_date_control_date_control_process(array $element, array &$f ); // Period. + $access = $date_control['type'] == 'period'; $element['date_control']['period'] = array( - '#access' => $date_control['type'] == 'period', + '#access' => $access, '#date_control' => $element, - '#default_value' => isset($date_control['period']) ? $date_control['period'] : '', + '#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' => $date_control['type'] == 'permanent', + '#access' => $access, '#ajax' => array( 'effect' => 'none', 'path' => 'culturefeed_elements/ajax/' . implode('/', $element['#array_parents']), 'progress' => array('type' => 'throbber'), 'wrapper' => $element['#id'] . '-ajax-wrapper', ), - '#value' => isset($date_control['permanent']) ? $date_control['permanent'] : 0, + '#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' => $date_control['type'] == 'period' || $date_control['type'] == 'permanent', + '#access' => $access, '#allowed_days' => $element['#allowed_days'], '#date_control' => $element, - '#default_value' => isset($date_control['opening_times']) ? $date_control['opening_times'] : '', + '#default_value' => $access && isset($date_control['opening_times']) ? $date_control['opening_times'] : '', '#type' => 'culturefeed_date_control_opening_times', ); diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc index 8be0e499..6390e8c2 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc @@ -188,7 +188,7 @@ function culturefeed_date_control_hybrid_value_callback(array $element, $input, $value = array('start_date' => '', 'start_time' => ''); - if (isset($element['#default_value']) && $element['#default_value'] && $element['#access']) { + if (isset($element['#default_value']) && $element['#default_value']) { $default_value = $element['#default_value']; if (isset($default_value['start_date']) && $default_value['start_date']) { diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc index ee11b42a..02715405 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/opening_times.inc @@ -120,7 +120,7 @@ function culturefeed_date_control_opening_times_value_callback(array $element, $ if ( isset($element['#default_value']) && isset($element['#default_value']['days']) && - $element['#default_value']['days'] && $element['#access'] + $element['#default_value']['days'] ) { // @todo This should be in the entry_ui module. diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc index cdfa2d94..77eb2078 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/period.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/period.inc @@ -174,7 +174,7 @@ function culturefeed_date_control_period_value_callback(array $element, $input, $value = array('start_date' => '', 'end_date' => ''); - if (isset($element['#default_value']) && $element['#default_value'] && $element['#access']) { + if (isset($element['#default_value']) && $element['#default_value']) { $default_value = $element['#default_value']; if ( diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc index 2f291b3a..185a9119 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -224,7 +224,7 @@ function culturefeed_date_control_timestamps_value_callback(array $element, $inp ), ); - if (isset($element['#default_value']) && $element['#default_value'] && $element['#access']) { + if (isset($element['#default_value']) && $element['#default_value']) { $stamps = array(); foreach ($element['#default_value'] as $default_value) { From f18c26437df7e9f4377e247f9bb4daac682f221f Mon Sep 17 00:00:00 2001 From: zuuperman Date: Wed, 10 Dec 2014 17:28:13 +0100 Subject: [PATCH 56/67] Change is admin and is member check to use the not-cached user object --- culturefeed_pages/includes/helpers.inc | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/culturefeed_pages/includes/helpers.inc b/culturefeed_pages/includes/helpers.inc index 3d46b3f0..1aad1789 100644 --- a/culturefeed_pages/includes/helpers.inc +++ b/culturefeed_pages/includes/helpers.inc @@ -397,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. From 469dc84e13e3510f05b0a6625471fde82f635efc Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Thu, 11 Dec 2014 21:40:21 +0100 Subject: [PATCH 57/67] add GTM tracking for all types of detail pages --- culturefeed.module | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/culturefeed.module b/culturefeed.module index f6c70b3a..38931d16 100644 --- a/culturefeed.module +++ b/culturefeed.module @@ -218,14 +218,44 @@ 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']) { + + 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); + } } } From b25c336a01d3220b4d37e867dcb50e6aa66947e8 Mon Sep 17 00:00:00 2001 From: Jonas Verhaeghe Date: Fri, 12 Dec 2014 10:50:55 +0100 Subject: [PATCH 58/67] CEP-694 --- culturefeed_pages/theme/theme.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/culturefeed_pages/theme/theme.inc b/culturefeed_pages/theme/theme.inc index 2b8a82f2..680639ab 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(); From fcd58592647569a7873d11172b63141b89b3fb1f Mon Sep 17 00:00:00 2001 From: zuuperman Date: Fri, 12 Dec 2014 11:40:29 +0100 Subject: [PATCH 59/67] Allow option to skip cache --- culturefeed_pages/includes/helpers.inc | 20 ++++++++++++++++++-- lib/Drupal/DrupalCultureFeed_Cache.php | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/culturefeed_pages/includes/helpers.inc b/culturefeed_pages/includes/helpers.inc index 1aad1789..49b9eab0 100644 --- a/culturefeed_pages/includes/helpers.inc +++ b/culturefeed_pages/includes/helpers.inc @@ -484,11 +484,27 @@ function culturefeed_pages_get_admins_of_page(CultureFeed_Cdb_Item_Page $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) { +function culturefeed_pages_get_validated_admins_of_page(CultureFeed_Cdb_Item_Page $page, $skip_cache = FALSE) { try { - $cf_pages = DrupalCultureFeed::getLoggedInUserInstance()->pages(); + + 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) { diff --git a/lib/Drupal/DrupalCultureFeed_Cache.php b/lib/Drupal/DrupalCultureFeed_Cache.php index e56c5e33..7cd6046b 100644 --- a/lib/Drupal/DrupalCultureFeed_Cache.php +++ b/lib/Drupal/DrupalCultureFeed_Cache.php @@ -16,7 +16,7 @@ public function __construct(CultureFeed $realCultureFeed, $loggedInUserId) { } public function getRealCultureFeed() { - return $this->realCultureFeed(); + return $this->realCultureFeed; } protected function getCachePrefix() { From fe58eb5c5cac7b65fe9ddc70a7785d8946136b8c Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Mon, 15 Dec 2014 11:35:10 +0100 Subject: [PATCH 60/67] make is_detail macro backwards compatible --- culturefeed.module | 3 +++ 1 file changed, 3 insertions(+) diff --git a/culturefeed.module b/culturefeed.module index 38931d16..74dc1402 100644 --- a/culturefeed.module +++ b/culturefeed.module @@ -228,6 +228,9 @@ function culturefeed_page_build(&$page) { $gtm_globals['detail_title'] = culturefeed_agenda_detail_title($event); $gtm_globals['detail_type'] = 'event'; $gtm_globals['cdbid'] = arg(3); + + // Make this backwards compatible + $gtm_globals['is_event_detail'] = TRUE; } } From 681d6226148c92b4f4cd8dfcd5f10d80d86d2b2f Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Mon, 15 Dec 2014 11:43:38 +0100 Subject: [PATCH 61/67] use is_event_detail for actors, productions and pages too --- culturefeed.module | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/culturefeed.module b/culturefeed.module index 74dc1402..1bea64c9 100644 --- a/culturefeed.module +++ b/culturefeed.module @@ -221,6 +221,9 @@ function culturefeed_page_build(&$page) { // 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); @@ -228,9 +231,6 @@ function culturefeed_page_build(&$page) { $gtm_globals['detail_title'] = culturefeed_agenda_detail_title($event); $gtm_globals['detail_type'] = 'event'; $gtm_globals['cdbid'] = arg(3); - - // Make this backwards compatible - $gtm_globals['is_event_detail'] = TRUE; } } From 54eb9a3893151c14ccc4545605705c12c179f364 Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Mon, 15 Dec 2014 12:14:30 +0100 Subject: [PATCH 62/67] track contact links on actor detail --- culturefeed_agenda/theme/theme.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/culturefeed_agenda/theme/theme.inc b/culturefeed_agenda/theme/theme.inc index 55d3176a..1fd05155 100644 --- a/culturefeed_agenda/theme/theme.inc +++ b/culturefeed_agenda/theme/theme.inc @@ -618,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); From 90c987decf0b40274fce1e06d8e426fbb5d39363 Mon Sep 17 00:00:00 2001 From: HnLn Date: Tue, 16 Dec 2014 16:20:32 +0100 Subject: [PATCH 63/67] MSS-94 fix validation and select minute autocomplete --- .../culturefeed_date_control/form/hybrid.inc | 8 +++++ .../form/timestamps.inc | 14 +++++--- .../culturefeed_date_control_time_select.js | 22 ++++++++++++ .../includes/culturefeed_entry_ui.pages.inc | 35 ++++++++++++------- 4 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 culturefeed_entry_ui/culturefeed_date_control/js/culturefeed_date_control_time_select.js diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc index 6390e8c2..d6a9e470 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/hybrid.inc @@ -86,6 +86,7 @@ function culturefeed_date_control_hybrid_process(array $element, array &$form_st $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, @@ -110,6 +111,7 @@ function culturefeed_date_control_hybrid_process(array $element, array &$form_st $element['end_time'] = array( '#access' => TRUE, + '#attributes' => array('class' => array('time-select-complete-minutes')), '#ajax' => $ajax_settings, '#date_format' => 'H:i', '#date_increment' => 30, @@ -131,6 +133,12 @@ function culturefeed_date_control_hybrid_process(array $element, array &$form_st '#value' => 0, ); + $element['#attached'] = array( + 'js' => array( + drupal_get_path('module', 'culturefeed_date_control') . '/js/culturefeed_date_control_time_select.js', + ), + ); + return $element; } diff --git a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc index 185a9119..27d93afb 100644 --- a/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc +++ b/culturefeed_entry_ui/culturefeed_date_control/form/timestamps.inc @@ -107,6 +107,7 @@ function culturefeed_date_control_timestamps_process(array $element, array &$for $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, @@ -117,6 +118,7 @@ function culturefeed_date_control_timestamps_process(array $element, array &$for $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, @@ -141,11 +143,15 @@ function culturefeed_date_control_timestamps_process(array $element, array &$for '#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'] = array( - 'css' => array( - drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control.css', - ), + $element['#attached']['css'] = array( + drupal_get_path('module', 'culturefeed_date_control') . '/css/culturefeed_date_control.css', ); } 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/includes/culturefeed_entry_ui.pages.inc b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc index 3594888c..ab285ba7 100644 --- a/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc +++ b/culturefeed_entry_ui/includes/culturefeed_entry_ui.pages.inc @@ -1562,19 +1562,25 @@ function culturefeed_entry_ui_event_save_validate($form, &$form_state) { $period = $values['when']['date_control']['period']; - // 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')); - } + // Form validation hasn't processed the dates values yet, so don't validate. + if (!is_array($period['start_date']) && !is_array($period['end_date'])) { + + // 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')); + } + + // 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.')); + } - // 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.')); } } @@ -1586,6 +1592,11 @@ function culturefeed_entry_ui_event_save_validate($form, &$form_state) { 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']); From a64147443c300eea04dcf4689843e655b05d3a19 Mon Sep 17 00:00:00 2001 From: Luk Dens Date: Wed, 17 Dec 2014 21:48:34 +0100 Subject: [PATCH 64/67] RPT-389 push site_name as consumer_name dimension to GTM --- culturefeed.module | 1 + 1 file changed, 1 insertion(+) diff --git a/culturefeed.module b/culturefeed.module index 1bea64c9..2bd963da 100644 --- a/culturefeed.module +++ b/culturefeed.module @@ -265,6 +265,7 @@ function culturefeed_page_build(&$page) { // 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. From 72e1660be71525e6fb5c19e05a577609bf9670e6 Mon Sep 17 00:00:00 2001 From: Stijn Swaanen Date: Fri, 19 Dec 2014 16:15:10 +0100 Subject: [PATCH 65/67] Changes for CEP-736 --- .../lib/Drupal/CultureFeedSearchPage.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php index 1707e994..7a863350 100644 --- a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php +++ b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php @@ -387,8 +387,13 @@ protected function addFacetFilters($params) { if (isset($params['coordinates'])) { $coordinates = explode(',', $params['coordinates']); - - $distance = new Parameter\Spatial\Distance(CULTUREFEED_SEARCH_DEFAULT_PROXIMITY_RANGE); + + if (isset($params['distance'])) { + $distance = new Parameter\Spatial\Distance($params['distance']); + } + else { + $distance = new Parameter\Spatial\Distance(CULTUREFEED_SEARCH_DEFAULT_PROXIMITY_RANGE); + } $point = new Parameter\Spatial\Point($coordinates[0], $coordinates[1]); $field = new Parameter\Spatial\SpatialField('physical_gis'); $this->parameters[] = new Parameter\Spatial\GeoFilterQuery($point, $distance, $field); From 8f9389c1360c19e516b7798c59c0fc0e97bf2c91 Mon Sep 17 00:00:00 2001 From: svenhoutmeyers Date: Mon, 22 Dec 2014 10:21:38 +0100 Subject: [PATCH 66/67] Fixing errors when swapping CF accounts --- culturefeed.helpers.inc | 4 +++- culturefeed.pages.inc | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) 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.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)) From 31b6b88744f90aca1db2bf48e8c6d53e1a24bfa8 Mon Sep 17 00:00:00 2001 From: svenhoutmeyers Date: Tue, 23 Dec 2014 15:49:56 +0100 Subject: [PATCH 67/67] adding tags filter to culturefeed_search_views --- .../culturefeed_search_views.info | 1 + .../views/culturefeed_search_views.views.inc | 9 ++++ ...handler_filter_culturefeed_search_tags.inc | 42 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 culturefeed_search_views/views/handlers/filter/views_handler_filter_culturefeed_search_tags.inc diff --git a/culturefeed_search_views/culturefeed_search_views.info b/culturefeed_search_views/culturefeed_search_views.info index 66bcd2ae..43e346c4 100644 --- a/culturefeed_search_views/culturefeed_search_views.info +++ b/culturefeed_search_views/culturefeed_search_views.info @@ -13,6 +13,7 @@ files[] = views/handlers/filter/views_handler_filter_culturefeed_search_type.inc files[] = views/handlers/filter/views_handler_filter_culturefeed_search_category.inc files[] = views/handlers/filter/views_handler_filter_culturefeed_search_agefrom.inc files[] = views/handlers/filter/views_handler_filter_culturefeed_search_city.inc +files[] = views/handlers/filter/views_handler_filter_culturefeed_search_tags.inc files[] = views/handlers/filter/views_handler_filter_culturefeed_search_createdby.inc files[] = views/handlers/filter/views_handler_filter_culturefeed_search_createdbycurrentuser.inc files[] = views/handlers/filter/views_handler_filter_culturefeed_search_free.inc diff --git a/culturefeed_search_views/views/culturefeed_search_views.views.inc b/culturefeed_search_views/views/culturefeed_search_views.views.inc index 6af6045a..85d81e54 100644 --- a/culturefeed_search_views/views/culturefeed_search_views.views.inc +++ b/culturefeed_search_views/views/culturefeed_search_views.views.inc @@ -46,6 +46,15 @@ function culturefeed_search_views_data() { ), ); } + + // Keywords + $data['cdb_items']['tags'] = array( + 'title' => t('Tags'), + 'help' => t('Tags'), + 'filter' => array( + 'handler' => 'views_handler_filter_culturefeed_search_tags', + ), + ); // Type $data['cdb_items']['type'] = array( diff --git a/culturefeed_search_views/views/handlers/filter/views_handler_filter_culturefeed_search_tags.inc b/culturefeed_search_views/views/handlers/filter/views_handler_filter_culturefeed_search_tags.inc new file mode 100644 index 00000000..638f4d8d --- /dev/null +++ b/culturefeed_search_views/views/handlers/filter/views_handler_filter_culturefeed_search_tags.inc @@ -0,0 +1,42 @@ +search_field = 'keywords'; + } + + /** + * @see views_handler_filter::value_form() + */ + function value_form(&$form, &$form_state) { + $form['value'] = array( + '#type' => 'textfield', + '#title' => t('Keywords'), + '#size' => 30, + '#default_value' => $this->value, + '#description' => t('For OR use this syntax: Mijnkindopkamp OR UiTPAS Regio Aalst. AND not supplied yet.'), + ); + } + + /** + * @see views_handler_filter::query() + */ + function query() { + + $values = explode(' OR ', $this->getValue()); + $keywords = array(); + foreach ($values as $value) { + $keywords[] = '"' . str_replace('"', '\"', $value) . '"'; + } + $this->query->add_where($this->options['group'], 'fq', $this->search_field . ':' . implode(' OR ', $keywords)); + } + +} \ No newline at end of file