public static function importTemplates($objTemplates, $intAccountId, &$arrTemplateIds, &$arrTemplateFieldIds, &$arrLinkFieldIds, $intParentId = 0) { foreach ($objTemplates->childNodes as $templateNode) { $objTemplate = new Template(); $objTemplate->setAccountId($intAccountId); $objTemplate->setParentId($intParentId); $objTemplate->setIsPage($templateNode->getAttribute("isPage")); $objTemplate->setIsContainer($templateNode->getAttribute("isContainer")); $objTemplate->setForceCreation($templateNode->getAttribute("forceCreation")); $objTemplate->setName($templateNode->getAttribute("name")); $objTemplate->setApiName($templateNode->getAttribute("apiName")); $objTemplate->setDescription($templateNode->getAttribute("description")); $objTemplate->setSort($templateNode->getAttribute("sort")); $objTemplate->save(); $arrTemplateIds[$templateNode->getAttribute("id")] = $objTemplate->getId(); //*** Add fields to the template. foreach ($templateNode->childNodes as $fieldsNode) { switch ($fieldsNode->nodeName) { case "fields": foreach ($fieldsNode->childNodes as $fieldNode) { $objField = new TemplateField(); $objField->setTemplateId($objTemplate->getId()); $objField->setRequired($fieldNode->getAttribute("required")); $objField->setName($fieldNode->getAttribute("name")); $objField->setApiName($fieldNode->getAttribute("apiName")); $objField->setDescription($fieldNode->getAttribute("description")); $objField->setTypeId($fieldNode->getAttribute("typeId")); $objField->setUsername($fieldNode->getAttribute("username")); $objField->setSort($fieldNode->getAttribute("sort")); $objField->save(); $arrTemplateFieldIds[$fieldNode->getAttribute("id")] = $objField->getId(); if ($fieldNode->getAttribute("typeId") == FIELD_TYPE_LINK) { array_push($arrLinkFieldIds, $fieldNode->getAttribute("id")); } //*** Add values to the field. foreach ($fieldNode->childNodes as $valuesNode) { switch ($valuesNode->nodeName) { case "values": foreach ($valuesNode->childNodes as $valueNode) { $objValue = new TemplateFieldValue(); $objValue->setName($valueNode->getAttribute("name")); $objValue->setValue($valueNode->getAttribute("value")); $objValue->setFieldId($objField->getId()); $objValue->save(); } break; } } } break; case "templates": self::importTemplates($fieldsNode, $intAccountId, $arrTemplateIds, $arrTemplateFieldIds, $arrLinkFieldIds, $objTemplate->getId()); break; } } } }