コード例 #1
0
 public function create_questionnaire()
 {
     build_validator_from_form($this->get_edit_form());
     $questionnaire_data = $this->input->post('questionnaire');
     if (isset($_FILES['file']['name']) && !empty($_FILES['file']['name'])) {
         $this->upload_file($questionnaire_data['upload_id']);
         $this->new_questionnaire();
         return;
     }
     $this->db->trans_begin();
     if ($this->form_validation->run()) {
         $questionnaire = new Questionnaire();
         $questionnaire->from_array($questionnaire_data, array('title', 'configuration'));
         if (isset($questionnaire_data['published']) && (int) $questionnaire_data['published'] == 1) {
             $questionnaire->published = true;
         } else {
             $questionnaire->published = false;
         }
         if (isset($questionnaire_data['attempts']) && $questionnaire_data['attempts'] !== '') {
             $questionnaire->attempts = (int) $questionnaire_data['attempts'];
         } else {
             $questionnaire->attempts = null;
         }
         if ($questionnaire->save() && $this->rename_upload_folder($questionnaire_data['upload_id'], $questionnaire->id)) {
             $this->db->trans_commit();
             add_success_flash_message('Dotazník <strong>' . $questionnaire->title . '</strong> s ID <strong>' . $questionnaire->id . '</strong> bol úspešne vytvorený.');
             redirect(site_url('questionnaires'));
         } else {
             $this->db->trans_rollback();
             $this->delete_upload_folder($questionnaire_data['upload_id']);
             add_error_flash_message('Dotazník <strong>' . $questionnaire->title . '</strong> sa nepodarilo vytvoriť.');
             redirect(site_url('questionnaires/new_questionnaire'));
         }
     } else {
         $this->new_questionnaire();
     }
 }