/** * Check for translations of sf_src_value (text) that with an explicitly * set sf_fv_id. * * @param array $data * @param int $row * @return boolean|string */ public function validate_object($data, $row) { $errors = array(); // look for facts foreach ($this->mapping as $fact_id => $def) { $from = $data[$def['trans_from']]; $to = $data[$def['trans_to']]; // if both are set, make sure they don't conflict if ($from && strlen($from) && $to && strlen($to)) { $fv_id = TranslationMap::find_translation($fact_id, $from); if ($fv_id && $fv_id != $to) { $confl = $this->headers[$def['trans_from']] . ' and ' . $this->headers[$def['trans_to']]; $errors[] = "(conflicting translated value between {$confl})"; } } } // combine any errors to return if (count($errors) > 0) { return "Errors on row {$row}: " . implode(', ', $errors); } else { return true; } }
/** * Get facts from row object * * @param array $obj row object * @param int $idx row index * @param array $fields field mapping def * @return array data */ protected function get_facts($obj, $idx, $fields) { $facts = array(); // determine if there are any facts to write foreach ($this->map_facts as $fid => $mapcols) { $sf = array(); foreach ($mapcols as $colidx => $fldname) { $val = $obj[$colidx]; if ($val && strlen($val)) { $sf[$fldname] = $val; } } // normalize and translate src_value text if (isset($sf['sf_src_value'])) { $sf['sf_src_value'] = air2_str_clean($sf['sf_src_value']); $fv_id = TranslationMap::find_translation($fid, $sf['sf_src_value']); if ($fv_id) { $sf['sf_fv_id'] = $fv_id; } } // ignore empty/null facts if (count($sf)) { $sf['TankSource'] = "TankSource_{$idx}"; $sf['tf_fact_id'] = $fid; $facts["TankFact_{$idx}_{$fid}"] = $sf; } } // return false for no data if (count($facts) == 0) { return false; } else { return $facts; } }