aboutsummaryrefslogtreecommitdiff
path: root/lib/sfIsisImporterRelations.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sfIsisImporterRelations.class.php')
-rw-r--r--lib/sfIsisImporterRelations.class.php33
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/sfIsisImporterRelations.class.php b/lib/sfIsisImporterRelations.class.php
index 8282845..6912305 100644
--- a/lib/sfIsisImporterRelations.class.php
+++ b/lib/sfIsisImporterRelations.class.php
@@ -61,15 +61,30 @@ class sfIsisImporterRelations extends sfIsisImporterEntities {
}
/**
- * Import a single many to many data.
+ * Import a single value to a many to many data model.
*
* @param object $model Model
* @param mixed $values Values to be added
* @param string $relation Relation name
+ * @param string $key Value key
*/
- public function addManyToMany(&$model, $value, $relation)
+ public function addManyToMany(&$model, $value, $relation, $key = 'name')
{
- $method = 'add'. $relation;
+ return $this->addToSharedModel($model, $value, $relation, $key, 'add');
+ }
+
+ /**
+ * Import a single value to a shared data model.
+ *
+ * @param object $model Model
+ * @param mixed $values Values to be added
+ * @param string $relation Relation name
+ * @param string $key Value key
+ * @param string $strategy Strategy do add the content into the database
+ */
+ public function addToSharedModel(&$model, $value, $relation, $key = 'name', $strategy = 'add')
+ {
+ $method = $strategy . $relation;
// Populate related data.
if (is_callable(array($this, $method)))
@@ -78,7 +93,7 @@ class sfIsisImporterRelations extends sfIsisImporterEntities {
}
else
{
- $data = $this->addEntity($relation, $value);
+ $data = $this->{$strategy .'Entity'}($relation, $value, $key);
}
// Get model and relation names and id fields.
@@ -101,12 +116,13 @@ class sfIsisImporterRelations extends sfIsisImporterEntities {
* @param object $model Model
* @param array $values Values to be added
* @param string $relation Relation name
+ * @param string $key Value key
*/
- public function addManyToManyEntities(&$model, array $values, $relation)
+ public function addManyToManyEntities(&$model, array $values, $relation, $key = 'name')
{
foreach ($values as $value)
{
- $this->addManyToMany($model, $value, $relation);
+ $this->addManyToMany($model, $value, $relation, $key);
}
}
@@ -116,12 +132,13 @@ class sfIsisImporterRelations extends sfIsisImporterEntities {
* @param object $model Model
* @param array $field Field data from ISIS database schema
* @param string $relation Relation name
+ * @param string $key Value key
*/
- public function addManyToManyMain(&$model, array $field, $relation)
+ public function addManyToManyMain(&$model, array $field, $relation, $key = 'name')
{
foreach (new IsisMainItemIterator($this, $field) as $value)
{
- $this->addManyToManyEntities($model, $this->explodeBrackets($value), $relation);
+ $this->addManyToManyEntities($model, $this->explodeBrackets($value), $relation, $key);
}
}
}