Parcourir la source

Ticket #3704 - Nested Forms: Several problems when Ghost is presented as an object.

AntonLV il y a 4 ans
Parent
commit
ffc33a1a2f

+ 8 - 2
inc/classes/BxDolForm.php

@@ -1163,8 +1163,14 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
 
 
                 // collect nested form values
                 // collect nested form values
                 $aSpecificValues = array ();
                 $aSpecificValues = array ();
-                if (isset($this->aParams['db']['submit_name']))
-                    $aSpecificValues = array ($this->aParams['db']['submit_name'] => 1);
+                if (isset($this->aParams['db']['submit_name'])) {
+                    $sSubmitName = $this->aParams['db']['submit_name'];
+                    if(is_array($sSubmitName))
+                        $sSubmitName = reset($sSubmitName);
+        
+                    $aSpecificValues = array ($sSubmitName => 1);
+                }
+
                 foreach ($oFormNested->aInputs as $r) {
                 foreach ($oFormNested->aInputs as $r) {
                     $sName = str_replace('[]', '', $r['name']);
                     $sName = str_replace('[]', '', $r['name']);
                     $aValue = $this->getSubmittedValue($sName, $this->aFormAttrs['method']);
                     $aValue = $this->getSubmittedValue($sName, $this->aFormAttrs['method']);

+ 32 - 15
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -142,7 +142,14 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         $sUniqId = genRndPwd (8, false);
         $sUniqId = genRndPwd (8, false);
         $aNestedForms = array();
         $aNestedForms = array();
         if (!$this->isSubmitted()){
         if (!$this->isSubmitted()){
-            $aNestedValues = $this->_oModule->_oDb->getNestedBy(array('type' => 'content_id', 'id' => $this->_iContentId, 'key_name' => $aInput['ghost_template']['params']['db']['key']), $aInput['ghost_template']['params']['db']['table']);
+            $aGhostTemplateParams = is_object($aInput['ghost_template']) ? $aInput['ghost_template']->aParams : $aInput['ghost_template']['params'];
+
+            $aNestedValues = $this->_oModule->_oDb->getNestedBy(array(
+                'type' => 'content_id', 
+                'id' => $this->_iContentId, 
+                'key_name' => $aGhostTemplateParams['db']['key']
+            ), $aGhostTemplateParams['db']['table']);
+
             foreach($aNestedValues as $aNestedValue) {
             foreach($aNestedValues as $aNestedValue) {
                 $aNestedValuesRv = array();
                 $aNestedValuesRv = array();
                 $oForm = $this->getNestedFormObject($aInput);  
                 $oForm = $this->getNestedFormObject($aInput);  
@@ -206,7 +213,14 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
     function genNestedForm (&$aInput)
     function genNestedForm (&$aInput)
     {
     {
         $sResult = '';
         $sResult = '';
-        $aNestedValues = $this->_oModule->_oDb->getNestedBy(array('type' => 'content_id', 'id' => $this->_iContentId, 'key_name' => $aInput['ghost_template']['params']['db']['key']), $aInput['ghost_template']['params']['db']['table']);
+        $aGhostTemplateParams = is_object($aInput['ghost_template']) ? $aInput['ghost_template']->aParams : $aInput['ghost_template']['params'];
+
+        $aNestedValues = $this->_oModule->_oDb->getNestedBy(array(
+            'type' => 'content_id', 
+            'id' => $this->_iContentId, 
+            'key_name' => $aGhostTemplateParams['db']['key']
+        ), $aGhostTemplateParams['db']['table']);
+
         foreach($aNestedValues as $aNestedValue) {
         foreach($aNestedValues as $aNestedValue) {
             $sValue = '';
             $sValue = '';
 			$aNestedValuesRv = array();
 			$aNestedValuesRv = array();
@@ -453,19 +467,20 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
 
 
         $iContentId = parent::insert ($aValsToAdd, $isIgnore);
         $iContentId = parent::insert ($aValsToAdd, $isIgnore);
         
         
-        if(!empty($iContentId)){
+        if(!empty($iContentId)) {
             foreach($this->aInputs as $aInput) {
             foreach($this->aInputs as $aInput) {
-                if ($aInput['type'] == 'nested_form'){
-			        if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
-				        foreach ($aInput['ghost_template'] as $oFormNested) {
-					        $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
-                            if ($aInput['rateable']){
+                if ($aInput['type'] == 'nested_form') {
+                    if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
+                        foreach ($aInput['ghost_template'] as $oFormNested) {
+                            $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
+
+                            if ($aInput['rateable']) {
                                 BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName(), $iNestedContentId);
                                 BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName(), $iNestedContentId);
                             }
                             }
-				        }
-			        }
+                        }
+                    }
                 }
                 }
-		    }
+            }
             
             
             if ($bMulticatEnabled)
             if ($bMulticatEnabled)
                 $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
                 $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
@@ -525,14 +540,16 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         $bMulticatEnabled = $this->_isMulticatEnabled();
         $bMulticatEnabled = $this->_isMulticatEnabled();
         if ($bMulticatEnabled)
         if ($bMulticatEnabled)
             $this->processMulticatBefore($CNF['FIELD_MULTICAT'], $aValsToAdd);
             $this->processMulticatBefore($CNF['FIELD_MULTICAT'], $aValsToAdd);
-        
+
         $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
         $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
-        
+
         foreach($this->aInputs as $aInput) {
         foreach($this->aInputs as $aInput) {
             if ($aInput['type'] == 'nested_form'){
             if ($aInput['type'] == 'nested_form'){
                 if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
                 if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
                     foreach ($aInput['ghost_template'] as $oFormNested) {
                     foreach ($aInput['ghost_template'] as $oFormNested) {
-                        $iNestedContentId = $oFormNested->aInputs[$aInput['name']]['value'];
+                        $aSpecificValues = $oFormNested->getSpecificValues();
+                        $iNestedContentId = $oFormNested->getSubmittedValue($aInput['name'], BX_DOL_FORM_METHOD_SPECIFIC, $aSpecificValues);
+
                         if (empty($iNestedContentId)){
                         if (empty($iNestedContentId)){
                             $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
                             $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
                             if ($aInput['rateable']){
                             if ($aInput['rateable']){
@@ -546,7 +563,7 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
                 }
                 }
             }
             }
         }
         }
-        
+
         if ($bMulticatEnabled)
         if ($bMulticatEnabled)
             $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
             $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);