Author: klemens
Date: 2014-06-27 11:49:35 +0200 (Fri, 27 Jun 2014)
New Revision: 4116
Added:
trunk/plugins/ullCorePlugin/lib/generator/tableConfiguration/TestTable1TableConfiguration.class.php
trunk/plugins/ullCorePlugin/lib/generator/tableConfiguration/TestTable2TableConfiguration.class.php
trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable1.class.php
trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable1Table.class.php
trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable2.class.php
trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable2Table.class.php
trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable1.class.php
trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable1Table.class.php
trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable2.class.php
trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable2Table.class.php
trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormManyToManyClassicTest.php
trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormManyToManySortableTest.php
Modified:
trunk/plugins/ullCorePlugin/config/doctrine/ullTableToolSchema.yml
trunk/plugins/ullCorePlugin/data/fixtures/ullCoreFixtures.yml
trunk/plugins/ullCorePlugin/lib/form/ullGeneratorForm.class.php
trunk/plugins/ullCorePlugin/lib/form/ullTableToolGeneratorForm.class.php
trunk/plugins/ullCorePlugin/lib/generator/columnConfigCollection/TestTableColumnConfigCollection.class.php
trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginUllRecord.class.php
trunk/plugins/ullCorePlugin/lib/ullColumnConfigCollection.class.php
trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormTest.php
Log:
Modified: trunk/plugins/ullCorePlugin/config/doctrine/ullTableToolSchema.yml
===================================================================
--- trunk/plugins/ullCorePlugin/config/doctrine/ullTableToolSchema.yml 2014-06-25 06:42:03 UTC (rev 4115)
+++ trunk/plugins/ullCorePlugin/config/doctrine/ullTableToolSchema.yml 2014-06-27 09:49:35 UTC (rev 4116)
@@ -72,7 +72,6 @@
actAs:
I18n:
fields: [my_string, my_text]
-# Taggable:
columns:
my_string:
type: string(64)
@@ -97,3 +96,65 @@
type: integer
relations:
UllUser:
+ Test1Entries:
+ class: TestTable1
+ refClass: TestTableToTestTable1
+ foreignAlias: TestEntries
+ local: test_table_id
+ foreign: test_table1_id
+ Test2Entries:
+ class: TestTable2
+ refClass: TestTableToTestTable2
+ foreignAlias: TestEntries
+ local: test_table_id
+ foreign: test_table2_id
+
+
+# For "classic" many to many tests
+TestTable1:
+ inheritance:
+ extends: UllRecord
+ type: concrete
+ columns:
+ my_string:
+ type: string(64)
+ notnull: true
+
+TestTableToTestTable1:
+ inheritance:
+ extends: UllRecord
+ type: concrete
+ columns:
+ test_table_id:
+ type: integer
+ notnull: true
+ test_table1_id:
+ type: integer
+ notnull: true
+
+
+# For many to many tests with "sortable"
+TestTable2:
+ inheritance:
+ extends: UllRecord
+ type: concrete
+ columns:
+ my_string:
+ type: string(64)
+ notnull: true
+
+TestTableToTestTable2:
+ inheritance:
+ extends: UllRecord
+ type: concrete
+ actAs:
+ Sortable:
+ uniqueBy: [test_table_id]
+ columns:
+ test_table_id:
+ type: integer
+ notnull: true
+ test_table2_id:
+ type: integer
+ notnull: true
+
\ No newline at end of file
Modified: trunk/plugins/ullCorePlugin/data/fixtures/ullCoreFixtures.yml
===================================================================
--- trunk/plugins/ullCorePlugin/data/fixtures/ullCoreFixtures.yml 2014-06-25 06:42:03 UTC (rev 4115)
+++ trunk/plugins/ullCorePlugin/data/fixtures/ullCoreFixtures.yml 2014-06-27 09:49:35 UTC (rev 4116)
@@ -587,4 +587,23 @@
# echo " x_$i:\n";
# echo " my_string: blabla$i\n";
#}
-#?>
\ No newline at end of file
+#?>
+
+
+# for "classic" many to many testing
+TestTable1:
+ tt1_1:
+ my_string: Pear
+ tt1_2:
+ my_string: Apple
+ tt1_3:
+ my_string: Banana
+
+# for "sortable" many to many testing
+TestTable2:
+ tt2_1:
+ my_string: Roadbiker
+ tt2_2:
+ my_string: Mountainbiker
+ tt2_3:
+ my_string: Citybiker
Modified: trunk/plugins/ullCorePlugin/lib/form/ullGeneratorForm.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/form/ullGeneratorForm.class.php 2014-06-25 06:42:03 UTC (rev 4115)
+++ trunk/plugins/ullCorePlugin/lib/form/ullGeneratorForm.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -43,18 +43,17 @@
)
{
$this->modelName = get_class($object);
-
$this->requestAction = $requestAction;
-
$this->columnsConfig = $columnsConfig;
-
$this->setCultures($cultures);
-
- parent::__construct($object, $options, $CSRFSecret);
-
- // called (again) after parent:__construct, because sfFormDoctrine:L52
- // overwrites defaults with emtpy array *#!?$
- $this->setDefaults($defaults);
+
+ // From sfFormDoctrine
+ $this->object = $object;
+ $this->isNew = !$this->getObject()->exists();
+
+ // Skip sfFormDoctrine Constructor because it overwrites the defaults
+ sfFormSymfony::__construct($defaults, $options, $CSRFSecret);
+
$this->updateDefaultsFromObject();
}
@@ -75,8 +74,6 @@
{
$this->getWidgetSchema()->setFormFormatterName('ullTable');
}
-
-// $this->embedI18n(array('en', 'de'));
}
@@ -200,14 +197,15 @@
{
$defaults[$fieldName] = array(
'value' => $defaults[$fieldName],
- 'id' => $this->getObject()->id
+ 'id' => $this->getObject()->id,
);
}
// Also artificial columns without a default value can need the identifier
else
{
$defaults[$fieldName] = array(
- 'id' => $this->getObject()->id
+ 'value' => null,
+ 'id' => $this->getObject()->id,
);
}
}
@@ -249,6 +247,8 @@
} //end foreach form field
+// var_dump($defaults);
+
$this->setDefaults($defaults);
}
@@ -347,6 +347,7 @@
/**
* Removes values that were not set via POST request
+ * TODO: what is the exact usecase for this?
*
* @return none
*/
@@ -368,6 +369,7 @@
}
}
+
/**
* Outputs human readable information of an sfForm for debbugging purposes
* because var_dump($sfForm) is unreadable.
@@ -613,7 +615,7 @@
// are not overwritten by column config defaults
$defaults = $this->getObject()->toArray(false) + $defaults;
}
-
+
// handle embedded forms
foreach ($this->embeddedForms as $name => $form)
{
Modified: trunk/plugins/ullCorePlugin/lib/form/ullTableToolGeneratorForm.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/form/ullTableToolGeneratorForm.class.php 2014-06-25 06:42:03 UTC (rev 4115)
+++ trunk/plugins/ullCorePlugin/lib/form/ullTableToolGeneratorForm.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -5,6 +5,13 @@
*/
class ullTableToolGeneratorForm extends ullGeneratorForm
{
+
+ protected
+ // Remember original form values from directly after binding
+ $originalValues = array()
+ ;
+
+
/**
* Override getting the default values form the object
*
@@ -13,23 +20,43 @@
{
parent::updateDefaultsFromObject();
- //iterate all column configs and load defaults for
- //many to many relationships
+ $this->loadManyToManyDefaults();
+
+ $this->loadTranlationsDefaults();
+
+ }
+
+
+ /**
+ * Iterate all column configs and load defaults for
+ * many to many relationships
+ */
+ protected function loadManyToManyDefaults()
+ {
foreach ($this->columnsConfig as $columnName => $columnConfig)
{
if ($columnConfig->isActive() &&
- $columnConfig->getMetaWidgetClassName() == 'ullMetaWidgetManyToMany')
+ 'ullMetaWidgetManyToMany' === $columnConfig->getMetaWidgetClassName())
{
// Get all connected objects for an existing object
if ($this->getObject()->exists())
{
- $this->setDefault($columnName,
- $this->getPrimaryKeysEfficiently($this->object, $columnName));
+ $this->setDefault($columnName,
+ $this->getObject()->findAssociatedPrimaryKeys($columnName)
+ );
}
}
}
-
- // Move translation values into plain defaults array
+ }
+
+
+
+ /**
+ * Move translation values into plain defaults array
+ *
+ */
+ protected function loadTranlationsDefaults()
+ {
if ($this->isI18n())
{
$defaults = $this->getDefaults();
@@ -38,7 +65,6 @@
if (isset($translations[@$this->cultures[0]]))
{
-
$i18nFields = $translations[$this->cultures[0]];
unset($i18nFields['id']);
unset($i18nFields['lang']);
@@ -58,9 +84,10 @@
}
$this->setDefaults($defaults);
- }
+ }
}
+
/**
* Override the update functionality of the object
*
@@ -122,63 +149,21 @@
return $object;
}
- /**
- * Override sfFormDoctrine's doUpdateObject() to provide support
- * for our custom many to many relation handling (= prevent
- * thousands of related records from loading/hydrating).
- *
- * @see sfFormDoctrine::doUpdateObject()
- */
- protected function doUpdateObject($values)
- {
- $unset = array();
- $associations = array();
- $relations = $this->getObject()->getTable()->getManyToManyRelations();
-
- foreach ($relations as $relationName => $relation)
- {
- if (isset($values[$relationName]))
- {
- $unset[] = $relationName;
- if ($this->object->exists())
- {
- unset($values[$relationName]);
- }
- }
- }
-
- parent::doUpdateObject($values);
-
- foreach ($relations as $relationName => $relation)
- {
- if ($this->object->exists() || !in_array($relationName, $unset))
- {
- $componentName = $relation->getClass();
- $collection = Doctrine_Collection::create($componentName);
- $this->getObject()->set($relationName, $collection, false);
- }
- }
- }
-
/**
* Override parent's doSave() to provide support for many
* to many relationships (also see saveManyToMany()).
*/
protected function doSave($connection = null)
{
- //iterate all column configs and call saveManyToMany
- //which handles updating of many to many association
- //tables
- foreach ($this->columnsConfig as $columnName => $columnConfig)
- {
- if ($columnConfig->getMetaWidgetClassName() == 'ullMetaWidgetManyToMany')
- {
- $this->saveManyToMany($columnName, $connection);
- }
- }
-
+ // Remember the original values e.g. for many to many sortable handling
+ $this->originalValues = $this->values;
+
+ $this->saveManyToMany();
+
parent::doSave($connection);
+
+ $this->handleManytoManySortablePostSave();
}
@@ -186,92 +171,63 @@
* Handles updating of association tables for a given many to many
* relationship. Note: This was mostly copied from generated
* symfony form code and then adapted for general use.
- *
- * @param string $columnName the name of the many to many relationship
+ *
+ * This code replaced the native symfony/doctrine many to many relationship
+ * handling because of sortable and a bug
+ *
http://www.ullright.org/ullWiki/show/doctrine-ullright
*/
- protected function saveManyToMany($columnName, $connection = null)
+ protected function saveManyToMany()
{
- if (!$this->isValid())
+ //iterate all column configs and call saveManyToMany
+ //which handles updating of many to many association
+ //tables
+ foreach ($this->columnsConfig as $columnName => $columnConfig)
{
- throw $this->getErrorSchema();
- }
-
- if ( !isset($this->widgetSchema[$columnName]))
- {
- // somebody has unset this widget
- return;
- }
-
- if ($connection === null)
- {
- $connection = $this->getConnection();
- }
-
- // Normalize values
- $values = $this->getValue($columnName);
- if (!is_array($values))
- {
- $values = array();
- }
+ // Ignore fields that are not writeable, inactive or no many to many association
+ if ( ! (
+ 'w' === $columnConfig->getAccess() &&
+ 'ullMetaWidgetManyToMany' === $columnConfig->getMetaWidgetClassName()
+ ))
+ {
+ continue;
+ }
+
+ // Normalize values
+ $foreignIds = $this->getValue($columnName);
+ if (!$foreignIds)
+ {
+ $foreignIds = array();
+ }
- $existing = $this->getPrimaryKeysEfficiently($this->object, $columnName);
-
- // Calculate associations to be deleted
- $unlink = array_diff($existing, $values);
+ // Remove form values for this field, because we do not want
+ // Doctrine_Record::fromArray() to do the many to many handling
+ unset($this->values[$columnName]);
+
+ $existing = $this->object->findAssociatedPrimaryKeys($columnName);
- if (count($unlink))
- {
- // Delete associations in the database
- if ($this->object->exists())
+ // Calculate associations to be deleted
+ $unlink = array_diff($existing, $foreignIds);
+
+ if (count($unlink))
{
- $relation = $this->object->getTable()->getRelation($columnName);
-
- foreach (array_values($unlink) as $unlinkValue)
- {
- $q = new Doctrine_Query();
- $q
- ->from($relation->getAssociationTable()->getComponentName())
- ->where($relation->getLocalRefColumnName() . ' = ?', $this->object->id)
- ->andWhere($relation->getForeignRefColumnName() . ' = ?', $unlinkValue)
- ;
- $result = $q->execute();
- $result->delete();
- }
- }
+ $this->object->unlink($columnName, array_values($unlink));
+ }
- // Removes Doctrine object relations
- $this->object->unlink($columnName, array_values($unlink));
- }
-
- // Calculates associations which need to be added
- $link = array_diff($values, $existing);
+ // Calculates associations which need to be added
+ $link = array_diff($foreignIds, $existing);
- if (count($link))
- {
- // Create associations in the database
- if ($this->object->exists())
+ if (count($link))
{
- $relation = $this->object->getTable()->getRelation($columnName);
- $associationObjectName = $relation->getAssociationTable()->getComponentName();
-
- foreach (array_values($link) as $linkValue)
- {
- $associationObject = new $associationObjectName();
- $associationObject[$relation->getLocalRefColumnName()] = $this->object->id;
- $associationObject[$relation->getForeignRefColumnName()] = $linkValue;
- $associationObject->save();
- }
+ $this->object->link($columnName, array_values($link));
}
- // Create Doctrine object relations
- $this->object->link($columnName, array_values($link));
- // Refresh relations
- $this->object->refreshRelated($columnName);
- }
-
+ } // end of foreach column
}
+
/**
+ * TODO: WHAT IS THIS SH**T ?
+ *
* This function solves performance problems regarding $this->object->$columnName,
* which was originally used by this class.
* Imagine e.g. mailingListObject->Subscribers is not loaded, so lazy loading
@@ -284,6 +240,7 @@
* @param Doctrine_Record $record
* @param string $columnName
*/
+ /*
protected function getPrimaryKeysEfficiently($record, $columnName)
{
//would accessing $columnName trigger lazy load?
@@ -305,4 +262,46 @@
return $results;
}
+ */
+
+
+ /**
+ * After saving the object, set the correct order (=position)
+ * for many to many association records
+ *
+ * TODO: maybe find a less performance intensive way
+ */
+ protected function handleManytoManySortablePostSave()
+ {
+ foreach ($this->columnsConfig as $columnName => $columnConfig)
+ {
+ $isSortable = $this->getColumnsConfig()->offsetGet($columnName)
+ ->getWidgetOption('is_sortable');
+
+ // Ignore fields that are not writeable, inactive or not sortable
+ if ( ! (
+ 'w' === $columnConfig->getAccess() &&
+ 'ullMetaWidgetManyToMany' === $columnConfig->getMetaWidgetClassName() &&
+ $columnConfig->getWidgetOption('is_sortable')
+ ))
+ {
+ continue;
+ }
+
+ // Normalize values
+ $foreignIds = $this->originalValues[$columnName];
+ if (!$foreignIds)
+ {
+ $foreignIds = array();
+ }
+
+ foreach ($foreignIds as $i => $foreignId)
+ {
+ $associationRecord = $this->object
+ ->findAssociationRecordBy($columnName, $foreignId);
+
+ $associationRecord->moveToPosition($i + 1);
+ }
+ }
+ }
}
\ No newline at end of file
Modified: trunk/plugins/ullCorePlugin/lib/generator/columnConfigCollection/TestTableColumnConfigCollection.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/generator/columnConfigCollection/TestTableColumnConfigCollection.class.php 2014-06-25 06:42:03 UTC (rev 4115)
+++ trunk/plugins/ullCorePlugin/lib/generator/columnConfigCollection/TestTableColumnConfigCollection.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -8,8 +8,8 @@
*/
protected function applyCustomSettings()
{
- $this['my_string']->
- setLabel(__('My custom string label', null, 'ullCoreMessages'))
+ $this['my_string']
+ ->setLabel(__('My custom string label', null, 'ullCoreMessages'))
;
$this['my_email']
->setMetaWidgetClassName('ullMetaWidgetEmail')
@@ -38,8 +38,16 @@
'label' => __('Text with image'),
),
))
- ;
+ ;
+
+ $this->useManyToManyRelation('Test1Entries');
+ $this->useManyToManyRelation('Test2Entries');
+ $this['Test2Entries']
+ // Optional, only if you want to multiselect in a particular order
+ ->setWidgetOption('is_sortable', true)
+ ;
+
$this->disable(array(
'my_useless_column'
));
Added: trunk/plugins/ullCorePlugin/lib/generator/tableConfiguration/TestTable1TableConfiguration.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/generator/tableConfiguration/TestTable1TableConfiguration.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/generator/tableConfiguration/TestTable1TableConfiguration.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,33 @@
+<?php
+/**
+ * TableConfiguration for TestTable
+ *
+ * @author
klemens.ul...@ull.at
+ *
+ */
+class TestTable1TableConfiguration extends ullTableConfiguration
+{
+ /**
+ * (non-PHPdoc)
+ * @see plugins/ullCorePlugin/lib/ullTableConfiguration#applyCustomSettings()
+ */
+ protected function applyCustomSettings()
+ {
+ $this
+ ->setToStringColumn('my_string')
+ ->setName(__('TestTable1Label', null, 'testMessages'))
+ ->setDescription(__('TestTable1 for automated testing', null, 'testMessages'))
+// ->setSearchColumns(array('id', 'my_string'))
+// ->setOrderBy('id')
+// ->setListColumns(array(
+// 'my_string',
+// 'my_text',
+// 'my_boolean',
+// 'my_email',
+// 'my_select_box',
+// 'ull_user_id',
+// ))
+ ;
+ }
+
+}
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/lib/generator/tableConfiguration/TestTable2TableConfiguration.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/generator/tableConfiguration/TestTable2TableConfiguration.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/generator/tableConfiguration/TestTable2TableConfiguration.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,33 @@
+<?php
+/**
+ * TableConfiguration for TestTable
+ *
+ * @author
klemens.ul...@ull.at
+ *
+ */
+class TestTable2TableConfiguration extends ullTableConfiguration
+{
+ /**
+ * (non-PHPdoc)
+ * @see plugins/ullCorePlugin/lib/ullTableConfiguration#applyCustomSettings()
+ */
+ protected function applyCustomSettings()
+ {
+ $this
+ ->setToStringColumn('my_string')
+ ->setName(__('TestTable2Label', null, 'testMessages'))
+ ->setDescription(__('TestTable2 for automated testing', null, 'testMessages'))
+// ->setSearchColumns(array('id', 'my_string'))
+// ->setOrderBy('id')
+// ->setListColumns(array(
+// 'my_string',
+// 'my_text',
+// 'my_boolean',
+// 'my_email',
+// 'my_select_box',
+// 'ull_user_id',
+// ))
+ ;
+ }
+
+}
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable1.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable1.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable1.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * PluginTestTable1
+ *
+ * This class has been auto-generated by the Doctrine ORM Framework
+ *
+ * @package ##PACKAGE##
+ * @subpackage ##SUBPACKAGE##
+ * @author ##NAME## <##EMAIL##>
+ * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
+ */
+abstract class PluginTestTable1 extends BaseTestTable1
+{
+
+}
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable1Table.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable1Table.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable1Table.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * PluginTestTable1Table
+ *
+ * This class has been auto-generated by the Doctrine ORM Framework
+ */
+class PluginTestTable1Table extends UllRecordTable
+{
+ /**
+ * Returns an instance of this class.
+ *
+ * @return object PluginTestTable1Table
+ */
+ public static function getInstance()
+ {
+ return Doctrine_Core::getTable('PluginTestTable1');
+ }
+}
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable2.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable2.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable2.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * PluginTestTable2
+ *
+ * This class has been auto-generated by the Doctrine ORM Framework
+ *
+ * @package ##PACKAGE##
+ * @subpackage ##SUBPACKAGE##
+ * @author ##NAME## <##EMAIL##>
+ * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
+ */
+abstract class PluginTestTable2 extends BaseTestTable2
+{
+
+}
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable2Table.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable2Table.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTable2Table.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * PluginTestTable2Table
+ *
+ * This class has been auto-generated by the Doctrine ORM Framework
+ */
+class PluginTestTable2Table extends UllRecordTable
+{
+ /**
+ * Returns an instance of this class.
+ *
+ * @return object PluginTestTable2Table
+ */
+ public static function getInstance()
+ {
+ return Doctrine_Core::getTable('PluginTestTable2');
+ }
+}
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable1.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable1.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable1.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * PluginTestTableToTestTable1
+ *
+ * This class has been auto-generated by the Doctrine ORM Framework
+ *
+ * @package ##PACKAGE##
+ * @subpackage ##SUBPACKAGE##
+ * @author ##NAME## <##EMAIL##>
+ * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
+ */
+abstract class PluginTestTableToTestTable1 extends BaseTestTableToTestTable1
+{
+
+}
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable1Table.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable1Table.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable1Table.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * PluginTestTableToTestTable1Table
+ *
+ * This class has been auto-generated by the Doctrine ORM Framework
+ */
+class PluginTestTableToTestTable1Table extends UllRecordTable
+{
+ /**
+ * Returns an instance of this class.
+ *
+ * @return object PluginTestTableToTestTable1Table
+ */
+ public static function getInstance()
+ {
+ return Doctrine_Core::getTable('PluginTestTableToTestTable1');
+ }
+}
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable2.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable2.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable2.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * PluginTestTableToTestTable2
+ *
+ * This class has been auto-generated by the Doctrine ORM Framework
+ *
+ * @package ##PACKAGE##
+ * @subpackage ##SUBPACKAGE##
+ * @author ##NAME## <##EMAIL##>
+ * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
+ */
+abstract class PluginTestTableToTestTable2 extends BaseTestTableToTestTable2
+{
+
+}
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable2Table.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable2Table.class.php (rev 0)
+++ trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginTestTableToTestTable2Table.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * PluginTestTableToTestTable2Table
+ *
+ * This class has been auto-generated by the Doctrine ORM Framework
+ */
+class PluginTestTableToTestTable2Table extends UllRecordTable
+{
+ /**
+ * Returns an instance of this class.
+ *
+ * @return object PluginTestTableToTestTable2Table
+ */
+ public static function getInstance()
+ {
+ return Doctrine_Core::getTable('PluginTestTableToTestTable2');
+ }
+}
\ No newline at end of file
Modified: trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginUllRecord.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginUllRecord.class.php 2014-06-25 06:42:03 UTC (rev 4115)
+++ trunk/plugins/ullCorePlugin/lib/model/doctrine/PluginUllRecord.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -68,4 +68,84 @@
}
}
+
+ /**
+ * Find a many to many relation association record for the current record
+ *
+ * Example: find the many to many (link table) record for group id 23
+ * $user->findAssociationRecord('UllGroup', 23);
+ * Returns an UllEntityGroup record
+ *
+ * @param string $relationName name of the many to many relation
+ * @param mixed $value
+ * @param string $columnName optional, default = foreign column name
+ *
+ * @throws InvalidArgumentException
+ * @return Doctrine_Record
+ */
+ public function findAssociationRecordBy($relationName, $value, $columnName = null)
+ {
+ $relation = $this->getTable()->getRelation($relationName);
+
+ if (! $relation instanceof Doctrine_Relation_Association)
+ {
+ throw new InvalidArgumentException('Invalid association ' . $relationName);
+ }
+
+ $associationRecordName = $relation->getAssociationTable()->getComponentName();
+ $localColumn = $relation->getLocalRefColumnName();
+ $foreignColumn = $relation->getForeignRefColumnName();
+
+ // default handling
+ if (null === $columnName)
+ {
+ $columnName = $foreignColumn;
+ }
+
+ $q = new Doctrine_Query();
+ $q
+ ->from($associationRecordName . ' x')
+ ->where('x.' . $localColumn . ' = ?', $this->id)
+ ->andWhere('x.' . $columnName . ' = ?', $value)
+ ;
+ $record = $q->fetchOne();
+
+ return $record;
+ }
+
+
+ /**
+ * Find foreign primary keys for the given many to many relation
+ * for the current object
+ *
+ * @param string $relationName
+ * @throws InvalidArgumentException
+ *
+ * @return array
+ */
+ public function findAssociatedPrimaryKeys($relationName)
+ {
+ $relation = $this->getTable()->getRelation($relationName);
+
+ if (! $relation instanceof Doctrine_Relation_Association)
+ {
+ throw new InvalidArgumentException('Invalid association ' . $relationName);
+ }
+
+ $associationRecordName = $relation->getAssociationTable()->getComponentName();
+ $localColumn = $relation->getLocalRefColumnName();
+ $foreignColumn = $relation->getForeignRefColumnName();
+
+ $q = new Doctrine_Query();
+ $q
+ ->select('x.' . $foreignColumn)
+ ->from($associationRecordName . ' x')
+ ->where('x.' . $localColumn . ' = ?', $this->id)
+ ;
+ $results = $q->execute(null, DOCTRINE::HYDRATE_NONE);
+ $results = ullCoreTools::array_flatten($results);
+
+ return $results;
+ }
+
}
\ No newline at end of file
Modified: trunk/plugins/ullCorePlugin/lib/ullColumnConfigCollection.class.php
===================================================================
--- trunk/plugins/ullCorePlugin/lib/ullColumnConfigCollection.class.php 2014-06-25 06:42:03 UTC (rev 4115)
+++ trunk/plugins/ullCorePlugin/lib/ullColumnConfigCollection.class.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -1016,7 +1016,9 @@
->setWidgetOption('owner_relation_name', $relationAlias)
->setValidatorOption('model', $model)
->setValidatorOption('query', $q)
- ->setIsSortable(false) //at the moment, we do not have support for this
+ //TODO: what is this? used anywhere?
+// ->setIsSortable(false) //at the moment, we do not have support for this
+ ->setInjectIdentifier(true)
;
}
Added: trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormManyToManyClassicTest.php
===================================================================
--- trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormManyToManyClassicTest.php (rev 0)
+++ trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormManyToManyClassicTest.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,137 @@
+<?php
+
+include dirname(__FILE__) . '/../../../../../test/bootstrap/unit.php';
+
+class myTestCase extends sfDoctrineTestCase
+{
+ public function generateForm(Doctrine_Record $object)
+ {
+ $generator = new ullTableToolGenerator('TestTable', 'w', 'edit');
+// $generator->getColumnsConfig()->disableAllExcept(array(
+// 'my_string',
+// 'my_email',
+// 'Test1Entries',
+// ));
+ $generator->buildForm($object);
+ $form = $generator->getForm();
+
+ return $form;
+ }
+}
+
+// create context since it is required by ->getUser() etc.
+sfContext::createInstance($configuration);
+sfContext::getInstance()->getConfiguration()->loadHelpers('I18N');
+
+$t = new myTestCase(14, new lime_output_color, $configuration);
+$path = sfConfig::get('sf_root_dir') . '/plugins/ullCorePlugin/data/fixtures/';
+$t->setFixturesPath($path);
+
+
+/**
+ * MANY TO MANY "CLASSIC"
+ */
+
+$t->begin('many to many handling - create');
+
+ $object = new TestTable();
+ $form = $t->generateForm($object);
+
+ $postValues = array (
+ 'my_string_translation_en' => 'Heidi',
+ 'my_string_translation_de' => 'Heidi',
+ 'my_email' => '
he...@ull.at',
+ 'Test1Entries' => array(
+ 0 => '2', //Apple
+ 1 => '1', //Pear
+ ),
+ );
+
+ $form->bindAndSave($postValues);
+
+ $t->is(count($object->Test1Entries), 2, 'Created two Test1Entries object relations');
+ $t->is($object->Test1Entries[0]['my_string'], 'Pear', 'First one is pear');
+ $t->is($object->Test1Entries[1]['my_string'], 'Apple', 'Second one is apple');
+
+ $id = $object->id;
+
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $manyToManyEntries = Doctrine::getTable('TestTableToTestTable1')
+ ->findByTestTableId($id)->toArray();
+
+ $t->is(count($manyToManyEntries), 2, 'Created two association records');
+ $t->is($manyToManyEntries[0]['test_table1_id'], 1, 'Created record for pear');
+ $t->is($manyToManyEntries[1]['test_table1_id'], 2, 'Created record for apple');
+
+
+$t->diag('many to many handling - update');
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $object = Doctrine::getTable('TestTable')->find($id);
+ $form = $t->generateForm($object);
+
+ $postValues = array (
+ 'my_string_translation_en' => 'Heidi',
+ 'my_string_translation_de' => 'Heidi',
+ 'my_email' => '
hei...@ull.at',
+ 'Test1Entries' => array(
+ 0 => '2', //Apple
+ 1 => '3', //Banana
+ ),
+ );
+
+ $form->bindAndSave($postValues);
+
+ $t->is(count($object->Test1Entries), 2, 'Still two Test1Entries object relations');
+// foreach ($object->Test1Entries as $entry)
+// {
+// if (in_array($entry['my_string'], array('Pear', 'Apple')))
+// {
+// $t->pass('Pear or Apple is there');
+// }
+// }
+ $t->is($object->Test1Entries[1]['my_string'], 'Apple', 'Apple is here');
+ $t->is($object->Test1Entries[2]['my_string'], 'Banana', 'Banana is here');
+
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $manyToManyEntries = Doctrine::getTable('TestTableToTestTable1')
+ ->findByTestTableId($id)->toArray();
+
+ $t->is(count($manyToManyEntries), 2, 'Still two associations');
+ $t->is($manyToManyEntries[0]['test_table1_id'], 2, 'Apple is still here');
+ $t->is($manyToManyEntries[1]['test_table1_id'], 3, 'And Banana instead of Pear');
+
+
+$t->diag('many to many handling - delete');
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $object = Doctrine::getTable('TestTable')->find($id);
+ $form = $t->generateForm($object);
+
+ $postValues = array (
+ 'my_string_translation_en' => 'Heidi',
+ 'my_string_translation_de' => 'Heidi',
+ 'my_email' => '
hei...@ull.at',
+ );
+
+ $form->bindAndSave($postValues);
+
+ $t->is(count($object->Test1Entries), 0, 'Removed object relations');
+// $form->debug();
+// var_dump($form->isValid());
+
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $manyToManyEntries = Doctrine::getTable('TestTableToTestTable1')
+ ->findByTestTableId($id)->toArray();
+
+ $t->is(count($manyToManyEntries), 0, 'All assocications deleted');
+
+
\ No newline at end of file
Added: trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormManyToManySortableTest.php
===================================================================
--- trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormManyToManySortableTest.php (rev 0)
+++ trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormManyToManySortableTest.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -0,0 +1,125 @@
+<?php
+
+include dirname(__FILE__) . '/../../../../../test/bootstrap/unit.php';
+
+class myTestCase extends sfDoctrineTestCase
+{
+ public function generateForm(Doctrine_Record $object)
+ {
+ $generator = new ullTableToolGenerator('TestTable', 'w', 'edit');
+// $generator->getColumnsConfig()->disableAllExcept(array(
+// 'my_string',
+// 'my_email',
+// 'Test2Entries',
+// ));
+ $generator->buildForm($object);
+ $form = $generator->getForm();
+
+ return $form;
+ }
+}
+
+// create context since it is required by ->getUser() etc.
+sfContext::createInstance($configuration);
+sfContext::getInstance()->getConfiguration()->loadHelpers('I18N');
+
+$t = new myTestCase(7, new lime_output_color, $configuration);
+$path = sfConfig::get('sf_root_dir') . '/plugins/ullCorePlugin/data/fixtures/';
+$t->setFixturesPath($path);
+
+
+/**
+ * MANY TO MANY "SORTABLE"
+ */
+
+$t->begin('many to many sortable handling - create');
+
+ $object = new TestTable();
+ $form = $t->generateForm($object);
+
+ $postValues = array (
+ 'my_string_translation_en' => 'Pippi',
+ 'my_string_translation_de' => 'Pippi',
+ 'my_email' => '
pi...@ull.at',
+ 'Test2Entries' => array(
+ 0 => '3', //Citybiker
+ 1 => '1', //Roadbiker
+ ),
+ );
+
+ $form->bindAndSave($postValues);
+
+ $id = $object->id;
+
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $manyToManyEntries = Doctrine::getTable('TestTableToTestTable2')
+ ->findByTestTableId($id)->toArray();
+
+ $t->is(count($manyToManyEntries), 2, 'Created two association records');
+
+ $assoc = $object->findAssociationRecordBy('Test2Entries', 1);
+ $t->is($assoc['position'], 2, 'Roadbiker has the correct position');
+
+ $assoc = $object->findAssociationRecordBy('Test2Entries', 3);
+ $t->is($assoc['position'], 1, 'Citybiker has the correct position');
+
+
+$t->diag('many to many sortable handling - update');
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $object = Doctrine::getTable('TestTable')->find($id);
+ $form = $t->generateForm($object);
+
+ $postValues = array (
+ 'my_string_translation_en' => 'Pippi',
+ 'my_string_translation_de' => 'Pippi',
+ 'my_email' => '
pip...@ull.at',
+ 'Test2Entries' => array(
+ 0 => '2', //Mountainbiker
+ 1 => '3', //Roadbiker
+ ),
+ );
+
+ $form->bindAndSave($postValues);
+
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $manyToManyEntries = Doctrine::getTable('TestTableToTestTable2')
+ ->findByTestTableId($id)->toArray();
+
+ $t->is(count($manyToManyEntries), 2, 'Still two associations');
+
+ $assoc = $object->findAssociationRecordBy('Test2Entries', 2);
+ $t->is($assoc['position'], 1, 'Mountainbiker has position 1');
+
+ $assoc = $object->findAssociationRecordBy('Test2Entries', 3);
+ $t->is($assoc['position'], 2, 'Roadbiker has position 2');
+
+
+$t->diag('many to many sortable handling - delete');
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $object = Doctrine::getTable('TestTable')->find($id);
+ $form = $t->generateForm($object);
+
+ $postValues = array (
+ 'my_string_translation_en' => 'Pippi',
+ 'my_string_translation_de' => 'Pippi',
+ 'my_email' => '
pip...@ull.at',
+ );
+
+ $form->bindAndSave($postValues);
+
+ $t->clearTables();
+ $t->clearDoctrineResultCache();
+
+ $manyToManyEntries = Doctrine::getTable('TestTableToTestTable2')
+ ->findByTestTableId($id)->toArray();
+
+ $t->is(count($manyToManyEntries), 0, 'All assocications deleted');
+
\ No newline at end of file
Modified: trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormTest.php
===================================================================
--- trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormTest.php 2014-06-25 06:42:03 UTC (rev 4115)
+++ trunk/plugins/ullCorePlugin/test/unit/ullTableTool/ullTableToolGeneratorFormTest.php 2014-06-27 09:49:35 UTC (rev 4116)
@@ -16,6 +16,7 @@
// create context since it is required by ->getUser() etc.
sfContext::createInstance($configuration);
+sfContext::getInstance()->getConfiguration()->loadHelpers('I18N');
$t = new myTestCase(3, new lime_output_color, $configuration);
$path = sfConfig::get('sf_root_dir') . '/plugins/ullCorePlugin/data/fixtures/';
@@ -46,5 +47,4 @@
$fields = $form->getWidgetSchema()->getFields();
$t->isa_ok($fields['test_field'], 'sfWidgetFormInput', 'added ullMetaWidgetString: write access: form now contains a sfWidgetFormInput');
-
-
\ No newline at end of file
+
\ No newline at end of file