application/controllers/api/v1/Person.php
	Fixed conflicts

application/models/person/Person_model.php
	Fixed conflicts

ci_hack.php
	Load the language class otherwise some VileSci functionalities would crash
	Ex: Personen -> Zusammenlegen

tests/codesniffer/FHComplete/ruleset.xml
	Turned off ParamCommentFullStop option
This commit is contained in:
paolo
2016-04-08 16:53:52 +02:00
parent 5e59fc3c17
commit 1131bff3ec
4 changed files with 215 additions and 229 deletions
+121 -131
View File
@@ -17,47 +17,43 @@ defined('BASEPATH') || exit('No direct script access allowed');
class Person extends APIv1_Controller
{
//public $session;
/**
* Person API constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->model('person/person_model');
parent::__construct();
$this->load->model('person/person_model');
}
public function person_get()
{
//if (!$this->session_model->validate($this->get('session_id'), $this->get('device_id')))
//if(!$this->session_model->validate($this->get('session_id'), $this->get('device_id')))
// $this->response(array(['success' => false, 'message' => 'access denied']), REST_Controller::HTTP_UNAUTHORIZED);
$code = $this->get('code');
$person_id = $this->get('person_id');
$code = $this->get('code');
$person_id = $this->get('person_id');
if (!is_null($code))
{
$result = $this->person_model->getPersonByCode($code);
}
elseif (!is_null($person_id))
{
$result = $this->person_model->getPerson($person_id);
}
else
{
$result = $this->person_model->getPerson();
}
if(!is_null($code))
{
$result = $this->person_model->getPersonByCode($code);
}
elseif(!is_null($person_id))
{
$result = $this->person_model->getPerson($person_id);
}
else
{
$result = $this->person_model->getPerson();
}
<<<<<<< HEAD
if ($result['err'])
if($result['err'])
{
$payload = [
'success' => false,
'message' => $result['msg'].': '.$result['retval']
];
$httpstatus = REST_Controller::HTTP_OK;
'success' => false,
'message' => $result['msg'].': '.$result['retval']
];
$httpstatus = REST_Controller::HTTP_OK;
}
else
{
@@ -69,114 +65,108 @@ class Person extends APIv1_Controller
$payload['data'] = $result;
$httpstatus = REST_Controller::HTTP_OK;
}
=======
if (empty($result))
{
$payload = [
'success' => false,
'message' => 'Person not found'
];
$httpstatus = REST_Controller::HTTP_OK;
}
else
{
// return all available persons
$payload = [
'success' => true,
'message' => 'Persons found'
];
$payload['data'] = $result;
$httpstatus = REST_Controller::HTTP_OK;
}
>>>>>>> 97ddc838a8c9e707d3bf5a6a700301252d2f5ed8
// Set the response and exit
$this->response($payload, $httpstatus);
if(empty($result))
{
$payload = [
'success' => false,
'message' => 'Person not found'
];
$httpstatus = REST_Controller::HTTP_OK;
}
else
{
// return all available persons
$payload = [
'success' => true,
'message' => 'Persons found'
];
$payload['data'] = $result;
$httpstatus = REST_Controller::HTTP_OK;
}
// Set the response and exit
$this->response($payload, $httpstatus);
}
public function person_post()
{
$result = $this->person_model->savePerson($this->post());
if($result != FALSE)
{
$httpstatus = REST_Controller::HTTP_OK;
$payload = [
'success' => true,
'message' => 'Person saved.'
];
$payload['data'] = $result;
}
else
{
$payload = [
'success' => false,
'message' => 'Could not save person.'
];
$httpstatus = REST_Controller::HTTP_OK;
}
$this->response($payload, $httpstatus);
}
public function personUpdate_post()
{
$result = $this->person_model->updatePerson($this->post());
if($result != FALSE)
{
$httpstatus = REST_Controller::HTTP_OK;
$payload = [
'success' => true,
'message' => 'Person updated.'
];
$payload['data'] = $result;
}
else
{
$payload = [
'success' => false,
'message' => 'Could not update person.'
];
$httpstatus = REST_Controller::HTTP_OK;
}
//
$this->response($payload, $httpstatus);
}
public function checkBewerbung_get()
{
$result = $this->person_model->checkBewerbung($this->get("email"),$this->get("studiensemester_kurzbz"));
$httpstatus = REST_Controller::HTTP_OK;
$payload = [
'success' => true,
'message' => 'Bewerbung exists.'
];
$payload['data'] = $result;
$this->response($payload, $httpstatus);
}
public function checkZugangscodePerson_get()
{
$result = $this->person_model->checkZugangscodePerson($this->get("code"));
$httpstatus = REST_Controller::HTTP_OK;
if(!empty($result))
{
$payload = [
'success' => true,
'message' => 'Zugangscode exists.'
];
$payload['data'] = $result;
}
else
{
$payload = [
'success' => false,
'message' => 'Zugangscode does not exist.'
];
$httpstatus = REST_Controller::HTTP_OK;
}
$this->response($payload, $httpstatus);
$result = $this->person_model->savePerson($this->post());
if($result != FALSE)
{
$httpstatus = REST_Controller::HTTP_OK;
$payload = [
'success' => true,
'message' => 'Person saved.'
];
$payload['data'] = $result;
}
else
{
$payload = [
'success' => false,
'message' => 'Could not save person.'
];
$httpstatus = REST_Controller::HTTP_OK;
}
$this->response($payload, $httpstatus);
}
}
public function personUpdate_post()
{
$result = $this->person_model->updatePerson($this->post());
if($result != FALSE)
{
$httpstatus = REST_Controller::HTTP_OK;
$payload = [
'success' => true,
'message' => 'Person updated.'
];
$payload['data'] = $result;
}
else
{
$payload = [
'success' => false,
'message' => 'Could not update person.'
];
$httpstatus = REST_Controller::HTTP_OK;
}
$this->response($payload, $httpstatus);
}
public function checkBewerbung_get()
{
$result = $this->person_model->checkBewerbung($this->get("email"),$this->get("studiensemester_kurzbz"));
$httpstatus = REST_Controller::HTTP_OK;
$payload = [
'success' => true,
'message' => 'Bewerbung exists.'
];
$payload['data'] = $result;
$this->response($payload, $httpstatus);
}
public function checkZugangscodePerson_get()
{
$result = $this->person_model->checkZugangscodePerson($this->get("code"));
$httpstatus = REST_Controller::HTTP_OK;
if(!empty($result))
{
$payload = [
'success' => true,
'message' => 'Zugangscode exists.'
];
$payload['data'] = $result;
}
else
{
$payload = [
'success' => false,
'message' => 'Zugangscode does not exist.'
];
$httpstatus = REST_Controller::HTTP_OK;
}
$this->response($payload, $httpstatus);
}
}
+74 -86
View File
@@ -2,35 +2,23 @@
class Person_model extends DB_Model
{
public function __construct($uid = null)
{
parent::__construct($uid);
$this->dbTable = 'public.tbl_person';
parent::__construct($uid);
$this->dbTable = 'public.tbl_person';
}
public function getPerson($person_id = null)
{
if (is_null($person_id))
{
$query = $this->db->get_where('public.tbl_person', array());
return $query->result_object();
}
$query = $this->db->get_where('public.tbl_person', array('person_id' => $person_id));
return $query->row_object();
if(is_null($person_id))
{
$query = $this->db->get_where('public.tbl_person', array());
return $query->result_object();
}
$query = $this->db->get_where('public.tbl_person', array('person_id' => $person_id));
return $query->row_object();
}
public function getPersonByCode($code)
{
if ($this->fhc_db_acl->bb->isBerechtigt('person', 's'))
{
$query = $this->db->get_where('public.tbl_person', array('zugangscode' => $code));
return $query->result_object();
}
}
<<<<<<< HEAD
/**
* Laedt Personendaten einer Person mittels Code
* @param string $code DB-Attr: tbl_benutzer.zugangscode .
@@ -38,7 +26,7 @@ class Person_model extends DB_Model
*/
public function getPersonByCode($code)
{
if ($this->fhc_db_acl->bb->isBerechtigt('person','s'))
if($this->fhc_db_acl->bb->isBerechtigt('person','s'))
{
$query = $this->db->get_where('public.tbl_person', array('zugangscode' => $code));
return $query->result_object();
@@ -48,7 +36,8 @@ class Person_model extends DB_Model
return $this->_general_error($this->fhc_db_acl->bb->errormsg);
//return false;
}
=======
}
/**
* Laedt Personendaten eine BenutzerUID
* @param string $uid DB-Attr: tbl_benutzer.uid .
@@ -56,36 +45,35 @@ class Person_model extends DB_Model
*/
public function getPersonFromBenutzerUID($uid)
{
if (!$this->fhc_db_acl->bb->isBerechtigt('person', 's'))
{
$this->db->select('tbl_person.*');
$this->db->from('public.tbl_person JOIN public.tbl_benutzer USING (person_id)');
$query = $this->db->get_where(null, array('uid' => $uid));
return $query->result_object();
>>>>>>> 97ddc838a8c9e707d3bf5a6a700301252d2f5ed8
}
if(!$this->fhc_db_acl->bb->isBerechtigt('person', 's'))
{
$this->db->select('tbl_person.*');
$this->db->from('public.tbl_person JOIN public.tbl_benutzer USING (person_id)');
$query = $this->db->get_where(null, array('uid' => $uid));
return $query->result_object();
}
}
public function savePerson($person)
{
//TODO check berechtigung
// if ($this->fhc_db_acl->bb->isBerechtigt('person', 'sui'))
// if($this->fhc_db_acl->bb->isBerechtigt('person', 'sui'))
// {
$data = array(
"vorname"=>$person["vorname"],
"nachname"=>$person["nachname"],
"gebdatum"=>$person["gebdatum"],
"aktiv" => true,
"zugangscode"=>$person["zugangscode"],
"insertamum"=>date('Y-m-d H:i:s'),
"insertvon"=>$person["insertvon"],
"vorname"=>$person["vorname"],
"nachname"=>$person["nachname"],
"gebdatum"=>$person["gebdatum"],
"aktiv" => true,
"zugangscode"=>$person["zugangscode"],
"insertamum"=>date('Y-m-d H:i:s'),
"insertvon"=>$person["insertvon"],
);
if($this->db->insert("public.tbl_person", $data)){
return $this->db->insert_id();
return $this->db->insert_id();
}
else
{
return false;
return false;
}
// }
// else
@@ -96,64 +84,64 @@ class Person_model extends DB_Model
public function checkBewerbung($email, $studiensemester_kurzbz=NULL)
{
$this->db->distinct();
if(is_null($studiensemester_kurzbz))
{
$this->db->select("p.person_id, p.zugangscode, p.insertamum")
->from("public.tbl_person p")
->join("public.tbl_kontakt k", "p.person_id=k.person_id")
->join("public.tbl_benutzer b", "p.person_id=b.person_id", "left")
->where("k.kontakttyp", 'email')
->where("(kontakt='".$email."'".
" OR alias ||'@technikum-wien.at'='".$email."'".
" OR uid ||'@technikum-wien.at'='".$email."')")
->order_by("p.insertamum", "DESC")
->limit(1)
;
}
else
{
$this->db->select("p.person_id,p.zugangscode,p.insertamum")
->from("public.tbl_person p")
->join("public.tbl_kontakt k", "p.person_id=k.person_id")
->join("public.tbl_benutzer b", "p.person_id=b.person_id", "left")
->join("public.tbl_prestudent ps", "p.person_id=ps.person_id")
->join("public.tbl_prestudentstatus pst", "pst.prestudent_id=ps.prestudent_id")
->where("k.kontakttyp", 'email')
->where("(kontakt='".$email."'".
" OR alias ||'@technikum-wien.at'='".$email."'".
" OR uid ||'@technikum-wien.at'='".$email."')")
->where("studiensemester_kurzbz='".$studiensemester_kurzbz."'")
->order_by("p.insertamum", "DESC")
->limit(1)
;
}
return $this->db->get()->result_array();
$this->db->distinct();
if(is_null($studiensemester_kurzbz))
{
$this->db->select("p.person_id, p.zugangscode, p.insertamum")
->from("public.tbl_person p")
->join("public.tbl_kontakt k", "p.person_id=k.person_id")
->join("public.tbl_benutzer b", "p.person_id=b.person_id", "left")
->where("k.kontakttyp", 'email')
->where("(kontakt='".$email."'".
" OR alias ||'@technikum-wien.at'='".$email."'".
" OR uid ||'@technikum-wien.at'='".$email."')")
->order_by("p.insertamum", "DESC")
->limit(1)
;
}
else
{
$this->db->select("p.person_id,p.zugangscode,p.insertamum")
->from("public.tbl_person p")
->join("public.tbl_kontakt k", "p.person_id=k.person_id")
->join("public.tbl_benutzer b", "p.person_id=b.person_id", "left")
->join("public.tbl_prestudent ps", "p.person_id=ps.person_id")
->join("public.tbl_prestudentstatus pst", "pst.prestudent_id=ps.prestudent_id")
->where("k.kontakttyp", 'email')
->where("(kontakt='".$email."'".
" OR alias ||'@technikum-wien.at'='".$email."'".
" OR uid ||'@technikum-wien.at'='".$email."')")
->where("studiensemester_kurzbz='".$studiensemester_kurzbz."'")
->order_by("p.insertamum", "DESC")
->limit(1)
;
}
return $this->db->get()->result_array();
}
public function checkZugangscodePerson($code)
{
$this->db->select("p.person_id")
->from("public.tbl_person p")
->where("p.zugangscode", $code);
return $this->db->get()->result_array();
$this->db->select("p.person_id")
->from("public.tbl_person p")
->where("p.zugangscode", $code);
return $this->db->get()->result_array();
}
public function updatePerson($person)
{
//TODO check berechtigung
// if ($this->fhc_db_acl->bb->isBerechtigt('person', 'sui'))
// if($this->fhc_db_acl->bb->isBerechtigt('person', 'sui'))
// {
//TODO set other columns to be updated
$this->db->set("zugangscode", $person["zugangscode"]);
$this->db->where("person_id", $person["person_id"]);
if($this->db->update("public.tbl_person")){
return true;
return true;
}
else
{
return false;
return false;
}
// }
// else
@@ -161,4 +149,4 @@ class Person_model extends DB_Model
// return "Nicht berechtigt";
// }
}
}
}
+16 -9
View File
@@ -302,16 +302,24 @@ require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Contro
* depending on another class that uses it.
*
*/
$CFG =& load_class('Config', 'core');
$CFG =& load_class('Config', 'core');
// Do we have any manually set config items in the index.php file?
if (isset($assign_to_config) && is_array($assign_to_config))
// Do we have any manually set config items in the index.php file?
if (isset($assign_to_config) && is_array($assign_to_config))
{
foreach ($assign_to_config as $key => $value)
{
foreach ($assign_to_config as $key => $value)
{
$CFG->set_item($key, $value);
}
$CFG->set_item($key, $value);
}
}
/*
* ------------------------------------------------------
* Load the Language class
* ------------------------------------------------------
*/
$LANG =& load_class('Lang', 'core');
function &get_instance()
{
return CI_Controller::get_instance();
@@ -430,5 +438,4 @@ trait db_extra
else
die('Invalid DB Boolean. Wrong DB-Engine?');
}
}
}
+4 -3
View File
@@ -22,14 +22,15 @@
</properties>
</rule>
<rule ref="FHComplete.Commenting.FunctionComment.ParamCommentFullStop">
<severity>0</severity>
</rule>
<!--
Temporarily ignore until API docblock formatting and line length issues in core code are fixed.
<rule ref="FHComplete.Commenting.FunctionComment.ParamCommentNotCapital">
<severity>0</severity>
</rule>
<rule ref="FHComplete.Commenting.FunctionComment.ParamCommentFullStop">
<severity>0</severity>
</rule>
<rule ref="FHComplete.Commenting.FunctionComment.ThrowsNotCapital">
<severity>0</severity>
</rule>