'V textu není žádná varianta (chybí \'xx\')',
'1.2' => 'Chybí počáteční, nebo ukončovací značka \'xx\'',
'1.3' => 'Minimální počet variant odpovědí je 2',
'2.1' => 'Chybí počáteční, nebo ukončovací značka \'xx\'',
'2.2' => 'Minimální počet variant odpovědí je 2',
'3.1' => 'Věta musí obsahovat přesně 2 části',
'4.1' => 'Chybí počáteční, nebo ukončovací značka \'xx\'',
'4.2' => 'Správná odpověď musí být právě 1',
'5.1' => 'V textu není žádná varianta (chybí \'xx\')',
'5.2' => 'Chybí počáteční, nebo ukončovací značka \'xx\'',
'5.3' => 'Minimální počet variant odpovědí je 2',
'11.1' => 'V textu není žádná varianta (chybí \'xx\')',
'11.2' => 'Chybí počáteční, nebo ukončovací značka \'xx\'',
'11.3' => 'Minimální počet variant odpovědí je 2',
);
public $spravne_gramatika = '';
public $spatne_gramatika = '';
public function validateAnswer($answer) {
// var_dump($answer);
$text = $this->get('text');
switch($this->Cviceni->get('typ')) {
/*
case 1:
$matches = array();
preg_match('@xx(.*?)xx@', $text, $matches);
list($correct) = explode(';', $matches[1]);
return trim($answer) == trim($correct);
break;*/
case 2:
$matches = array();
preg_match('@xx(.*?)xx@', $text, $matches);
$gramatika = array();
preg_match('@xx.*?xx(.*?)gg@', $text, $gramatika);
list($correct) = explode(';', $matches[1]);
$patternArr = array("`", "` ", "' ", "´", "´ ", ".");
$replaceArr = array("'", "'" , "'" , "'", "'" , "" );
$correct = str_replace($patternArr, $replaceArr, $correct);
$answer = str_replace($patternArr, $replaceArr, $answer);
$spravne = strtolower(trim($answer)) == strtolower(trim($correct));
if ($spravne) {
$this->spravne_gramatika .= '|'.trim($gramatika[1]).'|';
} else {
$this->spatne_gramatika .= '|'.trim($gramatika[1]).'|';
}
return strtolower(trim($answer)) == strtolower(trim($correct));
break;
case 3:
$tmp_lines = explode("\n", trim($text));
$right = array();
$gramatika = array();
$i=0;
foreach($tmp_lines AS $line) {
if (strlen(trim($line)) > 0) {
preg_match('@xx(.*?)gg@', $line, $tmp); // zjistíme gramatiku
$gramatika[$i] = @$tmp[1];
$line = preg_replace('@xx.*?gg@', 'xx', $line); // a pak ji odstraníme
list(,$right[$i]) = explode('xx', trim($line));
$i++;
}
}
// var_dump($right);
// var_dump(count($right));
// $this->spatne_gramatika = print_r($gramatika, true);
$answerArr = explode('|', $answer);
// var_dump($answerArr);
// echo '
';
//
if (count($right) == count($answerArr)) {
// die('xa');
$spravne = true;
foreach($right AS $idx=>$r) {
if (trim($r) != trim($answerArr[$idx])) {
$spravne = false;
$this->spatne_gramatika .= '|'.trim($gramatika[$idx]).'|';
} else {
$this->spravne_gramatika .= '|'.trim($gramatika[$idx]).'|';
}
}
return $spravne;
}
return false;
break;
case 4:
$matches = array();
preg_match('@xx(.*?)xx@', $text, $matches);
$gramatika = array();
preg_match('@xx.*?xx(.*?)gg@', $text, $gramatika);
$patternArr = array("`", "` ", "' ", "´", "´ ", ".");
$replaceArr = array("'", "'" , "'" , "'", "'" , "" );
$correct = str_replace($patternArr, $replaceArr, $matches[1]);
$answer = str_replace($patternArr, $replaceArr, $answer);
$spravne = strtolower(trim($answer)) == strtolower(trim($correct));
if ($spravne) {
$this->spravne_gramatika .= '|'.trim($gramatika[1]).'|';
} else {
$this->spatne_gramatika .= '|'.trim($gramatika[1]).'|';
}
return $spravne;
break;
case 5:
case 1:
$spravne = true;
$odpovediArr = explode('|', $answer);
$matches = array();
preg_match_all('@xx(.*?)xx@', $text, $matches);
$gramatika = array();
preg_match_all('@xx.*?xx(.*?)gg@', $text, $gramatika);
foreach($matches[0] AS $idx=>$match) {
list($correct) = explode(';', $matches[1][$idx]);
if (strtolower(trim($correct)) != strtolower(trim($odpovediArr[$idx]))) {
$spravne = false;
$this->spatne_gramatika .= '|'.trim($gramatika[1][$idx]).'|';
} else {
$this->spravne_gramatika .= '|'.trim($gramatika[1][$idx]).'|';
}
}
return $spravne;
break;
case 11:
$spravne = 0;
$odpovediArr = explode('|', $answer);
$matches = array();
preg_match_all('@xx(.*?)xx@', $text, $matches);
$gramatika = array();
preg_match_all('@xx.*?xx(.*?)gg@', $text, $gramatika);
foreach($matches[0] AS $idx=>$match) {
list($correct) = explode(';', $matches[1][$idx]);
if (strtolower(trim($correct)) == strtolower(trim($odpovediArr[$idx]))) {
++$spravne;
$this->spravne_gramatika .= '|'.trim($gramatika[1][$idx]).'|';
} else {
$this->spatne_gramatika .= '|'.trim($gramatika[1][$idx]).'|';
}
}
return $spravne;
break;
}
return false;
}
public function getCorrectAnswer() {
$text = $this->get('text');
switch($this->Cviceni->get('typ')) {
case 1:
case 2:
case 4:
case 5:
case 11:
$spravne = array();
$matches = array();
preg_match_all('@xx(.*?)xx@', $text, $matches);
foreach($matches[0] AS $idx=>$match) {
list($correct) = explode(';', $matches[1][$idx]);
$spravne[] = trim($correct);
}
return implode('|',$spravne);
break;
case 3:
list(,$right) = explode('xx', trim($text));
return $right;
break;
}
return false;
}
public static function validateAnswer3($text, $answer) {
/*
* Vyskocil - nepoužívá se, vyhodnocování přetahovaček už probíhá po větách přes standardní validateAnswer výše
*/
if (empty($answer) || empty($text))
return false;
$tmp_lines = explode("\n", trim($text));
$right = array();
$i=0;
foreach($tmp_lines AS $line) {
if (strlen(trim($line)) > 0)
list(,$right[$i++]) = explode('xx', trim($line));
}
$answerArr = explode('|', $answer);
if (count($right) == count($answerArr)) {
$spravne = true;
foreach($right AS $idx=>$r) {
if (trim($r) != trim($answerArr[$idx])) {
$spravne = false;
break;
}
}
return $spravne;
}
return false;
}
public function generateZadani() {
switch($this->Cviceni->get('typ')) {
/*
case 1:
$TEXT = $this->get('text');
$matches = array();
preg_match('@xx(.*?)xx@', $TEXT, $matches);
$tmp = explode(';', $matches[1]);
$varianty = array();
foreach($tmp AS $t)
$varianty[] = trim($t);
shuffle($varianty);
return trim(str_replace($matches[0], 'xx'.implode(';', $varianty).'xx', $TEXT));
break;*/
case 2:
$TEXT = $this->get('text');
$matches = array();
preg_match('@xx(.*?)xx@', $TEXT, $matches);
$tmp = explode(';', $matches[1]);
$varianty = array();
foreach($tmp AS $t)
$varianty[] = trim($t);
shuffle($varianty);
return trim(str_replace($matches[0], 'xx'.implode(';', $varianty).'xx', $TEXT));
break;
case 3:
$TEXT = $this->get('text');
$lines = array();
$tmp_lines = explode("\n", trim($TEXT));
$left = $right = array();
$i=0;
foreach($tmp_lines AS $line) {
if (strlen(trim($line)) > 0) {
$parts = explode('xx', trim($line));
$left[$i] = $parts[0];
$right[$i] = $parts[1];
++$i;
}
}
$promichano = false;
$new_right = array();
while($promichano === false) {
$new_right = $right;
$promichano = true;
shuffle($new_right);
foreach($left AS $idx=>$val) {
if ($right[$idx] == $new_right[$idx]) {
$promichano = false;
break;
}
}
}
$ret = "";
foreach($left AS $idx=>$l) {
$ret .= "{$l} xx {$new_right[$idx]}\n";
}
return trim($ret);
break;
case 4:
return trim($this->get('text'));
break;
case 5:
case 1:
case 11:
$TEXT = $this->get('text');
$output = $TEXT;
$matches = array();
preg_match_all('@xx(.*?)xx@', $TEXT, $matches);
foreach($matches[0] AS $idx=>$match) {
$tmp = explode(';', $matches[1][$idx]);
$varianty = array();
foreach($tmp AS $t)
$varianty[] = trim($t);
shuffle($varianty);
$output = str_replace($matches[0][$idx], 'xx'.implode(';',$varianty).'xx', $output);
}
return trim($output);
break;
}
}
public static function generateZadani3($text) {
$TEXT = $text;
$lines = array();
$tmp_lines = explode("\n", trim($TEXT));
$left = $right = array();
$i=0;
foreach($tmp_lines AS $line) {
if (strlen(trim($line)) > 0) {
$parts = explode('xx', trim($line));
$left[$i] = $parts[0];
$right[$i] = $parts[1];
++$i;
}
}
$promichano = false;
$new_right = array();
while($promichano === false) {
$new_right = $right;
$promichano = true;
shuffle($new_right);
foreach($left AS $idx=>$val) {
if ($right[$idx] == $new_right[$idx]) {
$promichano = false;
break;
}
}
}
$ret = "";
foreach($left AS $idx=>$l) {
$ret .= "{$l} xx {$new_right[$idx]}\n";
}
return trim($ret);
}
public static function validateText($typ, $text) {
$error = -1;
$text = str_replace(array('XX','Xx','xX'), array ('xx','xx','xx'), $text);
switch($typ) {
//case 1:
case 2:
$matches = array();
if (preg_match('@xx(.*?)xx@', $text, $matches)) {
$parts = explode(';', $matches[1]);
if (count($parts) < 2)
$error = "{$typ}.2";
} else
$error = "{$typ}.1";
break;
case 3:
$parts = explode('xx', $text);
if (count($parts) != 2)
$error = "{$typ}.1";
/*
$lines = array();
$tmp_lines = explode("\n", trim($text));
foreach($tmp_lines AS $line) {
if (strlen(trim($line)) > 0)
$lines[] = trim($line);
}
if (count($lines) >= 2) {
foreach($lines AS $line) {
if ((count($parts = explode('xx', $line)) != 2) || (strlen(trim($parts[0])) == 0) || (strlen(trim($parts[1])) == 0)) {
$error = "{$typ}.2";
break;
}
}
} else {
$error = "{$typ}.1";
}*/
break;
case 4:
$matches = array();
if (preg_match('@xx(.*?)xx@', $text, $matches)) {
$parts = explode(';', $matches[1]);
if ((count($parts) != 1) || (strlen(trim($parts[0])) == 0))
$error = "{$typ}.2";
} else
$error = "{$typ}.1";
break;
case 5:
case 1:
case 11:
$matches = array();
//kontrola parovych znacek
if (preg_match_all('@xx@', $text, $matches)) {
if ((count($matches[0]) % 2) != 0) {
$error = "{$typ}.2";
} else {
preg_match_all('@xx(.*?)xx@', $text, $matches);
foreach($matches[1] AS $hodnoty) {
$parts = explode(';', $hodnoty);
if (count($parts) < 2) {
$error = "{$typ}.3";
break;
}
}
}
} else {
$error = "{$typ}.1";
}
break;
}
return $error;
}
public function getGramatikaKodArr() {
$text = $this->get('text');
$gram = array();
switch($this->Cviceni->get('typ')) {
case 1:
case 2:
case 4:
case 5:
case 11:
$matches = array();
preg_match_all('@xx.*?xx(.*?)gg@', $text, $matches);
foreach($matches[1] AS $match) {
$gram[] = trim ($match);
}
break;
case 3:
preg_match('@xx(.*?)gg@', $text, $tmp); // zjistíme gramatiku
$gram[] = $tmp[1];
break;
}
return $gram;
}
public function save(Doctrine_Connection $conn = null)
{
$otazka = $this->get('text');
$otazka = str_replace(array('XX','Xx','xX'), array ('xx','xx','xx'), $otazka);
$otazka = self::odstranVicenasobneMezery($otazka);
$this->set('text',$otazka);
return parent::save($conn);
}
/**
* Odstrani vícenásobné mezery v řetězci
*
* @param string $str
* @return string
*/
private static function odstranVicenasobneMezery($str)
{
$result = str_replace(array(" "), array(" "), $str);
if($result != $str)
{
$result = self::odstranVicenasobneMezery($result);
}
return $result;
}
}