/**
 * Function to validate parameters
 *
 * @param array $params
 * @return string $errorMessage
 */
function _validateParams($params)
{
    $errorMessage = '';
    if (!isset($params['id']) && empty($params['label'])) {
        return ts('Label can not be empty when adding a new CiviRule Trigger');
    }
    if (_checkClassNameObjectNameOperation($params) == FALSE) {
        return ts('Either class_name or a combination of object_name and op is mandatory');
    }
    if (isset($params['cron']) && $params['cron'] == 1) {
        $params['object_name'] = null;
        $params['op'] = null;
        if (!isset($params['class_name']) || empty($params['class_name'])) {
            return ts('For a cron type trigger the class_name is mandatory');
        }
    }
    if (isset($params['object_name']) && !empty($params['object_name'])) {
        $extensionConfig = CRM_Civirules_Config::singleton();
        if (!in_array($params['object_name'], $extensionConfig->getValidTriggerObjectNames())) {
            return ts('ObjectName passed in parameters (' . $params['object_name'] . ')is not a valid object for a CiviRule Trigger');
        }
    }
    if (isset($params['op']) && !empty($params['op'])) {
        $extensionConfig = CRM_Civirules_Config::singleton();
        if (!in_array($params['op'], $extensionConfig->getValidTriggerOperations())) {
            return ts('Operation passed in parameters (' . $params['op'] . ')is not a valid operation for a CiviRule Trigger');
        }
    }
    if (CRM_Civirules_BAO_Trigger::triggerExists($params) == TRUE) {
        return ts('There is already a trigger for this class_name or combination of object_name and op');
    }
    return $errorMessage;
}
 /**
  * Method post
  *
  * @param string $op
  * @param string $objectName
  * @param int $objectId
  * @param object $objectRef
  * @access public
  * @static
  */
 public static function post($op, $objectName, $objectId, &$objectRef)
 {
     $extensionConfig = CRM_Civirules_Config::singleton();
     if (!in_array($op, $extensionConfig->getValidTriggerOperations())) {
         return;
     }
     //find matching rules for this objectName and op
     $triggers = CRM_Civirules_BAO_Rule::findRulesByObjectNameAndOp($objectName, $op);
     foreach ($triggers as $trigger) {
         if ($trigger instanceof CRM_Civirules_Trigger_Post) {
             $trigger->triggerTrigger($op, $objectName, $objectId, $objectRef);
         }
     }
 }