Skip to content

Commit

Permalink
Task #4 and a manual merge of task #18: added the ability to show dif…
Browse files Browse the repository at this point in the history
…ferent messages to different users (e.g. "You did this" vs. "Username did this") and added support for multilingual templates.
  • Loading branch information
IceCreamYou committed Jul 8, 2011
1 parent ffedc70 commit 5beff8a
Show file tree
Hide file tree
Showing 6 changed files with 367 additions and 162 deletions.
84 changes: 76 additions & 8 deletions activity_log.admin.js
Expand Up @@ -2,25 +2,39 @@ Drupal.behaviors.activityLogAdmin = function (context) {
// Make sure we can run context.find().
var ctxt = $(context);

// Control toggling visibility of the acting UID field.
var acting_uid = new Array();
acting_uid['group_method'] = false;
acting_uid['stream_owner'] = false;
acting_uid['viewer'] = false;
var toggle_acting_uid = function() {
for (var key in acting_uid) {
if (acting_uid[key]) {
ctxt.find('#edit-settings-acting-uid-wrapper').show();
return;
}
}
ctxt.find('#edit-settings-acting-uid-wrapper').hide();
}

// Show/hide grouping settings.
var $group_method = ctxt.find('input:radio[name="settings[grouping][group_method]"]:checked');
var handle_gm = function() {
var val = $group_method.val();
var val = ctxt.find('input:radio[name="settings[grouping][group_method]"]:checked').val();
if (val == 'target_action') {
ctxt.find('#edit-settings-grouping-group-interval-wrapper').hide();
ctxt.find('#edit-settings-grouping-group-max-wrapper').hide();
ctxt.find('#edit-settings-grouping-group-summary-wrapper').hide();
ctxt.find('#edit-settings-grouping-collapse-method-wrapper').hide();
ctxt.find('#edit-settings-grouping-group-template-wrapper').show();
ctxt.find('#activity-log-admin-description').hide();
ctxt.find('.activity-log-admin-description').hide();
}
else if (val == 'action' || val == 'user_action') {
ctxt.find('#edit-settings-grouping-group-interval-wrapper').show();
ctxt.find('#edit-settings-grouping-group-max-wrapper').show();
ctxt.find('#edit-settings-grouping-group-summary-wrapper').show();
ctxt.find('#edit-settings-grouping-collapse-method-wrapper').show();
ctxt.find('#edit-settings-grouping-group-template-wrapper').show();
ctxt.find('#activity-log-admin-description').show();
ctxt.find('.activity-log-admin-description').show();
}
else if (val == 'none') {
ctxt.find('#edit-settings-grouping-group-interval-wrapper').hide();
Expand All @@ -29,15 +43,17 @@ Drupal.behaviors.activityLogAdmin = function (context) {
ctxt.find('#edit-settings-grouping-collapse-method-wrapper').hide();
ctxt.find('#edit-settings-grouping-group-template-wrapper').hide();
}
acting_uid['group_method'] = (val == 'user_action');
toggle_acting_uid();
};
handle_gm();
ctxt.find('input:radio[name="settings[grouping][group_method]"]').change(handle_gm);

// Show/hide stream owner exposed fields.
var fields = Drupal.settings.activity_log.stream_owner_expose_fields;
var so_fields = Drupal.settings.activity_log.stream_owner_expose_fields;
var handle_so = function() {
var shown = new Array();
$.each(fields, function(k, v) {
$.each(so_fields, function(k, v) {
for (var val in v) {
if (ctxt.find('input:checkbox[name="settings[visibility][stream_owner_entity_group]['+ k +']"]').attr('checked')) {
if ($.inArray(v[val], shown) == -1) {
Expand All @@ -50,6 +66,10 @@ Drupal.behaviors.activityLogAdmin = function (context) {
}
ctxt.find('#edit-settings-'+ type +'-wrapper').show();
shown[v[val]] = v[val];
if (type == 'acting-uid') {
acting_uid['stream_owner'] = true;
toggle_acting_uid();
}
}
}
}
Expand All @@ -64,14 +84,62 @@ Drupal.behaviors.activityLogAdmin = function (context) {
else if (f[val] == 'type') {
type = 'visibility-stream-owner-type';
}
if (f[val] != 'acting_uid' || $group_method.val() != 'user_action') {
if (f[val] != 'acting_uid') {
ctxt.find('#edit-settings-'+ type +'-wrapper').hide();
}
else {
acting_uid['stream_owner'] = false;
toggle_acting_uid();
}
}
}
};
handle_so();
$.each(fields, function(key, value) {
$.each(so_fields, function(key, value) {
ctxt.find('input:checkbox[name="settings[visibility][stream_owner_entity_group]['+ key +']"]').change(handle_so);
});

// Show/hide viewer exposed fields.
var vi_fields = Drupal.settings.activity_log.viewer_expose_fields;
var handle_vi = function() {
var shown = new Array();
$.each(vi_fields, function(k, v) {
for (var val in v) {
if (ctxt.find('input:checkbox[name="settings[visibility][viewer_entity_group]['+ k +']"]').attr('checked')) {
if ($.inArray(v[val], shown) == -1) {
var type = 'acting-uid';
if (v[val] == 'id') {
type = 'visibility-viewer-id';
}
ctxt.find('#edit-settings-'+ type +'-wrapper').show();
shown[v[val]] = v[val];
if (type == 'acting-uid') {
acting_uid['viewer'] = true;
toggle_acting_uid();
}
}
}
}
});
var f = ['id', 'acting_uid'];
for (var val in f) {
if (shown[f[val]] == undefined || shown[f[val]] == null) {
var type = 'acting-uid';
if (f[val] == 'id') {
type = 'visibility-viewer-id';
}
if (f[val] != 'acting_uid') {
ctxt.find('#edit-settings-'+ type +'-wrapper').hide();
}
else {
acting_uid['viewer'] = false;
toggle_acting_uid();
}
}
}
};
handle_vi();
$.each(vi_fields, function(key, value) {
ctxt.find('input:checkbox[name="settings[visibility][viewer_entity_group]['+ key +']"]').change(handle_vi);
});
}
35 changes: 27 additions & 8 deletions activity_log.entity_groups.inc
Expand Up @@ -23,38 +23,45 @@ function activity_log_entity_groups($stream_owner = TRUE) {
'items callback' => 'activity_log_eg_custom',
'title' => t('Custom'),
'expose fields' => array('id', 'type'),
'weight' => -100,
),
'acting user' => array(
'items callback' => 'activity_log_eg_acting_user',
'title' => t('Acting user'),
'expose fields' => array('acting_uid'),
'weight' => -95,
),
'target entity' => array(
'items callback' => 'activity_log_eg_target_entity',
'title' => t('The entity on which the action was performed'),
'additional arguments' => array($stream_owner),
'weight' => -90,
),
);
if ($og) {
$groups['active groups'] = array(
'items callback' => 'activity_log_eg_active_groups',
'title' => t('Active groups'),
'weight' => -85,
);
$groups['active groups members'] = array(
'items callback' => 'activity_log_eg_active_groups_members',
'title' => t('Active group members'),
'weight' => -80,
);
}
if ($ur) {
$groups['acting user relationships'] = array(
'items callback' => 'activity_log_eg_acting_user_rels',
'title' => t("The acting user's relationships"),
'expose fields' => array('acting_uid'),
'weight' => -75,
);
$groups['custom user relationships'] = array(
'items callback' => 'activity_log_eg_custom_user_rels',
'title' => t("A custom user's relationships"),
'expose fields' => array('id'),
'weight' => -70,
);
$ur_types = user_relationships_types_load();
foreach ($ur_types as $type) {
Expand All @@ -63,12 +70,14 @@ function activity_log_entity_groups($stream_owner = TRUE) {
'title' => t("The acting user's %type relationships", array('%type' => $type->name)),
'expose fields' => array('acting_uid'),
'additional arguments' => array($type),
'weight' => -65,
);
$groups['custom user relationships '. $type->rtid] = array(
'items callback' => 'activity_log_eg_custom_user_rels_type',
'title' => t("A custom user's %type relationships", array('%type' => $type->name)),
'expose fields' => array('id'),
'additional arguments' => array($type),
'weight' => -60,
);
}
}
Expand All @@ -77,61 +86,71 @@ function activity_log_entity_groups($stream_owner = TRUE) {
'items callback' => 'activity_log_eg_active_groups_rels_acting_user',
'title' => t('Members of active groups who have a relationship with the acting user'),
'expose fields' => array('acting_uid'),
'weight' => -55,
);
$groups['active groups relationships custom user'] = array(
'items callback' => 'activity_log_eg_active_groups_rels_custom_user',
'title' => t('Members of active groups who have a relationship with a custom user'),
'expose fields' => array('id'),
'weight' => -50,
);
foreach ($ur_types as $type) {
$groups['active groups relationships '. $type->rtid .' acting user'] = array(
'items callback' => 'activity_log_eg_active_groups_rels_type_acting_user',
'title' => t('Members of active groups who have a %type relationship with the acting user', array('%type' => $type->name)),
'expose fields' => array('acting_uid'),
'additional arguments' => array($type),
'weight' => -45,
);
$groups['active groups relationships '. $type->rtid .' custom user'] = array(
'items callback' => 'activity_log_eg_active_groups_rels_type_custom_user',
'title' => t('Members of active groups who have a %type relationship with a custom user', array('%type' => $type->name)),
'expose fields' => array('id'),
'additional arguments' => array($type),
'weight' => -40,
);
}
}
if ($co) {
$groups['node commenters'] = array(
'items callback' => 'activity_log_eg_node_commenters',
'title' => t('Other people who have commented on this node (including the node author)'),
'weight' => -35,
);
}
if ($tx) {
$groups['node terms'] = array(
'items callback' => 'activity_log_eg_node_terms',
'title' => t('The taxonomy terms used in a node'),
'weight' => -30,
);
}
if ($fc) {
$groups['status commenters'] = array(
'items callback' => 'activity_log_eg_status_commenters',
'title' => t('Other people who have commented on this status (including the sender and recipient)'),
'weight' => -25,
);
}
if ($ft) {
$groups['mentioned users'] = array(
'items callback' => 'activity_log_eg_mentioned_users',
'title' => t('The users @mentioned in a status'),
'weight' => -20,
);
$groups['hashtag terms'] = array(
'items callback' => 'activity_log_eg_hashtag_terms',
'title' => t('The taxonomy terms corresponding to the #hashtags in a status'),
);
}
if ($tx) {
$groups['node terms'] = array(
'items callback' => 'activity_log_eg_node_terms',
'title' => t('The taxonomy terms used in a node'),
'weight' => -15,
);
}
if (!$stream_owner) {
unset($groups['active groups'], $groups['hashtag terms'], $groups['node terms']);
unset($groups['active groups'], $groups['hashtag terms'], $groups['node terms'], $groups['custom']['expose fields'][1]);
$groups['target entity']['title'] = t('The user on which the action was performed, if applicable');
$groups['everyone'] = array(
'items callback' => 'activity_log_eg_everyone',
'title' => t('Everyone'),
'weight' => -105,
);
}
return $groups;
Expand All @@ -140,7 +159,7 @@ function activity_log_entity_groups($stream_owner = TRUE) {
/**
* Returns the entitity IDs for the Custom group.
*/
function activity_log_eg_custom($event, $settings, $id, $type) {
function activity_log_eg_custom($event, $settings, $id, $type = 'user') {
return array($type => array($id));
}

Expand Down
23 changes: 8 additions & 15 deletions activity_log.install
Expand Up @@ -100,20 +100,6 @@ function activity_log_schema() {
'default' => 0,
'description' => 'The ID of the user who took the action.',
),
'stream_owner_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The ID of the entity in whose stream this record should appear.',
),
'stream_owner_type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type of the stream owner.',
),
'target_id' => array(
'type' => 'int',
'unsigned' => TRUE,
Expand Down Expand Up @@ -145,7 +131,6 @@ function activity_log_schema() {
'tid' => array('tid'),
'created' => array('created'),
'acting_uid' => array('acting_uid'),
'stream_owner_id' => array('stream_owner_id'),
'target_id' => array('target_id'),
),
'primary key' => array('aid'),
Expand Down Expand Up @@ -199,6 +184,13 @@ function activity_log_schema() {
'default' => '',
'description' => 'The entity type of the stream owner.',
),
'viewer_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The ID of the user to whom this message will appear.',
),
'target_id' => array(
'type' => 'int',
'unsigned' => TRUE,
Expand All @@ -225,6 +217,7 @@ function activity_log_schema() {
'tid' => array('tid'),
'last_updated' => array('last_updated'),
'stream_owner_id' => array('stream_owner_id'),
'viewer_id' => array('viewer_id'),
'target_id' => array('target_id'),
'acting_uid' => array('acting_uid'),
),
Expand Down
11 changes: 9 additions & 2 deletions activity_log.module
Expand Up @@ -294,9 +294,7 @@ function activity_log_evaluate_record($record) {
$master_element = array('#settings' => array(
'grouping' => array(
'group_summary' => $record->group_summary,
'group_template' => $record->group_template,
),
'template' => $record->template,
'visibility' => array(
'stream_owner_id' => '',
'viewer_id' => '',
Expand All @@ -305,6 +303,15 @@ function activity_log_evaluate_record($record) {
'tid' => $record->tid,
'#eval input' => $record->eval_input,
));
// Use the template for the right language. (template, grouping|group_template)
$user_lang = user_preferred_language($GLOBALS['user'])->language;
$default_lang = language_default('language');
$lang_templates = unserialize($record->template);
$lang_group_templates = unserialize($record->group_template);
$master_element['#settings']['template'] =
empty($lang_templates[$user_lang]) ? $lang_templates[$default_lang] : $lang_templates[$user_lang]; // fall back to English
$master_element['#settings']['grouping']['group_template'] =
empty($lang_group_templates[$user_lang]) ? $lang_group_templates[$default_lang] : $lang_group_templates[$user_lang]; // fall back to English
// Evaluate all of our grouped events.
$template = '';
$group_template = '';
Expand Down

0 comments on commit 5beff8a

Please sign in to comment.