protected function importTemplates(&$ids, &$errors, $children)
{
$type = ucfirst(substr($children['name'], 0, -1));
$class = 'Gc\\' . $type . '\\Model';
foreach ($children['children'] as $child) {
$model = $class::fromIdentifier((string) $child->identifier);
$attributes = $child->attributes();
$id = (int) $attributes['id'];
if (empty($model)) {
$model = $class::fromId($id);
if (empty($model)) {
$model = new $class();
}
}
$identifier = (string) $child->identifier;
$name = (string) $child->name;
$model->addData(array('name' => empty($name) ? null : $name, 'identifier' => empty($identifier) ? null : $identifier, 'description' => (string) $child->description, 'content' => (string) $child->content));
try {
if (!empty($model)) {
$model->save();
$ids[$children['name']][$id] = $model->getId();
}
} catch (Exception $e) {
$errors[] = sprintf($this->serviceLocator->get('MvcTranslator')->translate('Cannot save %s with identifier (%s) or id (%d)'), $type, $identifier, $id);
}
}
}