function updateToDatabase()
 {
     // Convert timestamps to sql format
     $event_sql = CommonTools::timeToSql($this->event_date);
     $opens = CommonTools::timeToSql($this->opens);
     $closes = CommonTools::timeToSql($this->closes);
     $send_confirmation_sql = CommonTools::booleanToSql($this->send_confirmation);
     // Save the updated info to database
     $sql = "UPDATE ilmo_masiinat SET " . "title='{$this->title}' , " . "description='{$this->description}', opens='{$opens}' , eventdate='{$event_sql}', " . "closes='{$closes}', send_confirmation='{$send_confirmation_sql}', confirmation_message='{$this->confirmation_message}' WHERE id='{$this->id}'";
     $this->database->doQuery($sql);
     // Updates the questions
     $oldQuestions = $this->selectQuestionsFromDatabaseAndReturnAsTable();
     // Remove questions that have been removed from the gadget
     $questionIdsToRemove = $this->getQuestionIdsToRemove($oldQuestions);
     if (count($questionIdsToRemove) > 0) {
         $questionsToRemoveSqlArray = CommonTools::idArrayToSql($questionIdsToRemove);
         $sql = "DELETE FROM ilmo_answers WHERE " . Database::fieldIsInArray($questionIdsToRemove, 'question_id');
         $this->database->doQuery($sql, array(), array());
         $sql = "DELETE FROM ilmo_questions WHERE " . Database::fieldIsInArray($questionIdsToRemove, 'id');
         $this->database->doQuery($sql, array(), array());
     }
     // FIXME The questions database update should be moved to Question class
     // Update questions that have been changed
     $questionsToUpdateArray = $this->getQuestionIdsToUpdate($oldQuestions);
     foreach ($questionsToUpdateArray as $questionId) {
         $question = $this->questions[$questionId];
         $questionString = $question->getQuestion();
         $type = $question->getType();
         $options = CommonTools::arrayToSql($question->getOptions());
         $public = CommonTools::booleanToSql($question->getPublic());
         $required = CommonTools::booleanToSql($question->getRequired());
         $sql = "UPDATE ilmo_questions SET " . "question='{$questionString}', type='{$type}', options='{$options}', public={$public}, required={$required} WHERE id={$questionId}";
         $this->database->doQuery($sql);
     }
     // Adds new questions
     $questionsToAddArray = $this->getNewQuestionToAdd();
     foreach ($questionsToAddArray as $questionToAdd) {
         $questionToAdd->insertToDatabase();
     }
 }