-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.php
More file actions
39 lines (31 loc) · 983 Bytes
/
Copy pathimport.php
File metadata and controls
39 lines (31 loc) · 983 Bytes
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
<?php
require_once 'vendor/autoload.php';
use Model\FlashcardsRepository;
use Entity\Flashcard;
$flashcardRepository = new FlashcardsRepository();
$fn = fopen("flashcards.txt", "r");
$error = 0;
$result = false;
while (!feof($fn)) {
//Parse csv flashcard
$data = fgetcsv($fn, ",");
$question = $data[0];
$answer = $data[1];
$flashcard = new Flashcard();
$flashcard->setQuestion($question);
$flashcard->setAnswer($answer);
$flashcard->setHasQuestionAnswer(md5($question) . md5($answer));
$flashcard->setHasAnswerQuestion(md5($answer) . md5($question));
// Uncomment this for don't have duplicate entries on the database
//if ($flashcardRepository->checkIfExist($flashcard)) {
$result = $flashcardRepository->persist($flashcard);
//}
if (!$result) {
$error++;
}
}
if ($error != 0) {
echo "Import error, some flashcards could not be imported";
} else {
echo "Import successfully completed";
}