<?phpclasswebform_civirules_trigger{privatestatic$singleton;private$submission;privatefunction__construct(){}/** * @return \webform_civirules_trigger */publicstaticfunctiongetSingleton(){if(!self::$singleton){self::$singleton=newwebform_civirules_trigger();}returnself::$singleton;}/** * @return \webform_civirules_trigger */publicfunctionsetSubmission($submission){$this->submission=$submission;return$this;}publicfunctiontrigger(){if(!$this->submission||!$this->submission->sid||!$this->submission->nid){return;}$db=db_query('SELECT * FROM {webform_civicrm_submissions_civirules_trigger} WHERE sid = :sid',array(':sid'=>$this->submission->sid));if(($row=$db->fetchAssoc())&&$row->trigger_fired){// This submission did already fire a civirules trigger.return;}$db=db_query('SELECT * FROM {webform_civicrm_submissions} WHERE sid = :sid',array(':sid'=>$this->submission->sid));if($row=$db->fetchAssoc()){// First update webform_civicrm_submissions_civirules_trigger so that we do not trigger again on this submission.$webform_civicrm_submissions_civirules_trigger=array('sid'=>$this->submission->sid,'trigger_fired'=>1,);drupal_write_record('webform_civicrm_submissions_civirules_trigger',$webform_civicrm_submissions_civirules_trigger);$data=unserialize($row['civicrm_data']);$contacts=array();if($row['contact_id']){foreach(explode('-',trim($row['contact_id'],'-'))as$c=>$cid){$contacts[$c]=$cid;}foreach($contactsas$c=>$cid){if($cid){$trigger=newCRM_WebformCivirules_Trigger();$trigger->triggerTrigger($cid,$c,$data,$contacts,$this->submission->sid,$this->submission->nid);}}}}}}