Ejemplo n.º 1
0
 function delete_course_item($post_id)
 {
     global $wpdb;
     // delete lesson from course's section
     $query = $wpdb->prepare("\n\t\t\t\tDELETE FROM {$wpdb->prefix}learnpress_section_items\n\t\t\t\tWHERE item_id = %d\n\t\t\t", $post_id);
     $wpdb->query($query);
     learn_press_reset_auto_increment('learnpress_section_items');
 }
 /**
  * Remove all answers to prepare for inserting new
  */
 public function empty_answers()
 {
     global $wpdb;
     $query = $wpdb->prepare("\n\t\t\tDELETE FROM {$wpdb->learnpress_question_answers}\n\t\t\tWHERE question_id = %d\n\t\t", $this->id);
     do_action('learn_press_before_delete_question_answers', $this->id);
     $wpdb->query($query);
     do_action('learn_press_delete_question_answers', $this->id);
     learn_press_reset_auto_increment('learnpress_question_answers');
 }
Ejemplo n.º 3
0
 /**
  * Delete all answers assign to question being deleted
  *
  * @param $post_id
  */
 function delete_question_answers($post_id)
 {
     global $wpdb;
     $query = $wpdb->prepare("\n\t\t\t\tDELETE FROM {$wpdb->prefix}learnpress_question_answers\n\t\t\t\tWHERE question_id = %d\n\t\t\t", $post_id);
     $wpdb->query($query);
     learn_press_reset_auto_increment('learnpress_question_answers');
     // also, delete question from quiz
     $wpdb->query($wpdb->prepare("\n\t\t\t\t\tDELETE FROM {$wpdb->prefix}learnpress_quiz_questions\n\t\t\t\t\tWHERE question_id = %d\n\t\t\t\t", $post_id));
     learn_press_reset_auto_increment('learnpress_quiz_questions');
 }
Ejemplo n.º 4
0
 /**
  * Delete all questions assign to quiz being deleted
  *
  * @param $post_id
  */
 function delete_quiz_questions($post_id)
 {
     LP_Debug::instance()->add('Before delete post ' . $post_id);
     global $wpdb;
     $query = $wpdb->prepare("\n\t\t\t\tDELETE FROM {$wpdb->prefix}learnpress_quiz_questions\n\t\t\t\tWHERE quiz_id = %d\n\t\t\t", $post_id);
     $wpdb->query($query);
     learn_press_reset_auto_increment('learnpress_quiz_questions');
     // delete quiz from course's section
     $query = $wpdb->prepare("\n\t\t\t\tDELETE FROM {$wpdb->prefix}learnpress_section_items\n\t\t\t\tWHERE item_id = %d\n\t\t\t", $post_id);
     $wpdb->query($query);
     learn_press_reset_auto_increment('learnpress_section_items');
 }
Ejemplo n.º 5
0
 /**
  * Delete all questions assign to quiz being deleted
  *
  * @param $post_id
  */
 function delete_course_sections($post_id)
 {
     global $wpdb;
     // delete all items in section first
     $section_ids = $wpdb->get_col($wpdb->prepare("SELECT section_id FROM {$wpdb->prefix}learnpress_sections WHERE section_course_id = %d", $post_id));
     if ($section_ids) {
         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}learnpress_section_items WHERE section_id IN(" . join(',', $section_ids) . ")"));
         learn_press_reset_auto_increment('learnpress_section_items');
     }
     // delete all sections
     $query = $wpdb->prepare("\n\t\t\t\tDELETE FROM {$wpdb->prefix}learnpress_sections\n\t\t\t\tWHERE section_course_id = %d\n\t\t\t", $post_id);
     $wpdb->query($query);
     learn_press_reset_auto_increment('learnpress_sections');
 }
 static function save($new, $old, $post_id, $field)
 {
     global $wpdb, $post;
     //LP_Debug::instance()->add( __CLASS__ . '::' . __FUNCTION__ . '(' . join( ',', func_get_args() ) . ')' );
     $questions = learn_press_get_request('learn_press_question');
     /*if( $all_questions = LP_Quiz::get_quiz( $post->ID )->get_questions() ){
     			$all_questions = array_keys( $all_questions );
     		}*/
     // Get all ids of questions stored
     $remove_ids = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\tSELECT question_id\n\t\t\t\t\tFROM {$wpdb->prefix}learnpress_quiz_questions\n\t\t\t\t\tWHERE quiz_id = %d\n\t\t\t\t", $post->ID));
     // delete all questions stored
     $query = $wpdb->prepare("\n\t\t\t\tDELETE\n\t\t\t\tFROM {$wpdb->prefix}learnpress_quiz_questions\n\t\t\t\tWHERE quiz_id = %d\n\t\t\t", $post->ID, 1);
     $wpdb->query($query);
     learn_press_reset_auto_increment('learnpress_quiz_questions');
     do_action('learn_press_remove_quiz_questions', $remove_ids, $post->ID);
     if (!$questions) {
         return;
     }
     $titles = learn_press_get_request('learn-press-question-name');
     $values = array();
     $order = 1;
     // update the title of questions and save all data
     foreach ($questions as $id => $data) {
         $question = LP_Question_Factory::get_question($id);
         if (!empty($titles[$id])) {
             $wpdb->update($wpdb->posts, array('post_title' => $titles[$id]), array('ID' => $id), array('%s'));
         }
         $question->save($data);
         $insert_data = apply_filters('learn_press_quiz_question_insert_data', array('question_id' => $id, 'quiz_id' => $post->ID, 'params' => ''));
         $values[] = $wpdb->prepare("(%d, %d, %s, %d)", $insert_data['quiz_id'], $insert_data['question_id'], $insert_data['param'], $order++);
     }
     $query = "\n\t\t\t\tINSERT INTO {$wpdb->learnpress_quiz_questions}(`quiz_id`, `question_id`, `params`, `question_order`)\n\t\t\t\tVALUES " . join(',', $values) . "\n\t\t\t";
     $wpdb->query($query);
     do_action('learn_press_insert_quiz_questions', $questions, $post->ID);
 }
 static function remove_course_section()
 {
     $id = learn_press_get_request('id');
     if ($id) {
         global $wpdb;
         $query = $wpdb->prepare("\n\t\t\t\t\tDELETE FROM {$wpdb->prefix}learnpress_section_items\n\t\t\t\t\tWHERE section_id = %d\n\t\t\t\t", $id);
         $wpdb->query($query);
         learn_press_reset_auto_increment('learnpress_section_items');
         $query = $wpdb->prepare("\n\t\t\t\t\tDELETE FROM {$wpdb->prefix}learnpress_sections\n\t\t\t\t\tWHERE section_id = %d\n\t\t\t\t", $id);
         $wpdb->query($query);
         learn_press_reset_auto_increment('learnpress_sections');
     }
     die;
 }