Example #1
0
 /**
  * Tests for event note_deleted.
  */
 public function test_note_deleted_event()
 {
     // Delete a note.
     $sink = $this->redirectEvents();
     note_delete($this->eventnote);
     $events = $sink->get_events();
     $event = array_pop($events);
     // Delete note event.
     $sink->close();
     // Validate event data.
     $this->assertInstanceOf('\\core\\event\\note_deleted', $event);
     $this->assertEquals($this->eventnote->id, $event->objectid);
     $this->assertEquals($this->eventnote->usermodified, $event->userid);
     $this->assertEquals($this->eventnote->userid, $event->relateduserid);
     $this->assertEquals('post', $event->objecttable);
     $this->assertEquals(null, $event->get_url());
     $this->assertEquals($this->noterecord, $event->get_record_snapshot('post', $event->objectid));
     $this->assertEquals(NOTES_STATE_SITE, $event->other['publishstate']);
     // Test legacy data.
     $logurl = new \moodle_url('index.php', array('course' => $this->eventnote->courseid, 'user' => $this->eventnote->userid));
     $logurl->set_anchor('note-' . $this->eventnote->id);
     $arr = array($this->eventnote->courseid, 'notes', 'delete', $logurl, 'delete note');
     $this->assertEventLegacyLogData($arr, $event);
     $this->assertEventContextNotUsed($event);
 }
Example #2
0
}
// require login to access notes
require_login($course);
// locate context information
$context = get_context_instance(CONTEXT_COURSE, $course->id);
// check capability
if (!has_capability('moodle/notes:manage', $context)) {
    print_error('nopermissiontodelete', 'notes');
}
if (empty($CFG->enablenotes)) {
    print_error('notesdisabled', 'notes');
}
if (data_submitted() && confirm_sesskey()) {
    //if data was submitted and is valid, then delete note
    $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user='******'notes', 'delete', 'index.php?course=' . $note->courseid . '&user='******'#note-' . $note->id, 'delete note');
    } else {
        print_error('cannotdeletepost', 'notes', $returnurl);
    }
    redirect($returnurl);
} else {
    // if data was not submitted yet, then show note data with a delete confirmation form
    $strnotes = get_string('notes', 'notes');
    $optionsyes = array('id' => $noteid, 'sesskey' => sesskey());
    $optionsno = array('course' => $course->id, 'user' => $note->userid);
    // output HTML
    if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
        $nav[] = array('name' => get_string('participants'), 'link' => $CFG->wwwroot . '/user/index.php?id=' . $course->id, 'type' => 'misc');
    }
    $nav[] = array('name' => fullname($user), 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $course->id, 'type' => 'misc');
Example #3
0
 /**
  * Delete notes about users.
  * Note: code should be matching the /notes/delete.php checks.
  *
  * @param array $notes An array of ids for the notes to delete.
  * @return null
  * @since Moodle 2.5
  */
 public static function delete_notes($notes = array())
 {
     global $CFG;
     $params = self::validate_parameters(self::delete_notes_parameters(), array('notes' => $notes));
     // Check if note system is enabled.
     if (!$CFG->enablenotes) {
         throw new moodle_exception('notesdisabled', 'notes');
     }
     $warnings = array();
     foreach ($params['notes'] as $noteid) {
         $note = note_load($noteid);
         if (isset($note->id)) {
             // Ensure the current user is allowed to run this function.
             $context = context_course::instance($note->courseid);
             self::validate_context($context);
             require_capability('moodle/notes:manage', $context);
             note_delete($note);
         } else {
             $warnings[] = array('item' => 'note', 'itemid' => $noteid, 'warningcode' => 'badid', 'message' => 'Note does not exist');
         }
     }
     return $warnings;
 }
Example #4
0
// locate context information
$context = context_course::instance($course->id);

// check capability
if (!has_capability('moodle/notes:manage', $context)) {
    print_error('nopermissiontodelete', 'notes');
}

if (empty($CFG->enablenotes)) {
    print_error('notesdisabled', 'notes');
}

if (data_submitted() && confirm_sesskey()) {
//if data was submitted and is valid, then delete note
    $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user='******'cannotdeletepost', 'notes', $returnurl);
    }
    redirect($returnurl);

} else {
// if data was not submitted yet, then show note data with a delete confirmation form
    $strnotes = get_string('notes', 'notes');
    $optionsyes = array('id'=>$noteid, 'sesskey'=>sesskey());
    $optionsno  = array('course'=>$course->id, 'user'=>$note->userid);

// output HTML
    $link = null;
    if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', context_system::instance())) {
        $link = new moodle_url('/user/index.php',array('id'=>$course->id));
    }
Example #5
0
 if (false === $t_page_info) {
     echo "page not found";
     exit;
 }
 $t_url = $t_page_info['url'];
 if ('accept' === $f_action) {
     note_accept($f_note_id);
 } else {
     if ('decline' === $f_action) {
         note_decline($f_note_id);
     } else {
         if ('archive' === $f_action) {
             note_archive($f_note_id);
         } else {
             if ('delete' === $f_action) {
                 note_delete($f_note_id);
             } else {
                 if ('pack' === $f_action) {
                     # in this case id = 0
                     note_pack_deleted();
                 } else {
                     if ('queue' === $f_action) {
                         note_pending($f_note_id);
                     } else {
                         if ('edit' === $f_action) {
                             util_header_redirect("{$g_note_add_page}?f_note_id={$f_note_id}");
                         }
                     }
                 }
             }
         }
Example #6
0
}
require_login($course);
if (empty($CFG->enablenotes)) {
    print_error('notesdisabled', 'notes');
}
if (!($user = $DB->get_record('user', array('id' => $note->userid)))) {
    print_error('invaliduserid');
}
$context = context_course::instance($course->id);
if (!has_capability('moodle/notes:manage', $context)) {
    print_error('nopermissiontodelete', 'notes');
}
if (data_submitted() && confirm_sesskey()) {
    // If data was submitted and is valid, then delete note.
    $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user='******'notes', 'notes');
    $optionsyes = array('id' => $noteid, 'sesskey' => sesskey());
    $optionsno = array('course' => $course->id, 'user' => $note->userid);
    // Output HTML.
    $link = null;
    if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', context_system::instance())) {
        $link = new moodle_url('/user/index.php', array('id' => $course->id));
    }
    $PAGE->navbar->add(get_string('participants'), $link);
    $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)));
    $PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $course->id)));
    $PAGE->navbar->add(get_string('delete'));
Example #7
0
if (empty($CFG->enablenotes)) {
    print_error('notesdisabled', 'notes');
}
if (!($user = $DB->get_record('user', array('id' => $note->userid)))) {
    print_error('invaliduserid');
}
// locate context information
$context = context_course::instance($course->id);
// check capability
if (!has_capability('moodle/notes:manage', $context)) {
    print_error('nopermissiontodelete', 'notes');
}
if (data_submitted() && confirm_sesskey()) {
    //if data was submitted and is valid, then delete note
    $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user='******'cannotdeletepost', 'notes', $returnurl);
    }
    redirect($returnurl);
} else {
    // if data was not submitted yet, then show note data with a delete confirmation form
    $strnotes = get_string('notes', 'notes');
    $optionsyes = array('id' => $noteid, 'sesskey' => sesskey());
    $optionsno = array('course' => $course->id, 'user' => $note->userid);
    // output HTML
    $link = null;
    if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', context_system::instance())) {
        $link = new moodle_url('/user/index.php', array('id' => $course->id));
    }
    $PAGE->navbar->add(get_string('participants'), $link);
    $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)));