1
0
Эх сурвалжийг харах

Ticket #1430 - Mature-audience content filter (PG, PG13, R): Update filters on Profile created / Birthday changed.

AntonLV 4 жил өмнө
parent
commit
707db6c23a

+ 70 - 0
inc/classes/BxDolContentFilter.php

@@ -224,6 +224,76 @@ class BxDolContentFilter extends BxDolFactory implements iBxDolSingleton
             'table' => $sContentTable
             'table' => $sContentTable
         ];
         ];
     }
     }
+
+    public function updateValuesByProfile($aProfile)
+    {
+        if(!is_array($aProfile))
+            $aProfile = BxDolProfileQuery::getInstance()->getProfiles(['type' => 'id', 'id' => (int)$aProfile]);
+
+        if(!BxDolRequest::serviceExists($aProfile['type'], 'get_info'))
+            return;
+
+        $aFilters = BxDolFormQuery::getDataItems($this->_sDataList, true, BX_DATA_VALUES_ALL);
+        $aProfileInfo = bx_srv($aProfile['type'], 'get_info', [$aProfile['content_id'], false]);
+
+        $iCfwValue = (int)$aProfile['cfw_value'];
+        $bUpdateCfwValue = false;
+
+        $iCfwItems = $iCfuItems = 0;
+        $bUpdateCfwItems = $bUpdateCfuItems = false;
+        foreach($aFilters as $aFilter) {
+            $iFilter = (int)$aFilter['Value'];
+
+            if(!empty($aFilter['Data'])) {
+                $aData = unserialize($aFilter['Data']);
+                if(empty($aData) || !is_array($aData))
+                    continue;
+            }
+            else
+                $aData = [
+                    'is_allowed_watch' => ['module' => 'system', 'method' => 'is_allowed_cfilter', 'params' => ['watch'], 'class' => 'BaseServiceProfiles'],
+                    'is_allowed_use' => ['module' => 'system', 'method' => 'is_allowed_cfilter', 'params' => ['use'], 'class' => 'BaseServiceProfiles'],
+                ];
+
+            if(!empty($aData['is_allowed_watch'])) {
+                $aData['is_allowed_watch']['params'] = array_merge($aData['is_allowed_watch']['params'], [$iFilter, $aProfileInfo]);
+
+                $iWatch = call_user_func_array('bx_srv', $aData['is_allowed_watch']);
+                if($iWatch === false)
+                    continue;
+
+                if($iWatch == 0) {
+                    $iCfwValue &= ~ (1 << ($iFilter - 1));
+                    $bUpdateCfwValue = true;
+                }
+
+                $iCfwItems |= $iWatch;
+                $bUpdateCfwItems = true;
+            }
+
+            if(!empty($aData['is_allowed_use']) && (int)$aProfile['cfu_locked'] == 0) {
+                $aData['is_allowed_use']['params'] = array_merge($aData['is_allowed_use']['params'], [$aFilter['Value'], $aProfileInfo]);
+
+                $iUse = call_user_func_array('bx_srv', $aData['is_allowed_use']);
+                if($iUse === false)
+                    continue;
+
+                $iCfuItems |= $iUse;
+                $bUpdateCfuItems = true;
+            }
+        }
+
+        $oProfileQuery = BxDolProfileQuery::getInstance();
+
+        if($bUpdateCfwValue) 
+            $oProfileQuery->changeCfwValue($aProfile['id'], $iCfwValue);
+
+        if($bUpdateCfwItems)
+            $oProfileQuery->changeCfwItems($aProfile['id'], $iCfwItems);
+
+        if($bUpdateCfuItems)
+            $oProfileQuery->changeCfuItems($aProfile['id'], $iCfuItems);
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 4 - 67
inc/classes/BxDolCronProfile.php

@@ -29,76 +29,13 @@ class BxDolCronProfile extends BxDolCron
         foreach($aProfileModules as $aProfileModule) 
         foreach($aProfileModules as $aProfileModule) 
             $aProfileTypes[] = $aProfileModule['name'];
             $aProfileTypes[] = $aProfileModule['name'];
 
 
-        $oProfileQuery = BxDolProfileQuery::getInstance();
-
-        $aProfiles = $oProfileQuery->getProfiles(['type' => 'active', 'types' => $aProfileTypes]);
+        $aProfiles = BxDolProfileQuery::getInstance()->getProfiles(['type' => 'active', 'types' => $aProfileTypes]);
         if(empty($aProfiles) || !is_array($aProfiles))
         if(empty($aProfiles) || !is_array($aProfiles))
             return;
             return;
 
 
-        $aFilters = BxDolFormQuery::getDataItems('sys_content_filter', true, BX_DATA_VALUES_ALL);
-
-        foreach($aProfiles as $aProfile) {
-            if(!BxDolRequest::serviceExists($aProfile['type'], 'get_info'))
-                continue;
-
-            $aProfileInfo = bx_srv($aProfile['type'], 'get_info', [$aProfile['content_id'], false]);
-
-            $iCfwValue = (int)$aProfile['cfw_value'];
-            $bUpdateCfwValue = false;
-
-            $iCfwItems = $iCfuItems = 0;
-            $bUpdateCfwItems = $bUpdateCfuItems = false;
-            foreach($aFilters as $aFilter) {
-                $iFilter = (int)$aFilter['Value'];
-
-                if(!empty($aFilter['Data'])) {
-                    $aData = unserialize($aFilter['Data']);
-                    if(empty($aData) || !is_array($aData))
-                        continue;
-                }
-                else
-                    $aData = [
-                        'is_allowed_watch' => ['module' => 'system', 'method' => 'is_allowed_cfilter', 'params' => ['watch'], 'class' => 'BaseServiceProfiles'],
-                        'is_allowed_use' => ['module' => 'system', 'method' => 'is_allowed_cfilter', 'params' => ['use'], 'class' => 'BaseServiceProfiles'],
-                    ];
-
-                if(!empty($aData['is_allowed_watch'])) {
-                    $aData['is_allowed_watch']['params'] = array_merge($aData['is_allowed_watch']['params'], [$iFilter, $aProfileInfo]);
-                    
-                    $iWatch = call_user_func_array('bx_srv', $aData['is_allowed_watch']);
-                    if($iWatch === false)
-                        continue;
-
-                    if($iWatch == 0) {
-                        $iCfwValue &= ~ (1 << ($iFilter - 1));
-                        $bUpdateCfwValue = true;
-                    }
-
-                    $iCfwItems |= $iWatch;
-                    $bUpdateCfwItems = true;
-                }
-
-                if(!empty($aData['is_allowed_use']) && (int)$aProfile['cfu_locked'] == 0) {
-                    $aData['is_allowed_use']['params'] = array_merge($aData['is_allowed_use']['params'], [$aFilter['Value'], $aProfileInfo]);
-
-                    $iUse = call_user_func_array('bx_srv', $aData['is_allowed_use']);
-                    if($iUse === false)
-                        continue;
-
-                    $iCfuItems |= $iUse;
-                    $bUpdateCfuItems = true;
-                }
-            }
-
-            if($bUpdateCfwValue) 
-                $oProfileQuery->changeCfwValue($aProfile['id'], $iCfwValue);
-
-            if($bUpdateCfwItems)
-                $oProfileQuery->changeCfwItems($aProfile['id'], $iCfwItems);
-
-            if($bUpdateCfuItems)
-                $oProfileQuery->changeCfuItems($aProfile['id'], $iCfuItems);
-        }
+        $oCf = BxDolContentFilter::getInstance();
+        foreach($aProfiles as $aProfile)
+            $oCf->updateValuesByProfile($aProfile);
     }
     }
 }
 }
 
 

