From 4eb178a51f91dec315ce3de7089bffd6bcbf8d22 Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 30 Jul 2010 17:58:44 -0300 Subject: Fixes around getEntity --- lib/sfIsisImporter.class.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'lib/sfIsisImporter.class.php') diff --git a/lib/sfIsisImporter.class.php b/lib/sfIsisImporter.class.php index 4fd6353..45046db 100644 --- a/lib/sfIsisImporter.class.php +++ b/lib/sfIsisImporter.class.php @@ -243,17 +243,39 @@ class sfIsisImporter extends IsisConnector } } + /** + * Get an existing entity. + * + * @param string $entity Entity name + * @param string $value Value to search for + * @param string $by Field to search $value + * @return mixed Entity data or false + */ + public function getEntity($entity, $value, $by = 'name') + { + $findby = 'findOneBy'. ucfirst($by); + $data = Doctrine_Core::getTable($entity)->{$findby}($value); + + if (!$data) + { + return $data; + } + + return false; + } + /** * Add a new entity into the database if needed, returning * the corresponding object. * - * @param string $name Genre name - * @return Genre Genre data + * @param string $entity Entity name + * @param string $name Name value + * @return object Entity data */ public function addEntity($entity, $name) { $name = $this->entityName($name); - $data = Doctrine_Core::getTable($entity)->findOneByName($name); + $data = $this->getEntity($entity, $name); if (!$data) { -- cgit v1.2.3