From 3c98988c1c6c87d738d01310429d61aef3647109 Mon Sep 17 00:00:00 2001 From: hainberg Date: Thu, 12 Sep 2019 13:51:54 +0200 Subject: [PATCH] Added new method hasVertrag() This method checks if a Projektbetreuer has a corresponding contract. If vertrag_id is null => is still a new Projektauftrag If vertrag_id is present => Projektauftrag has been ordered and a contract has been created. --- .../education/Projektbetreuer_model.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/application/models/education/Projektbetreuer_model.php b/application/models/education/Projektbetreuer_model.php index 32743be82..746e4c052 100644 --- a/application/models/education/Projektbetreuer_model.php +++ b/application/models/education/Projektbetreuer_model.php @@ -11,4 +11,34 @@ class Projektbetreuer_model extends DB_Model $this->dbTable = 'lehre.tbl_projektbetreuer'; $this->pk = array('betreuerart_kurzbz', 'projektarbeit_id', 'person_id'); } + + /** + * Checks if Projektauftrag has a contract. + * @param $person_id + * @param $projektarbeit_id + * @return array|bool|int Returns vertrag_id if contract exists. False if doesnt exist. On error array. + */ + public function hasVertrag($person_id, $projektarbeit_id) + { + if (is_numeric($person_id) && is_numeric($projektarbeit_id)) + { + $result = $this->load(array( + 'person_id' => $person_id, + 'projektarbeit_id' => $projektarbeit_id + )); + + if (hasData($result)) + { + return (is_null($result->retval[0]->vertrag_id)) ? false : intval($result->retval[0]->vertrag_id); + } + else + { + return error($result->msg, EXIT_ERROR); + } + } + else + { + return error ('Incorrect parameter type'); + } + } }