delete is improved
This commit is contained in:
parent
826d3016d2
commit
294747446f
|
@ -62,15 +62,32 @@ class Form_model extends CI_Model {
|
||||||
public function delete_form($form_id) {
|
public function delete_form($form_id) {
|
||||||
// Begin transaction
|
// Begin transaction
|
||||||
$this->db->trans_start();
|
$this->db->trans_start();
|
||||||
|
|
||||||
// Delete options related to the form using a join
|
// Delete options related to the form using a join
|
||||||
$this->db->query("DELETE o FROM options o
|
$this->db->query("DELETE o FROM options o
|
||||||
JOIN questions q ON o.question_id = q.question_id
|
JOIN questions q ON o.question_id = q.question_id
|
||||||
WHERE q.form_id = ?", array($form_id));
|
WHERE q.form_id = ?", array($form_id));
|
||||||
|
|
||||||
// Delete questions related to the form
|
// Delete questions related to the form
|
||||||
|
// First, get question_ids to delete response_answers
|
||||||
|
$question_ids = $this->db->select('question_id')
|
||||||
|
->from('questions')
|
||||||
|
->where('form_id', $form_id)
|
||||||
|
->get()
|
||||||
|
->result();
|
||||||
|
|
||||||
|
foreach ($question_ids as $question) {
|
||||||
|
$this->db->where('question_id', $question->question_id);
|
||||||
|
$this->db->delete('response_answers');
|
||||||
|
}
|
||||||
|
|
||||||
$this->db->where('form_id', $form_id);
|
$this->db->where('form_id', $form_id);
|
||||||
$this->db->delete('questions');
|
$this->db->delete('questions');
|
||||||
|
|
||||||
|
// Delete responses related to the form
|
||||||
|
$this->db->where('form_id', $form_id);
|
||||||
|
$this->db->delete('responses');
|
||||||
|
|
||||||
// Delete the form itself
|
// Delete the form itself
|
||||||
$this->db->where('form_id', $form_id);
|
$this->db->where('form_id', $form_id);
|
||||||
$this->db->delete('forms');
|
$this->db->delete('forms');
|
||||||
|
@ -82,6 +99,8 @@ class Form_model extends CI_Model {
|
||||||
return $this->db->trans_status();
|
return $this->db->trans_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function update_form($form_id, $data) {
|
public function update_form($form_id, $data) {
|
||||||
$this->db->where('form_id', $form_id);
|
$this->db->where('form_id', $form_id);
|
||||||
$this->db->update('forms', $data);
|
$this->db->update('forms', $data);
|
||||||
|
|
Loading…
Reference in New Issue