public function edit() { //$this->autoRender = false; // if ($this->request->is('get')) { // $query = $this->request->query; // if (key_exists('edit', $query)) { // $this->set(['questionId' => $query['questionId'],'questionText' => $query['questionText'],'options' => $query['options'], 'status' => $query['status']]); // } else { // $questionTable = new Table\QuestionTable(); // $questionTable->deleteQuestion($query['questionId']); // $this->redirect(['controller' => 'QuestionForm', 'action' => 'index']); // } if ($this->request->is('post')) { $data = $this->request->data; $questionTable = new Table\QuestionTable(); $optionsTable = new Table\OptionsTable(); if (key_exists('edit', $data)) { $questionText = base64_encode($data['questionText']); //print_r($data); $this->set(['questionId' => $data['questionId'], 'questionText' => $questionText, 'options' => $data['options'], 'status' => $data['status']]); // print_r($data); //return; } elseif (key_exists('delete', $data)) { $questionTable->deleteQuestion($data['questionId']); $this->redirect(['controller' => 'QuestionForm', 'action' => 'index']); } elseif (key_exists('save', $data)) { //$this->autoRender = false; $updatedOption = explode(',', $data['options']); $status = parent::getActive($data['status']); $update = $questionTable->update($data['questionId'], $data['questiontext'], $status); if ($update) { $questionDto = new DownloadDto\QuestionDto($data['questionId'], $data['questiontext']); $syncController = new SyncController(); $syncController->questionEntry(json_encode($questionDto), UPDATE); $optionsTable->update($data['questionId'], $this->filterOption($updatedOption)); } $this->redirect(['controller' => 'QuestionForm', 'action' => 'index']); } } }
public function add() { \Cake\Log\Log::debug("you are in destination add method"); if ($this->request->is('post')) { $data = $this->request->data; $destinationTable = new Table\DestinationTable(); $status = parent::getActive($data['status']); if ($destinationTable->addNewDestiantion($data['tilte'], $data['latitude'], $data['longitude'], $status)) { echo '<script>alert("Destination added !")</script>'; $this->redirect(['controller' => 'DestinationForm', 'action' => 'index']); } else { echo '<script>alert("Unknown Error occured !")</script>'; } } }