You are here

function classified_notifications_classified_purge_alter in Classified Ads 7.3

Same name and namespace in other branches
  1. 6.3 modules/classified_notifications/classified_notifications.module \classified_notifications_classified_purge_alter()

Implements hook_classified_purge_alter().

File

modules/classified_notifications/classified_notifications.module, line 107
Optional notification features for classified module.

Code

function classified_notifications_classified_purge_alter($ads_bunch) {
  foreach ($ads_bunch as $uid => $ads) {

    // TODO Convert "user_load" to "user_load_multiple" if "$uid" is not a uid.
    // To return a single user object, wrap "user_load_multiple" with
    // "array_shift" or equivalent.
    // Example: array_shift(user_load_multiple(array(), $uid))
    $account = user_load($uid);
    $account->ads = $ads;

    // Do not notify anonyms or users without mail.
    if (!$account->uid || !$account->mail) {
      continue;
    }
    $params['account'] = $account;
    $message = drupal_mail('classified_notifications', 'purge', $account->mail, user_preferred_language($account), $params, NULL, TRUE);
    $job = array(
      'description' => t('Classified Ads: purge notifications for !name (@mail)', array(
        '!name' => l($account->name, 'user/' . $account->uid),
        '@mail' => $account->mail,
      )),
      'key' => 'purge',
      'message' => $message,
    );
    $queue = DrupalQueue::get('classified_notifications', TRUE);
    $queue
      ->createQueue();
    $queue
      ->createItem($job);
  }
}