Example #1
0
/**
 * Given an ID of an instance of this module, this function will
 * permanently delete the instance and any data that depends on it.
 */
function facetoface_delete_instance($id) {
    global $CFG, $DB;
  require_once $CFG->dirroot.'/local/evaluations/lib.php';
  require_once $CFG->dirroot.'/group/lib.php';
    if (!$facetoface = $DB->get_record('facetoface', array('id' => $id))) {
        return false;
    }

    $result = true;

    $transaction = $DB->start_delegated_transaction();

    $DB->delete_records_select(
        'facetoface_signups_status',
        "signupid IN
        (
            SELECT
            id
            FROM
    {facetoface_signups}
    WHERE
    sessionid IN
    (
        SELECT
        id
        FROM
    {facetoface_sessions}
    WHERE
    facetoface = ? ))
    ", array($facetoface->id));
    /*===========When batch delete that time we delete records from 'course_modules' and 'context' data tables started by rajut*/
    
    $get_course_modules_id=$DB->get_record('course_modules',array('instance'=>$facetoface->id));
    //print_object($get_course_modules_id);
     $get_course_modules_id_context=$DB->get_record('context',array('contextlevel'=>70,'instanceid'=>$get_course_modules_id->id));
      //print_object($get_course_modules_id_context);
    $DB->delete_records('context', array('id' => $get_course_modules_id_context->id));
    $DB->delete_records('course_modules', array('id' => $get_course_modules_id->id->id));
    //exit;
/*===========When batch delete that time we delete records from 'course_modules' and 'context' data tables Ended by rajut*/
    $DB->delete_records_select('facetoface_signups', "sessionid IN (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id));

    $DB->delete_records_select('facetoface_sessions_dates', "sessionid in (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id));

    // Notifications.
    $DB->delete_records('facetoface_notification', array('facetofaceid' => $facetoface->id));
    $DB->delete_records_select('facetoface_notification_sent',
            "sessionid IN (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id));
    $DB->delete_records_select('facetoface_notification_hist',
            "sessionid IN (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id));

    $DB->delete_records('facetoface_sessions', array('facetoface' => $facetoface->id));

   

    $DB->delete_records('event', array('modulename' => 'facetoface', 'instance' => $facetoface->id));

    facetoface_grade_item_delete($facetoface);

    $transaction->allow_commit();
    /*=====================Started by rajut when delete batch?delete local_batch_users and local_batch_courses===========*/
    $local_batch_courses=$DB->record_exists('local_batch_courses', array('batchid' => $facetoface->id));
    if($local_batch_courses==1){
        $assigned_course=$DB->get_record('local_batch_courses',array('batchid' => $facetoface->id));

       $assigned_users=$DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid= $facetoface->id");
       if(!empty($assigned_users)){
            foreach($assigned_users as $assigned_user){ 
                $manual = enrol_get_plugin('manual');
                $studentrole = $DB->get_record('role', array('shortname'=>'student'));
                $instance = $DB->get_record('enrol', array('courseid'=>$assigned_course->courseid, 'enrol'=>'manual'), '*', MUST_EXIST);
                if($instance){
                   $timeend='';
                   if(!$DB->record_exists_sql("SELECT * FROM {course_completions} WHERE course=$assigned_course->courseid AND userid=$assigned_user->userid and timecompleted!=''")){
                        $local_batch_courses=$DB->get_records_sql("SELECT lbu.* FROM {local_batch_users} lbu
                                                                  JOIN {facetoface} fa ON fa.id=lbu.f2fid and fa.active in (0,1,8,3)
                                                                  where lbu.courseid=$assigned_course->courseid and lbu.userid=$assigned_user->userid
                                                                and fa.id!=$facetoface->id");
					   if(count($local_batch_courses)==0){
                           $manual->unenrol_user($instance,$assigned_user->userid, $studentrole->id,time(),$timeend);
                        }
                        //$manual->unenrol_user($instance,$assigned_user->userid, $studentrole->id,time(),$timeend);
                   }
                }
            $deleterecord_users=$DB->delete_records('local_batch_users',array('id'=>$assigned_user->id,'userid'=>$assigned_user->userid));
            }
       }
       if($assigned_course->groupid!=0)
       groups_delete_group($assigned_course->groupid);
     $deleterecord_course=$DB->delete_records('local_batch_courses',array('id'=>$assigned_course->id,'courseid'=>$assigned_course->courseid));
    
    }else{
        
        $assigned_users=$DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid= $facetoface->id");
       if(!empty($assigned_users)){
            foreach($assigned_users as $assigned_user){    
             $deleterecord_users=$DB->delete_records('local_batch_users',array('id'=>$assigned_user->id,'userid'=>$assigned_user->userid));
            }
       }
        
    }
    $local_evaluation_feedback=$DB->record_exists('local_evaluation', array('classid' => $facetoface->id));
   
     if($local_evaluation_feedback==1){
           $feedbacks=$DB->get_records('local_evaluation',array('classid'=>$facetoface->id));
           
           foreach($feedbacks as $feedback){
            
             $deletefeedback=delete_complete_evaluation($feedback->id);
              //print_object($deletefeedback);exit;
           }
     }
      $DB->delete_records('facetoface', array('id' => $facetoface->id));
    /*=====================Ended by rajut when delete batch?delete local_batch_users and local_batch_courses===========*/
    
    
    return $result;
}
Example #2
0
/**
 * Given an ID of an instance of this module, this function will
 * permanently delete the instance and any data that depends on it.
 */
function facetoface_delete_instance($id) {
    global $CFG, $DB;

    if (!$facetoface = $DB->get_record('facetoface', array('id' => $id))) {
        return false;
    }

    $result = true;

    $transaction = $DB->start_delegated_transaction();

    $DB->delete_records_select(
        'facetoface_signups_status',
        "signupid IN
        (
            SELECT
            id
            FROM
    {facetoface_signups}
    WHERE
    sessionid IN
    (
        SELECT
        id
        FROM
    {facetoface_sessions}
    WHERE
    facetoface = ? ))
    ", array($facetoface->id));

    $DB->delete_records_select('facetoface_signups', "sessionid IN (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id));

    $DB->delete_records_select('facetoface_sessions_dates', "sessionid in (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id));

    // Notifications.
    $DB->delete_records('facetoface_notification', array('facetofaceid' => $facetoface->id));
    $DB->delete_records_select('facetoface_notification_sent',
            "sessionid IN (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id));
    $DB->delete_records_select('facetoface_notification_hist',
            "sessionid IN (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id));

    $DB->delete_records('facetoface_sessions', array('facetoface' => $facetoface->id));

    $DB->delete_records('facetoface', array('id' => $facetoface->id));

    $DB->delete_records('event', array('modulename' => 'facetoface', 'instance' => $facetoface->id));

    facetoface_grade_item_delete($facetoface);

    $transaction->allow_commit();

    return $result;
}
Example #3
0
    function test_facetoface_grade_item_delete() {
        // Test variables.
        $facetoface1 = $this->facetoface['f2f0'];
        $f2f = $this->array_to_object($facetoface1);

        // Test for valid case.
        $this->assertTrue((bool)facetoface_grade_item_delete($f2f), $this->msgtrue);

        $this->resetAfterTest(true);
    }