diff --git a/application/controllers/api/v1/system/Message.php b/application/controllers/api/v1/system/Message.php index b7f70e187..7cfbc7737 100644 --- a/application/controllers/api/v1/system/Message.php +++ b/application/controllers/api/v1/system/Message.php @@ -23,45 +23,20 @@ class Message extends APIv1_Controller { parent::__construct(); // Load model MessageModel - $this->load->model('system/message_model', 'MessageModel'); - // Load set the uid of the model to let to check the permissions - $this->MessageModel->setUID($this->_getUID()); + $this->load->library('MessageLib', array('uid' => $this->_getUID())); } /** * @return void */ - public function getMessage() + public function getMessagesByPersonID() { - $messageID = $this->get('message_id'); + $person_id = $this->get('person_id'); + $all = $this->get('all'); - if (isset($messageID)) + if (isset($person_id)) { - $result = $this->MessageModel->load($messageID); - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } - - /** - * @return void - */ - public function postMessage() - { - if ($this->_validate($this->post())) - { - if (isset($this->post()['message_id'])) - { - $result = $this->MessageModel->update($this->post()['message_id'], $this->post()); - } - else - { - $result = $this->MessageModel->insert($this->post()); - } + $result = $this->messagelib->getMessagesByPerson($person_id, $all); $this->response($result, REST_Controller::HTTP_OK); } @@ -71,8 +46,38 @@ class Message extends APIv1_Controller } } - private function _validate($message = NULL) + /** + * @return void + */ + public function postMessage() { + if ($this->_validate($this->post())) + { + $this->messagelib->addRecipient($this->post()['person_id']); + $result = $this->messagelib->sendMessage( + $this->post()['person_id'], + $this->post()['subject'], + $this->post()['body'], + $this->post()['priority'], + $this->post()['relationmessage_id'], + $this->post()['oe_kurzbz'] + ); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + private function _validate($message = null) + { + if (!isset($message['person_id']) || !isset($message['subject']) || !isset($message['body'])) + { + return false; + } + return true; } } \ No newline at end of file diff --git a/application/libraries/MessageLib.php b/application/libraries/MessageLib.php index 2bb04ff2f..9d1cb1ce1 100644 --- a/application/libraries/MessageLib.php +++ b/application/libraries/MessageLib.php @@ -11,13 +11,18 @@ class MessageLib { private $recipients = array(); - public function __construct() + public function __construct($params) { require_once APPPATH.'config/message.php'; $this->ci =& get_instance(); //$this->ci->load->model('person/Person_model', 'PersonModel'); $this->ci->load->model('system/Message_model', 'MessageModel'); + if (is_array($params) && isset($params['uid'])) + { + $this->ci->MessageModel->setUID($params['uid']); + } + $this->ci->load->model('system/MsgStatus_model', 'MsgStatusModel'); $this->ci->load->model('system/Recipient_model', 'RecipientModel'); $this->ci->load->model('system/Attachment_model', 'AttachmentModel'); diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 4412c4078..cc7d2e930 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -92,7 +92,7 @@ WHERE person_id = ?'; if (! $all) $sql .= ' AND status<2'; $result = $this->db->query($sql, array($person_id)); - var_dump($result); + //var_dump($result); if (is_object($result)) return $this->_success($result->result()); else diff --git a/tests/codeception/_data/dump.sql b/tests/codeception/_data/dump.sql index 3090a1504..3a6fcb774 100644 --- a/tests/codeception/_data/dump.sql +++ b/tests/codeception/_data/dump.sql @@ -343,7 +343,8 @@ DELETE FROM system.tbl_rolleberechtigung WHERE berechtigung_kurzbz IN ( 'basis/lehrverband', 'basis/log', 'basis/mitarbeiter', - 'basis/msg_message', + 'basis/msg_message', + 'basis/message', 'basis/msg_thread', 'basis/notiz', 'basis/notizzuordnung', @@ -419,7 +420,8 @@ DELETE FROM system.tbl_rolleberechtigung WHERE berechtigung_kurzbz IN ( 'basis/vw_studiensemester', 'lehre/reservierung', 'lehre/reihungstest', - 'wawi/inventar:begrenzt' + 'wawi/inventar:begrenzt', + 'fs/dms' ); -- DELETE FROM system.tbl_berechtigung @@ -569,6 +571,7 @@ DELETE FROM system.tbl_berechtigung WHERE berechtigung_kurzbz IN ( 'basis/log', 'basis/mitarbeiter', 'basis/msg_message', + 'basis/message', 'basis/msg_thread', 'basis/notiz', 'basis/notizzuordnung', @@ -644,7 +647,8 @@ DELETE FROM system.tbl_berechtigung WHERE berechtigung_kurzbz IN ( 'basis/vw_studiensemester', 'lehre/reservierung', 'lehre/reihungstest', - 'wawi/inventar:begrenzt' + 'wawi/inventar:begrenzt', + 'fs/dms' ); -- INSERT Permissions @@ -870,6 +874,7 @@ INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES(' INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES('lehre/reihungstest', ''); INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES('wawi/inventar:begrenzt', ''); INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES('fs/dms', ''); +INSERT INTO system.tbl_berechtigung (berechtigung_kurzbz, beschreibung) VALUES('basis/message', ''); -- INSERT link between user admin and permissions INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('basis/archiv', 'admin', 'suid'); @@ -1094,6 +1099,7 @@ INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('lehre/reihungstest', 'admin', 'suid'); INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('wawi/inventar:begrenzt', 'admin', 'suid'); INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('fs/dms', 'admin', 'suid'); +INSERT INTO system.tbl_rolleberechtigung (berechtigung_kurzbz, rolle_kurzbz, art) VALUES('basis/message', 'admin', 'suid'); -- EMPTY public.tbl_statistik DELETE FROM public.tbl_statistik;