diff --git a/application/controllers/components/stv/Notiz.php b/application/controllers/components/stv/Notiz.php new file mode 100644 index 000000000..33205a862 --- /dev/null +++ b/application/controllers/components/stv/Notiz.php @@ -0,0 +1,177 @@ +load->library('AuthLib'); + $this->load->library('VariableLib', ['uid' => getAuthUID()]); + + // Load language phrases + $this->loadPhrases([ + 'ui' + ]); + } + + public function getNotizen($person_id) + { + $this->load->model('person/Notiz_model', 'NotizModel'); + + $result = $this->NotizModel->getNotiz($person_id, true); + + if (isError($result)) { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + $this->outputJson(getError($result)); + } else { + $this->outputJson(getData($result) ?: []); + } + } + + public function loadNotiz($notiz_id) + { + $this->load->model('person/Notiz_model', 'NotizModel'); + $this->NotizModel->addJoin('public.tbl_notiz_dokument', 'notiz_id', 'LEFT'); + + $this->NotizModel->addSelect('*'); + + $this->NotizModel->addLimit(1); + + $result = $this->NotizModel->loadWhere( + array('notiz_id' => $notiz_id) + ); + if (isError($result)) { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + $this->outputJson($result); + } + + elseif (!hasData($result)) { + $this->outputJson($result); //success mit Wert null + // $this->outputJson(getData($result) ?: []); + } + else + { + $this->outputJsonSuccess(current(getData($result))); + } + } + + public function addNewNotiz($person_id) + { + $_POST = json_decode($this->input->raw_input_stream, true); + $this->load->library('form_validation'); + + + $this->form_validation->set_rules('titel', 'titel', 'required'); + $this->form_validation->set_rules('text', 'Text', 'required'); + + if ($this->form_validation->run() == false) + { + return $this->outputJsonError($this->form_validation->error_array()); + } + + $this->load->model('person/Notiz_model', 'NotizModel'); + + $uid = getAuthUID(); + $titel = isset($_POST['titel']) ? $_POST['titel'] : null; + $text = isset($_POST['text']) ? $_POST['text'] : null; + //$verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : null; + $verfasser_uid = $uid; + $start = isset($_POST['von']) ? $_POST['von'] : null; + $ende = isset($_POST['bis']) ? $_POST['bis'] : null; + $erledigt = $_POST['erledigt']; + +/* $dms_id = isset($_POST['dms_id']) ? $_POST['dms_id'] : null; + $bearbeiter_uid = isset($_POST['bearbeiter_uid']) ? $_POST['bearbeiter_uid'] : null; + +*/ + + $result = $this->NotizModel->addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $start, $ende); + + // var_dump($result); + +/* $result = $this->NotizModel->insert( + [ + 'titel' => $titel, + 'text' => $text, + 'insertvon' => $uid, + 'insertamum' => date('c'), + 'verfasser_uid' => $verfasser_uid, + 'bearbeiter_uid' => $bearbeiter_uid, + 'start' => $start, + 'ende' => $ende, + 'erledigt' => $_POST['erledigt'], + //'dms_id' => $dms_id + ] + );*/ + if (isError($result)) + { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + return $this->outputJson($result); + } + return $this->outputJsonSuccess(true); + } + + public function updateNotiz($notiz_id) + { + $uid = getAuthUID(); + $this->load->library('form_validation'); + $_POST = json_decode($this->input->raw_input_stream, true); + + $this->form_validation->set_rules('titel', 'titel', 'required'); + $this->form_validation->set_rules('text', 'Text', 'required'); + + if ($this->form_validation->run() == false) + { + return $this->outputJsonError($this->form_validation->error_array()); + } + + $this->load->model('person/Notiz_model', 'NotizModel'); + + if(!$notiz_id) + { + return $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + } + + // $person_id = isset($_POST['person_id']) ? $_POST['person_id'] : null; + $uid = getAuthUID(); + $titel = isset($_POST['titel']) ? $_POST['titel'] : null; + $text = isset($_POST['text']) ? $_POST['text'] : null; + $verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : null; + $bearbeiter_uid = $uid; + $start = isset($_POST['von']) ? $_POST['von'] : null; + $ende = isset($_POST['bis']) ? $_POST['bis'] : null; + $erledigt = $_POST['erledigt']; + + $result = $this->NotizModel->update( + [ + 'notiz_id' => $notiz_id + ], + [ + 'titel' => $titel, + 'updatevon' => $uid, + 'updateamum' => date('c'), + 'text' => $text, + 'verfasser_uid' => $verfasser_uid, + 'bearbeiter_uid' => $bearbeiter_uid, + 'start' => $start, + 'ende' => $ende, + 'erledigt' => $erledigt + ] + ); + + if (isError($result)) + { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + return $this->outputJson(getError($result)); + } + return $this->outputJsonSuccess(true); + } + + + +} \ No newline at end of file diff --git a/application/controllers/components/stv/Notizen.php b/application/controllers/components/stv/Notizen.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/application/models/person/Notiz_model.php b/application/models/person/Notiz_model.php index bfd8aa258..5a8bf1858 100644 --- a/application/models/person/Notiz_model.php +++ b/application/models/person/Notiz_model.php @@ -133,15 +133,56 @@ class Notiz_model extends DB_Model return $result; } + /** + * Add a Notiz for a given person + */ + public function addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $von, $bis) + { + // Loads model Notizzuordnung_model + $this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel'); + + // Start DB transaction + $this->db->trans_start(false); + + $result = $this->insert(array('titel' => $titel, 'text' => $text, 'erledigt' => $erledigt, 'verfasser_uid' => $verfasser_uid, + "insertvon" => $verfasser_uid, 'start' => $von, 'ende' => $bis)); + + if (isSuccess($result)) + { + $notiz_id = $result->retval; + $result = $this->NotizzuordnungModel->insert(array('notiz_id' => $notiz_id, 'person_id' => $person_id)); + } + + // Transaction complete! + $this->db->trans_complete(); + + // Check if everything went ok during the transaction + if ($this->db->trans_status() === false || isError($result)) + { + $this->db->trans_rollback(); + $result = error($result->msg, EXIT_ERROR); + } + else + { + $this->db->trans_commit(); + $result = success($notiz_id); + } + + return $result; + } + /** * gets all Notizen for a person * @param $person_id */ - public function getNotiz($person_id) + public function getNotiz($person_id, $withDoc=false) { // Join with the table public.tbl_notizzuordnung using notiz_id $this->addJoin('public.tbl_notizzuordnung', 'notiz_id'); + if($withDoc) + $this->addJoin('public.tbl_notiz_dokument', 'notiz_id', 'LEFT'); + return $this->loadWhere(array('person_id' => $person_id)); } diff --git a/public/css/Studentenverwaltung.css b/public/css/Studentenverwaltung.css index 5f6050abf..85601381a 100644 --- a/public/css/Studentenverwaltung.css +++ b/public/css/Studentenverwaltung.css @@ -1,5 +1,6 @@ @import './components/searchbar.css'; @import './components/verticalsplit.css'; +@import './components/Notiz.css'; html { font-size: .875em; diff --git a/public/css/components/Notiz.css b/public/css/components/Notiz.css new file mode 100644 index 000000000..75c69ec80 --- /dev/null +++ b/public/css/components/Notiz.css @@ -0,0 +1,6 @@ +.notizTitle { + color: darkred; +} +.notizText { + color: darkblue; +} \ No newline at end of file diff --git a/public/js/components/Notiz/Notiz.js b/public/js/components/Notiz/Notiz.js new file mode 100644 index 000000000..ae3ff8c7a --- /dev/null +++ b/public/js/components/Notiz/Notiz.js @@ -0,0 +1,138 @@ +export default { + props: ['titel', 'text', 'von', 'bis', 'action', 'document', 'erledigt', 'verfasser', 'bearbeiter'], + computed: { + intTitel: { + get() { + return this.titel; + }, + set(value) { + this.$emit('update:titel', value); + } + }, + intText: { + get() { + return this.text; + }, + set(value) { + this.$emit('update:text', value); + } + }, + intVon: { + get() { + return this.von; + }, + set(value) { + this.$emit('update:von', value); + } + }, + intBis: { + get() { + return this.bis; + }, + set(value) { + this.$emit('update:bis', value); + } + }, + intDocument: { + get() { + return this.document; + }, + set(value) { + this.$emit('update:document', value); + } + }, + intErledigt: { + get() { + return this.erledigt; + }, + set(value) { + this.$emit('update:erledigt', value); + } + }, + intVerfasser: { + get() { + return this.verfasser; + }, + set(value) { + this.$emit('update:verfasser', value); + } + }, + intBearbeiter: { + get() { + return this.bearbeiter; + }, + set(value) { + this.$emit('update:bearbeiter', value); + } + }, + }, + methods: { + + }, + template: ` +