added Kontakt Model; extended Person Model

This commit is contained in:
Stefan Puraner
2016-04-06 15:46:01 +02:00
parent 30a9e9882e
commit 97ddc838a8
7 changed files with 2563 additions and 2213 deletions
+1 -1
View File
@@ -301,7 +301,7 @@ $config['rest_keys_table'] = 'ci_apikey';
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
*/
$config['rest_enable_keys'] = TRUE;
$config['rest_enable_keys'] = FALSE;
/*
|--------------------------------------------------------------------------
@@ -0,0 +1,80 @@
<?php
/**
* FH-Complete
*
* @package FHC-API
* @author FHC-Team
* @copyright Copyright (c) 2016, fhcomplete.org
* @license GPLv3
* @link http://fhcomplete.org
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
defined('BASEPATH') || exit('No direct script access allowed');
class Kontakt extends REST_Controller
{
//public $session;
/**
* Person API constructor.
*/
public function __construct()
{
parent::__construct();
$this->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);
}
}
+127 -33
View File
@@ -11,57 +11,151 @@
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
defined('BASEPATH') || exit('No direct script access allowed');
class Person extends REST_Controller
{
//public $session;
//public $session;
/**
* Person API constructor.
*/
public function __construct()
{
parent::__construct();
parent::__construct();
$this->load->model('person/person_model');
$this->load->model('person/person_model');
}
public function person_get()
{
//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);
//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');
if (!is_null($code))
$result = $this->person_model->getPersonByCode($code);
else
$result = $this->person_model->getPerson();
// var_dump($result[0]);
$code = $this->get('code');
$person_id = $this->get('person_id');
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;
}
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();
}
// 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);
}
}
@@ -0,0 +1,32 @@
<?php
class Kontakt extends FHC_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('kontakt/kontakt_model');
}
public function index()
{
$data['person'] = $this->person_model->getPersonen();
$data['title'] = 'Personen Archiv';
$this->load->view('templates/header', $data);
$this->load->view('kontakt/index', $data);
$this->load->view('templates/footer');
}
public function view($slug = null)
{
$data['person_item'] = $this->person_model->getPersonen($slug);
if (empty($data['person_item']))
show_404();
$data['title'] = $data['person_item']->titelpre;
$this->load->view('templates/header', $data);
$this->load->view('kontakt/view', $data);
$this->load->view('templates/footer');
}
}
@@ -0,0 +1,47 @@
<?php
class Kontakt_model extends DB_Model
{
public function __construct($uid = null)
{
parent::__construct($uid);
$this->dbTable = 'public.tbl_kontakt';
}
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();
}
}
+132 -35
View File
@@ -1,47 +1,144 @@
<?php
class Person_model extends DB_Model
class Person_model extends DB_Model
{
public function __construct($uid=null)
public function __construct($uid = null)
{
parent::__construct($uid);
$this->dbTable = 'public.tbl_person';
}
public function getPerson($person_id = null)
{
if (is_null($person_id))
{
parent::__construct($uid);
$this->dbTable='public.tbl_person';
$query = $this->db->get_where('public.tbl_person', array());
return $query->result_object();
}
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();
}
$query = $this->db->get_where('public.tbl_person', array('person_id' => $person_id));
return $query->row_object();
}
public function getPersonByCode($code)
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();
}
$query = $this->db->get_where('public.tbl_person', array('zugangscode' => $code));
return $query->result_object();
}
}
/**
* Laedt Personendaten eine BenutzerUID
* @param string $uid DB-Attr: tbl_benutzer.uid .
* @return bool
*/
public function getPersonFromBenutzerUID($uid)
/**
* Laedt Personendaten eine BenutzerUID
* @param string $uid DB-Attr: tbl_benutzer.uid .
* @return bool
*/
public function getPersonFromBenutzerUID($uid)
{
if (!$this->fhc_db_acl->bb->isBerechtigt('person', 's'))
{
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();
}
$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'))
// {
$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"],
);
if($this->db->insert("public.tbl_person", $data)){
return $this->db->insert_id();
}
else
{
return false;
}
// }
// else
// {
// return "Nicht berechtigt";
// }
}
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();
}
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();
}
public function updatePerson($person)
{
//TODO check berechtigung
// 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;
}
else
{
return false;
}
// }
// else
// {
// return "Nicht berechtigt";
// }
}
}
File diff suppressed because it is too large Load Diff