Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add() {
- if (!empty($this->data)) {
- $this->Person->create();
- $this->data['Concept'] = array_map(null,$this->data['Concept']['Concept'],$this->data['Concept']['period_id']);
- $this->data['Concept'] = $this->_array_change_key_name(array('concept_id','from_period_id'),$this->data['Concept']);
- if ($this->Person->save($this->data)) {
- $this->Session->setFlash(__('The person has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The person could not be saved. Please, try again.', true));
- }
- }
- $roles = $this->Person->Role->find('list');
- $concepts = $this->Person->Concept->find('list');
- $cities = $this->Person->City->find('list');
- $this->set(compact('roles', 'concepts','cities'));
- }
- function edit($id = null) {
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid person', true));
- $this->redirect(array('action' => 'index'));
- }
- if (!empty($this->data)) { //pr($this->data);
- $this->data['Concept'] = array_map(null,$this->data['Concept']['Concept'],$this->data['Concept']['period_id']);
- $this->data['Concept'] = $this->_array_change_key_name(array('concept_id','from_period_id'),$this->data['Concept']);
- if ($this->Person->save($this->data)) {
- $this->Session->setFlash(__('The person has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The person could not be saved. Please, try again.', true));
- }
- }
- if (empty($this->data)) {
- $this->data = $this->Person->read(null, $id);
- }
- $i = 0;
- $this->Period->recursive = 0;
- foreach($this->data['Concept'] as $personPeriod) {
- $arr[$i] = $this->data['Concept'][$i]['ConceptsPerson']['from_period_id']; //Obtengo un array con los todos los periods_id de las actividades
- $aux[$i] = $this->Period->find('first',array(
- 'conditions'=>array('Period.id' => $this->data['Concept'][$i]['ConceptsPerson']['from_period_id'] ),
- 'fields' => array('Period.from_date')
- ));
- $this->data['Concept'][$i]['ConceptsPerson']['from_date'] = $aux[$i]['Period']['from_date'];
- $i++;
- }
- $periods = json_encode($arr);
- $roles = $this->Person->Role->find('list');
- $concepts = array_values($this->Person->Concept->query('SELECT Concept.id, Concept.description FROM concepts AS Concept
- WHERE Concept.id NOT IN
- (SELECT conceptpeople.concept_id
- FROM concepts_people as conceptpeople
- WHERE (conceptpeople.to_period_id = "0" AND conceptpeople.person_id = "'.$this->data['Person']['id'].'") OR
- conceptpeople.person_id = "'.$this->data['Person']['id'].'")'));
- $concepts = Set::combine($concepts, '{n}.Concept.id', '{n}.Concept.description');
- $cities = $this->Person->City->find('list');
- $this->set(compact('roles','concepts','cities','periods'));
- }
Add Comment
Please, Sign In to add comment