0

I am using Rules Scheduler and Flag to handle troublesome users by issuing a one-week ban. I flag the user with a temporary ban flag, and then the user sees a special block that says "You have been temporarily banned for being a jerk." I have a rule that automatically schedules the user to be unflagged one week later.

However, I want to show users how much time they have remaining. My first thought was to create a block/content pane in Views, so I made a view of type Rules scheduler, but when I went to add the UID as a Contextual Filter, I realized that Rules scheduler views only provide these options:

  • Null
  • Component name

Is there some other way I can show the user how much time they have until an arbitrary Rules Scheduler action will be evaluated?

What I tried

Based on this question, I added a filter for user-provided identifier, set the value to a garbage value (punishme), and added views_pre_view() as follows:

function MYMODULE_views_pre_view(&$view) {
  global $user;
  if ($view->name == 'punishment_show_details') {
    if ($user->uid) {
      $newvalue = 'punish/' . $user->uid;
      $view->display[$view->current_display]->handler->options['filters']['rules_scheduler']['value'] = 'punish/' . $user->uid;
    }
  }
}

However, this doesn't work; for some reason, when I dpm() the view, the value for filters is empty.

2 Answers 2

0

Why not add a user profile field that stores the ban removal date? Then you could use the "Time ago" formatter with the "Time hence" setting and then just set or unset it using the rule (and it's associated de-ban rule). You can show that field using Views and/or on the user's profile page. Or panels. Or custom code... etc.

2
  • I'll consider this, but my general question is about how to show users the date that a rule that applies to them has been scheduled for, which might be necessary in a variety of other situations where your suggested approach might not work. Commented Nov 1, 2015 at 14:49
  • Since all of the Scheduler data is stored inside the data column, you'd have to iterate through every Scheduled rule entity and find the matching rule and the grab the information from it. It'd be far easier, faster, and simpler, to just take the rules that creates the scheduled rule and write the metadata into a place like the user profile. Rules and the rules scheduler just isn't currently built for this. But if you wanted to make it more generic, you'd still need to capture the rule save, grab the info you want, and write it somewhere.
    – nvahalik
    Commented Nov 2, 2015 at 2:05
0

I solved this by creating a view with a filter of user-provided identifier, setting the default value to "changeme," and then adding the following code to a custom module to provide the correct identifier (to match the identifiers used to schedule my rules):

function MYMODULE_views_pre_view(&$view) {
  global $user;
  if ($view->name == 'punishment_show_details') {
    if ($user->uid) {
      $newvalue = 'punish/' . $user->uid;
      $view->display[$view->current_display]->handler->options['filters']['identifier']['value'] = 'punish/' . $user->uid;
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.