Author: annis
Date: 2010-03-23 19:09:56 +0100 (Tue, 23 Mar 2010)
New Revision: 28730
Modified:
plugins/ahDoctrineEasyEmbeddedRelationsPlugin/trunk/lib/form/ahBaseFormDoctrine.class.php
plugins/ahDoctrineEasyEmbeddedRelationsPlugin/trunk/package.xml
Log:
added TODO file; fixed a few bugs
Modified:
plugins/ahDoctrineEasyEmbeddedRelationsPlugin/trunk/lib/form/ahBaseFormDoctrine.class.php
===================================================================
---
plugins/ahDoctrineEasyEmbeddedRelationsPlugin/trunk/lib/form/ahBaseFormDoctrine.class.php
2010-03-23 17:59:44 UTC (rev 28729)
+++
plugins/ahDoctrineEasyEmbeddedRelationsPlugin/trunk/lib/form/ahBaseFormDoctrine.class.php
2010-03-23 18:09:56 UTC (rev 28730)
@@ -30,14 +30,32 @@
$formArgs = !isset($relations[$relationName]['newFormClassArgs']) ?
array() : $relations[$relationName]['newFormClassArgs'];
$r = new ReflectionClass($formClass);
- $newForm = $r->newInstanceArgs(array_merge(array(null),
array($formArgs)));
+ //sfContext::getInstance()->getLogger()->info($relation);
+
+ if (Doctrine_Relation::MANY === $relation->getType())
+ {
+ $newFormObjectClass = $relation->getClass();
+ $newFormObject = new $newFormObjectClass();
+ $newFormObject[get_class($this->getObject())] = $this->getObject();
+ } else
+ {
+ $newFormObject = $this->getObject()->$relationName;
+ }
+
+ $newForm = $r->newInstanceArgs(array_merge(array($newFormObject),
array($formArgs)));
+ $newFormIdentifiers =
$newForm->getObject()->getTable()->getIdentifierColumnNames();
+ foreach ($newFormIdentifiers as $primaryKey)
+ {
+ unset($newForm[$primaryKey]);
+ }
+ unset($newForm[$relation->getForeignColumnName()]);
+
// FIXME/TODO: check if this even works for one-to-one
// CORRECTION 1: Not really, it creates another record but doesn't
link it to this object!
// CORRECTION 2: No, it can't, silly! For that to work the id of the
not-yet-existant related record would have to be known...
// Think about overriding the save method and after calling
parent::save($con) we should update the relations that:
// 1. are one-to-one AND
// 2. are LocalKey :)
- $newForm->setDefault($relation->getForeignColumnName(),
$this->object[$relation->getLocalColumnName()]);
if (isset($relations[$relationName]['newFormLabel']))
{
$newForm->getWidgetSchema()->setLabel($relations[$relationName]['newFormLabel']);
@@ -101,12 +119,21 @@
{
if (!isset($keys['noNewForm']) || !$keys['noNewForm'])
{
- foreach ($keys['considerNewFormEmptyFields'] as $key)
+ if (isset($keys['considerNewFormEmptyFields']) &&
count($keys['considerNewFormEmptyFields']) > 0 &&
isset($values['new_'.$relationName]))
{
- if ('' === trim($values['new_'.$relationName][$key]))
+ $emptyFields = 0;
+ foreach ($keys['considerNewFormEmptyFields'] as $key)
{
+ if ('' === trim($values['new_'.$relationName][$key])) {
+ $emptyFields++;
+ } elseif (is_array($values['new_'.$relationName][$key]) &&
count($values['new_'.$relationName][$key]) === 0) {
+ $emptyFields++;
+ }
+ }
+
+ if ($emptyFields === count($keys['considerNewFormEmptyFields'])) {
+ sfContext::getInstance()->getLogger()->info('Dropping relation
:'.$relationName);
unset($values['new_'.$relationName], $this['new_'.$relationName]);
- break;
}
}
}
@@ -141,21 +168,17 @@
$relation = $this->getObject()->getTable()->getRelation($relationName);
foreach ($ids as $index => $id)
{
- if ($relation->isOneToOne())
- {
+ if ($relation->isOneToOne()) {
unset($values[$relationName]);
}
- else
- {
+ else {
unset($values[$relationName][$index]);
}
- if (!$relation->isOneToOne())
- {
+ if (!$relation->isOneToOne()) {
unset($this->object[$relationName][$index]);
}
- else
- {
+ else {
$this->object->clearRelated($relationName);
}
@@ -197,7 +220,10 @@
*/
$relationName = $this->getRelationByEmbeddedFormClass($form);
- if (($relationName && !array_key_exists($form->getObject()->getId(),
array_flip($this->scheduledForDeletion[$relationName]))) || !$relationName)
+
//sfContext::getInstance()->getLogger()->info(print_r($this->scheduledForDeletion,
true));
+ //sfContext::getInstance()->getLogger()->info($relationName);
+
+ if (!$relationName ||
!isset($this->scheduledForDeletion[$relationName]) || ($relationName &&
!array_key_exists($form->getObject()->getId(),
array_flip($this->scheduledForDeletion[$relationName]))))
{
$form->saveEmbeddedForms($con);
$form->getObject()->save($con);
Modified: plugins/ahDoctrineEasyEmbeddedRelationsPlugin/trunk/package.xml
===================================================================
--- plugins/ahDoctrineEasyEmbeddedRelationsPlugin/trunk/package.xml
2010-03-23 17:59:44 UTC (rev 28729)
+++ plugins/ahDoctrineEasyEmbeddedRelationsPlugin/trunk/package.xml
2010-03-23 18:09:56 UTC (rev 28730)
@@ -33,6 +33,7 @@
</dir>
<file name="LICENSE" role="data"/>
<file name="README" role="data"/>
+ <file name="TODO" role="data"/>
</dir>
</contents>
<dependencies>
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.