added method to parse post data

This commit is contained in:
Stefan Puraner
2016-05-20 17:34:22 +02:00
parent dfea2bab26
commit cf272c0e40
4 changed files with 50 additions and 44 deletions
@@ -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);
@@ -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;
}
}
}
@@ -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)
{
+37 -5
View File
@@ -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;
}
}
}
}