International Developer Logo Last Updated 27.08.08 at 11.48
On Sale
This months front cover, click to see the table of contents.
Subscribe
 
TUTORIALS

Online Course Management with Moodle


  05.10.06

The update function is similar, passing the module’s ID to the insert_record() function for each image, The difference here is that we delete the existing image records in advance. The end result is as shown.

 

function draganddrop_update_instance($draganddrop) {

    $draganddrop->timemodified = time();

    $draganddrop->id = $draganddrop->instance;

    $image1->ddid = $draganddrop->id;

    $image1->url = $draganddrop->image1;

    $image2->ddid = $draganddrop->id;

    $image2->url = $draganddrop->image2;

    $image3->ddid = $draganddrop->id;

    $image3->url = $draganddrop->image3;

    //delete all images

    delete_records(“draganddrop_images”, “ddid”, “$draganddrop->id”);

    insert_record(“draganddrop_images”, $image1);

    insert_record(“draganddrop_images”, $image2);

    insert_record(“draganddrop_images”, $image3);

    return update_record(“draganddrop”, $draganddrop);

}

 

The delete function removes all the images prior to deleting the master record. This is done to ensure that no foreign key restraints prevent the deletion of child records from the images table. The delete_records() function automatically generates and executes the SQL statements based on the parameters passed.

 

function draganddrop_delete_instance($id) {

    if (! $draganddrop = get_record(“draganddrop”, “id”, “$id”)) {

        return false;

    }

    $result = true;

    if (! delete_records(“draganddrop_images”, “ddid”, “$draganddrop->id”)) {

        $result = false;

    }

    if (! delete_records(“draganddrop”, “id”, “$draganddrop->id”)) {

        $result = false;

    }

    return $result;

}




   Previous Page  1 2 3 4 5 6 7 8 9 10 ... Next Page   

HAVE YOUR SAY
This article is rated  Rate this article