Просмотр исходного кода

#281 Groups: notification for new group request for group admins only

Alex Trofimov 10 лет назад
Родитель
Сommit
c0895cb1b2

+ 3 - 3
modules/boonex/groups/classes/BxGroupsAlertsResponse.php

@@ -37,13 +37,13 @@ class BxGroupsAlertsResponse extends BxDolAlertsResponse
         // join group events
         switch ($oAlert->sAction) {
         case 'join_invitation':
-            $this->sendMailInvitation($oAlert, $oAlert->iObject, $oAlert->iSender);
+            $this->sendMailInvitation($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
             break;
         case 'join_request':
-            $this->sendMailJoinRequest($oAlert, $oAlert->iObject, $oAlert->iSender);
+            $this->sendMailJoinRequest($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
             break;
         case 'join_request_accepted':
-            $this->sendMailJoinRequestAccepted($oAlert, $oAlert->iObject, $oAlert->iSender);
+            $this->sendMailJoinRequestAccepted($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
             break;
         }
 

+ 20 - 5
modules/boonex/groups/classes/BxGroupsModule.php

@@ -126,19 +126,19 @@ class BxGroupsModule extends BxBaseModProfileModule
         // send invitation to the group (@see BxGroupsAlertsResponse)
         if ($iIgnoreJoinConfirmation && !$oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && bx_get_logged_profile_id() != $iProfileId) {
 
-            bx_alert($this->getName(), 'join_invitation', $iProfileId, bx_get_logged_profile_id(), array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId));
+            bx_alert($this->getName(), 'join_invitation', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId, 'profile' => $iProfileId, 'notification_subobject_id' => $iProfileId, 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]));
 
         }
         // send notification to group's admins that new connection is pending confirmation (@see BxGroupsAlertsResponse)
         elseif (!$iIgnoreJoinConfirmation && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && $aContentInfo['join_confirmation']) {
 
-            bx_alert($this->getName(), 'join_request', $iProfileId, bx_get_logged_profile_id(), array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId));
+            bx_alert($this->getName(), 'join_request', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId, 'profile' => $iProfileId, 'notification_subobject_id' => $iProfileId, 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]));
 
         }
         // send notification that join request was accepted (@see BxGroupsAlertsResponse)
         else if (!$iIgnoreJoinConfirmation && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id(), true) && $oGroupProfile->getModule() != $this->getName() && bx_get_logged_profile_id() != $iProfileId) {
             
-            bx_alert($this->getName(), 'join_request_accepted', $iProfileId, bx_get_logged_profile_id(), array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId));
+            bx_alert($this->getName(), 'join_request_accepted', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId, 'profile' => $iProfileId, 'notification_subobject_id' => $iProfileId, 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]));
 
         }
 
@@ -236,19 +236,34 @@ class BxGroupsModule extends BxBaseModProfileModule
                 array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
 
                 array('group' => $sModule . '_fan_added', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'fan_added', 'module_name' => $sModule, 'module_method' => 'get_notifications_fan_added', 'module_class' => 'Module'),
+                array('group' => $sModule . '_join_request', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'join_request', 'module_name' => $sModule, 'module_method' => 'get_notifications_join_request', 'module_class' => 'Module', 'module_event_privacy' => 'bx_groups_allow_view_notification_to'),
             ),
             'alerts' => array(
                 array('unit' => $sModule, 'action' => 'doVote'),
                 array('unit' => $sModule, 'action' => 'undoVote'),
                 array('unit' => $sModule, 'action' => 'fan_added'),
+                array('unit' => $sModule, 'action' => 'join_request'),
             )
         );
     }
 
+    /**
+     * Notification about new member requst in the group
+     */
+    public function serviceGetNotificationsJoinRequest($aEvent)
+    {
+        return $this->_serviceGetNotification($aEvent, '_bx_groups_txt_ntfs_join_request');
+    }
+    
 	/**
-     * Entry post comment for Notifications module
+     * Notification about new member in the group
      */
     public function serviceGetNotificationsFanAdded($aEvent)
+    {
+        return $this->_serviceGetNotification($aEvent, '_bx_groups_txt_ntfs_fan_added');
+    }
+
+    public function _serviceGetNotification($aEvent, $sLangKey)
     {
     	$CNF = &$this->_oConfig->CNF;
 
@@ -272,7 +287,7 @@ class BxGroupsModule extends BxBaseModProfileModule
 			'entry_author' => $oGroupProfile->id(), // $aContentInfo[$CNF['FIELD_AUTHOR']],
 			'subentry_sample' => $oProfile->getDisplayName(),
 			'subentry_url' => $oProfile->getUrl(),
-			'lang_key' => '_bx_groups_txt_ntfs_fan_added',
+			'lang_key' => $sLangKey,
 		);
     }
 

+ 33 - 0
modules/boonex/groups/classes/BxGroupsPrivacyNotifications.php

