From 1131bff3ec73027f5e81a34553f944290a406772 Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 8 Apr 2016 16:53:52 +0200 Subject: [PATCH] Changes: 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 --- application/controllers/api/v1/Person.php | 252 ++++++++++----------- application/models/person/Person_model.php | 160 ++++++------- ci_hack.php | 25 +- tests/codesniffer/FHComplete/ruleset.xml | 7 +- 4 files changed, 215 insertions(+), 229 deletions(-) diff --git a/application/controllers/api/v1/Person.php b/application/controllers/api/v1/Person.php index 0d1d120bc..cdd5bb863 100644 --- a/application/controllers/api/v1/Person.php +++ b/application/controllers/api/v1/Person.php @@ -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); + } +} \ No newline at end of file diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index e8c987fc0..437933ed1 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -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"; // } } -} +} \ No newline at end of file diff --git a/ci_hack.php b/ci_hack.php index 9d771aab8..69cdbe070 100755 --- a/ci_hack.php +++ b/ci_hack.php @@ -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?'); } -} - +} \ No newline at end of file diff --git a/tests/codesniffer/FHComplete/ruleset.xml b/tests/codesniffer/FHComplete/ruleset.xml index 6673d18fe..94572c624 100644 --- a/tests/codesniffer/FHComplete/ruleset.xml +++ b/tests/codesniffer/FHComplete/ruleset.xml @@ -22,14 +22,15 @@ + + 0 + +