Alex Trofimov před 8 roky
rodič
revize
b71267cbac

+ 6 - 1
modules/boonex/channels/classes/BxCnlAlertsResponse.php

@@ -20,7 +20,12 @@ class BxCnlAlertsResponse extends BxBaseModGroupsAlertsResponse
     public function response($oAlert)
     {
         parent::response($oAlert);
-        
+
+        $aProfileModulesAutofollowLabels = array('bx_persons', 'bx_organizations');
+        if (in_array($oAlert->sUnit, $aProfileModulesAutofollowLabels) && in_array($oAlert->sAction, array('added', 'edited'))) {
+            $this->_oModule->followLabels($oAlert->sUnit, $oAlert->iObject);
+        }
+
         if ($oAlert->sUnit == 'meta_keyword' && $oAlert->sAction == 'added'){
             if (isset($oAlert->aExtras['meta']) && isset($oAlert->aExtras['object']) && isset($oAlert->iObject) && isset($oAlert->iSender)){
                 $this->_oModule->processHashtag($oAlert->aExtras['meta'], $oAlert->aExtras['object'], $oAlert->iObject, $oAlert->iSender);

+ 34 - 0
modules/boonex/channels/classes/BxCnlModule.php

@@ -208,6 +208,40 @@ class BxCnlModule extends BxBaseModGroupsModule
     {
         return true;
     }
+
+    public function followLabels($sModule, $iContentId)
+    {
+        if (!getParam('bx_channels_labels_autofollow'))
+            return;
+        
+        if (!($oModuleProfiles = BxDolModule::getInstance($sModule)))
+            return;
+
+        if (!($aContentInfo = $oModuleProfiles->_oDb->getContentInfoById($iContentId)) || !($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule)))
+            return;
+
+        $CNF = &$oModuleProfiles->_oConfig->CNF;
+        
+        if (!$oModuleProfiles->serviceActAsProfile() || !isset($CNF['FIELD_LABELS']) || empty($aContentInfo[$CNF['FIELD_ID']]))
+            return;
+
+        if (!($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) || !$oMetatags->keywordsIsEnabled() || !($aLabels = $oMetatags->keywordsGet($aContentInfo[$CNF['FIELD_ID']])))
+            return;
+
+        if (!($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')))
+            return;
+
+        foreach ($aLabels as $sLabel) {
+
+            if (!($iContentIdChannel = $this->_oDb->getChannelIdByName($sLabel)))
+                continue;
+
+            if (!($oProfileChannel = BxDolProfile::getInstanceByContentAndType($iContentIdChannel, 'bx_channels')))
+                continue;
+
+            $oConn->addConnection($oProfile->id(), $oProfileChannel->id());
+        }
+    }
 }
 
 /** @} */

+ 1 - 0
modules/boonex/channels/install/langs/en.xml

@@ -7,6 +7,7 @@
 	<string name="_bx_channels_option_per_page_browse"><![CDATA[Number of items per page]]></string>
 	<string name="_bx_channels_option_num_rss"><![CDATA[Number of items in RSS feed]]></string>
 	<string name="_bx_channels_option_searchable_fields"><![CDATA[Searchable fields]]></string>
+	<string name="_bx_channels_option_labels_autofollow"><![CDATA[Auto-follow channels when used as labels in profiles]]></string>
 	
 	<string name="_bx_channels_form_profile"><![CDATA[Channels]]></string>
 	<string name="_bx_channels_form_profile_display_add"><![CDATA[Add Channel]]></string>

+ 7 - 2
modules/boonex/channels/install/sql/enable.sql

@@ -16,7 +16,8 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `e
 ('bx_channels_num_rss', '10', @iCategId, '_bx_channels_option_num_rss', 'digit', '', '', '', 12),
 ('bx_channels_per_page_browse_showcase', '32', @iCategId, '_sys_option_per_page_browse_showcase', 'digit', '', '', '', 15),
 ('bx_channels_per_page_browse_recommended', '10', @iCategId, '_sys_option_per_page_browse_recommended', 'digit', '', '', '', 16),
-('bx_channels_searchable_fields', 'channel_name', @iCategId, '_bx_channels_option_searchable_fields', 'list', 'a:2:{s:6:"module";s:11:"bx_channels";s:6:"method";s:21:"get_searchable_fields";}', '', '', 30);
+('bx_channels_searchable_fields', 'channel_name', @iCategId, '_bx_channels_option_searchable_fields', 'list', 'a:2:{s:6:"module";s:11:"bx_channels";s:6:"method";s:21:"get_searchable_fields";}', '', '', 30),
+('bx_channels_labels_autofollow', 'on', @iCategId, '_bx_channels_option_labels_autofollow', 'checkbox', '', '', '', 40);
 
 
 -- PAGES
@@ -391,6 +392,10 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_channels', 'timeline_vote', @iHandler),
 ('bx_channels', 'timeline_report', @iHandler),
 ('bx_channels', 'timeline_repost', @iHandler),
+('bx_persons', 'added', @iHandler),
+('bx_persons', 'edited', @iHandler),
+('bx_organizations', 'added', @iHandler),
+('bx_organizations', 'edited', @iHandler),
 ('meta_keyword', 'added', @iHandler),
 ('meta_keyword', 'url', @iHandler),
 ('meta_keyword', 'deleted', @iHandler);
@@ -407,4 +412,4 @@ INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `defau
 
 INSERT INTO `sys_objects_uploader` (`object`, `active`, `override_class_name`, `override_class_file`) VALUES
 ('bx_channels_cover_crop', 1, 'BxCnlUploaderCoverCrop', 'modules/boonex/channels/classes/BxCnlUploaderCoverCrop.php'),
-('bx_channels_picture_crop', 1, 'BxCnlUploaderPictureCrop', 'modules/boonex/channels/classes/BxCnlUploaderPictureCrop.php');
+('bx_channels_picture_crop', 1, 'BxCnlUploaderPictureCrop', 'modules/boonex/channels/classes/BxCnlUploaderPictureCrop.php');