$parentResource->save(); $parentID = $parentResource->resourceID; $parentInserted++; } elseif ($numberOfParents == 1) { // Else, attach the resource to its parent. $parentResource = $resourceObj->getResourceByTitle($data[$_POST['parentResource']]); $parentID = $parentResource[0]->resourceID; $parentAttached++; } if ($numberOfParents == 0 || $numberOfParents == 1) { $resourceRelationship = new ResourceRelationship(); $resourceRelationship->resourceID = $resource->resourceID; $resourceRelationship->relatedResourceID = $parentID; $resourceRelationship->relationshipTypeID = '1'; //hardcoded because we're only allowing parent relationships if (!$resourceRelationship->exists()) { $resourceRelationship->save(); } } } } $row++; } print "<h2>Results</h2>"; print "<p>" . ($row - 1) . " rows have been processed. {$inserted} rows have been inserted.</p>"; print "<p>{$parentInserted} parents have been created. {$parentAttached} resources have been attached to an existing parent.</p>"; print "<p>{$organizationsInserted} organizations have been created"; if (count($arrayOrganizationsCreated) > 0) { print " (" . implode(',', $arrayOrganizationsCreated) . ")"; } print ". {$organizationsAttached} resources have been attached to an existing organization.</p>";