From 58c0c37b33fc4521065ad06b4222fde3e71468e2 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 31 Aug 2010 18:22:58 -0300 Subject: Changes into relations api --- lib/sfIsisImporterEntities.class.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'lib/sfIsisImporterEntities.class.php') diff --git a/lib/sfIsisImporterEntities.class.php b/lib/sfIsisImporterEntities.class.php index 56c2883..cd66afd 100644 --- a/lib/sfIsisImporterEntities.class.php +++ b/lib/sfIsisImporterEntities.class.php @@ -126,24 +126,40 @@ class sfIsisImporterEntities extends IsisConnector { * * @param string $entity Entity name * @param string $name Name value + * @param string $key Value key * @return object Entity data */ - public function addEntity($entity, $name) + public function addEntity($entity, $name, $key = 'name') { $name = $this->entityName($name); - $data = $this->getEntity($entity, $name); + $data = $this->getEntity($entity, $name, $key); if (!$data) { $this->log("Adding new $entity $name."); - $data = new $entity(); - $data->name = $name; - $data->save(); + $data = $this->newEntity($entity, $name, $key); } return $data; } + /** + * Add a new entity into the database. + * + * @param string $entity Entity name + * @param string $name Name value + * @param string $key Value key + * @return object Entity data + */ + public function newEntity($entity, $name, $key = 'name') + { + $data = new $entity(); + $data->{$key} = $name; + $data->save(); + + return $data; + } + /** * Add an element into the database if needed, returning * the resulting object. -- cgit v1.2.3