Skip to content

Commit

Permalink
Add WIP of automated missed bucket emails
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisarusso committed Jul 3, 2015
1 parent 2feea47 commit 96edd7c
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ function compost_customizations_cron() {
}

compost_customizations_queue_reminders();

compost_customizations_queue_forgotten_bucket_emails();
}

// Implementation per http://rbayliss.net/drupal-queue-api
Expand Down Expand Up @@ -690,4 +692,51 @@ function compost_customizations_queue_reminders() {
}
}
}
}

/**
* Function to queue up text and email reminders from cron runs.
*/
function compost_customizations_queue_forgotten_bucket_emails() {

// Retrieve all members who have been marked as a forgotten
// bucket but have not yet been notified
$query = new EntityFieldQuery();

$query->entityCondition('entity_type', 'user')
->fieldCondition('field_active', 'value', 1);
//->fieldCondition('field_reminded_about_forgotten_b', 'value', 0);

$result = $query->execute();
$user_uids = array_keys($result['user']);
$users = entity_load('user', $user_uids);

foreach ($users as $user) {
if (empty($user->field_forgotten_bucket)) {
continue;
}

foreach ($user->field_forgotten_bucket[LANGUAGE_NONE] as $forgotten_bucket) {
$collection_id = $forgotten_bucket['value'];
$forgotten_bucket_entity = entity_load('field_collection_item', array($collection_id));
$reminded = $forgotten_bucket_entity[$collection_id]->field_reminded_about_forgotten_b[LANGUAGE_NONE][0]['value'];
// If they weren't reminded, let's queue them up, and set them to reminded
if (!$reminded) {
// @todo: Queue email
$user_wrapper = entity_metadata_wrapper('user', $user);
$raw_collection = $user_wrapper->field_forgotten_bucket->value();
//$raw_collection[0]->field_reminded_about_forgotten_b->set(1);
$collection = entity_metadata_wrapper('field_collection_item', $raw_collection[0]);
$collection->field_reminded_about_forgotten_b->set(1);
// @todo: remove after finishing
if ($collection_id == 6) {
// Set to reminded
$collection->save();
}


$been = 'reminded?';
}
}
}
}

0 comments on commit 96edd7c

Please sign in to comment.