diff --git a/application/controllers/api/frontend/v1/messages/Messages.php b/application/controllers/api/frontend/v1/messages/Messages.php index d080cbee3..65c354c4f 100644 --- a/application/controllers/api/frontend/v1/messages/Messages.php +++ b/application/controllers/api/frontend/v1/messages/Messages.php @@ -19,7 +19,8 @@ class Messages extends FHCAPI_Controller 'getVorlagentext' => ['admin:r', 'assistenz:r'], 'getPreviewText' => ['admin:r', 'assistenz:r'], 'getReplyData' => ['admin:r', 'assistenz:r'], - 'getPersonIdFromUid' => ['admin:r', 'assistenz:r'], + 'getPersonId' => ['admin:r', 'assistenz:r'], + 'getUid' => ['admin:r', 'assistenz:r'], ]); //Load Models @@ -42,17 +43,8 @@ class Messages extends FHCAPI_Controller public function getMessages($id, $type_id) { - switch($type_id) - { - case 'uid': - $id = $this->_getPersonIdFromUid($id); - break; - case 'person_id': - $id = $id; - break; - default: - $this->terminateWithError("MESSAGES::getMessages logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); - break; + if($type_id != 'person_id'){ + $id = $this->_getPersonId($id, $type_id); } $result = $this->MessageModel->getMessagesForTable($id); @@ -74,15 +66,13 @@ class Messages extends FHCAPI_Controller $this->load->model('system/Vorlage_model', 'VorlageModel'); - //39 Stück Variante OE $result = $this->VorlageModel->getAllVorlagenByOe($oe_kurzbz->oe_kurzbz); $data = $this->getDataOrTerminateWithError($result); $this->terminateWithSuccess($data); - //IF ADMIN 167 + //If admin $this->VorlageModel->addOrder('vorlage_kurzbz', 'ASC'); - //only HTML-vorlagen -> for admin $result = $this->VorlageModel->loadWhere( array( 'mimetype' => 'text/html' @@ -97,7 +87,7 @@ class Messages extends FHCAPI_Controller public function getVorlagentext($vorlage_kurzbz) { //$this->terminateWithError("vor " . $vorlage_kurzbz, self::ERROR_TYPE_GENERAL); - //$studiengang_kz = 227; //TODO(Manu) check dynamisieren NULL + //$studiengang_kz = 227; //TODO(Manu) dynamisieren NULL $studiengang_kz = 0; $this->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel'); $this->VorlagestudiengangModel->addOrder('version', 'DESC'); @@ -127,49 +117,32 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($data); } - public function getMsgVarsPrestudent($uid) + public function getMsgVarsPrestudent($id, $typeId) { - $prestudent_id = $this-> _getPrestudentIdFromUid($uid); + $prestudent_id = ($typeId == 'prestudent_id') ? $id : $this->_getPrestudentIdFromUid($id); $result = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); $data = $this->getDataOrTerminateWithError($result); - $this->terminateWithSuccess($data); } public function getMsgVarsLoggedInUser() { - $uid = getAuthUID(); - $result = $this->MessageModel->getMsgVarsLoggedInUser(); - $data = $this->getDataOrTerminateWithError($result); - $this->terminateWithSuccess($data); } public function getNameOfDefaultRecipient($id, $type_id) { - switch($type_id) - { - case 'uid': - $id = $this->_getPersonIdFromUid($id); - break; - case 'person_id': - $id = $id; - break; - default: - $this->terminateWithError("MESSAGES::getNameOfDefaultRecipient logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); - break; - } + $id = $type_id!='person_id)' ? $this->_getPersonId($id, $type_id) : $id; $this->load->model('person/Person_model', 'PersonModel'); $result = $this->PersonModel->load($id); - //$this->terminateWithSuccess($result); $data = $this->getDataOrTerminateWithError($result); $name = current($data); @@ -178,8 +151,11 @@ class Messages extends FHCAPI_Controller public function sendMessage($recipient_id) { + //is always uid in FAS + //TODO(Manu) make dynamic for other ids + //default setting - $receiversPersonId = $this->_getPersonIdFromUid($recipient_id); + $receiversPersonId = $this->_getPersonId($recipient_id, 'uid'); $uid = getAuthUID(); $this->load->model('person/Benutzer_model', 'BenutzerModel'); @@ -216,15 +192,13 @@ class Messages extends FHCAPI_Controller $subject = $this->input->post('subject'); $body = $this->input->post('body'); - - + $relationmessage_id = $this->input->post('relationmessage_id'); $typeId = $this->input->post('type_id'); $id = $this->input->post('id'); if($typeId == 'uid') { - //$this->terminateWithError("uid ", self::ERROR_TYPE_GENERAL); $prestudent_id = $this-> _getPrestudentIdFromUid($id); //parseMessagetext for variables Prestudent @@ -240,7 +214,7 @@ class Messages extends FHCAPI_Controller } elseif($typeId == 'prestudent_id') { - $this->terminateWithError("prestudent_id ", self::ERROR_TYPE_GENERAL); + // $this->terminateWithError("prestudent_id ", self::ERROR_TYPE_GENERAL); $result = $this->MessagesModel->parseMessageTextPrestudent($id, $body); $bodyParsed = $this->getDataOrTerminateWithError($result); @@ -250,7 +224,7 @@ class Messages extends FHCAPI_Controller $this->terminateWithError("type_id " . $typeId . " not valid", self::ERROR_TYPE_GENERAL); } - $result = $this->messagelib->sendMessageUser($receiversPersonId, $subject, $bodyParsed, $benutzer->person_id); + $result = $this->messagelib->sendMessageUser($receiversPersonId, $subject, $bodyParsed, $benutzer->person_id, null, $relationmessage_id); $this->terminateWithSuccess($result); } @@ -271,17 +245,15 @@ class Messages extends FHCAPI_Controller case 'uid': $prestudent_id = $this->_getPrestudentIdFromUid($id); $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $data); - break; - case 'person_id': - $id = $id; + case 'prestudent_id': + $result = $this->MessagesModel->parseMessageTextPrestudent($id, $data); break; default: $this->terminateWithError("MESSAGES::getPreviewText logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); break; } - //$this->terminateWithSuccess($result); $bodyParsed = $this->getDataOrTerminateWithError($result); $this->terminateWithSuccess($bodyParsed); @@ -289,10 +261,8 @@ class Messages extends FHCAPI_Controller public function getReplyData($messageId) { - // return $this->terminateWithError("in get ReplyBody" . $messageId, self::ERROR_TYPE_GENERAL); //TODO(Manu) validation of messageId: if number - $this->MessageModel->addSelect('public.tbl_msg_message.*'); $this->MessageModel->addSelect('r.*'); $this->MessageModel->addSelect('p.nachname'); @@ -304,14 +274,9 @@ class Messages extends FHCAPI_Controller array('r.message_id' => $messageId) ); - // $this->terminateWithSuccess((getData($result) ?: [])); $dataMessage = $this->getDataOrTerminateWithError($result); - $prefix = "Re: "; // reply subject prefix -/* $body = current($dataMessage->body); - $subject = $dataMessage->subject;*/ - $subject = $dataMessage[0]->subject; $body = $dataMessage[0]->body; @@ -323,8 +288,6 @@ class Messages extends FHCAPI_Controller $dataMessage[0]->replySubject = $prefix . $subject; $this->terminateWithSuccess($dataMessage); - - } public function deleteMessage($messageId) @@ -353,30 +316,94 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($result); } - public function getPersonIdFromUid($uid) + public function getPersonId($id, $typeId) { - $this->load->model('person/Benutzer_model', 'BenutzerModel'); - $result = $this->BenutzerModel->loadWhere( - ['uid' => $uid] - ); + if ($typeId == 'uid') + { + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $result = $this->BenutzerModel->loadWhere( + ['uid' => $id] + ); + } + elseif($typeId == 'prestudent_id') + { + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $result = $this->PrestudentModel->loadWhere( + ['prestudent_id' => $id] + ); + } $data = $this->getDataOrTerminateWithError($result); - $benutzer = current($data); + $person = current($data); - $this->terminateWithSuccess($benutzer->person_id); + $this->terminateWithSuccess($person->person_id); } - private function _getPersonIdFromUid($uid) + public function getUid($id, $typeId) { - $this->load->model('person/Benutzer_model', 'BenutzerModel'); - $result = $this->BenutzerModel->loadWhere( - ['uid' => $uid] - ); + if (!$typeId) + { + $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Type ID']), self::ERROR_TYPE_GENERAL); + } + elseif ($typeId == 'person_id') + { + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $result = $this->BenutzerModel->loadWhere( + ['person_id' => $id] + ); + } + elseif($typeId == 'prestudent_id') + { + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $result = $this->PrestudentModel->loadWhere( + ['prestudent_id' => $id] + ); + + $data = $this->getDataOrTerminateWithError($result); + $person = current($data); + $person_id = $person->person_id; + + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $result = $this->BenutzerModel->loadWhere( + ['person_id' => $person_id] + ); + } + elseif($typeId == 'uid') + { + $this->terminateWithSuccess($id); + } + else + { + $this->terminateWithError("MESSAGES::getUID logic for type_id " . $typeId . " not defined yet", self::ERROR_TYPE_GENERAL); + } $data = $this->getDataOrTerminateWithError($result); $benutzer = current($data); - return $benutzer->person_id; + $this->terminateWithSuccess($benutzer->uid); + } + + private function _getPersonId($id, $typeId) + { + if ($typeId == 'uid') + { + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $result = $this->BenutzerModel->loadWhere( + ['uid' => $id] + ); + } + elseif($typeId == 'prestudent_id') + { + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $result = $this->PrestudentModel->loadWhere( + ['prestudent_id' => $id] + ); + } + + $data = $this->getDataOrTerminateWithError($result); + $person = current($data); + + return $person->person_id; } private function _getPrestudentIdFromUid($uid) diff --git a/public/js/api/messages/person.js b/public/js/api/messages/person.js index 7693c5189..e53f23f6a 100644 --- a/public/js/api/messages/person.js +++ b/public/js/api/messages/person.js @@ -11,11 +11,14 @@ export default { getMessageVarsPerson(){ return this.$fhcApi.get('api/frontend/v1/messages/messages/getMessageVarsPerson/'); }, - getMsgVarsPrestudent(uid){ - return this.$fhcApi.get('api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + uid); + getMsgVarsPrestudent(params){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + params.id + '/' + params.type_id); }, - getPersonIdFromUid(uid){ - return this.$fhcApi.get('api/frontend/v1/messages/messages/getPersonIdFromUid/' + uid); + getPersonId(params){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getPersonId/'+ params.id + '/' + params.type_id); + }, + getUid(params){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getUid/'+ params.id + '/' + params.type_id); }, getVorlagentext(vorlage_kurzbz){ return this.$fhcApi.get('api/frontend/v1/messages/messages/getVorlagentext/' + vorlage_kurzbz); @@ -29,7 +32,6 @@ export default { }, getReplyData(messageId){ return this.$fhcApi.get('api/frontend/v1/messages/messages/getReplyData/' + messageId); - }, sendMessage(form, id, data) { return this.$fhcApi.post(form,'api/frontend/v1/messages/messages/sendMessage/' + id, diff --git a/public/js/components/Messages/Details/NewMessage/NewDiv.js b/public/js/components/Messages/Details/NewMessage/NewDiv.js index 1eb59aa20..d8611d611 100644 --- a/public/js/components/Messages/Details/NewMessage/NewDiv.js +++ b/public/js/components/Messages/Details/NewMessage/NewDiv.js @@ -44,14 +44,16 @@ export default { data(){ return { formData: { - recipient: this.id, + recipient: null, subject: null, body: null, vorlage_kurzbz: null, selectedValue: '', + relationmessage_id: null }, statusNew: true, vorlagen: [], + recipientsArray: [], defaultRecipient: null, editor: null, isVisible: false, @@ -66,7 +68,9 @@ export default { itemsUser: [], previewText: null, previewBody: "", - replyData: null + replyData: null, + uid: null, + messageSent: false } }, methods: { @@ -105,19 +109,22 @@ export default { sendMessage() { //TODO(Manu) check default recipient(s) const data = new FormData(); + const params = { id: this.id, type_id: this.typeId }; + const merged = { ...this.formData, ...params }; data.append('data', JSON.stringify(merged)); + //this.uid is important for existing sendFunction return this.$fhcApi.factory.messages.person.sendMessage( this.$refs.formMessage, - this.id, + this.uid, data) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); @@ -129,6 +136,10 @@ export default { //this.resetForm(); //closeModal //closewindwo + this.messageSent = true; + //TODO(Manu) hier route definieren? ist kein child sondern mit route aufgerufen + //würde allerdings neues fenster aktualisiert öffnen, altes bleibt ohne reload gleich + //Reload vorheriges tab??? this.$emit('reloadTable'); } ); @@ -148,13 +159,13 @@ export default { //closewindwo }); }, - getPreviewText(){ + getPreviewText(id, typeId){ const data = new FormData(); data.append('data', JSON.stringify(this.formData.body)); return this.$fhcApi.factory.messages.person.getPreviewText({ - id: this.id, - type_id: this.typeId}, data) + id: id, + type_id: typeId}, data) .then(response => { this.previewText = response.data; }).catch(this.$fhcAlert.handleSystemError) @@ -167,7 +178,8 @@ export default { insertVariable(selectedItem){ if (this.editor) { this.editor.insertContent(selectedItem.value + " "); - //TODO(Manu) check: nicht mal mit Punkt adden gehts ohne eintrag nach vars + //TODO(Manu) check: Laden von Variblen geht nicht wenn kein Zeichen danach kommt + // nicht mal mit Punkt adden gehts ohne eintrag nach vars /* this.editor.focus(); this.editor.setDirty(true);*/ @@ -183,9 +195,6 @@ export default { console.error("Editor instance is not available."); } }, -/* replyMessage(message_id){ - console.log("auf message " + message_id + " antworten"); - },*/ resetForm(){ this.formData = { vorlage_kurzbz: null, @@ -219,11 +228,22 @@ export default { //just for testing: this.isVisible = true; }, - showPreview(){ - this.getPreviewText().then(() => { + showPreview(id, typeId){ + this.getPreviewText(id, typeId).then(() => { this.previewBody = this.previewText; }); }, + getUid(id, typeId){ + const params = { + id: id, + type_id: typeId + }; + this.$fhcApi.factory.messages.person.getUid(params) + .then(result => { + this.uid = result.data; + }) + .catch(this.$fhcAlert.handleSystemError); + } }, watch: { 'formData.body': { @@ -238,7 +258,6 @@ export default { }, 'formData.vorlage_kurzbz': { handler(newVal){ - // console.log("Vorlage: " + newVal); if (newVal && newVal != null) { this.formData.subject = newVal; @@ -248,6 +267,9 @@ export default { }, }, created(){ + if(this.typeId != 'uid') + this.getUid(this.id, this.typeId); + if(this.typeId == 'person_id'){ this.$fhcApi.factory.messages.person.getMessageVarsPerson() .then(result => { @@ -259,8 +281,13 @@ export default { }) .catch(this.$fhcAlert.handleSystemError); } - if(this.typeId == 'uid') { - this.$fhcApi.factory.messages.person.getMsgVarsPrestudent(this.id) + + if(this.typeId == 'uid' || this.typeId == 'prestudent_id') { + const params = { + id: this.id, + type_id: this.typeId + }; + this.$fhcApi.factory.messages.person.getMsgVarsPrestudent(params) .then(result => { this.fieldsPrestudent = result.data; const prestudent = this.fieldsPrestudent[0]; @@ -294,20 +321,21 @@ export default { }) .then(result => { this.defaultRecipient = result.data; + this.recipientsArray.push({'uid': this.uid, + 'details': this.defaultRecipient}); }) .catch(this.$fhcAlert.handleSystemError); + //case of reply if(this.messageId != null) { - - //get replayBody.. body receivername, receiverSurname, sentDate of message this.$fhcApi.factory.messages.person.getReplyData(this.messageId) .then(result => { this.replyData = result.data; this.formData.subject = this.replyData[0].replySubject; this.formData.body = this.replyData[0].replyBody; + this.formData.relationmessage_id = this.messageId; }) .catch(this.$fhcAlert.handleSystemError); - } }, @@ -320,12 +348,11 @@ export default { template: `