diff --git a/application/controllers/system/infocenter/InfoCenter.php b/application/controllers/system/infocenter/InfoCenter.php index f1cd674b7..92932b8ea 100644 --- a/application/controllers/system/infocenter/InfoCenter.php +++ b/application/controllers/system/infocenter/InfoCenter.php @@ -64,6 +64,7 @@ class InfoCenter extends VileSci_Controller $this->load->model('person/person_model', 'PersonModel'); $this->load->model('system/message_model', 'MessageModel'); $this->load->model('system/filters_model', 'FiltersModel'); + $this->load->model('system/personLock_model', 'PersonLockModel'); // Loads libraries $this->load->library('DmsLib'); @@ -110,10 +111,20 @@ class InfoCenter extends VileSci_Controller if (!is_numeric($person_id)) show_error('person id is not numeric!'); - $persondata = $this->_loadPersonData($person_id); - if (!isset($persondata)) + $personexists = $this->PersonModel->load($person_id); + if(isError($personexists)) + show_error($personexists->retval); + + if (empty($personexists->retval[0])) show_error('person does not exist!'); + //mark person as locked for editing + $result = $this->PersonLockModel->lockPerson($person_id, $this->uid, self::APP); + + if(isError($result)) + show_error($result->retval); + + $persondata = $this->_loadPersonData($person_id); $prestudentdata = $this->_loadPrestudentData($person_id); $this->load->view( @@ -129,6 +140,20 @@ class InfoCenter extends VileSci_Controller ); } + /** + * unlocks page from edit by a person, redirects to overview filter page + * @param $person_id + */ + public function unlockPerson($person_id) + { + $result = $this->PersonLockModel->unlockPerson($person_id, self::APP); + + if(isError($result)) + show_error($result->retval); + + redirect(self::URL_PREFIX); + } + /** * Saves if a document has been formal geprueft. saves current timestamp if checked as geprueft, or null if not. */ @@ -235,7 +260,7 @@ class InfoCenter extends VileSci_Controller } //check if still Interessent and not freigegeben yet - if($lastStatus->retval[0]->status_kurzbz === 'Interessent' && !isset($lastStatus->retval[0]->bestaetigtam)) + if ($lastStatus->retval[0]->status_kurzbz === 'Interessent' && !isset($lastStatus->retval[0]->bestaetigtam)) { $result = $this->PrestudentstatusModel->insert( array( @@ -517,6 +542,13 @@ class InfoCenter extends VileSci_Controller */ private function _loadPersonData($person_id) { + $lockedby = $this->PersonLockModel->checkIfLocked($person_id); + + if (isError($lockedby)) + { + show_error($lockedby->retval); + } + $stammdaten = $this->PersonModel->getPersonStammdaten($person_id, true); if (isError($stammdaten)) @@ -567,6 +599,7 @@ class InfoCenter extends VileSci_Controller $messagelink = base_url('/index.ci.php/system/Messages/write/'.$user_person->retval[0]->person_id); $data = array ( + 'lockedby' => isset($lockedby->retval[0]->uid) ? $lockedby->retval[0]->uid : null, 'stammdaten' => $stammdaten->retval, 'dokumente' => $dokumente->retval, 'dokumente_nachgereicht' => $dokumente_nachgereicht->retval, @@ -606,7 +639,7 @@ class InfoCenter extends VileSci_Controller $zgvpruefung = $prestudent->retval[0]; - if(isset($zgvpruefung->prestudentstatus)) + if (isset($zgvpruefung->prestudentstatus)) { $position = strpos($zgvpruefung->prestudentstatus->anmerkung, 'Alt:'); diff --git a/application/models/system/PersonLock_model.php b/application/models/system/PersonLock_model.php new file mode 100644 index 000000000..1a3edd917 --- /dev/null +++ b/application/models/system/PersonLock_model.php @@ -0,0 +1,90 @@ +dbTable = 'system.tbl_person_lock'; + $this->pk = 'lock_id'; + } + + /** + * checks if a specific person is locked. By default, looks for any entries in locktable for the person. + * Alternatively, looks only for locks in a certain app + * @param $person_id + * @param null $app + * @return array all locks for a person if locked, null otherwise + */ + public function checkIfLocked($person_id, $app = null) + { + $lockdata = $app === null ? array('person_id' => $person_id) : array('person_id' => $person_id, 'app' => $app); + + $result = $this->loadWhere($lockdata); + + if($result->error) + return error($result->retval); + else + { + if(count($result->retval) > 0) + return success($result->retval); + else + return success(null); + } + } + + /** + * locks a person. returns null if person was not locked (e.g. when already locked) + * @param $person_id + * @param $uid user who locks the person + * @param $app optional, application in which person is locked + * @return array inserted lock id if person was locked, null otherwise + */ + public function lockPerson($person_id, $uid, $app = null) + { + $locked = $this->checkIfLocked($person_id, $app); + + if($locked->error) + return error($locked->retval); + + //insert only if not already locked + if($locked->retval === null) + return $this->insert(array('person_id' => $person_id, 'uid' => $uid, 'app' => $app)); + else + return success(null); + } + + /** + * remove a lock for a person. By default, removes any entries in locktable for the person + * Alternatively, removes only locks in a certain app + * @param $person_id + * @param null $app + * @return array deleted lock ids if person was locked, null otherwise + */ + public function unlockPerson($person_id, $app = null) + { + $deleted = array(); + $locks = $this->checkIfLocked($person_id, $app); + + if ($locks->retval === null) + return success(null); + + foreach ($locks->retval as $lock) + { + $result = $this->delete($lock->lock_id); + if($result->error) + return error($result->retval); + + $deleted[] = $lock; + } + + return success($deleted); + } +} diff --git a/application/views/system/infocenter/infocenter.php b/application/views/system/infocenter/infocenter.php index 8244e8c67..a61e8b392 100644 --- a/application/views/system/infocenter/infocenter.php +++ b/application/views/system/infocenter/infocenter.php @@ -9,7 +9,7 @@ 'sbadmintemplate' => true, 'tablesorter' => true, 'customCSSs' => 'skin/tablesort_bootstrap.css', - 'customJSs' => array('include/js/infocenterPersonDataset.js', 'include/js/bootstrapper.js') + 'customJSs' => array('include/js/bootstrapper.js', 'include/js/infocenter/infocenterPersonDataset.js') ) ); ?> @@ -40,9 +40,6 @@ -