• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

chat/classes/class.ilObjChat.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00034 require_once "classes/class.ilObjectGUI.php";
00035 require_once "chat/classes/class.ilChatServerConfig.php";
00036 require_once "chat/classes/class.ilChatServerCommunicator.php";
00037 require_once "chat/classes/class.ilChatUser.php";
00038 require_once "chat/classes/class.ilChatRoom.php";
00039 require_once "chat/classes/class.ilFileDataChat.php";
00040 
00041 class ilObjChat extends ilObject
00042 {
00043         var $server_conf;
00044         var $server_comm;
00045         var $chat_room;
00046         var $chat_user;
00047 
00054         function ilObjChat($a_id = 0,$a_call_by_reference = true)
00055         {
00056                 $this->type = "chat";
00057                 $this->ilObject($a_id,$a_call_by_reference);
00058 
00059                 $this->server_conf =& new ilChatServerConfig();
00060                 $this->server_comm =& new ilChatServerCommunicator($this);
00061                 $this->chat_user =& new ilChatUser();
00062                 $this->chat_room =& new ilChatRoom($this->getRefId());
00063         }
00064 
00065         function read()
00066         {
00067                 // USED ilObjectFactory::getInstance...
00068                 parent::read();
00069 
00070                 $this->server_conf =& new ilChatServerConfig();
00071                 $this->server_comm =& new ilChatServerCommunicator($this);
00072                 $this->chat_user =& new ilChatUser();
00073                 $this->chat_room =& new ilChatRoom($this->getRefId());
00074         }
00075 
00076         function ilClone($a_parent_ref)
00077         {
00078                 $tmp_obj =& ilObjectFactory::getInstanceByRefId(parent::ilClone($a_parent_ref));
00079         }
00080 
00081 
00082         function delete()
00083         {
00084                 if(!parent::delete())
00085                 {
00086                         return false;
00087                 }
00088                 $rooms = $this->chat_room->getAllRoomsOfObject();
00089                 foreach($rooms as $id)
00090                 {
00091                         $this->chat_room->delete($id);
00092                 }
00093 
00094                 // FINALLY DELETE MESSAGES IN PUBLIC ROOM
00095                 $query = "DELETE FROM chat_room_messages ".
00096                         "WHERE chat_id = '".$this->getRefId()."'";
00097 
00098                 $res = $this->ilias->db->query($query);
00099 
00100                 // AND ALL USERS
00101                 $query = "DELETE FROM chat_user ".
00102                         "WHERE chat_id = '".$this->getRefId()."'";
00103 
00104                 $res = $this->ilias->db->query($query);
00105 
00106                 return true;
00107         }
00108 
00109         function sendMessage($a_id)
00110         {
00111                 include_once "./classes/class.ilMail.php";
00112 
00113                 $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
00114 
00115                 // GET USER OBJECT
00116                 $tmp_user = ilObjectFactory::getInstanceByObjId($a_id);
00117 
00118                 // GET USERS LANGUAGE
00119                 $tmp_lang =& new ilLanguage($tmp_user->getLanguage());
00120                 $tmp_lang->loadLanguageModule("chat");
00121 
00122                 $message = $tmp_mail_obj->sendMail($this->__formatRecipient($tmp_user),"","",$this->__formatSubject($tmp_lang),
00123                                                                                    $this->__formatBody($tmp_user,$tmp_lang),array(),array("normal"));
00124 
00125                 unset($tmp_mail_obj);
00126                 unset($tmp_lang);
00127                 unset($tmp_user);
00128 
00129                 return true;
00130         }
00131 
00132         function getHTMLDirectory()
00133         {
00134                 $tmp_tpl =& new ilTemplate("tpl.chat_export.html",true,true);
00135                 
00136                 $this->chat_room->setRoomId(0);
00137 
00138                 $tmp_tpl->setVariable("CHAT_NAME",$this->getTitle());
00139                 $tmp_tpl->setVariable("CHAT_DATE",strftime("%c",time()));
00140                 $tmp_tpl->setVariable("CONTENT",$this->chat_room->getAllMessages());
00141 
00142                 $file_obj =& new ilFileDataChat($this);
00143                 
00144                 // return directory name of index.html
00145                 return $file_obj->addFile('index.html',$tmp_tpl->get());
00146         }
00147 
00148         // PRIVATE
00149         function __formatRecipient(&$user)
00150         {
00151                 if(is_object($user))
00152                 {
00153                         return $user->getLogin();
00154                 }
00155                 return false;
00156         }
00157 
00158         function __formatSubject(&$lang)
00159         {
00160                 return $lang->txt("chat_invitation_subject");
00161         }
00162 
00163         function __formatBody(&$user,&$lang)
00164         {
00165                 $room_id = $this->chat_room->getRoomId();
00166 
00167                 $body = $lang->txt("chat_invitation_body")." ";
00168                 $body .= $this->ilias->account->getFullname();
00169                 $body .= "\n";
00170                 $body .= $lang->txt("chat_chatroom_body")." ".$this->chat_room->getTitle()."\n\n";
00171                 $body .= "<a class=\"navigation\" href=\"./chat/chat.php?room_id=".$room_id."&ref_id=".$this->getRefId()."\" target=\"_blank\">".
00172                         $lang->txt("chat_to_chat_body")."</a>";
00173 
00174                 return $body;
00175         }
00176         // SET/GET
00177 } // END class.ilObjTest
00178 ?>

Generated on Fri Dec 13 2013 09:06:33 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1