-
Notifications
You must be signed in to change notification settings - Fork 9
/
addview.php
69 lines (58 loc) · 2.49 KB
/
addview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/* @var $DB mysqli_native_moodle_database */
/* @var $OUTPUT core_renderer */
/* @var $PAGE moodle_page */
?>
<?php
/**
* Screen for adding new FLASHCARD_CARDS_PER_PAGE cards
*
* @package mod-flashcard
* @category mod
* @author Tomasz Muras
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
/* @var $OUTPUT core_renderer */
if (!defined('MOODLE_INTERNAL')) {
error("Illegal direct access to this screen");
}
require_once('cardsedit_form.php');
if ($action != '') {
$result = include "{$CFG->dirroot}/mod/flashcard/editview.controller.php";
}
$cardsnum = $DB->count_records('flashcard_deckdata', array('flashcardid' => $flashcard->id));
$form = new flashcard_cardsedit_form(null, array('noaddbutton' => true, 'context' => $context));
$form->set_data(array('view' => 'add', 'id' => $cm->id));
if ($fromform = $form->get_data()) {
$fileoptions = array(
'subdirs' => false,
'maxfiles' => -1,
'maxbytes' => 0,
);
foreach ($fromform->cardid as $k => $id) {
if ($fromform->question[$k]['text'] || $fromform->answer[$k]['text']) {
//insert new
$newcard = new object();
$newcard->answertext = '';
$newcard->questiontext = '';
$newcard->flashcardid = $flashcard->id;
$newcard->id = $DB->insert_record('flashcard_deckdata', $newcard);
//$newcard->questiontext = $fromform->question[$k]['text'];
//$data = file_postupdate_standard_editor($fromform->question[$k]['text'], 'summary', $editoroptions, $context, 'course', 'section', $section->id);
//$section->summary = $data->summary;
$savedquestion = file_save_draft_area_files($fromform->question[$k]['itemid'], $context->id, 'mod_flashcard',
'question', $newcard->id, $fileoptions, $fromform->question[$k]['text']);
$newcard->questiontext = $savedquestion;
$savedanswer = file_save_draft_area_files($fromform->answer[$k]['itemid'], $context->id, 'mod_flashcard',
'answer', $newcard->id, $fileoptions, $fromform->answer[$k]['text']);
$newcard->answertext = $savedanswer;
$DB->update_record('flashcard_deckdata', $newcard);
}
}
//redirect to the last page of edit
$url = new moodle_url('view.php', array('a' => $flashcard->id, 'view' => 'edit', 'subview' => 'add', 'page' => -1));
redirect($url);
}
echo $out;
echo $OUTPUT->heading("Add new cards");
$form->display();