/** * @param LabelableBaseModelWithAttributes $t_instance * @param SimpleXMLElement $po_labels * @param array $pa_locales array * @param bool $pb_force_preferred * @return bool */ protected static function addLabelsFromXMLElement($t_instance, $po_labels, $pa_locales, $pb_force_preferred = false) { require_once __CA_LIB_DIR__ . "/ca/LabelableBaseModelWithAttributes.php"; if (!$t_instance instanceof LabelableBaseModelWithAttributes) { return false; } /** @var LabelableBaseModelWithAttributes $t_instance */ foreach ($po_labels->children() as $vo_label) { $va_label_values = array(); $vs_locale = self::getAttribute($vo_label, "locale"); $vn_locale_id = $pa_locales[$vs_locale]; $vb_preferred = self::getAttribute($vo_label, "preferred"); if ($pb_force_preferred || (bool) $vb_preferred || is_null($vb_preferred)) { $vb_preferred = true; } else { $vb_preferred = false; } foreach ($vo_label->children() as $vo_field) { $va_label_values[$vo_field->getName()] = (string) $vo_field; } $va_existing_labels = $vb_preferred ? $t_instance->getPreferredLabels(array($vn_locale_id)) : $t_instance->getNonPreferredLabels(array($vn_locale_id)); if ($va_existing_labels && ($vn_label_id = $va_existing_labels[(int) $t_instance->getPrimaryKey()][(int) $vn_locale_id][0]['label_id'])) { $t_instance->editLabel($vn_label_id, $va_label_values, $vn_locale_id, null, $vb_preferred); } else { $t_instance->addLabel($va_label_values, $vn_locale_id, false, $vb_preferred); } } return true; }