From bb31ca3127470a2abf15b5110e8b80f9fdc6e4a3 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 21 Sep 2010 16:32:06 -0300 Subject: Adding method addOneToManySubfields --- lib/sfIsisImporterRelations.class.php | 37 ++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/sfIsisImporterRelations.class.php b/lib/sfIsisImporterRelations.class.php index 956d287..bf41120 100644 --- a/lib/sfIsisImporterRelations.class.php +++ b/lib/sfIsisImporterRelations.class.php @@ -44,10 +44,12 @@ class sfIsisImporterRelations extends sfIsisImporterEntities { } /** - * Add simple entities data into the model. + * Add simple entities data into the model using main item data. * - * @param object $model Model - * @param array $field Field data from ISIS database schema + * @param object $model Model + * @param array $field Field data from ISIS database schema + * @param string $entity Entity name + * @param string $key Optional data key */ public function addOneToManyMain(&$model, array $field, $entity, $key = 'name') { @@ -60,6 +62,35 @@ class sfIsisImporterRelations extends sfIsisImporterEntities { } } + /** + * Add simple entities data into the model using subfield data. + * + * @param object $model Model + * @param array $field Field data from ISIS database schema + * @param string $entity Entity name + */ + public function addOneToManySubfields(&$model, array $field, $entity) + { + $relations = array(); + + foreach (new IsisSubfieldIterator($this->isis, $field) as $row => $subfield) + { + if (!isset($relations[$row])) + { + // Initialize a new relation. + $relations[$row] = $this->addOneToMany($model, $entity); + } + + $relations[$row]->{$subfield} = $this->isis->getSubfield($field, $subfield, $row); + } + + // Save all relations. + foreach($relations as $relation) + { + $relation->save(); + } + } + /** * Import a single value to a many to many data model. * -- cgit v1.2.3