示例#1
0
 /**
  * Save a conversation
  *
  * @since	3.0
  * @access	public
  */
 public function save()
 {
     $config = DiscussHelper::getConfig();
     $app = JFactory::getApplication();
     $my = JFactory::getUser();
     $ajax = new Disjax();
     $content = JRequest::getVar('contents');
     $recipientId = JRequest::getInt('recipient');
     // Test for valid recipients.
     if (!$recipientId) {
         return $ajax->send();
     }
     // Test for empty contents here.
     if (empty($content)) {
         exit;
     }
     // Do not allow user to send a message to himself, it's crazy.
     if ($recipientId == $my->id) {
         echo JText::_('You should not start a conversation with your self.');
         return $ajax->send();
     }
     // Initialize conversation table.
     $conversation = DiscussHelper::getTable('Conversation');
     // Check if this conversation already exist in the system.
     $state = $conversation->loadByRelation($my->id, $recipientId);
     $model = DiscussHelper::getModel('Conversation');
     // If the conversation does not exist, we need to create the conversation and add a recipient.
     if (!$state) {
         $date = DiscussHelper::getDate()->toMySQL();
         $conversation->created = $date;
         $conversation->created_by = $my->id;
         $conversation->lastreplied = $date;
         $conversation->store();
         // Add participant to this conversation.
         $model->addParticipant($conversation->id, $recipientId, $my->id);
     } else {
         // Set last replied date if this is a reply.
         $conversation->lastreplied = DiscussHelper::getDate()->toMySQL();
         $conversation->store();
     }
     // Initialize message table.
     $message = DiscussHelper::getTable('ConversationMessage');
     $message->message = $content;
     $message->conversation_id = $conversation->id;
     $message->created = DiscussHelper::getDate()->toMySQL();
     $message->created_by = $my->id;
     $message->store();
     // Add message map so that recipient can view the message.
     $model->addMessageMap($conversation->id, $message->id, $recipientId, $my->id);
     // Format conversation replies.
     $data = array($message);
     DiscussHelper::formatConversationReplies($data);
     $reply = $data[0];
     // Send notification to the recipient.
     $conversation->notify($reply);
     $options = new stdClass();
     $options->content = JText::_('COM_EASYDISCUSS_CONVERSATION_MESSAGE_SUCCESSFULLY_SENT');
     $options->title = JText::_('COM_EASYDISCUSS_DIALOG_TITLE_NEW_CONVERSATION');
     $buttons = array();
     $button = new stdClass();
     $button->title = JText::_('COM_EASYDISCUSS_BUTTON_CLOSE');
     $button->action = 'disjax.closedlg();';
     $buttons[] = $button;
     $options->buttons = $buttons;
     $options->width = 500;
     $ajax = DiscussHelper::getHelper('Ajax');
     $ajax->resolve($options);
     return $ajax->send();
 }
示例#2
0
 /**
  * Displays the conversation.
  *
  * @since	3.0
  * @access	public
  */
 public function read()
 {
     $id = JRequest::getInt('id');
     $app = JFactory::getApplication();
     $my = JFactory::getUser();
     // Do not allow non logged in users to view anything in conversation.
     if (!$my->id) {
         $returnURL = base64_encode(JRequest::getURI());
         //DiscussHelper::setMessageQueue( JText::_( 'COM_EASYDISCUSS_NOT_ALLOWED' ) , DISCUSS_QUEUE_ERROR );
         //$app->redirect( DiscussRouter::_( 'index.php?option=com_easydiscuss&view=index' , false ) );
         $app->redirect(DiscussHelper::getLoginLink($returnURL));
         $app->close();
     }
     // Try to load the conversation
     $conversation = DiscussHelper::getTable('Conversation');
     $state = $conversation->load($id);
     // The conversation id needs to be valid.
     if (!$state) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CONVERSATION_INVALID'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false));
         $app->close();
     }
     // Check if the current logged in user has access to this conversation.
     $model = DiscussHelper::getModel('Conversation');
     if (!$model->hasAccess($conversation->id, $my->id)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NOT_ALLOWED'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false));
         $app->close();
     }
     $doc = JFactory::getDocument();
     $result = $conversation->getParticipants($my->id);
     $user = DiscussHelper::getTable('Profile');
     $user->load($result[0]);
     DiscussHelper::setPageTitle(JText::sprintf('COM_EASYDISCUSS_VIEW_CONVERSATION_TITLE', $this->escape($user->getName())));
     // Mark this message as read for the current logged in user.
     $conversation->markAsRead($my->id);
     // Check if it is view all messages
     $viewAll = JRequest::getVar('show');
     $count = JRequest::getInt('count');
     if ($viewAll == 'all') {
         // For future use
         $count = '';
     }
     if ($viewAll == 'previous') {
         $count = JRequest::getInt('count');
         // Check if the value is integer, we do no want any weird values
         if (isset($count) && is_int($count)) {
             // Convert to absolute number
             $count = abs($count);
         }
     }
     // Get replies in the conversation
     $replies = $model->getMessages($conversation->id, $my->id, $viewAll, $count);
     // Format conversation replies.
     DiscussHelper::formatConversationReplies($replies);
     // Format the conversation object.
     $data = array($conversation);
     DiscussHelper::formatConversations($data);
     $theme = new DiscussThemes();
     $theme->set('replies', $replies);
     $theme->set('conversation', $data[0]);
     echo $theme->fetch('conversation.read.php');
 }