function preProcess()
 {
     $this->setDefaults(array('hh_mode' => CRM_Householdmerge_Logic_Configuration::getHouseholdMode(), 'hh_head_mode' => CRM_Householdmerge_Logic_Configuration::getHouseholdHeadMode(), 'hh_member_relation' => CRM_Householdmerge_Logic_Configuration::getHeadRelationID(), 'hh_head_relation' => CRM_Householdmerge_Logic_Configuration::getMemberRelationID()));
 }
 /**
  * Identify the contact to be considered the HEAD under the given member_data objects
  * 
  * @return int  contact_id of the head
  */
 protected function identifyHead(&$members)
 {
     $method = CRM_Householdmerge_Logic_Configuration::getHouseholdHeadMode();
     if ($method == 'topdonor2y_m') {
         // init donations array
         $donations = array();
         foreach ($members as $member_id => $member) {
             $donations[$member_id] = 0;
         }
         $contact_ids = implode(',', array_keys($members));
         $td_amounts_sql = "\n          SELECT contact_id AS contact_id, \n                 SUM(total_amount) AS amount\n           FROM civicrm_contribution\n          WHERE contact_id IN ({$contact_ids})\n            AND (is_test IS NULL OR is_test = 0)\n            AND (contribution_status_id = 1)\n            AND (receive_date BETWEEN (NOW() - INTERVAL 2 YEAR) AND NOW())\n          GROUP BY contact_id;\n          ";
         $td_amounts = CRM_Core_DAO::executeQuery($td_amounts_sql);
         while ($td_amounts->fetch()) {
             $donations[$td_amounts->contact_id] = $td_amounts->amount;
         }
         // now determin the head
         $topdonor_id = NULL;
         $topdonor_amount = NULL;
         foreach ($donations as $member_id => $donation_amount) {
             if ($donation_amount > $topdonor_amount || $topdonor_amount === NULL) {
                 $topdonor_id = $member_id;
                 $topdonor_amount = $donation_amount;
             } elseif ($donation_amount == $topdonor_amount) {
                 if ($members[$member_id]['gender_id'] == 2) {
                     // if donor has same amount and is male => take over
                     $topdonor_id = $member_id;
                     $topdonor_amount = $donation_amount;
                 }
             }
         }
         // now $topdonor_id should be the HEAD
         return $topdonor_id;
     } else {
         error_log("UNDEFINED METHOD TO DETERMINE HEAD: {$method}");
         return reset(array_keys($members));
     }
 }