+ 9 - 0
inc/classes/BxDolProfileQuery.php

@@ -71,6 +71,15 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
         $sOrderClause = "`tp`.`id` ASC";
         $sOrderClause = "`tp`.`id` ASC";
 
 
     	switch($aParams['type']) {
     	switch($aParams['type']) {
+            case 'id':
+                $aMethod['name'] = 'getRow';
+                $aMethod['params'][1] = [
+                    'id' => $aParams['id']
+                ];
+
+                $sWhereClause = " AND `tp`.`id`=:id";
+                break;
+
             case 'active':
             case 'active':
                 $sWhereClause = " AND `tp`.`status`='active'";
                 $sWhereClause = " AND `tp`.`status`='active'";
 
 

+ 10 - 0
modules/base/profile/classes/BxBaseModProfileFormsEntryHelper.php

@@ -106,6 +106,9 @@ class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
         if (!$this->isAutoApproval(BX_DOL_PROFILE_ACTIVATE_EDIT) && BX_PROFILE_STATUS_ACTIVE == $sStatus){
         if (!$this->isAutoApproval(BX_DOL_PROFILE_ACTIVATE_EDIT) && BX_PROFILE_STATUS_ACTIVE == $sStatus){
             $aTrackTextFieldsChanges = array ();
             $aTrackTextFieldsChanges = array ();
         }
         }
+
+        if(isset($CNF['FIELD_BIRTHDAY']) && isset($aContentInfo[$CNF['FIELD_BIRTHDAY']]))
+            $oForm->addTrackFields($CNF['FIELD_BIRTHDAY'], $aContentInfo);
     }
     }
 
 
     public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
     public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
