From 91684799129c6de1852a9bf43bce9d36c34610f0 Mon Sep 17 00:00:00 2001 From: paolo Date: Tue, 10 May 2016 15:30:00 +0200 Subject: [PATCH] - Moved class Studiengang to Studiengang2 to prevent class name conflicts - Added a route rule to let to call Studiengang2 controller with the urn /api/v1/organisation/studiengang/ - Moved Kontank controller to /api/v1/person - Kontakt controller has two method getKontakt and postKontakt --- application/config/routes.php | 5 +- application/controllers/api/v1/Kontakt.php | 80 ------------------- .../api/v1/organisation/Studiengang2.php | 34 ++++++++ .../controllers/api/v1/person/Kontakt.php | 70 ++++++++++++++++ application/core/FHC_Model.php | 9 ++- application/models/person/Kontakt_model.php | 38 +-------- 6 files changed, 113 insertions(+), 123 deletions(-) delete mode 100644 application/controllers/api/v1/Kontakt.php create mode 100644 application/controllers/api/v1/organisation/Studiengang2.php create mode 100644 application/controllers/api/v1/person/Kontakt.php diff --git a/application/config/routes.php b/application/config/routes.php index 968ee1396..0bdb099c2 100755 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -49,8 +49,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | Examples: my-controller/index -> my_controller/index | my-controller/my-method -> my_controller/my_method */ -$route['person/(:any)'] = 'person/view/$1'; -$route['person'] = 'person'; $route['default_controller'] = 'Vilesci'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; + +// Class name conflicts +$route['api/v1/organisation/studiengang/(:any)'] = 'api/v1/organisation/studiengang2/$1'; \ No newline at end of file diff --git a/application/controllers/api/v1/Kontakt.php b/application/controllers/api/v1/Kontakt.php deleted file mode 100644 index 7f9c05112..000000000 --- a/application/controllers/api/v1/Kontakt.php +++ /dev/null @@ -1,80 +0,0 @@ -load->model('kontakt/Kontakt_model'); - } - - public function kontaktPerson_get() - { - $result = $this->Kontakt_model->getKontaktPerson($this->get("person_id")); - if($result != FALSE) - { - $httpstatus = REST_Controller::HTTP_OK; - $payload = [ - 'success' => true, - 'message' => 'Kontakt found.' - ]; - $payload['data'] = $result; - } - else - { - $payload = [ - 'success' => false, - 'message' => 'Could not find Kontakt.' - ]; - $httpstatus = REST_Controller::HTTP_OK; - } - - $this->response($payload, $httpstatus); - } - - public function kontakt_post() - { - $result = $this->Kontakt_model->saveKontakt($this->post()); - if($result != FALSE) - { - $httpstatus = REST_Controller::HTTP_OK; - $payload = [ - 'success' => true, - 'message' => 'Kontakt saved.' - ]; - $payload['data'] = $result; - } - else - { - $payload = [ - 'success' => false, - 'message' => 'Could not save Kontakt.' - ]; - $httpstatus = REST_Controller::HTTP_OK; - } - - $this->response($payload, $httpstatus); - } - -} diff --git a/application/controllers/api/v1/organisation/Studiengang2.php b/application/controllers/api/v1/organisation/Studiengang2.php new file mode 100644 index 000000000..237a85f11 --- /dev/null +++ b/application/controllers/api/v1/organisation/Studiengang2.php @@ -0,0 +1,34 @@ +load->model('organisation/studiengang_model', 'StudiengangModel'); + // Load set the uid of the model to let to check the permissions + $this->StudiengangModel->setUID($this->_getUID()); + } + + public function getAllForBewerbung() + { + $this->response($this->StudiengangModel->getAllForBewerbung(), REST_Controller::HTTP_OK); + } +} \ No newline at end of file diff --git a/application/controllers/api/v1/person/Kontakt.php b/application/controllers/api/v1/person/Kontakt.php new file mode 100644 index 000000000..759f69120 --- /dev/null +++ b/application/controllers/api/v1/person/Kontakt.php @@ -0,0 +1,70 @@ +load->model('person/kontakt_model', 'KontaktModel'); + // Load set the uid of the model to let to check the permissions + $this->KontaktModel->setUID($this->_getUID()); + } + + public function getKontakt() + { + $personID = $this->get("person_id"); + + if(isset($personID)) + { + $result = $this->KontaktModel->loadWhere(array('person_id' => $personID)); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + public function postKontakt() + { + $post = $this->post(); + + if(is_array($post)) + { + if(isset($post['kontakt_id'])) + { + $result = $this->KontaktModel->update($post['kontakt_id'], $post); + } + else + { + $result = $this->KontaktModel->insert($post); + } + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } +} \ No newline at end of file diff --git a/application/core/FHC_Model.php b/application/core/FHC_Model.php index 6f0e5337b..d4c6d3b12 100644 --- a/application/core/FHC_Model.php +++ b/application/core/FHC_Model.php @@ -10,12 +10,13 @@ class FHC_Model extends CI_Model $this->load->helper('language'); $this->lang->load('fhc_model'); $this->lang->load('fhcomplete'); - if (is_null($uid) && isset($this->session->uid)) + + $uid = NULL; + if(is_null($uid) && isset($this->session->uid)) + { $uid = $this->session->uid; - else - $uid = null; + } $this->load->library('FHC_DB_ACL', array('uid' => $uid)); - //$this->load->library('FHC_DB_ACL'); } /** --------------------------------------------------------------- diff --git a/application/models/person/Kontakt_model.php b/application/models/person/Kontakt_model.php index 8bd905641..5c25f563e 100644 --- a/application/models/person/Kontakt_model.php +++ b/application/models/person/Kontakt_model.php @@ -1,7 +1,6 @@ dbTable = 'public.tbl_kontakt'; $this->pk = 'kontakt_id'; } - - public function saveKontakt($kontakt) - { - //TODO check berechtigung -// if ($this->fhc_db_acl->bb->isBerechtigt('person', 'sui')) -// { - $data = array( - "person_id"=>$kontakt["person_id"], - "kontakttyp"=>$kontakt["kontakttyp"], - "kontakt"=>$kontakt["kontakt"], - "insertvon"=>$kontakt["insertvon"], - "insertamum"=>date('Y-m-d H:i:s') - ); - if($this->db->insert("public.tbl_kontakt", $data)){ - return $this->db->insert_id(); - } - else - { - return false; - } -// } -// else -// { -// return "Nicht berechtigt"; -// } - } - - public function getKontaktPerson($person_id) - { - $this->db->select("*") - ->from("public.tbl_kontakt k") - ->where("k.person_id", $person_id); - - return $this->db->get()->result_array(); - } -} +} \ No newline at end of file