From ff80ff05754b39010cf0f467f07e82ba85decc7d Mon Sep 17 00:00:00 2001 From: zuuperman Date: Thu, 19 Sep 2013 14:12:54 +0200 Subject: [PATCH] Added config for page created + remove the activity when a page is deleted --- culturefeed_pages/includes/pages.inc | 23 ++++++++++++++---- culturefeed_social/culturefeed_social.info | 1 + .../Drupal/CultureFeedActivityConfigBase.php | 4 ++++ .../CultureFeedActivityConfigPageCreated.php | 24 +++++++++++++++++++ culturefeed_userpoints_ui/theme/theme.inc | 6 +++++ 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 culturefeed_social/lib/Drupal/CultureFeedActivityConfigPageCreated.php diff --git a/culturefeed_pages/includes/pages.inc b/culturefeed_pages/includes/pages.inc index e1c1606c..51ab8174 100644 --- a/culturefeed_pages/includes/pages.inc +++ b/culturefeed_pages/includes/pages.inc @@ -848,6 +848,7 @@ function culturefeed_pages_remove_page_confirm_form($form, &$form_state, $page, */ function culturefeed_pages_remove_page_confirm_form_submit($form, &$form_state) { + $form_state['redirect'] = ''; $page = $form_state['page']; // Send request to remove a page. @@ -863,19 +864,33 @@ function culturefeed_pages_remove_page_confirm_form_submit($form, &$form_state) if (!empty($cf_user->pageMemberships)) { foreach ($cf_user->pageMemberships as $key => $membership) { if ($membership->page->getId() != $page->getId()) { - culturefeed_pages_set_active_page($page); + culturefeed_pages_set_active_page($membership->page); break; } } } - } catch (Exception $e) { watchdog_exception('culturefeed_pages', $e); - form_set_error('', t('There was an error while deleting the page.')); + return; } - $form_state['redirect'] = ''; + // Also remove the activity for it. + try { + + $query = new CultureFeed_SearchActivitiesQuery(); + $query->max = 1; + $query->type = CultureFeed_Activity::TYPE_PAGE_CREATED; + $query->userId = $cf_user->id; + $query->nodeId = $page->getId(); + $activities = DrupalCultureFeed::searchActivities($query); + if ($activities && $activities->total > 0) { + DrupalCultureFeed::deleteActivity($activities->objects[0]->id); + } + } + catch (Exception $e) { + watchdog_exception('culturefeed_pages', $e); + } } diff --git a/culturefeed_social/culturefeed_social.info b/culturefeed_social/culturefeed_social.info index 8521dc2f..aef67cf2 100644 --- a/culturefeed_social/culturefeed_social.info +++ b/culturefeed_social/culturefeed_social.info @@ -22,5 +22,6 @@ files[] = lib/Drupal/CultureFeedActivityConfigNewEvent.php files[] = lib/Drupal/CultureFeedActivityConfigReview.php files[] = lib/Drupal/CultureFeedActivityConfigMediaPhoto.php files[] = lib/Drupal/CultureFeedActivityConfigMediaVideo.php +files[] = lib/Drupal/CultureFeedActivityConfigPageCreated.php dependencies[] = culturefeed_search \ No newline at end of file diff --git a/culturefeed_social/lib/Drupal/CultureFeedActivityConfigBase.php b/culturefeed_social/lib/Drupal/CultureFeedActivityConfigBase.php index 6d4d46bf..ca74ed51 100644 --- a/culturefeed_social/lib/Drupal/CultureFeedActivityConfigBase.php +++ b/culturefeed_social/lib/Drupal/CultureFeedActivityConfigBase.php @@ -117,6 +117,10 @@ public static function loadByType($type) { $config = new CultureFeedActivityMediaVideo(); break; + case CultureFeed_Activity::TYPE_PAGE_CREATED: + $config = new CultureFeedActivityConfigPageCreated(); + break; + default: return NULL; diff --git a/culturefeed_social/lib/Drupal/CultureFeedActivityConfigPageCreated.php b/culturefeed_social/lib/Drupal/CultureFeedActivityConfigPageCreated.php new file mode 100644 index 00000000..df27ec1a --- /dev/null +++ b/culturefeed_social/lib/Drupal/CultureFeedActivityConfigPageCreated.php @@ -0,0 +1,24 @@ +allowedTypes = array( + CultureFeed_Activity::CONTENT_TYPE_CULTUREFEED_PAGE, + ); + + $this->action = t('page'); + $this->viewPrefix = t('has'); + $this->viewSuffix = t('created'); + $this->label = t('Page created'); + } + +} + diff --git a/culturefeed_userpoints_ui/theme/theme.inc b/culturefeed_userpoints_ui/theme/theme.inc index f3eae7d1..b669b4e3 100644 --- a/culturefeed_userpoints_ui/theme/theme.inc +++ b/culturefeed_userpoints_ui/theme/theme.inc @@ -370,6 +370,9 @@ function theme_culturefeed_userpoints_ui_points_earned_message($variables) { $total_points_message = format_plural($total_points, '@count punt', '@count punten'); $config = CultureFeedActivityConfigBase::loadByType($activity->type); + if (!$config) { + return; + } $message = '

' . t('Congratulations! you collected') . ' ' . $points_message . ' ' . t('with your @action and have now', array('@action' => strtolower($config->action))) . ' ' . $total_points_message . '

'; @@ -390,6 +393,9 @@ function theme_culturefeed_userpoints_ui_points_lost_message($variables) { $total_points_message = format_plural($total_points, '@count punt', '@count punten'); $config = CultureFeedActivityConfigBase::loadByType($activity->type); + if (!$config) { + return; + } $message = '

' . t('You lost') . ' ' . $points_message . ' ' . t('with your @action and have now', array('@action' => strtolower($config->action))) . ' ' . $total_points_message . '

';