Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function addTopicParticipants( $topicID, $invitedUsers, $readingMemberID )
- {
- //-----------------------------------------
- // INIT
- //-----------------------------------------
- $topicData = $this->fetchTopicData( $topicID );
- $memberData = IPSMember::load( intval( $readingMemberID ), 'extendedProfile,groups' );
- $currentParticipants = $this->fetchTopicParticipants( $topicID );
- //-----------------------------------------
- // Can access this topic?
- //-----------------------------------------
- if ( $this->canAccessTopic( $memberData['member_id'], $topicData, $currentParticipants ) !== TRUE )
- {
- throw new Exception( 'NO_PERMISSION' );
- }
- //-----------------------------------------
- // Build invited users
- //-----------------------------------------
- $invitedUsersData = $this->checkAndReturnInvitedUsers( $invitedUsers, $memberData, count($currentParticipants) );
- if ( isset($invitedUsersData[ $topicData['mt_starter_id'] ]) )
- {
- if ( $memberData['member_id'] == $topicData['mt_starter_id'] )
- {
- throw new Exception( 'CANT_INVITE_SELF' );
- }
- }
- if ( isset($invitedUsersData[ $topicData['mt_to_member_id'] ]) OR isset($invitedUsersData[ $topicData['mt_starter_id'] ]) )
- {
- throw new Exception( 'CANT_INVITE_RECIPIENT_EXIST' );
- }
- //-----------------------------------------
- // Knock out ones that are already participated
- // At this point $currentParticipants contains non-active
- // participants. This is OK as we don't want the ability
- // to keep re-inviting those who choose to leave.
- //-----------------------------------------
- $existInBoth = array_intersect( array_keys( $currentParticipants ), array_keys( $invitedUsersData ) );
- if ( count( $existInBoth ) )
- {
- foreach( $existInBoth as $id )
- {
- unset( $invitedUsersData[ $id ] );
- }
- }
- //-----------------------------------------
- // Anything left?
- //-----------------------------------------
- if ( ! count( $invitedUsersData ) )
- {
- throw new Exception( 'NO_ONE_TO_INVITE' );
- }
- //-----------------------------------------
- // Update the topic
- // Now we can strip non-active participants
- //-----------------------------------------
- $__topicParticipants = array_merge( array_keys( $this->_stripNonActiveParticipants( $currentParticipants ) ), array_keys( $invitedUsersData ) );
- /* Fix up so they're unique and indexed by member ID */
- if ( is_array( $__topicParticipants ) AND count ( $__topicParticipants ) )
- {
- foreach( $__topicParticipants as $_mid )
- {
- $_topicParticipants[ $_mid ] = $_mid;
- }
- }
- /* Remove topic starter */
- unset( $_topicParticipants[ $topicData['mt_starter_id'] ] );
- /* Remove recipient */
- unset( $_topicParticipants[ $topicData['mt_to_member_id'] ] );
- $this->DB->update( 'message_topics', array( 'mt_invited_members' => serialize( $_topicParticipants ),
- 'mt_to_count' => count( $_topicParticipants ) + 1 ), 'mt_id=' . $topicID );
- //-----------------------------------------
- // Add the users to the invite tree
- //-----------------------------------------
- foreach( $invitedUsersData as $id => $toMember )
- {
- $this->DB->insert( 'message_topic_user_map', array( 'map_user_id' => $id,
- 'map_topic_id' => $topicID,
- 'map_folder_id' => 'myconvo',
- 'map_user_active' => 1,
- 'map_has_unread' => 1,
- 'map_user_banned' => 0,
- 'map_read_time' => 0,
- 'map_left_time' => 0,
- 'map_ignore_notification' => 0,
- 'map_last_topic_reply' => $topicData['mt_last_post_time'] ) );
- $new_vdir = $this->rebuildFolderCount( $toMember['member_id'], array( 'myconvo' => 'plus:1', 'new' => 'plus:1' ), TRUE, array( 'core' => array( 'msg_count_total' => 'plus:1',
- 'msg_count_new' => 'plus:1' ) ) );
- //-----------------------------------------
- // Notifications library
- //-----------------------------------------
- $classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications' );
- $notifyLibrary = new $classToLoad( $this->registry );
- $toMember['language'] = $toMember['language'] == "" ? IPSLib::getDefaultLanguage() : $toMember['language'];
- IPSText::getTextClass('email')->getTemplate( "personal_convo_invite", $toMember['language'] );
- IPSText::getTextClass('email')->buildMessage( array(
- 'NAME' => $toMember['members_display_name'],
- 'POSTER' => $memberData['members_display_name'],
- 'TITLE' => $topicData['mt_title'],
- 'LINK' => "?app=members&module=messaging§ion=view&do=showConversation&topicID={$topicID}" ) );
- IPSText::getTextClass('email')->subject = sprintf(
- IPSText::getTextClass('email')->subject,
- $this->registry->output->buildSEOUrl( 'showuser=' . $memberData['member_id'], 'public', $memberData['members_seo_name'], 'showuser' ),
- $memberData['members_display_name'],
- $this->registry->output->buildUrl( "app=members&module=messaging§ion=view&do=showConversation&topicID={$topicID}", 'public' )
- );
- $notifyLibrary->setMember( $toMember );
- $notifyLibrary->setFrom( $memberData );
- $notifyLibrary->setNotificationKey( 'invite_private_message' );
- $notifyLibrary->setNotificationUrl( $this->registry->output->buildUrl( "app=members&module=messaging§ion=view&do=showConversation&topicID={$topicID}", 'public' ) );
- $notifyLibrary->setNotificationText( IPSText::getTextClass('email')->message );
- $notifyLibrary->setNotificationTitle( IPSText::getTextClass('email')->subject );
- try
- {
- $notifyLibrary->sendNotification();
- }
- catch( Exception $e ){}
- }
- return TRUE;
- }
- /**
- * Delete personal topics
- *
- * @param int Owner Member dID
- * @param array Array of IDs to delete
- * @param string [ Raw SQL to query on when selecting messages to delete, optional ]
- * @param bool Force hard delete
- * @return mixed bool or exception
- *
- * <code>
- * Exception Codes:
- * NO_SUCH_MEMBER: The member ID does not exist
- * NO_IDS_TO_DELETE: No IDs to delete (empty id array)
- * </code>
- */
- public function deleteTopics( $memberID, $ids, $rawSQL=NULL, $hardDelete=false )
- {
- //-----------------------------------------
- // Grab data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement