Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.94 KB | None | 0 0
  1. public function addTopicParticipants( $topicID, $invitedUsers, $readingMemberID )
  2.  
  3. {
  4.  
  5. //-----------------------------------------
  6.  
  7. // INIT
  8.  
  9. //-----------------------------------------
  10.  
  11.  
  12.  
  13. $topicData = $this->fetchTopicData( $topicID );
  14.  
  15. $memberData = IPSMember::load( intval( $readingMemberID ), 'extendedProfile,groups' );
  16.  
  17. $currentParticipants = $this->fetchTopicParticipants( $topicID );
  18.  
  19.  
  20.  
  21. //-----------------------------------------
  22.  
  23. // Can access this topic?
  24.  
  25. //-----------------------------------------
  26.  
  27.  
  28.  
  29. if ( $this->canAccessTopic( $memberData['member_id'], $topicData, $currentParticipants ) !== TRUE )
  30.  
  31. {
  32.  
  33. throw new Exception( 'NO_PERMISSION' );
  34.  
  35. }
  36.  
  37.  
  38.  
  39. //-----------------------------------------
  40.  
  41. // Build invited users
  42.  
  43. //-----------------------------------------
  44.  
  45.  
  46.  
  47. $invitedUsersData = $this->checkAndReturnInvitedUsers( $invitedUsers, $memberData, count($currentParticipants) );
  48.  
  49.  
  50.  
  51. if ( isset($invitedUsersData[ $topicData['mt_starter_id'] ]) )
  52.  
  53. {
  54.  
  55. if ( $memberData['member_id'] == $topicData['mt_starter_id'] )
  56.  
  57. {
  58.  
  59. throw new Exception( 'CANT_INVITE_SELF' );
  60.  
  61. }
  62.  
  63. }
  64.  
  65.  
  66.  
  67. if ( isset($invitedUsersData[ $topicData['mt_to_member_id'] ]) OR isset($invitedUsersData[ $topicData['mt_starter_id'] ]) )
  68.  
  69. {
  70.  
  71. throw new Exception( 'CANT_INVITE_RECIPIENT_EXIST' );
  72.  
  73. }
  74.  
  75.  
  76.  
  77. //-----------------------------------------
  78.  
  79. // Knock out ones that are already participated
  80.  
  81. // At this point $currentParticipants contains non-active
  82.  
  83. // participants. This is OK as we don't want the ability
  84.  
  85. // to keep re-inviting those who choose to leave.
  86.  
  87. //-----------------------------------------
  88.  
  89.  
  90.  
  91. $existInBoth = array_intersect( array_keys( $currentParticipants ), array_keys( $invitedUsersData ) );
  92.  
  93.  
  94.  
  95. if ( count( $existInBoth ) )
  96.  
  97. {
  98.  
  99. foreach( $existInBoth as $id )
  100.  
  101. {
  102.  
  103. unset( $invitedUsersData[ $id ] );
  104.  
  105. }
  106.  
  107. }
  108.  
  109.  
  110.  
  111. //-----------------------------------------
  112.  
  113. // Anything left?
  114.  
  115. //-----------------------------------------
  116.  
  117.  
  118.  
  119. if ( ! count( $invitedUsersData ) )
  120.  
  121. {
  122.  
  123. throw new Exception( 'NO_ONE_TO_INVITE' );
  124.  
  125. }
  126.  
  127.  
  128.  
  129. //-----------------------------------------
  130.  
  131. // Update the topic
  132.  
  133. // Now we can strip non-active participants
  134.  
  135. //-----------------------------------------
  136.  
  137.  
  138.  
  139. $__topicParticipants = array_merge( array_keys( $this->_stripNonActiveParticipants( $currentParticipants ) ), array_keys( $invitedUsersData ) );
  140.  
  141.  
  142.  
  143. /* Fix up so they're unique and indexed by member ID */
  144.  
  145. if ( is_array( $__topicParticipants ) AND count ( $__topicParticipants ) )
  146.  
  147. {
  148.  
  149. foreach( $__topicParticipants as $_mid )
  150.  
  151. {
  152.  
  153. $_topicParticipants[ $_mid ] = $_mid;
  154.  
  155. }
  156.  
  157. }
  158.  
  159.  
  160.  
  161. /* Remove topic starter */
  162.  
  163. unset( $_topicParticipants[ $topicData['mt_starter_id'] ] );
  164.  
  165.  
  166.  
  167. /* Remove recipient */
  168.  
  169. unset( $_topicParticipants[ $topicData['mt_to_member_id'] ] );
  170.  
  171.  
  172.  
  173. $this->DB->update( 'message_topics', array( 'mt_invited_members' => serialize( $_topicParticipants ),
  174.  
  175. 'mt_to_count' => count( $_topicParticipants ) + 1 ), 'mt_id=' . $topicID );
  176.  
  177.  
  178.  
  179. //-----------------------------------------
  180.  
  181. // Add the users to the invite tree
  182.  
  183. //-----------------------------------------
  184.  
  185.  
  186.  
  187. foreach( $invitedUsersData as $id => $toMember )
  188.  
  189. {
  190.  
  191. $this->DB->insert( 'message_topic_user_map', array( 'map_user_id' => $id,
  192.  
  193. 'map_topic_id' => $topicID,
  194.  
  195. 'map_folder_id' => 'myconvo',
  196.  
  197. 'map_user_active' => 1,
  198.  
  199. 'map_has_unread' => 1,
  200.  
  201. 'map_user_banned' => 0,
  202.  
  203. 'map_read_time' => 0,
  204.  
  205. 'map_left_time' => 0,
  206.  
  207. 'map_ignore_notification' => 0,
  208.  
  209. 'map_last_topic_reply' => $topicData['mt_last_post_time'] ) );
  210.  
  211.  
  212.  
  213.  
  214.  
  215. $new_vdir = $this->rebuildFolderCount( $toMember['member_id'], array( 'myconvo' => 'plus:1', 'new' => 'plus:1' ), TRUE, array( 'core' => array( 'msg_count_total' => 'plus:1',
  216.  
  217. 'msg_count_new' => 'plus:1' ) ) );
  218.  
  219.  
  220.  
  221. //-----------------------------------------
  222.  
  223. // Notifications library
  224.  
  225. //-----------------------------------------
  226.  
  227.  
  228.  
  229. $classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications' );
  230.  
  231. $notifyLibrary = new $classToLoad( $this->registry );
  232.  
  233.  
  234.  
  235. $toMember['language'] = $toMember['language'] == "" ? IPSLib::getDefaultLanguage() : $toMember['language'];
  236.  
  237.  
  238.  
  239. IPSText::getTextClass('email')->getTemplate( "personal_convo_invite", $toMember['language'] );
  240.  
  241.  
  242.  
  243. IPSText::getTextClass('email')->buildMessage( array(
  244.  
  245. 'NAME' => $toMember['members_display_name'],
  246.  
  247. 'POSTER' => $memberData['members_display_name'],
  248.  
  249. 'TITLE' => $topicData['mt_title'],
  250.  
  251. 'LINK' => "?app=members&module=messaging&section=view&do=showConversation&topicID={$topicID}" ) );
  252.  
  253.  
  254.  
  255. IPSText::getTextClass('email')->subject = sprintf(
  256.  
  257. IPSText::getTextClass('email')->subject,
  258.  
  259. $this->registry->output->buildSEOUrl( 'showuser=' . $memberData['member_id'], 'public', $memberData['members_seo_name'], 'showuser' ),
  260.  
  261. $memberData['members_display_name'],
  262.  
  263. $this->registry->output->buildUrl( "app=members&module=messaging&section=view&do=showConversation&topicID={$topicID}", 'public' )
  264.  
  265. );
  266.  
  267.  
  268.  
  269. $notifyLibrary->setMember( $toMember );
  270.  
  271. $notifyLibrary->setFrom( $memberData );
  272.  
  273. $notifyLibrary->setNotificationKey( 'invite_private_message' );
  274.  
  275. $notifyLibrary->setNotificationUrl( $this->registry->output->buildUrl( "app=members&module=messaging&section=view&do=showConversation&topicID={$topicID}", 'public' ) );
  276.  
  277. $notifyLibrary->setNotificationText( IPSText::getTextClass('email')->message );
  278.  
  279. $notifyLibrary->setNotificationTitle( IPSText::getTextClass('email')->subject );
  280.  
  281.  
  282.  
  283. try
  284.  
  285. {
  286.  
  287. $notifyLibrary->sendNotification();
  288.  
  289. }
  290.  
  291. catch( Exception $e ){}
  292.  
  293. }
  294.  
  295.  
  296.  
  297. return TRUE;
  298.  
  299. }
  300.  
  301. /**
  302.  
  303. * Delete personal topics
  304.  
  305. *
  306.  
  307. * @param int Owner Member dID
  308.  
  309. * @param array Array of IDs to delete
  310.  
  311. * @param string [ Raw SQL to query on when selecting messages to delete, optional ]
  312.  
  313. * @param bool Force hard delete
  314.  
  315. * @return mixed bool or exception
  316.  
  317. *
  318.  
  319. * <code>
  320.  
  321. * Exception Codes:
  322.  
  323. * NO_SUCH_MEMBER: The member ID does not exist
  324.  
  325. * NO_IDS_TO_DELETE: No IDs to delete (empty id array)
  326.  
  327. * </code>
  328.  
  329. */
  330.  
  331. public function deleteTopics( $memberID, $ids, $rawSQL=NULL, $hardDelete=false )
  332.  
  333. {
  334.  
  335. //-----------------------------------------
  336.  
  337. // Grab data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement