aboutsummaryrefslogtreecommitdiff
path: root/lib/sfIsisImporterRelations.class.php
diff options
context:
space:
mode:
authorSilvio <s1lv10@uol.com.br>2010-08-31 18:22:58 -0300
committerSilvio <s1lv10@uol.com.br>2010-08-31 18:22:58 -0300
commit58c0c37b33fc4521065ad06b4222fde3e71468e2 (patch)
treeaa8e3d090cbe0c19f641954e3d754fddc62ff4c1 /lib/sfIsisImporterRelations.class.php
parent81cd263f4598115cc90817300f69a869fa5e444a (diff)
downloadsf_isis_importer_plugin-58c0c37b33fc4521065ad06b4222fde3e71468e2.tar.gz
sf_isis_importer_plugin-58c0c37b33fc4521065ad06b4222fde3e71468e2.tar.bz2
Changes into relations api
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);
}
}
}