diff --git a/application/controllers/api/v1/crm/Prestudent.php b/application/controllers/api/v1/crm/Prestudent.php index 6ee24463a..3bc18849b 100644 --- a/application/controllers/api/v1/crm/Prestudent.php +++ b/application/controllers/api/v1/crm/Prestudent.php @@ -34,11 +34,11 @@ class Prestudent extends APIv1_Controller public function getPrestudent() { $prestudentID = $this->get('prestudent_id'); - + if (isset($prestudentID)) { $result = $this->PrestudentModel->load($prestudentID); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -46,18 +46,18 @@ class Prestudent extends APIv1_Controller $this->response(); } } - + /** * @return void */ public function getPrestudentByPersonID() { $person_id = $this->get('person_id'); - + if (isset($person_id)) { $result = $this->PrestudentModel->load(array('person_id' => $person_id)); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -65,7 +65,7 @@ class Prestudent extends APIv1_Controller $this->response(); } } - + /** * @return void */ @@ -73,14 +73,14 @@ class Prestudent extends APIv1_Controller { $prestudent_id = $this->get('prestudent_id'); $titel = $this->get('titel'); - + if (isset($prestudent_id) && isset($titel)) { // Loads model Notiz_model $this->load->model('person/Notiz_model', 'NotizModel'); - + $result = $this->NotizModel->getSpecialization($prestudent_id, $titel); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -88,7 +88,7 @@ class Prestudent extends APIv1_Controller $this->response(); } } - + /** * @return void */ @@ -98,7 +98,7 @@ class Prestudent extends APIv1_Controller $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); $studiengang_kz = $this->get('studiengang_kz'); $status_kurzbz = $this->get('status_kurzbz'); - + if (isset($person_id)) { $result = $this->PrestudentModel->getLastStatuses( @@ -107,7 +107,7 @@ class Prestudent extends APIv1_Controller $studiengang_kz, $status_kurzbz ); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -115,21 +115,56 @@ class Prestudent extends APIv1_Controller $this->response(); } } - + + /** + * Get all Persons with a Status in the define Timerange + * Additionally ALL Prestudents of this person are included. + * (Not only the ones with the status) + * + * @return void + */ + public function getPrestudentsPerStatus() + { + $this->load->model('person/person_model', 'PersonModel'); + $status_kurzbz = $this->get('status_kurzbz'); + $von = $this->get('von'); + $bis = $this->get('bis'); + + if (isset($status_kurzbz)) + { + $result = $this->PersonModel->getPersonFromStatus( + $status_kurzbz, + $von, + $bis + ); + + // Remove person images from result array to reduce useless traffic + foreach($result->retval as $key=>$val) + { + unset($result->retval[$key]->foto); + } + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + /** * @return void */ public function postRmSpecialization() { $notiz_id = $this->post()['notiz_id']; - + if (isset($notiz_id)) { // Loads model Notiz_model $this->load->model('person/Notiz_model', 'NotizModel'); - + $result = $this->NotizModel->rmSpecialization($notiz_id); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -137,7 +172,7 @@ class Prestudent extends APIv1_Controller $this->response(); } } - + /** * @return void */ @@ -146,14 +181,14 @@ class Prestudent extends APIv1_Controller $prestudent_id = $this->post()['prestudent_id']; $titel = $this->post()['titel']; $text = $this->post()['text']; - + if (isset($prestudent_id) && isset($titel) && isset($text)) { // Loads model Notiz_model $this->load->model('person/Notiz_model', 'NotizModel'); - + $result = $this->NotizModel->addSpecialization($prestudent_id, $titel, $text); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -168,7 +203,7 @@ class Prestudent extends APIv1_Controller public function postPrestudent() { $prestudent = $this->post(); - + if ($this->_validate($this->post())) { if (isset($prestudent['prestudent_id'])) @@ -179,7 +214,7 @@ class Prestudent extends APIv1_Controller { $result = $this->PrestudentModel->insert($prestudent); } - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -187,7 +222,7 @@ class Prestudent extends APIv1_Controller $this->response(); } } - + /** * @return void */ @@ -196,7 +231,7 @@ class Prestudent extends APIv1_Controller if ($this->_validate($this->delete())) { $result = $this->PrestudentModel->delete($this->delete()['prestudent_id']); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -204,28 +239,28 @@ class Prestudent extends APIv1_Controller $this->response(); } } - + /** * @return void */ public function postAddReihungstest() { $ddReihungstest = $this->post(); - + if ($this->_validateReihungstest($ddReihungstest)) { if(isset($ddReihungstest['new']) && $ddReihungstest['new'] == true) { // Remove new parameter to avoid DB insert errors unset($ddReihungstest['new']); - + $result = $this->reihungstestlib->insertPersonReihungstest($ddReihungstest); } else { $result = $this->reihungstestlib->updatePersonReihungstest($ddReihungstest); } - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -233,18 +268,18 @@ class Prestudent extends APIv1_Controller $this->response(); } } - + /** * @return void */ public function postDelReihungstest() { $ddReihungstest = $this->post(); - + if (isset($ddReihungstest['rt_person_id'])) { $result = $this->reihungstestlib->deletePersonReihungstest($ddReihungstest); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -252,19 +287,19 @@ class Prestudent extends APIv1_Controller $this->response(); } } - + private function _validate($prestudent = NULL) { return true; } - + private function _validateReihungstest($ddReihungstest = NULL) { if (!isset($ddReihungstest['person_id']) || !isset($ddReihungstest['rt_id']) || !isset($ddReihungstest['studienplan_id'])) { return false; } - + return true; } -} \ No newline at end of file +} diff --git a/application/controllers/api/v1/crm/Prestudentstatus.php b/application/controllers/api/v1/crm/Prestudentstatus.php index 93ad9aeb1..814bf0617 100644 --- a/application/controllers/api/v1/crm/Prestudentstatus.php +++ b/application/controllers/api/v1/crm/Prestudentstatus.php @@ -35,11 +35,11 @@ class Prestudentstatus extends APIv1_Controller $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); $status_kurzbz = $this->get('status_kurzbz'); $prestudent_id = $this->get('prestudent_id'); - + if (isset($ausbildungssemester) && isset($studiensemester_kurzbz) && isset($status_kurzbz) && isset($prestudent_id)) { $result = $this->PrestudentstatusModel->load(array($ausbildungssemester, $studiensemester_kurzbz, $status_kurzbz, $prestudent_id)); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -47,7 +47,7 @@ class Prestudentstatus extends APIv1_Controller $this->response(); } } - + /** * @return void */ @@ -56,11 +56,11 @@ class Prestudentstatus extends APIv1_Controller $prestudent_id = $this->get("prestudent_id"); $studiensemester_kurzbz = $this->get("studiensemester_kurzbz"); $status_kurzbz = $this->get("status_kurzbz"); - + if (isset($prestudent_id)) { $result = $this->PrestudentstatusModel->getLastStatus($prestudent_id, $studiensemester_kurzbz, $status_kurzbz); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -75,14 +75,14 @@ class Prestudentstatus extends APIv1_Controller public function postPrestudentstatus() { $prestudentstatus = $this->post(); - + if ($this->_validate($prestudentstatus)) { if(isset($prestudentstatus['new']) && $prestudentstatus['new'] == true) { // Remove new parameter to avoid DB insert errors unset($prestudentstatus['new']); - + $result = $this->PrestudentstatusModel->insert($prestudentstatus); } else @@ -95,7 +95,7 @@ class Prestudentstatus extends APIv1_Controller $result = $this->PrestudentstatusModel->update($pksArray, $prestudentstatus); } - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -103,14 +103,14 @@ class Prestudentstatus extends APIv1_Controller $this->response(); } } - + /** * @return void */ public function deletePrestudentstatus() { $prestudentstatus = $this->delete(); - + if ($this->_validate($prestudentstatus)) { $pksArray = array($prestudentstatus['ausbildungssemester'], @@ -120,7 +120,7 @@ class Prestudentstatus extends APIv1_Controller ); $result = $this->PrestudentstatusModel->delete($pksArray); - + $this->response($result, REST_Controller::HTTP_OK); } else @@ -128,9 +128,34 @@ class Prestudentstatus extends APIv1_Controller $this->response(); } } - + private function _validate($prestudentstatus = null) { return true; } + + /** + * Get list of Status entries of a prestudent according to the filter + * + * @return void + */ + public function getStatusByFilter() + { + $prestudent_id = $this->get("prestudent_id"); + $status_kurzbz = $this->get("status_kurzbz"); + $ausbildungssemester = $this->get("ausbildungssemester"); + $studiensemester_kurzbz = $this->get("studiensemester_kurzbz"); + + if (isset($prestudent_id)) + { + $result = $this->PrestudentstatusModel->getStatusByFilter($prestudent_id, $status_kurzbz, $ausbildungssemester, $studiensemester_kurzbz); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + } diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index ee21dec11..39ad17da5 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -11,7 +11,7 @@ class Prestudent_model extends DB_Model $this->dbTable = 'public.tbl_prestudent'; $this->pk = 'prestudent_id'; } - + /** * @return void */ @@ -24,7 +24,7 @@ class Prestudent_model extends DB_Model return $isEntitled; if (($isEntitled = $this->isEntitled('public.tbl_status', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) return $isEntitled; - + $query = 'SELECT * FROM public.tbl_prestudent p JOIN ( @@ -37,33 +37,33 @@ class Prestudent_model extends DB_Model WHERE ps.ausbildungssemester = 1'; $parametersArray = array($person_id); - + if ($studiensemester_kurzbz != '') { array_push($parametersArray, $studiensemester_kurzbz); $query .= ' AND ps.studiensemester_kurzbz = ?'; } - + if (isset($studiengang_kz)) { array_push($parametersArray, $studiengang_kz); $query .= ' AND p.studiengang_kz = ?'; } - + if ($status_kurzbz != '') { array_push($parametersArray, $status_kurzbz); $query .= ' AND ps.status_kurzbz = ?'; } - + return $this->execQuery($query, $parametersArray); } - + /** - * + * */ public function updateAufnahmegruppe($prestudentIdArray, $aufnahmegruppe) - { + { return $this->execQuery( 'UPDATE public.tbl_prestudent SET aufnahmegruppe_kurzbz = ? @@ -74,7 +74,7 @@ class Prestudent_model extends DB_Model ) ); } - + /** * Returns a list of prestudent with additional information: * - person_id @@ -104,7 +104,7 @@ class Prestudent_model extends DB_Model aufnahmegruppe_kurzbz, SUM(rtp.punkte) AS punkte' ); - + $this->addJoin('public.tbl_person p', 'person_id', 'LEFT'); $this->addJoin( '( @@ -123,39 +123,39 @@ class Prestudent_model extends DB_Model $this->addJoin('lehre.tbl_studienordnung so', 'studienordnung_id'); $this->addJoin('public.tbl_studiengang sg', 'sg.studiengang_kz = so.studiengang_kz'); $this->addJoin('public.tbl_studiengangstyp sgt', 'typ'); - + $this->addJoin('public.tbl_rt_person rtp', 'rtp.person_id = p.person_id AND rtp.studienplan_id = s.studienplan_id', 'LEFT'); - + $this->addOrder('p.person_id', 'ASC'); $this->addOrder('prestudent_id', 'ASC'); - + $parametersArray = array('p.aktiv' => true, 'ps.status_kurzbz' => 'Interessent'); - + if ($studiengang != null) { $parametersArray['public.tbl_prestudent.studiengang_kz'] = $studiengang; } - + if ($studiensemester != null) { $parametersArray['ps.studiensemester_kurzbz'] = $studiensemester; } - + if ($gruppe != null) { $parametersArray['aufnahmegruppe_kurzbz'] = $gruppe; } - + if ($reihungstest != null) { $parametersArray['rtp.rt_id'] = $reihungstest; } - + if ($stufe != null) { $parametersArray['ps.rt_stufe'] = $stufe; } - + $this->addGroupBy( array( 'p.person_id', @@ -174,7 +174,7 @@ class Prestudent_model extends DB_Model 'aufnahmegruppe_kurzbz' ) ); - + return $this->loadWhere($parametersArray); } -} \ No newline at end of file +} diff --git a/application/models/crm/Prestudentstatus_model.php b/application/models/crm/Prestudentstatus_model.php index 48619645b..beb5eb845 100644 --- a/application/models/crm/Prestudentstatus_model.php +++ b/application/models/crm/Prestudentstatus_model.php @@ -12,7 +12,7 @@ class Prestudentstatus_model extends DB_Model $this->pk = array('ausbildungssemester', 'studiensemester_kurzbz', 'status_kurzbz', 'prestudent_id'); $this->hasSequence = false; } - + /** * @return void */ @@ -25,7 +25,7 @@ class Prestudentstatus_model extends DB_Model return $isEntitled; if (($isEntitled = $this->isEntitled('public.tbl_status', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) return $isEntitled; - + $query = 'SELECT tbl_prestudentstatus.*, bezeichnung AS studienplan_bezeichnung, tbl_status.bezeichnung_mehrsprachig @@ -35,7 +35,7 @@ class Prestudentstatus_model extends DB_Model AND prestudent_id = ?'; $parametersArray = array($prestudent_id); - + if ($studiensemester_kurzbz != '') { array_push($parametersArray, $studiensemester_kurzbz); @@ -46,17 +46,17 @@ class Prestudentstatus_model extends DB_Model array_push($parametersArray, $status_kurzbz); $query .= ' AND status_kurzbz = ?'; } - + $query .= ' ORDER BY datum DESC, insertamum DESC, ext_id DESC LIMIT 1'; - + return $this->execQuery($query, $parametersArray); } - + /** - * + * */ public function updateStufe($prestudentIdArray, $stufe) - { + { return $this->execQuery( 'UPDATE public.tbl_prestudentstatus SET rt_stufe = ? @@ -68,4 +68,51 @@ class Prestudentstatus_model extends DB_Model ) ); } -} \ No newline at end of file + + /** + * Get all Prestudent status entries according to the given filter + * + * @param prestudent_id ID of the Prestudent. + * @param $status_kurzbz kurzbz of the status. + * @param $ausbildungssemester ausbildungssemester of the status. + * @param $studiensemester_kurzbz studiensemster of the status. + * + * @return result object with all the status entries + */ + public function getStatusByFilter($prestudent_id, $status_kurzbz = '', $ausbildungssemester = '', $studiensemester_kurzbz = '') + { + // Checks if the operation is permitted by the API caller + if (($isEntitled = $this->isEntitled('public.tbl_prestudentstatus', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $isEntitled; + + $query = ' + SELECT + tbl_prestudentstatus.* + FROM + public.tbl_prestudentstatus + WHERE + prestudent_id = ?'; + + $parametersArray = array($prestudent_id); + + if ($studiensemester_kurzbz != '') + { + array_push($parametersArray, $studiensemester_kurzbz); + $query .= ' AND studiensemester_kurzbz = ?'; + } + if ($status_kurzbz != '') + { + array_push($parametersArray, $status_kurzbz); + $query .= ' AND status_kurzbz = ?'; + } + if ($ausbildungssemester != '') + { + array_push($parametersArray, $ausbildungssemester); + $query .= ' AND ausbildungssemester = ?'; + } + + $query .= ' ORDER BY datum DESC, insertamum DESC, ext_id DESC'; + + return $this->execQuery($query, $parametersArray); + } +} diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index 5192cc316..8298c0d1e 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -3,7 +3,7 @@ class Person_model extends DB_Model { /** - * + * */ public function __construct() { @@ -11,16 +11,16 @@ class Person_model extends DB_Model $this->dbTable = 'public.tbl_person'; $this->pk = 'person_id'; } - + public function getPersonKontaktByZugangscode($zugangscode, $email) { $this->addJoin('public.tbl_kontakt', 'person_id'); - + return $this->loadWhere(array('zugangscode' => $zugangscode, 'kontakt' => $email)); } /** - * + * */ public function checkBewerbung($email, $studiensemester_kurzbz = null) { @@ -34,10 +34,10 @@ class Person_model extends DB_Model return $isEntitled; if (($isEntitled = $this->isEntitled('public.tbl_prestudentstatus', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) return $isEntitled; - + $checkBewerbungQuery = ''; $parametersArray = array($email, $email, $email); - + if (is_null($studiensemester_kurzbz)) { $checkBewerbungQuery = 'SELECT DISTINCT p.person_id, p.zugangscode, p.insertamum @@ -60,13 +60,13 @@ class Person_model extends DB_Model AND studiensemester_kurzbz = ? ORDER BY p.insertamum DESC LIMIT 1'; - + array_push($parametersArray, $studiensemester_kurzbz); } - + return $this->execQuery($checkBewerbungQuery, $parametersArray); } - + public function updatePerson($person) { if (isset($person['svnr']) && $person['svnr'] != '') @@ -88,7 +88,46 @@ class Person_model extends DB_Model } } } - + return $this->PersonModel->update($person['person_id'], $person); } -} \ No newline at end of file + + /** + * @return void + */ + public function getPersonFromStatus($status_kurzbz, $von, $bis) + { + // Checks if the operation is permitted by the API caller + if (($isEntitled = $this->isEntitled('public.tbl_prestudent', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $isEntitled; + if (($isEntitled = $this->isEntitled('public.tbl_prestudentstatus', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $isEntitled; + + $this->addJoin('public.tbl_prestudent', 'person_id'); + + $result = $this->loadTree( + 'public.tbl_person', + array( + 'public.tbl_prestudent' + ), + 'EXISTS ( + SELECT + 1 + FROM + public.tbl_prestudentstatus + JOIN public.tbl_prestudent USING(prestudent_id) + WHERE + person_id=tbl_person.person_id + AND status_kurzbz='.$this->escape($status_kurzbz).' + AND datum >= '.$this->escape($von).' + AND datum <= '.$this->escape($bis).' + )', + array( + 'prestudenten' + ) + ); + + return $result; + } + +}