@@ -0,0 +1,33 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Groups Groups
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+bx_import('Privacy', 'bx_groups');
+
+class BxGroupsPrivacyNotifications extends BxGroupsPrivacy
+{
+    function __construct($aOptions, $oTemplate = false)
+    {
+        parent::__construct($aOptions, $oTemplate);
+    }
+
+    function check($iObjectId, $iViewerId = 0)
+    {
+        if (!parent::check($iObjectId, $iViewerId))
+            return false;
+
+        if (!($aEvent = BxDolService::call('bx_notifications', 'get_event_by_id', array($iObjectId))))
+            return false;
+
+        return $this->_oModule->_oDb->isAdmin($aEvent['object_owner_id'], $iViewerId ? $iViewerId : bx_get_logged_profile_id());
+    }
+}
+
+/** @} */

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

@@ -209,6 +209,7 @@
     <string name="_bx_groups_txt_private_group"><![CDATA[Private group]]></string>
 
     <string name="_bx_groups_txt_ntfs_fan_added"><![CDATA[<a class="bx-ntfs-content-profile" href="{owner_link}">{owner_name}</a> group has got new member - <a href="{subentry_url}">{subentry_sample}</a>]]></string>
+    <string name="_bx_groups_txt_ntfs_join_request"><![CDATA[<a class="bx-ntfs-content-profile" href="{owner_link}">{owner_name}</a> group has new request from <a href="{subentry_url}">{subentry_sample}</a>]]></string>
 
     <string name="_bx_groups_privacy_group_closed"><![CDATA[Closed]]></string>
     <string name="_bx_groups_privacy_group_secret"><![CDATA[Secret]]></string>

+ 1 - 0
modules/boonex/groups/install/langs/ru.xml

@@ -208,6 +208,7 @@
     <string name="_bx_groups_txt_private_group"><![CDATA[Приватная группа]]></string>
 
     <string name="_bx_groups_txt_ntfs_fan_added"><![CDATA[В группу "<a class="bx-ntfs-content-profile" href="{owner_link}">{owner_name}</a>" добавился новый член - <a href="{subentry_url}">{subentry_sample}</a>]]></string>
+    <string name="_bx_groups_txt_ntfs_join_request"><![CDATA[В группу "<a class="bx-ntfs-content-profile" href="{owner_link}">{owner_name}</a>" хочет присоединиться новый член - <a href="{subentry_url}">{subentry_sample}</a>]]></string>
 
     <string name="_bx_groups_privacy_group_closed"><![CDATA[Закрытая группа]]></string>
     <string name="_bx_groups_privacy_group_secret"><![CDATA[Секретная группа]]></string>

+ 1 - 1
modules/boonex/groups/install/sql/disable.sql

@@ -56,7 +56,7 @@ DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandler;
 
 -- PRIVACY 
 
-DELETE FROM `sys_objects_privacy` WHERE `object` = 'bx_groups_allow_view_to';
+DELETE FROM `sys_objects_privacy` WHERE `object` IN('bx_groups_allow_view_to', 'bx_groups_allow_view_notification_to');
 
 -- EMAIL TEMPLATES
 

+ 2 - 1
modules/boonex/groups/install/sql/enable.sql

@@ -389,7 +389,8 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 -- PRIVACY 
 
 INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
-('bx_groups_allow_view_to', 'bx_groups', 'view', '_bx_groups_form_profile_input_allow_view_to', '3', 'bx_groups_data', 'id', 'author', 'BxGroupsPrivacy', 'modules/boonex/groups/classes/BxGroupsPrivacy.php');
+('bx_groups_allow_view_to', 'bx_groups', 'view', '_bx_groups_form_profile_input_allow_view_to', '3', 'bx_groups_data', 'id', 'author', 'BxGroupsPrivacy', 'modules/boonex/groups/classes/BxGroupsPrivacy.php'),
+('bx_groups_allow_view_notification_to', 'bx_groups', 'view_event', '_bx_groups_form_profile_input_allow_view_notification_to', '3', 'bx_notifications_events', 'id', 'object_owner_id', 'BxGroupsPrivacyNotifications', 'modules/boonex/groups/classes/BxGroupsPrivacyNotifications.php');
 
 -- EMAIL TEMPLATES
 

+ 9 - 0
modules/boonex/notifications/classes/BxNtfsModule.php

@@ -90,6 +90,15 @@ class BxNtfsModule extends BxBaseModNotificationsModule
         return array('content' => $sContent, 'menu' => $oMenu); 
     }
 
+    public function serviceGetEventById($iId)
+    {
+        $aParams = [
+            'browse' => 'id',
+            'value' => $iId,
+        ];
+    	return $this->_oDb->getEvents($aParams);
+    }
+
     public function serviceGetUnreadNotificationsNum($iOwnerId = 0)
     {
     	if(!$iOwnerId)