コード例 #1
0
ファイル: lib.php プロジェクト: gabrielrosset/moodle
/**
 * function that takes in a dataid and adds a record
 * this is used everytime an add template is submitted
 *
 * @global object
 * @global object
 * @param object $data
 * @param int $groupid
 * @return bool
 */
function data_add_record($data, $groupid = 0)
{
    global $USER, $DB;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = context_module::instance($cm->id);
    $record = new stdClass();
    $record->userid = $USER->id;
    $record->dataid = $data->id;
    $record->groupid = $groupid;
    $record->timecreated = $record->timemodified = time();
    if (has_capability('mod/data:approve', $context)) {
        $record->approved = 1;
    } else {
        $record->approved = 0;
    }
    $record->id = $DB->insert_record('data_records', $record);
    // Trigger an event for creating this record.
    $event = \mod_data\event\record_created::create(array('objectid' => $record->id, 'context' => $context, 'other' => array('dataid' => $data->id)));
    $event->trigger();
    return $record->id;
}
コード例 #2
0
ファイル: edit.php プロジェクト: educakanchay/campus
            // Insert a whole lot of empty records to make sure we have them.
            $records = array();
            foreach ($fields as $field) {
                $content = new stdClass();
                $content->recordid = $recordid;
                $content->fieldid = $field->id;
                $records[] = $content;
            }
            // Bulk insert the records now. Some records may have no data but all must exist.
            $DB->insert_records('data_content', $records);
            // Add all provided content.
            foreach ($processeddata->fields as $fieldname => $field) {
                $field->update_content($recordid, $datarecord->{$fieldname}, $fieldname);
            }
            // Trigger an event for updating this record.
            $event = \mod_data\event\record_created::create(array('objectid' => $rid, 'context' => $context, 'courseid' => $course->id, 'other' => array('dataid' => $data->id)));
            $event->add_record_snapshot('data', $data);
            $event->trigger();
            if (!empty($datarecord->saveandview)) {
                $viewurl = new moodle_url('/mod/data/view.php', array('d' => $data->id, 'rid' => $recordid));
                redirect($viewurl);
            }
        }
    }
}
// End of form processing.
/// Print the page header
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($data->name), 2);
echo $OUTPUT->box(format_module_intro('data', $data, $cm->id), 'generalbox', 'intro');
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/data/edit.php?d=' . $data->id);