AntonLV 6 år sedan
förälder
incheckning
0ee9af49fb
2 ändrade filer med 97 tillägg och 44 borttagningar
  1. 14 6
      inc/classes/BxDolForm.php
  2. 83 38
      studio/classes/BxDolStudioForm.php

+ 14 - 6
inc/classes/BxDolForm.php

@@ -721,6 +721,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
     protected $oTemplate;
 
     protected $_isValid = true;
+    protected $_sChecker;
     protected $_sCheckerHelper;
     protected $_aSpecificValues;
 
@@ -755,6 +756,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
         if (!isset($this->aFormAttrs['action']))
             $this->aFormAttrs['action'] = '';
 
+        $this->_sChecker = isset($this->aParams['checker']) ? $this->aParams['checker'] : 'BxDolFormChecker';
         $this->_sCheckerHelper = isset($this->aParams['checker_helper']) ? $this->aParams['checker_helper'] : '';
     }
 
@@ -802,7 +804,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
     {
         $this->_aSpecificValues = $aSpecificValues;
 
-        $oChecker = new BxDolFormChecker($this->_sCheckerHelper);
+        $oChecker = new $this->_sChecker($this->_sCheckerHelper);
         $oChecker->setFormMethod($this->aFormAttrs['method'], $aSpecificValues);
         $oChecker->setFormParams($this->aParams);
         $oChecker->setFieldsCheckForSpam($this->_aFieldsCheckForSpam);
@@ -851,7 +853,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
 
     function insert ($aValsToAdd = array(), $isIgnore = false)
     {
-        $oChecker = new BxDolFormChecker($this->_sCheckerHelper);
+        $oChecker = new $this->_sChecker($this->_sCheckerHelper);
         $oChecker->setFormMethod($this->aFormAttrs['method'], $this->_aSpecificValues);
         $sSql = $oChecker->dbInsert($this->aParams['db'], $this->aInputs, $aValsToAdd, $isIgnore);
         if (!$sSql)
@@ -864,7 +866,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
 
     function update ($val, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
     {
-        $oChecker = new BxDolFormChecker($this->_sCheckerHelper);
+        $oChecker = new $this->_sChecker($this->_sCheckerHelper);
         $oChecker->setFormMethod($this->aFormAttrs['method'], $this->_aSpecificValues);
         $sSql = $oChecker->dbUpdate($val, $this->aParams['db'], $this->aInputs, $aValsToAdd, $aTrackTextFieldsChanges);
         if (!$sSql)
@@ -874,7 +876,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
 
     function delete ($val)
     {
-        $oChecker = new BxDolFormChecker($this->_sCheckerHelper);
+        $oChecker = new $this->_sChecker($this->_sCheckerHelper);
         $oChecker->setFormMethod($this->aFormAttrs['method'], $this->_aSpecificValues);
         $sSql = $oChecker->dbDelete($val, $this->aParams['db'], $this->aInputs);
         if (!$sSql)
@@ -891,7 +893,7 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
 
     function getCleanValue ($sName)
     {
-        $oChecker = new BxDolFormChecker($this->_sCheckerHelper);
+        $oChecker = new $this->_sChecker($this->_sCheckerHelper);
         $oChecker->setFormMethod($this->aFormAttrs['method'], $this->_aSpecificValues);
         $a = isset($this->aInputs[$sName]) ? $this->aInputs[$sName] : false;
         if ($a && isset($a['db']['pass']))
@@ -1190,7 +1192,13 @@ class BxDolFormChecker
                         $sSubmitName = $k;
 
             $a['name'] = str_replace('[]', '', $a['name']);
-            $val = BxDolForm::getSubmittedValue($a['name'], $this->_sFormMethod, $this->_aSpecificValues);
+
+            $sMethodGetSubmittedValue = 'getSubmittedValue' . bx_gen_method_name($a['name']);
+            if(method_exists($this, $sMethodGetSubmittedValue))
+                $val = $this->$sMethodGetSubmittedValue($a['name'], $this->_sFormMethod, $this->_aSpecificValues);
+            else
+                $val = BxDolForm::getSubmittedValue($a['name'], $this->_sFormMethod, $this->_aSpecificValues);
+
             if (isset(BxDolForm::$TYPES_FILE[$a['type']]))
                 $val = isset($_FILES[$a['name']]['name']) ? $_FILES[$a['name']]['name'] : '';
 

+ 83 - 38
studio/classes/BxDolStudioForm.php

@@ -85,81 +85,126 @@ class BxDolStudioForm extends BxBaseFormView
         return (int)$iId;
     }
 
-	function getCleanValue ($sName)
+    function getCleanValue ($sName)
     {
-		$aResult = parent::getCleanValue($sName);
+        $aResult = parent::getCleanValue($sName);
 
-		$a = isset($this->aInputs[$sName]) ? $this->aInputs[$sName] : false;
-		if($a && !empty($a['reverse']) && !empty($a['values']))
-			$aResult = array_diff(array_keys($a['values']), (is_array($aResult) ? $aResult : array()));
+        $a = isset($this->aInputs[$sName]) ? $this->aInputs[$sName] : false;
+        if($a && !empty($a['reverse']) && !empty($a['values']))
+            $aResult = array_diff(array_keys($a['values']), (is_array($aResult) ? $aResult : array()));
 
-		return $aResult;
+        return $aResult;
     }
 
     protected function processTranslations($sType = 'insert')
     {
-        $aType2Method = array(
-            'insert' => 'addLanguageString',
-            'update' => 'updateLanguageString'
-        );
-
-        $oLanguage = BxDolStudioLanguagesUtils::getInstance();
-
         $bResult = false;
         foreach($this->aInputs as $sName => $aInput) {
-            if(!in_array($aInput['type'], array('text_translatable', 'textarea_translatable')))
+            if(!in_array($aInput['type'], array('text_translatable', 'textarea_translatable', 'list_translatable')))
                 continue; 
 
-            $sKey = $this->getCleanValue($sName);
-            if(empty($sKey))
+            if($aInput['type'] == 'list_translatable') {
+                $iIndex = (int)$this->getCleanValue($sName . '_ind');
+                for($i = 0; $i < $iIndex; $i++) 
+                    if($this->_processTranslationsByName($sType, $sName . '_' . $i) !== false)
+                        $bResult = true;
+
                 continue;
+            }
 
-            $aValues = $this->getTranslationsValues($sType, $sName);
-            foreach($aValues as $iLanguageId => $sString)
-                if($oLanguage->{$aType2Method[$sType]}($sKey, $sString, $iLanguageId))
-                    $bResult = true;
+            if($this->_processTranslationsByName($sType, $sName) !== false)
+                $bResult = true;
         }
 
         return $bResult;
     }
 
-    protected function processTranslationsKey($sType = 'insert')
+    protected function _processTranslationsByName($sType, $sName)
     {
         $oLanguage = BxDolStudioLanguagesUtils::getInstance();
 
+        $aType2Method = array(
+            'insert' => 'addLanguageString',
+            'update' => 'updateLanguageString'
+        );
+
+        $bResult = false;
+
+        $sKey = $this->getCleanValue($sName);
+        if(empty($sKey))
+            return $bResult;
+
+        $aValues = $this->getTranslationsValues($sType, $sName);
+        foreach($aValues as $iLanguageId => $sString)
+            if($oLanguage->{$aType2Method[$sType]}($sKey, $sString, $iLanguageId))
+                $bResult = true;
+
+        return $bResult;
+    }
+
+    protected function processTranslationsKey($sType = 'insert')
+    {
         foreach($this->aInputs as $sName => $aInput) {
-            if(!in_array($aInput['type'], array('text_translatable', 'textarea_translatable'))) 
+            if(!in_array($aInput['type'], array('text_translatable', 'textarea_translatable', 'list_translatable'))) 
                 continue;
 
-            //--- Fill in the Key if some values are available only. 
-            $sKey = '';
-            $sKeyDefault = $this->getCleanValue($sName);
+            if($aInput['type'] == 'list_translatable') {
+                $iIndex = (int)$this->getCleanValue($sName . '_ind');
+                for($i = 0; $i < $iIndex; $i++)
+                    $this->_processTranslationsKeyByName($sType, $sName . '_' . $i);
 
-            $aValues = $this->getTranslationsValues($sType, $sName, true);
-            if(!empty($aValues) && is_array($aValues))
-                $sKey = $this->getTranslationsKey($sType, $sName, $sKeyDefault);
-
-            //--- Remove Key if it exists but no values for him
-            if(empty($sKey) && !empty($sKeyDefault)) 
-                $oLanguage->deleteLanguageString($sKeyDefault);
+                continue;
+            }
 
-            BxDolForm::setSubmittedValue($sName, $sKey, $this->aFormAttrs['method']);
+            $this->_processTranslationsKeyByName($sType, $sName);
         }
     }
 
-    protected function processTranslationsValues ()
+    protected function _processTranslationsKeyByName($sType, $sName)
     {
-        $aLanguages = BxDolStudioLanguagesUtils::getInstance()->getLanguages();
+        $oLanguage = BxDolStudioLanguagesUtils::getInstance();
+
+        //--- Fill in the Key if some values are available only. 
+        $sKey = '';
+        $sKeyDefault = $this->getCleanValue($sName);
+
+        $aValues = $this->getTranslationsValues($sType, $sName, true);
+        if(!empty($aValues) && is_array($aValues))
+            $sKey = $this->getTranslationsKey($sType, $sName, $sKeyDefault);
+
+        //--- Remove Key if it exists but no values for him
+        if(empty($sKey) && !empty($sKeyDefault)) 
+            $oLanguage->deleteLanguageString($sKeyDefault);
 
+        BxDolForm::setSubmittedValue($sName, $sKey, $this->aFormAttrs['method']);
+    }
+            
+    protected function processTranslationsValues()
+    {
         foreach($this->aInputs as $sName => $aInput) {
-            if(!in_array($aInput['type'], array('text_translatable', 'textarea_translatable')))
+            if(!in_array($aInput['type'], array('text_translatable', 'textarea_translatable', 'list_translatable')))
+                continue;
+
+            if($aInput['type'] == 'list_translatable') {
+                $iIndex = (int)$this->getCleanValue($sName . '_ind');
+                for($i = 0; $i < $iIndex; $i++)
+                    $this->_processTranslationsValuesByName($sName . '_' . $i);
+
                 continue;
+            }
 
-            foreach($aLanguages as $sLangName => $sLangTitle)
-                $this->aInputs[$sName]['values'][$sLangName] = BxDolForm::getSubmittedValue($sName . '-' . $sLangName, $this->aFormAttrs['method']);
+            $this->_processTranslationsValuesByName($sName);
         }
     }
 
+    protected function _processTranslationsValuesByName($sName)
+    {
+        $aLanguages = BxDolStudioLanguagesUtils::getInstance()->getLanguages();
+
+        foreach($aLanguages as $sLangName => $sLangTitle)
+            $this->aInputs[$sName]['values'][$sLangName] = BxDolForm::getSubmittedValue($sName . '-' . $sLangName, $this->aFormAttrs['method']);
+    }
+
     protected function getTranslationsKey($sType, $sName, $sValue)
     {
         $iRand = time();