From 440cac91d6c0f6f8318dac0a3413f657d1d2e3ae Mon Sep 17 00:00:00 2001 From: Stefan Puraner Date: Tue, 10 May 2016 13:46:01 +0200 Subject: [PATCH 1/3] person model: added method that return list of db columns --- .../controllers/api/v1/person/Person.php | 3 +- application/models/person/Person_model.php | 44 ++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/application/controllers/api/v1/person/Person.php b/application/controllers/api/v1/person/Person.php index ea708f8e5..7fcec6231 100644 --- a/application/controllers/api/v1/person/Person.php +++ b/application/controllers/api/v1/person/Person.php @@ -60,7 +60,8 @@ class Person extends APIv1_Controller } else { - $this->response(); + $fields = $this->PersonModel->getFields(); + $this->response($fields, REST_Controller::HTTP_OK); } } diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index 1a9192a88..7a8f0978d 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -11,11 +11,51 @@ class Person_model extends DB_Model $this->dbTable = 'public.tbl_person'; $this->pk = 'person_id'; } + + public function getFields() + { + $fields = array( + //Tabellenspalten + "person_id" => NULL, + "sprache" => NULL, + "anrede" => NULL, + "titelpost" => NULL, + "titelpre" => NULL, + "nachname" => NULL, + "vorname" => NULL, + "vornamen" => NULL, + "gebdatum" => NULL, + "gebort" => NULL, + "gebzeit" => NULL, + "foto" => NULL, + "anmerkungen" => NULL, + "homepage" => NULL, + "svnr" => NULL, + "ersatzkennzeichen" => NULL, + "familienstand" => NULL, + "anzahlkinder" => NULL, + "aktiv"=>TRUE, + "insertamum" => NULL, + "insertvon" => NULL, + "updateamum" => NULL, + "updatevon" => NULL, + "geschlecht" => "u", + "staatsbuergerschaft" => NULL, + "geburtsnation" => NULL, + "ext_id" => NULL, + "kurzbeschreibung"> NULL, + "zugangscode" => NULL, + "foto_sperre" => FALSE, + "matr_nr"=> NULL + ); + + return $this->_success($fields); + } /** * */ - /*public function checkBewerbung($email, $studiensemester_kurzbz = NULL) + public function checkBewerbung($email, $studiensemester_kurzbz = NULL) { $this->db->distinct(); @@ -51,5 +91,5 @@ class Person_model extends DB_Model ; } return $this->db->get()->result_array(); - }*/ + } } \ No newline at end of file From b0c1e50e47f47621c70fd495f9b359958850f126 Mon Sep 17 00:00:00 2001 From: Stefan Puraner Date: Wed, 11 May 2016 11:56:18 +0200 Subject: [PATCH 2/3] added workaround for parsing data --- application/config/config.php | 2 +- .../controllers/api/v1/person/Kontakt.php | 19 ++++++++- .../controllers/api/v1/person/Person.php | 31 +++++++++++--- application/models/person/Person_model.php | 40 ------------------- 4 files changed, 43 insertions(+), 49 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index 68b85b62f..96b966b37 100755 --- a/application/config/config.php +++ b/application/config/config.php @@ -207,7 +207,7 @@ $config['directory_trigger'] = 'd'; | your log files will fill up very fast. | */ -$config['log_threshold'] = 0; +$config['log_threshold'] = 4; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/api/v1/person/Kontakt.php b/application/controllers/api/v1/person/Kontakt.php index 759f69120..5a59507dc 100644 --- a/application/controllers/api/v1/person/Kontakt.php +++ b/application/controllers/api/v1/person/Kontakt.php @@ -41,13 +41,13 @@ class Kontakt extends APIv1_Controller } else { - $this->response(); + $this->response(); } } public function postKontakt() { - $post = $this->post(); + $post = $this->_parseData($this->post()); if(is_array($post)) { @@ -67,4 +67,19 @@ class Kontakt extends APIv1_Controller $this->response(); } } + + private function _parseData($person) + { + if(is_array($person)) + { + foreach($person as $key=>$value) + { + if($value === "") + { + $person[$key] = null; + } + } + return $person; + } + } } \ No newline at end of file diff --git a/application/controllers/api/v1/person/Person.php b/application/controllers/api/v1/person/Person.php index c3ea2e7ab..e44410847 100644 --- a/application/controllers/api/v1/person/Person.php +++ b/application/controllers/api/v1/person/Person.php @@ -60,8 +60,7 @@ class Person extends APIv1_Controller } else { - $fields = $this->PersonModel->getFields(); - $this->response($fields, REST_Controller::HTTP_OK); + $this->response(); } } @@ -70,15 +69,17 @@ class Person extends APIv1_Controller */ public function postPerson() { + $person = $this->_parseData($this->post()); + if($this->_validate($this->post())) { - if(isset($this->post()['person_id'])) + if(isset($person['person_id']) && !(is_null($person["person_id"])) && ($person["person_id"] != "")) { - $result = $this->PersonModel->update($this->post()['person_id'], $this->post()); + $result = $this->PersonModel->update($person['person_id'], $person); } else { - $result = $this->PersonModel->insert($this->post()); + $result = $this->PersonModel->insert($person); } $this->response($result, REST_Controller::HTTP_OK); @@ -108,6 +109,21 @@ class Person extends APIv1_Controller $this->response(); } } + + private function _parseData($person) + { + if(is_array($person)) + { + foreach($person as $key=>$value) + { + if($value === "") + { + $person[$key] = null; + } + } + return $person; + } + } private function _validate($person = NULL) { @@ -115,7 +131,10 @@ class Person extends APIv1_Controller { return false; } - + + //TODO + return true; + $person['nachname'] = trim($person['nachname']); $person['vorname'] = trim($person['vorname']); $person['vornamen'] = trim($person['vornamen']); diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index 613a3cb76..171f3a47e 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -11,46 +11,6 @@ class Person_model extends DB_Model $this->dbTable = 'public.tbl_person'; $this->pk = 'person_id'; } - - public function getFields() - { - $fields = array( - //Tabellenspalten - "person_id" => NULL, - "sprache" => NULL, - "anrede" => NULL, - "titelpost" => NULL, - "titelpre" => NULL, - "nachname" => NULL, - "vorname" => NULL, - "vornamen" => NULL, - "gebdatum" => NULL, - "gebort" => NULL, - "gebzeit" => NULL, - "foto" => NULL, - "anmerkungen" => NULL, - "homepage" => NULL, - "svnr" => NULL, - "ersatzkennzeichen" => NULL, - "familienstand" => NULL, - "anzahlkinder" => NULL, - "aktiv"=>TRUE, - "insertamum" => NULL, - "insertvon" => NULL, - "updateamum" => NULL, - "updatevon" => NULL, - "geschlecht" => "u", - "staatsbuergerschaft" => NULL, - "geburtsnation" => NULL, - "ext_id" => NULL, - "kurzbeschreibung"> NULL, - "zugangscode" => NULL, - "foto_sperre" => FALSE, - "matr_nr"=> NULL - ); - - return $this->_success($fields); - } /** * From cf272c0e405fcc7a72cc63c5223fef0ce71f55ab Mon Sep 17 00:00:00 2001 From: Stefan Puraner Date: Fri, 20 May 2016 17:34:22 +0200 Subject: [PATCH 3/3] added method to parse post data --- .../api/v1/crm/Prestudentstatus.php | 22 ++++++---- .../controllers/api/v1/person/Kontakt.php | 15 ------- .../controllers/api/v1/person/Person.php | 15 ------- application/core/APIv1_Controller.php | 42 ++++++++++++++++--- 4 files changed, 50 insertions(+), 44 deletions(-) diff --git a/application/controllers/api/v1/crm/Prestudentstatus.php b/application/controllers/api/v1/crm/Prestudentstatus.php index 5b19dbc61..f1bfda16a 100644 --- a/application/controllers/api/v1/crm/Prestudentstatus.php +++ b/application/controllers/api/v1/crm/Prestudentstatus.php @@ -55,22 +55,26 @@ class Prestudentstatus extends APIv1_Controller */ public function postPrestudentstatus() { - if ($this->_validate($this->post())) + $prestudentstatus = $this->_parseData($this->post()); + + $this->response($prestudentstatus); + + if ($this->_validate($prestudentstatus)) { - if (isset($this->post()['ausbildungssemester']) && isset($this->post()['studiensemester_kurzbz']) && - isset($this->post()['status_kurzbz']) && isset($this->post()['prestudent_id'])) + if (isset($prestudentstatus['ausbildungssemester']) && isset($prestudentstatus['studiensemester_kurzbz']) && + isset($prestudentstatus['status_kurzbz']) && isset($prestudentstatus['prestudent_id'])) { - $pksArray = array($this->post()['ausbildungssemester'], - $this->post()['studiensemester_kurzbz'], - $this->post()['status_kurzbz'], - $this->post()['prestudent_id'] + $pksArray = array($prestudentstatus['ausbildungssemester'], + $prestudentstatus['studiensemester_kurzbz'], + $prestudentstatus['status_kurzbz'], + $prestudentstatus['prestudent_id'] ); - $result = $this->PrestudentstatusModel->update($pksArray, $this->post()); + $result = $this->PrestudentstatusModel->update($pksArray, $prestudentstatus); } else { - $result = $this->PrestudentstatusModel->insert($this->post()); + $result = $this->PrestudentstatusModel->insert($prestudentstatus); } $this->response($result, REST_Controller::HTTP_OK); diff --git a/application/controllers/api/v1/person/Kontakt.php b/application/controllers/api/v1/person/Kontakt.php index 5d5407bf8..00015ff78 100644 --- a/application/controllers/api/v1/person/Kontakt.php +++ b/application/controllers/api/v1/person/Kontakt.php @@ -67,19 +67,4 @@ class Kontakt extends APIv1_Controller $this->response(); } } - - private function _parseData($person) - { - if(is_array($person)) - { - foreach($person as $key=>$value) - { - if($value === "") - { - $person[$key] = null; - } - } - return $person; - } - } } \ No newline at end of file diff --git a/application/controllers/api/v1/person/Person.php b/application/controllers/api/v1/person/Person.php index c0c3168ea..71edf5ef3 100644 --- a/application/controllers/api/v1/person/Person.php +++ b/application/controllers/api/v1/person/Person.php @@ -109,21 +109,6 @@ class Person extends APIv1_Controller $this->response(); } } - - private function _parseData($person) - { - if(is_array($person)) - { - foreach($person as $key=>$value) - { - if($value === "") - { - $person[$key] = null; - } - } - return $person; - } - } private function _validate($person = NULL) { diff --git a/application/core/APIv1_Controller.php b/application/core/APIv1_Controller.php index b33c5a530..cc3d3fef8 100644 --- a/application/core/APIv1_Controller.php +++ b/application/core/APIv1_Controller.php @@ -4,10 +4,42 @@ require_once APPPATH . '/libraries/REST_Controller.php'; class APIv1_Controller extends REST_Controller { - function __construct() - { - parent::__construct(); - //$this->load->library('session'); // -> autoload - //$this->load->library('database'); -> autoload + function __construct() + { + parent::__construct(); + //$this->load->library('session'); // -> autoload + //$this->load->library('database'); -> autoload + + } + + /** + * + * @param type $data + * @return typeparses empty string to NULL + */ + protected function _parseData($data) + { + if(is_array($data)) + { + foreach($data as $key=>$value) + { + if($value === "") + { + $data[$key] = NULL; + } + } + return $data; + } + elseif(is_object($data)) + { + //TODO + } + else + { + if($data == "") + { + return NULL; + } + } } } \ No newline at end of file