Skip to content

Commit

Permalink
Added config for page created + remove the activity when a page is de…
Browse files Browse the repository at this point in the history
…leted
  • Loading branch information
zuuperman committed Sep 19, 2013
1 parent 429f3f1 commit ff80ff0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
23 changes: 19 additions & 4 deletions culturefeed_pages/includes/pages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

}

Expand Down
1 change: 1 addition & 0 deletions culturefeed_social/culturefeed_social.info
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

class CultureFeedActivityConfigPageCreated extends CultureFeedActivityConfigBase {

public $type = CultureFeed_Activity::TYPE_PAGE_CREATED;

/**
* Constructor to load default values.
*/
public function __construct() {

parent::__construct();
$this->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');
}

}

6 changes: 6 additions & 0 deletions culturefeed_userpoints_ui/theme/theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<p>' . t('Congratulations! you collected') . ' <strong>' . $points_message . '</strong> ' . t('with your @action and have now', array('@action' => strtolower($config->action))) . ' <strong>' . $total_points_message . '</strong></p>';

Expand All @@ -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 = '<p>' . t('You lost') . ' <strong>' . $points_message . '</strong> ' . t('with your @action and have now', array('@action' => strtolower($config->action))) . ' <strong>' . $total_points_message . '</strong></p>';

Expand Down

0 comments on commit ff80ff0

Please sign in to comment.