You are here

function redhen_engagement_contact_score in RedHen CRM 7

Return the engagement score for a contact.

Parameters

RedhenContact $contact: Contact to get a computed score for.

Return value

int A contact's engagement score.

1 call to redhen_engagement_contact_score()
RedhenEngagement::save in modules/redhen_engagement/lib/redhen_engagement.entity.inc
Override parent to update a contacts engagement score.

File

modules/redhen_engagement/redhen_engagement.module, line 312
RedhenEngagement hook implementations and API

Code

function redhen_engagement_contact_score(RedhenContact $contact) {
  $score = 0;
  $query = db_select('redhen_engagement', 'e')
    ->condition('contact_id', $contact->contact_id, '=');
  $query
    ->join('redhen_engagement_score', 's', 'e.engagement_score = s.name');
  $query
    ->addExpression('SUM(score)', 'score');
  $result = $query
    ->execute();
  if ($result && ($col = $result
    ->fetchCol())) {
    $score = reset($col);
  }
  return $score;
}