Exemplo n.º 1
0
 /** 
  * this matcher does not really create suggestions, but rather enriches the parsed data
  */
 public function analyse(CRM_Banking_BAO_BankTransaction $btx, CRM_Banking_Matcher_Context $context)
 {
     $config = $this->_plugin_config;
     $data_parsed = $btx->getDataParsed();
     // itreate trough all rules
     foreach ($this->_plugin_config->rules as $rule) {
         if (empty($rule->fields)) {
             $fields = array('purpose');
         } else {
             $fields = $rule->fields;
         }
         // replace [[...]] style variables in the pattern
         $pattern = $rule->pattern;
         $variables = $this->getVariableList();
         foreach ($variables as $variable) {
             if (preg_match("#\\[\\[{$variable}\\]\\]#", $pattern)) {
                 $value = $this->getVariable($variable);
                 $pattern = preg_replace("#\\[\\[{$variable}\\]\\]#", print_r($value, 1), $pattern);
             }
         }
         // appy rule to all the fields listed...
         foreach ($fields as $field) {
             if (isset($data_parsed[$field])) {
                 $field_data = $data_parsed[$field];
                 $matches = array();
                 // match the pattern on the given field data
                 $match_count = preg_match_all($pattern, $field_data, $matches);
                 // and execute the actions for each match...
                 for ($i = 0; $i < $match_count; $i++) {
                     $this->processMatch($matches, $i, $data_parsed, $rule);
                 }
             }
         }
     }
     // save changes and that's it
     $btx->setDataParsed($data_parsed);
 }