コード例 #1
0
 /**
  * Delete entries
  *
  * @param array Array of entries to process
  * @return array Array of processed entries
  */
 protected function process_delete_entries($entries)
 {
     global $DB;
     if (empty($entries)) {
         return array();
     }
     $df = mod_dataform_dataform::instance($this->dataformid);
     $processed = array();
     $accessparams = array('dataformid' => $this->dataformid, 'viewid' => $this->viewid);
     foreach ($entries as $entry) {
         // Check permissions.
         if (!mod_dataform\access\entry_delete::validate($accessparams + array('entry' => $entry))) {
             continue;
         }
         $fields = $this->field_manager->get_fields();
         foreach ($fields as $field) {
             $field->delete_content($entry->id);
         }
         $DB->delete_records('dataform_entries', array('id' => $entry->id));
         $processed[$entry->id] = $entry;
         // Trigger event.
         $eventparams = array('objectid' => $entry->id, 'context' => $df->context, 'relateduserid' => $entry->userid, 'other' => array('dataid' => $this->dataformid, 'viewid' => $this->viewid, 'entryid' => $entry->id));
         $event = \mod_dataform\event\entry_deleted::create($eventparams);
         $event->add_record_snapshot('dataform_entries', $entry);
         $event->trigger();
         // Update calculated grades if applicable.
         $df->grade_manager->update_calculated_grades($entry);
     }
     return $processed;
 }
コード例 #2
0
 /**
  *
  */
 protected function display_delete($entry)
 {
     global $OUTPUT;
     $field = $this->_field;
     // Check delete permissions for target view.
     $viewid = !empty($entry->baseurl) ? $entry->baseurl->param('view') : 0;
     $accessparams = array('dataformid' => $field->dataid, 'viewid' => $viewid, 'entry' => $entry);
     if (!mod_dataform\access\entry_delete::validate($accessparams)) {
         return '';
     }
     $params = array('delete' => $entry->id, 'sesskey' => sesskey());
     $url = new moodle_url($entry->baseurl, $params);
     $str = get_string('delete');
     $attributes = array('id' => "id_deleteentry{$entry->id}");
     $actionlink = new action_menu_link($url, new pix_icon('t/delete', $str), $str, true, $attributes);
     if (!empty($options['actionmenu'])) {
         return $actionlink;
     } else {
         return $OUTPUT->render($actionlink);
     }
 }