-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patheditview.php
101 lines (87 loc) · 3.76 KB
/
editview.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/* @var $DB mysqli_native_moodle_database */
/* @var $OUTPUT core_renderer */
/* @var $PAGE moodle_page */
/**
* This view provides a way for editing questions
*
* @package mod-flashcard
* @category mod
* @author Gustav Delius
* @contributors Valery Fremaux
* @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";
}
$page = optional_param('page', 0, PARAM_INT);
$cardsnum = $DB->count_records('flashcard_deckdata', array('flashcardid' => $flashcard->id));
$form = new flashcard_cardsedit_form(null, array('context' => $context));
$fileoptions = array(
'subdirs' => false,
'maxfiles' => -1,
'maxbytes' => 0,
);
if ($fromform = $form->get_data()) {
foreach ($fromform->cardid as $k => $id) {
if ($id) {
//update
$newcard = new object();
$newcard->id = $id;
/*
$newcard->questiontext = $fromform->question[$k]['text'];
$newcard->answertext = $fromform->answer[$k]['text'];
*/
$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;
$newcard->flashcardid = $flashcard->id;
$DB->update_record('flashcard_deckdata', $newcard);
} elseif ($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);
$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;
$newcard->flashcardid = $flashcard->id;
$DB->update_record('flashcard_deckdata', $newcard);
}
}
}
if ($fromform && isset($fromform->addmore)) {
//empty page, redirect to add page
$url = new moodle_url('view.php', array('a' => $flashcard->id, 'view' => 'add'));
redirect($url);
} elseif ($fromform) {
$url = new moodle_url('view.php', array('a' => $flashcard->id, 'view' => 'edit', 'page' => $page));
redirect($url);
} else {
$pagedata = flashcard_get_page($flashcard, $page);
}
echo $out;
echo $OUTPUT->paging_bar($cardsnum, $page, FLASHCARD_CARDS_PER_PAGE, $url);
$toform = new object();
$toform->question = $pagedata->question;
$toform->answer = $pagedata->answer;
$toform->cardid = $pagedata->id;
$toform->view = 'edit';
$toform->id = $cm->id;
$form->set_data($toform);
$form->display();
$url = new moodle_url('/mod/flashcard/view.php', array('a' => $flashcard->id, 'view' => 'edit'));
echo $OUTPUT->paging_bar($cardsnum, $page, FLASHCARD_CARDS_PER_PAGE, $url);