Guest User

Untitled

a guest
Jan 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. function add() {
  2. if (!empty($this->data)) {
  3. $this->Person->create();
  4. $this->data['Concept'] = array_map(null,$this->data['Concept']['Concept'],$this->data['Concept']['period_id']);
  5. $this->data['Concept'] = $this->_array_change_key_name(array('concept_id','from_period_id'),$this->data['Concept']);
  6.  
  7. if ($this->Person->save($this->data)) {
  8. $this->Session->setFlash(__('The person has been saved', true));
  9. $this->redirect(array('action' => 'index'));
  10. } else {
  11. $this->Session->setFlash(__('The person could not be saved. Please, try again.', true));
  12. }
  13. }
  14. $roles = $this->Person->Role->find('list');
  15. $concepts = $this->Person->Concept->find('list');
  16. $cities = $this->Person->City->find('list');
  17. $this->set(compact('roles', 'concepts','cities'));
  18. }
  19.  
  20. function edit($id = null) {
  21. if (!$id && empty($this->data)) {
  22. $this->Session->setFlash(__('Invalid person', true));
  23. $this->redirect(array('action' => 'index'));
  24. }
  25. if (!empty($this->data)) { //pr($this->data);
  26. $this->data['Concept'] = array_map(null,$this->data['Concept']['Concept'],$this->data['Concept']['period_id']);
  27. $this->data['Concept'] = $this->_array_change_key_name(array('concept_id','from_period_id'),$this->data['Concept']);
  28.  
  29. if ($this->Person->save($this->data)) {
  30. $this->Session->setFlash(__('The person has been saved', true));
  31. $this->redirect(array('action' => 'index'));
  32. } else {
  33. $this->Session->setFlash(__('The person could not be saved. Please, try again.', true));
  34. }
  35. }
  36. if (empty($this->data)) {
  37. $this->data = $this->Person->read(null, $id);
  38. }
  39.  
  40. $i = 0;
  41. $this->Period->recursive = 0;
  42. foreach($this->data['Concept'] as $personPeriod) {
  43. $arr[$i] = $this->data['Concept'][$i]['ConceptsPerson']['from_period_id']; //Obtengo un array con los todos los periods_id de las actividades
  44. $aux[$i] = $this->Period->find('first',array(
  45. 'conditions'=>array('Period.id' => $this->data['Concept'][$i]['ConceptsPerson']['from_period_id'] ),
  46. 'fields' => array('Period.from_date')
  47. ));
  48. $this->data['Concept'][$i]['ConceptsPerson']['from_date'] = $aux[$i]['Period']['from_date'];
  49. $i++;
  50. }
  51.  
  52. $periods = json_encode($arr);
  53. $roles = $this->Person->Role->find('list');
  54. $concepts = array_values($this->Person->Concept->query('SELECT Concept.id, Concept.description FROM concepts AS Concept
  55. WHERE Concept.id NOT IN
  56. (SELECT conceptpeople.concept_id
  57. FROM concepts_people as conceptpeople
  58. WHERE (conceptpeople.to_period_id = "0" AND conceptpeople.person_id = "'.$this->data['Person']['id'].'") OR
  59. conceptpeople.person_id = "'.$this->data['Person']['id'].'")'));
  60.  
  61. $concepts = Set::combine($concepts, '{n}.Concept.id', '{n}.Concept.description');
  62. $cities = $this->Person->City->find('list');
  63.  
  64. $this->set(compact('roles','concepts','cities','periods'));
  65. }
Add Comment
Please, Sign In to add comment