/**
     * Method to determine if the condition is valid
     *
     * @param CRM_Civirules_EventData_EventData $eventData
     * @return bool
     */
    public function isConditionValid(CRM_Civirules_EventData_EventData $eventData)
    {
        $isConditionValid = FALSE;
        $contact_id = $eventData->getContactId();
        /*
         * retrieve count of contributions for donor grouped by extracted YMD from receive_date
         */
        $query = 'SELECT COUNT(DISTINCT CONCAT(EXTRACT(YEAR FROM receive_date),
EXTRACT(MONTH FROM receive_date), EXTRACT(DAY FROM receive_date))) AS distinctDates
FROM civicrm_contribution WHERE contact_id = %1 AND civicrm_contribution.contribution_status_id = %2';
        $params = array(1 => array($contact_id, 'Positive'), 2 => array(CRM_Civirules_Utils::getContributionStatusIdWithName('Completed'), 'Positive'));
        $periodStartDate = CRM_CivirulesConditions_Utils_Period::convertPeriodToStartDate($this->conditionParams);
        $periodEndDate = CRM_CivirulesConditions_Utils_Period::convertPeriodToEndDate($this->conditionParams);
        if ($periodStartDate) {
            $query .= " AND DATE(`receive_date`) >= '" . $periodStartDate->format('Y-m-d') . "'";
        }
        if ($periodEndDate) {
            $query .= " AND DATE(`receive_date`) <= '" . $periodEndDate->format('Y-m-d') . "'";
        }
        $dao = CRM_Core_DAO::executeQuery($query, $params);
        if ($dao->fetch()) {
            switch ($this->conditionParams['operator']) {
                case 1:
                    if ($dao->distinctDates != $this->conditionParams['no_of_days']) {
                        $isConditionValid = TRUE;
                    }
                    break;
                case 2:
                    if ($dao->distinctDates > $this->conditionParams['no_of_days']) {
                        $isConditionValid = TRUE;
                    }
                    break;
                case 3:
                    if ($dao->distinctDates >= $this->conditionParams['no_of_days']) {
                        $isConditionValid = TRUE;
                    }
                    break;
                case 4:
                    if ($dao->distinctDates < $this->conditionParams['no_of_days']) {
                        $isConditionValid = TRUE;
                    }
                    break;
                case 5:
                    if ($dao->distinctDates <= $this->conditionParams['no_of_days']) {
                        $isConditionValid = TRUE;
                    }
                    break;
                default:
                    if ($dao->distinctDates == $this->conditionParams['no_of_days']) {
                        $isConditionValid = TRUE;
                    }
                    break;
            }
        }
        return $isConditionValid;
    }
 /**
  * Returns value of the field
  *
  * @param object CRM_Civirules_EventData_EventData $eventData
  * @return mixed
  * @access protected
  */
 protected function getFieldValue(CRM_Civirules_EventData_EventData $eventData)
 {
     $completed_status_id = CRM_Core_OptionGroup::getValue('contribution_status', 'completed', 'name');
     $contact_id = $eventData->getContactId();
     $sql = "SELECT SUM(`total_amount`)\n            FROM `civicrm_contribution`\n            WHERE `contribution_status_id` = %1 AND `contact_id` = %2";
     $params[1] = array($completed_status_id, 'Integer');
     $params[2] = array($contact_id, 'Integer');
     $periodStartDate = CRM_CivirulesConditions_Utils_Period::convertPeriodToStartDate($this->conditionParams);
     $periodEndDate = CRM_CivirulesConditions_Utils_Period::convertPeriodToEndDate($this->conditionParams);
     if ($periodStartDate) {
         $sql .= " AND DATE(`receive_date`) >= '" . $periodStartDate->format('Y-m-d') . "'";
     }
     if ($periodEndDate) {
         $sql .= " AND DATE(`receive_date`) <= '" . $periodEndDate->format('Y-m-d') . "'";
     }
     $total_amount = (double) CRM_Core_DAO::singleValueQuery($sql, $params);
     return $total_amount;
 }