AntonLV 7 лет назад
Родитель
Сommit
2316916f23

+ 66 - 2
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -25,6 +25,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
     protected $_oMetatagsContentId = 0;
 
     protected $_sGhostTemplate = 'form_ghost_template.html';
+    
+    protected $_aTrackFieldsChanges;
 
     public function __construct($aInfo, $oTemplate = false)
     {
@@ -32,6 +34,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
 
         $this->_oModule = BxDolModule::getInstance($this->MODULE);
 
+        $this->_aTrackFieldsChanges = array();
+
         $CNF = &$this->_oModule->_oConfig->CNF;
         
         if (isset($CNF['FIELD_ADDED']) && isset($this->aInputs[$CNF['FIELD_ADDED']])) {
@@ -76,7 +80,45 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
             $aGroupChooser = $oPrivacy->getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
             
             $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = array_merge($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']], $aGroupChooser, $aSave);
-		}        
+        }        
+    }
+
+    /**
+     * Add field(s) which will be tracked during content update. 
+     */
+    public function addTrackFields($mixedFields, $mixedContent)
+    {
+        if(empty($mixedContent) || empty($mixedFields))
+            return;
+
+        if(!is_array($mixedContent)) {
+            $mixedContent = $this->_oModule->_oDb->getContentInfoById((int)$mixedContent);
+            if(empty($mixedContent) || !is_array($mixedContent))
+                return;
+        }
+
+        if(!is_array($mixedFields))
+            $mixedFields = array($mixedFields);
+
+        foreach($mixedFields as $sField) {
+            if(!isset($mixedContent[$sField]))
+                continue;
+
+            $this->_aTrackFieldsChanges[$sField] = array(
+                'old' => $mixedContent[$sField],
+            );
+        }
+    }
+
+    /**
+     * Checks if the field was changed.
+     */
+    public function isTrackFieldChanged($sField, $bReturnValues = false)
+    {
+        if(!isset($this->_aTrackFieldsChanges[$sField]) || $this->_aTrackFieldsChanges[$sField] === false)
+            return false;
+
+        return $bReturnValues ? $this->_aTrackFieldsChanges[$sField] : true;
     }
 
     function initChecker ($aValues = array (), $aSpecificValues = array())
@@ -167,7 +209,11 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'failed')
             $aValsToAdd[$CNF['FIELD_STATUS']] = 'active';
 
-        return parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
+        $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
+        if($mixedResult !== false)
+            $this->_processTrackFields($iContentId);
+
+        return $mixedResult;
     }
 
     protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
@@ -330,6 +376,24 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
     {
         return $this->_oModule->serviceGetContentOwnerProfileId($iContentId);
     }
+
+    protected function _processTrackFields($mixedContent)
+    {
+        if(empty($mixedContent) || empty($this->_aTrackFieldsChanges))
+            return;
+
+        if(!is_array($mixedContent)) {
+            $mixedContent = $this->_oModule->_oDb->getContentInfoById((int)$mixedContent);
+            if(empty($mixedContent) || !is_array($mixedContent))
+                return;
+        }
+
+        foreach($this->_aTrackFieldsChanges as $sField => $aValues)
+            if($mixedContent[$sField] == $aValues['old'])
+                $this->_aTrackFieldsChanges[$sField] = false;
+            else
+                $this->_aTrackFieldsChanges[$sField]['new'] = $mixedContent[$sField];
+    }
 }
 
 /** @} */

+ 5 - 5
modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php

@@ -267,7 +267,7 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         // update data in the DB
         $aTrackTextFieldsChanges = null;
 
-        $this->onDataEditBefore ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges);
+        $this->onDataEditBefore ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
 
         if (!$oForm->update ($aContentInfo[$CNF['FIELD_ID']], array(), $aTrackTextFieldsChanges)) {
             if (!$oForm->isValid())
@@ -416,12 +416,12 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         return '';
     }
 
-    public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
+    public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges, &$oProfile, &$oForm)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
         if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'failed')
-            $aTrackTextFieldsChanges = array();
+            $oForm->addTrackFields($CNF['FIELD_STATUS'], $aContentInfo);
     }
 
     public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
@@ -445,8 +445,8 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
             }
         }
 
-        if(isset($CNF['FIELD_STATUS']) && isset($aTrackTextFieldsChanges['data'][$CNF['FIELD_STATUS']]) && $aTrackTextFieldsChanges['data'][$CNF['FIELD_STATUS']] == 'failed')
-            if(isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')
+        if(isset($CNF['FIELD_STATUS']) && ($aTrackResult = $oForm->isTrackFieldChanged($CNF['FIELD_STATUS'], true)) !== false)
+            if($aTrackResult['old'] == 'failed' && $aTrackResult['new'] == 'active')
                 $this->_alertAfterAdd($aContentInfo);
 
         return '';

+ 1 - 1
modules/base/general/classes/BxBaseModGeneralGridAdministration.php

@@ -182,7 +182,7 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        if(!in_array($aRow[$CNF['FIELD_STATUS']], array('active', 'hidden'))) {
+        if(isset($CNF['FIELD_STATUS']) && isset($aRow[$CNF['FIELD_STATUS']]) && !in_array($aRow[$CNF['FIELD_STATUS']], array('active', 'hidden'))) {
             $sStatusKey = '_sys_status_' . $aRow[$CNF['FIELD_STATUS']];
             if(!empty($CNF['T']['txt_status_' . $aRow[$CNF['FIELD_STATUS']]]))
                 $sStatusKey = $CNF['T']['txt_status_' . $aRow[$CNF['FIELD_STATUS']]];

+ 1 - 1
modules/base/profile/classes/BxBaseModProfileFormsEntryHelper.php

@@ -71,7 +71,7 @@ class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
         return parent::deleteData ($iContentId, $aContentInfo, $oProfile, $oForm);
     }
 
-    public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
+    public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges, &$oProfile, &$oForm)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;