Example #1
0
 public function delete()
 {
     if (empty($this->id)) {
         return;
     }
     db_begin();
     $this->detach();
     // Delete all annotation feedback linked to this annotation.
     $sql = "SELECT af.id\n                    FROM {artefact} a\n                    INNER JOIN {artefact_annotation} an ON a.id = an.annotation\n                    INNER JOIN {artefact_annotation_feedback} f ON an.annotation = f.onannotation\n                    INNER JOIN {artefact} af ON f.artefact = af.id\n                    WHERE a.id = ?\n                    ORDER BY af.id DESC";
     $annotationfeedbackids = get_column_sql($sql, array($this->id));
     foreach ($annotationfeedbackids as $id) {
         $feedback = new ArtefactTypeAnnotationfeedback($id);
         $feedback->delete();
     }
     // Delete any embedded images for this annotation.
     // Don't use EmbeddedImage::delete_embedded_images() - it deletes by
     // the fileid. We need to delete by the resourceid.
     delete_records('artefact_file_embedded', 'resourceid', $this->id);
     delete_records('artefact_annotation', 'annotation', $this->id);
     parent::delete();
     db_commit();
 }