@@ -137,6 +140,10 @@ class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
         if(isset($CNF['FIELD_ALLOW_POST_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_POST_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST'])) !== false)
         if(isset($CNF['FIELD_ALLOW_POST_TO']) && !empty($aContentInfo[$CNF['FIELD_ALLOW_POST_TO']]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST'])) !== false)
             $oPrivacy->reassociateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_POST_TO']]);
             $oPrivacy->reassociateGroupCustomWithContent($oProfile->id(), $iContentId, (int)$aContentInfo[$CNF['FIELD_ALLOW_POST_TO']]);
 
 
+        // update content filters
+        if(isset($CNF['FIELD_BIRTHDAY']) && $oForm->isTrackFieldChanged($CNF['FIELD_BIRTHDAY']))
+            BxDolContentFilter::getInstance()->updateValuesByProfile($oProfile->getInfo());
+
         return '';
         return '';
     }
     }
 
 
@@ -190,6 +197,9 @@ class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
             $oAccount->updateProfileContext($iProfileId);
             $oAccount->updateProfileContext($iProfileId);
         }
         }
 
 
+        // update content filters
+        BxDolContentFilter::getInstance()->updateValuesByProfile($oProfile->getInfo());
+
         return '';
         return '';
     }
     }
 
 

+ 1 - 0
modules/boonex/persons/classes/BxPersonsConfig.php

@@ -47,6 +47,7 @@ class BxPersonsConfig extends BxBaseModProfileConfig
             'FIELD_TEXT' => 'description',
             'FIELD_TEXT' => 'description',
             'FIELD_PICTURE' => 'picture',
             'FIELD_PICTURE' => 'picture',
             'FIELD_COVER' => 'cover',
             'FIELD_COVER' => 'cover',
+            'FIELD_BIRTHDAY' => 'birthday',
             'FIELD_ALLOW_VIEW_TO' => 'allow_view_to',
             'FIELD_ALLOW_VIEW_TO' => 'allow_view_to',
             'FIELD_ALLOW_POST_TO' => 'allow_post_to',
             'FIELD_ALLOW_POST_TO' => 'allow_post_to',
             'FIELD_ALLOW_CONTACT_TO' => 'allow_contact_to',
             'FIELD_ALLOW_CONTACT_TO' => 'allow_contact_to',