From aa84bdec1e3dd02e1fb9f8c6fc09161576186cb5 Mon Sep 17 00:00:00 2001 From: ma0068 Date: Thu, 27 Nov 2025 14:46:55 +0100 Subject: [PATCH] ---staging---- --- application/config/stv.php | 1 + .../api/frontend/v1/messages/Messages.php | 292 ++++++++++++++---- .../api/frontend/v1/stv/Config.php | 6 +- public/js/api/factory/messages/messages.js | 47 ++- .../Messages/Details/NewMessage/Modal.js | 62 ++-- .../Messages/Details/TableMessages.js | 4 +- public/js/components/Messages/Messages.js | 8 +- .../Studentenverwaltung/Details/Messages.js | 58 ++-- 8 files changed, 368 insertions(+), 110 deletions(-) diff --git a/application/config/stv.php b/application/config/stv.php index e03c00084..913b1c015 100644 --- a/application/config/stv.php +++ b/application/config/stv.php @@ -115,6 +115,7 @@ $config['student_tab_order'] = [ $config['students_tab_order'] = [ 'banking', 'status', + 'messages', 'groups', 'finalexam', 'archive', diff --git a/application/controllers/api/frontend/v1/messages/Messages.php b/application/controllers/api/frontend/v1/messages/Messages.php index 355fe79a4..f3a40f72f 100644 --- a/application/controllers/api/frontend/v1/messages/Messages.php +++ b/application/controllers/api/frontend/v1/messages/Messages.php @@ -14,13 +14,16 @@ class Messages extends FHCAPI_Controller 'getMsgVarsPrestudent' => ['admin:r', 'assistenz:r'], 'getMsgVarsLoggedInUser' => ['admin:r', 'assistenz:r'], 'getNameOfDefaultRecipient' => ['admin:r', 'assistenz:r'], + 'getNameOfDefaultRecipients' => ['admin:r', 'assistenz:r'], 'sendMessage' => ['admin:r', 'assistenz:r'], + 'sendMessages' => ['admin:r', 'assistenz:r'], 'deleteMessage' => ['admin:r', 'assistenz:r'], 'getDataVorlage' => ['admin:r', 'assistenz:r'], 'getPreviewText' => ['admin:r', 'assistenz:r'], 'getReplyData' => ['admin:r', 'assistenz:r'], 'getPersonId' => ['admin:r', 'assistenz:r'], 'getUid' => ['admin:r', 'assistenz:r'], + 'getUids' => ['admin:r', 'assistenz:r'], ]); //Load Models @@ -110,13 +113,39 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($data); } - public function getMsgVarsPrestudent($id, $typeId) +/* public function getMsgVarsPrestudent($id, $typeId) { $prestudent_id = ($typeId == 'uid') ? $this->_getPrestudentIdFromUid($id) : $id; $result = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); $data = $this->getDataOrTerminateWithError($result); $this->terminateWithSuccess($data); + }*/ + + public function getMsgVarsPrestudent($typeId) + { + $ids = $this->input->post('ids'); + $messageVarsPrestudent = []; + + if($typeId == 'uid') + { + $prestudent_ids = []; + foreach ($ids as $id) + { + $prestudent_ids[] = $this->_getPrestudentIdFromUid($id); + } + } + else + $prestudent_ids = $ids; + + foreach ($prestudent_ids as $prestudent_id) + { + $result = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); + $data = $this->getDataOrTerminateWithError($result); + $messageVarsPrestudent[] = current($data); + } + + $this->terminateWithSuccess($messageVarsPrestudent); } public function getMsgVarsLoggedInUser() @@ -127,7 +156,7 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($data); } - public function getNameOfDefaultRecipient($id, $type_id) +/* public function getNameOfDefaultRecipient($id, $type_id) { $id = ($type_id != 'person_id') ? $this->_getPersonId($id, $type_id) : $id; @@ -138,11 +167,84 @@ class Messages extends FHCAPI_Controller $name = current($data); $this->terminateWithSuccess($name->vorname . " " . $name->nachname ); + }*/ + + public function getNameOfDefaultRecipients($type_id) + { + $ids = $this->input->post('ids'); + $recipients = []; + + if (empty($ids)) { + throw new InvalidArgumentException("Keine ID(s) übergeben."); + } + + $this->load->model('person/Person_model', 'PersonModel'); + if($type_id != 'person_id'){ + foreach ($ids as $id) + { + $person_id = $this->_getPersonId($id, $type_id); + $result = $this->PersonModel->load($person_id); + $data = $this->getDataOrTerminateWithError($result); + $name = current($data); + $recipients[$id] = $name->vorname . " " . $name->nachname; + } + } + else { + foreach ($ids as $id) { + $result = $this->PersonModel->load($id); + $data = $this->getDataOrTerminateWithError($result); + $name = current($data); + $recipients[$id] = $name->vorname . " " . $name->nachname; + } + } + + $this->terminateWithSuccess($recipients); } - public function sendMessage($recipient_id) + public function sendMessages() { - //has to be uid +/* if (isset($_POST['data'])) + { + $data = json_decode($_POST['data']); + unset($_POST['data']); + } + else + $this->terminateWithError("Data missing ", self::ERROR_TYPE_GENERAL); + + if (isset($_POST['ids'])) + { + $ids = json_decode($_POST['ids']); + unset($_POST['ids']); + } + else + $this->terminateWithError("IDs missing ", self::ERROR_TYPE_GENERAL); + + + if (isset($_POST['uids'])) + { + $uids = json_decode($_POST['uids']); + unset($_POST['uids']); + } + else + $this->terminateWithError("UIDs missing ", self::ERROR_TYPE_GENERAL); +*/ + + if (isset($_POST['data'])) + { + $data = json_decode($_POST['data']); + unset($_POST['data']); + foreach ($data as $k => $v) { + $_POST[$k] = $v; + } + } + + $this->terminateWithSuccess($data); + + } + + public function sendMessage($recipient_id, $return=false) + { + //has to be uid TODO(Manu) check // $this->terminateWithError("uid", $recipient_id, self::ERROR_TYPE_GENERAL); //default setting @@ -186,46 +288,51 @@ class Messages extends FHCAPI_Controller $relationmessage_id = $this->input->post('relationmessage_id'); $typeId = $this->input->post('type_id'); - $id = $this->input->post('id'); + $ids = $this->input->post('id'); - if($typeId == 'uid') + foreach ($ids as $id) { - $prestudent_id = $this-> _getPrestudentIdFromUid($id); + if($typeId == 'uid') + { + $prestudent_id = $this-> _getPrestudentIdFromUid($id); - //parseMessagetext for variables Prestudent - $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $body); - $bodyParsed = $this->getDataOrTerminateWithError($result); - } - if($typeId == 'mitarbeiter_uid') - { - $person_id = $this->_getPersonId($id, $typeId); + //parseMessagetext for variables Prestudent + $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $body); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + } + if($typeId == 'mitarbeiter_uid') + { + $person_id = $this->_getPersonId($id, $typeId); - $result = $this->MessagesModel->parseMessageTextPerson($person_id, $body); - $bodyParsed = $this->getDataOrTerminateWithError($result); - $this->terminateWithError($bodyParsed, self::ERROR_TYPE_GENERAL); + $result = $this->MessagesModel->parseMessageTextPerson($person_id, $body); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + $this->terminateWithError($bodyParsed[$id], self::ERROR_TYPE_GENERAL); + } + elseif($typeId == 'person_id') + { + $result = $this->MessagesModel->parseMessageTextPerson($id, $body); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + } + elseif($typeId == 'prestudent_id') + { + $result = $this->MessagesModel->parseMessageTextPrestudent($id, $body); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + } + else + { + $this->terminateWithError("type_id " . $typeId . " not valid", self::ERROR_TYPE_GENERAL); + } } - elseif($typeId == 'person_id') - { - $result = $this->MessagesModel->parseMessageTextPerson($id, $body); - $bodyParsed = $this->getDataOrTerminateWithError($result); - } - elseif($typeId == 'prestudent_id') - { - $result = $this->MessagesModel->parseMessageTextPrestudent($id, $body); - $bodyParsed = $this->getDataOrTerminateWithError($result); - } - else - { - $this->terminateWithError("type_id " . $typeId . " not valid", self::ERROR_TYPE_GENERAL); - } + + $result = $this->messagelib->sendMessageUser($receiversPersonId, $subject, $bodyParsed, $benutzer->person_id, null, $relationmessage_id); $this->terminateWithSuccess($result); } - public function getPreviewText($id, $type_id) + public function getPreviewText($type_id) { if (isset($_POST['data'])) { @@ -235,30 +342,45 @@ class Messages extends FHCAPI_Controller else $this->terminateWithError("Textbody missing ", self::ERROR_TYPE_GENERAL); - switch($type_id) + if (isset($_POST['ids'])) { - case 'uid': - $prestudent_id = $this->_getPrestudentIdFromUid($id); - $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $data); - break; - case 'prestudent_id': - $result = $this->MessagesModel->parseMessageTextPrestudent($id, $data); - break; - case 'person_id': - $result = $this->MessagesModel->parseMessageTextPerson($id, $data); - break; - case 'mitarbeiter_uid': - { - $person_id = $this->_getPersonId($id, $type_id); - $result = $this->MessagesModel->parseMessageTextPerson($person_id, $data); - } - break; - default: - $this->terminateWithError("MESSAGES::getPreviewText logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); - break; + $ids = json_decode($_POST['ids']); + unset($_POST['ids']); } + else + $this->terminateWithError("IDs missing ", self::ERROR_TYPE_GENERAL); - $bodyParsed = $this->getDataOrTerminateWithError($result); + $bodyParsed = []; + + foreach ($ids as $id) + { + switch($type_id) + { + case 'uid': + $prestudent_id = $this->_getPrestudentIdFromUid($id); + $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $data); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + break; + case 'prestudent_id': + $result = $this->MessagesModel->parseMessageTextPrestudent($id, $data); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + break; + case 'person_id': + $result = $this->MessagesModel->parseMessageTextPerson($id, $data); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + break; + case 'mitarbeiter_uid': + { + $person_id = $this->_getPersonId($id, $type_id); + $result = $this->MessagesModel->parseMessageTextPerson($person_id, $data); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + } + break; + default: + $this->terminateWithError("MESSAGES::getPreviewText logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); + break; + } + } $this->terminateWithSuccess($bodyParsed); } @@ -343,7 +465,7 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($person->person_id); } - public function getUid($id, $typeId) + public function getUid($typeId) { if (!$typeId) { @@ -387,6 +509,68 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($benutzer->uid); } + public function getUids($typeId) + { + $ids = $this->input->post('ids'); + $benutzerIds = []; + + 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'); + foreach ($ids as $id) + { + $result = $this->BenutzerModel->loadWhere( + ['person_id' => $id] + ); + $data = $this->getDataOrTerminateWithError($result); + $benutzer = current($data); + + $benutzerIds[$id] = $benutzer->uid; + } + } + elseif($typeId == 'prestudent_id') + { + $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + foreach ($ids as $id) + { + $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] + ); + $data = $this->getDataOrTerminateWithError($result); + $benutzer = current($data); + + $benutzerIds[$id] = $benutzer->uid; + } + } + elseif($typeId == 'uid' || $typeId == 'mitarbeiter_uid') + { + $this->terminateWithSuccess($ids); + } + else + { + $this->terminateWithError("MESSAGES::getUID logic for type_id " . $typeId . " not defined yet", self::ERROR_TYPE_GENERAL); + } + + + //$data = $this->getDataOrTerminateWithError($resultBenutzer); + //$benutzer = current($data); + + $this->terminateWithSuccess($benutzerIds); + } + private function _getPersonId($id, $typeId) { if ($typeId == 'uid' || $typeId == 'mitarbeiter_uid') diff --git a/application/controllers/api/frontend/v1/stv/Config.php b/application/controllers/api/frontend/v1/stv/Config.php index 97d626246..1dced3911 100644 --- a/application/controllers/api/frontend/v1/stv/Config.php +++ b/application/controllers/api/frontend/v1/stv/Config.php @@ -271,7 +271,6 @@ class Config extends FHCAPI_Controller $result['messages'] = [ 'title' => $this->p->t('stv', 'tab_messages'), 'component' => absoluteJsImportUrl('public/js/components/Stv/Studentenverwaltung/Details/Messages.js'), - 'showOnlyWithUid' => true ]; $result['grades'] = [ @@ -412,6 +411,11 @@ class Config extends FHCAPI_Controller 'component' => absoluteJsImportUrl('public/js/components/Stv/Studentenverwaltung/Details/Kontaktieren.js'), ]; + $result['messages'] = [ + 'title' => $this->p->t('stv', 'tab_messages'), + 'component' => absoluteJsImportUrl('public/js/components/Stv/Studentenverwaltung/Details/Messages.js'), + ]; + Events::trigger('stv_conf_students', function & () use (&$result) { return $result; }); diff --git a/public/js/api/factory/messages/messages.js b/public/js/api/factory/messages/messages.js index c6d4b67b6..1c2bbe66e 100644 --- a/public/js/api/factory/messages/messages.js +++ b/public/js/api/factory/messages/messages.js @@ -44,23 +44,40 @@ export default { url: 'api/frontend/v1/messages/messages/getMessageVarsPerson/' + userParams.id + '/' + userParams.type_id }; }, - getMsgVarsPrestudent(userParams){ + //TODO(Manu) enable for id_array +/* getMsgVarsPrestudent(userParams){ return { method: 'post', url: 'api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + userParams.id + '/' + userParams.type_id }; + }, */ + getMsgVarsPrestudent(ids, type_id){ + return { + method: 'post', + url: 'api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + type_id, + params: {ids} + }; }, + //TODO(Manu) enable for id_array getPersonId(params){ return { method: 'post', url: 'api/frontend/v1/messages/messages/getPersonId/' + params.id + '/' + params.type_id }; }, - getUid(userParams){ + //TODO(Manu) enable for id_array +/* getUid(userParams){ return { method: 'get', url: 'api/frontend/v1/messages/messages/getUid/' + userParams.id + '/' + userParams.type_id }; + }, */ + getUid(ids, type_id){ + return { + method: 'post', + url: 'api/frontend/v1/messages/messages/getUids/' + type_id, + params: {ids} + }; }, getDataVorlage(vorlage_kurzbz){ return { @@ -68,16 +85,25 @@ export default { url: 'api/frontend/v1/messages/messages/getDataVorlage/' + vorlage_kurzbz }; }, - getNameOfDefaultRecipient(params){ +/* getNameOfDefaultRecipient(params){ + console.log(params.id); return { method: 'get', url: 'api/frontend/v1/messages/messages/getNameOfDefaultRecipient/' + params.id + '/' + params.type_id }; - }, - getPreviewText(userParams, params){ + },*/ + //TODO(Manu) enable for id_array + getNameOfDefaultRecipients(ids, type_id){ return { method: 'post', - url: 'api/frontend/v1/messages/messages/getPreviewText/' + userParams.id + '/' + userParams.type_id, + url: 'api/frontend/v1/messages/messages/getNameOfDefaultRecipients/' + type_id, + params: {ids} + }; + }, + getPreviewText(type_id, params){ + return { + method: 'post', + url: 'api/frontend/v1/messages/messages/getPreviewText/' + type_id, params }; }, @@ -87,12 +113,19 @@ export default { url: 'api/frontend/v1/messages/messages/getReplyData/' + messageId }; }, - sendMessageFromModalContext(id, params) { +/* sendMessageFromModalContext(id, params) { return { method: 'post', url: 'api/frontend/v1/messages/messages/sendMessage/' + id, params }; + }, */ + sendMessageFromModalContext(params) { + return { + method: 'post', + url: 'api/frontend/v1/messages/messages/sendMessages/', + params + }; }, sendMessage(id, params) { return { diff --git a/public/js/components/Messages/Details/NewMessage/Modal.js b/public/js/components/Messages/Details/NewMessage/Modal.js index ce9235617..87b8d7c87 100644 --- a/public/js/components/Messages/Details/NewMessage/Modal.js +++ b/public/js/components/Messages/Details/NewMessage/Modal.js @@ -20,7 +20,7 @@ export default { }, typeId: String, id: { - type: [Number, String], + type: Array, required: true }, messageId: { @@ -43,6 +43,8 @@ export default { vorlagen: [], recipientsArray: [], defaultRecipient: null, + defaultRecipients: [], + defaultRecipientString: null, editor: null, fieldsUser: [], fieldsPerson: [], @@ -57,6 +59,7 @@ export default { previewBody: "", replyData: null, uid: null, + uids: null //necessary? } }, methods: { @@ -111,6 +114,10 @@ export default { }, sendMessage() { const data = new FormData(); + data.append('data', JSON.stringify(this.formData)); + data.append('ids', JSON.stringify(this.id)); + data.append('uids', JSON.stringify(this.uid)); + const params = { id: this.id, type_id: this.typeId @@ -121,8 +128,9 @@ export default { }; data.append('data', JSON.stringify(merged)); + //Modal Context? return this.$refs.formMessage - .call(this.endpoint.sendMessageFromModalContext(this.uid, data)) + .call(this.endpoint.sendMessageFromModalContext(data)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); this.hideModal('modalNewMessage'); @@ -146,14 +154,15 @@ export default { }, getPreviewText(){ const data = new FormData(); - data.append('data', JSON.stringify(this.formData.body)); + data.append('ids', JSON.stringify(this.id)); + return this.$api - .call(this.endpoint.getPreviewText({ - id: this.id, - type_id: this.typeId}, data)) + .call(this.endpoint.getPreviewText( + this.typeId, data)) .then(response => { - this.previewText = response.data; + const previews = response.data; + this.previewText = previews[this.defaultRecipient]; }).catch(this.$fhcAlert.handleSystemError) .finally(() => { //this.resetForm(); @@ -201,13 +210,10 @@ export default { this.previewBody = this.previewText; }); }, + //TODO(Manu) check if No_UID getUid(id, typeId){ - const params = { - id: id, - type_id: typeId - }; this.$api - .call(this.endpoint.getUid(params)) + .call(this.endpoint.getUid(this.id, this.typeId)) .then(result => { this.uid = result.data; }) @@ -281,12 +287,8 @@ export default { } if(this.typeId == 'prestudent_id' || this.typeId == 'uid'){ - const params = { - id: this.id, - type_id: this.typeId - }; this.$api - .call(this.endpoint.getMsgVarsPrestudent(params)) + .call(this.endpoint.getMsgVarsPrestudent(this.id, this.typeId)) .then(result => { this.fieldsPrestudent = result.data; const prestudent = this.fieldsPrestudent[0]; @@ -310,7 +312,7 @@ export default { }) .catch(this.$fhcAlert.handleSystemError); - this.$api +/* this.$api .call(this.endpoint.getNameOfDefaultRecipient({ id: this.id, type_id: this.typeId})) @@ -320,6 +322,16 @@ export default { 'uid': this.uid, 'details': this.defaultRecipient}); }) + .catch(this.$fhcAlert.handleSystemError);*/ + + //for multiaction too + this.$api + .call(this.endpoint.getNameOfDefaultRecipients(this.id, this.typeId)) + .then(result => { + this.defaultRecipients = result.data; + this.defaultRecipientString = Object.values(this.defaultRecipients).join("; "); + + }) .catch(this.$fhcAlert.handleSystemError); //case of reply @@ -367,6 +379,8 @@ export default { + + {{defaultRecipients}} | {{defaultRecipient}} || {{uid}}
@@ -381,7 +395,7 @@ export default { type="text" name="recipient" :label="$p.t('messages/recipient')" - v-model="defaultRecipient" + v-model="defaultRecipientString" disabled > @@ -502,17 +516,17 @@ export default { >

- +
diff --git a/public/js/components/Messages/Details/TableMessages.js b/public/js/components/Messages/Details/TableMessages.js index 2a12128eb..172607022 100644 --- a/public/js/components/Messages/Details/TableMessages.js +++ b/public/js/components/Messages/Details/TableMessages.js @@ -19,7 +19,7 @@ export default { }, typeId: String, id: { - type: [Number, String], + type: Array, required: true }, messageLayout: String, @@ -346,7 +346,7 @@ export default { });*/ }, created(){ - if(this.typeId != 'person_id') { + if(this.typeId != 'person_id' && Array.isArray(this.id) && this.id.length === 1) { const params = { id: this.id, type_id: this.typeId diff --git a/public/js/components/Messages/Messages.js b/public/js/components/Messages/Messages.js index 176c05b6b..53692d6a3 100644 --- a/public/js/components/Messages/Messages.js +++ b/public/js/components/Messages/Messages.js @@ -31,7 +31,7 @@ export default { } }, id: { - type: [Number, String], + type: Array, required: true }, showTable: Boolean, @@ -124,6 +124,7 @@ export default { }, template: `
+ {{typeId}} {{id}}
- - -
+ +
e.prestudent_id); + }, + person_ids() { + if (this.modelValue.person_id) + { + return [this.modelValue.person_id]; + } + return this.modelValue.map(e => e.person_id); + }, + }, template: `
- - - - + +
` }; \ No newline at end of file