function admin_edit id null data this- Ressourcetype- findByIdAndClien

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function admin_edit($id = null) {
$data = $this->Ressourcetype->findByIdAndClientId($id, $this->Session->read('User.id'));
$fields2save = array('shortdescr', 'description', 'active', 'client_id', 'ressourcecategory');
if (empty($this->data)) {
$this->data = $data;
} else {//save data
$this->data['Ressourcetype']['client_id'] = $this->Session->read('User.id');
if($data){//existing entry
$this->data['Ressourcetype']['id'] = $data['Ressourcetype']['id'];
$this->data['Ressource'] = $data['Ressource'];
} else {//new entry
if(!$this->__allow_add_ressourcetype()) {
$this->Session->setFlash('Maximale Anzahl der Objektkategorien');
$this->redirect('/admin/ressources/overview');
}
$this->data['Ressourcetype']['id'] = '';
$this->data['Ressourcetype']['ressourcecategory'] = 'free';
}
if ($this->Ressourcetype->save($this->data, true, $fields2save)) {
$this->Session->setFlash('Gespeichert');
$this->redirect('/admin/ressourcetypes/index');
} else {
$this->Session->setFlash('Fehler beim Speichern');
}
}
}