3

By using Rules Once per Day module, logged in user would be redirected to profile page on specific day. My issue is, every time when user logged in to the site, the user is redirected to profile page.

But I want this rule to work on specific days, like Monday and Thursday. How I can handle this without Rules Once per Day module?

I want to this functionality works at only once. How can I do this? Any suggestions?

  • I fixed this scenario by setting the flag on User and update the Rule for logged in user using Rules Once per Day module. So, when every time user logged in, Rule will check the user is flagged or not if flagged then redirect once and in action set user unflagged again so every time user will be check. – latikas Jul 24 '15 at 8:05
2

You could do it simply by rules module (no extra module required):

  1. Create a new rule.
  2. Select event - user has logged in
  3. Could add in a condition, check for a role for eg. This step is optional, and can be ignored if not required.
  4. Select an action - Page redirect, and add the url /user to the destination.
  5. Make sure you enable the rule.
  6. Test, test, and test ;-)

If you want to schedule this view to run on a particular day you could check on Scheduling rules. There is also a very good video from nodeone about the same.

  • I want to work this rule on specific day itself like Monday and Thursday. How i can handle this without Rules Once per Day module? Please suggest. – latikas Jul 22 '15 at 10:56
  • @latikas edited the question on how a rule could be scheduled. Check it out – AjitS Jul 22 '15 at 11:01
1

Even though the Rules module is one of those amazing Drupal modules, it does have some challenges with processing dates ... (= open issues in its issue queue).

Therefor consider using an approach as detailed in the (great) answer to the question about Rule to check if a date value is a specific day of the week ...

Another option is to write your own module for this. Refer to Drupal custom Rules how to write your own events conditions, actions and custom object (+custom tokens) for a great tutorial about how to do so. The main steps that are detailed in this tutorial are further described below (with the code included below quoted from that link).

Part 1: Defining the Event, Condition and Action

Define the Rules Event

/**
* Implementation of hook_rules_event_info().
* @ingroup rules
*/
function your_module_rules_event_info() {
  return array(
    'your_module_package_bought' => array(
      'label' => t('A package was bought'),
      'module' => 'your_module',
      'arguments' => array(
        'acting_user' => array('type' => 'user', 'label' => t('The user who bought the package.')),
        'package' => array('type' => 'package', 'label' => t('The purchased package.')),
      ),
    ),
  );
}

Define the Rules Condition

/**
 * implementation of hook_rules_condition_info()
 */
function your_module_rules_condition_info() {
  return array(
    'your_module_condition_package_type' => array(
      'label' => t('Type of the package'),
      'arguments' => array(
        'package_id' => array('type' => 'value', 'label' => t('The type of the purchased package.')),
        'package_type' => array('type' => 'string', 'label' => t('The type of the purchased package is')),
      ),
      'module' => 'your_module',
    ),
  );
}

Define the Rules Action

/**
 * Implementation of hook_rules_action_info().
 */
function packages_rules_action_info() {
  return array(
    'your_module_action_change_order_status' => array(
      'label' => t('Change the order status'),
      'arguments' => array(
        'order' => array('type' => 'value', 'label' => t('The order object.')),
      ),
      'module' => 'your_module',
    ),
  );
}

Part 2: Coding the custom Event, Condition and Action

Event:

Somewhere in your custom module, you need to include logic to trigger the event, with something similar to this example (note the your_module_package_bought in it):

  //here the code for buying a package will be located
  //when that code returns that a package was bought trigger the rule
  $order = order_load($oid);//$oid will be the id of the order made
  $package = package_load($pid);//pid will be the id of the bought package
  global $user;
  rules_invoke_event('your_module_package_bought', $user, $package, $order);

Condition:

To evaluate the Rules condition (to check if it is TRUE or FALSE), the function your_module_condition_package_type is executed using the arguments provided. Here is an example of how such function could look like:

function your_module_condition_package_type($pid, $type) {
  $package = package_load($pid);
  return ($package->type == $type) ? true : false;
}

Action:

Somewhere in your custom module, you need to include logic to perform the actual action, in this example it should be done within the function named your_module_action_change_order_status.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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