<?php
// use function Google\Cloud\Samples\PubSub\publish_message;
include "tools/simple_html_dom.php";
include "DatabaseHandler.php";
include 'MiniCurl.php';
class FillConjuction {
public $url;
public $conjuction;
function __construct($verb) {
// $this->connect ();
$this->conjuction["infinitive"] = ["none"=>$verb];
$this->url = "https://www.verbformen.com/search/eingabe/?w=$verb";
}
public function findConjuctions($verb) {
// if($word)
if ($verb) {
echo $contents = file_get_contents ( $url );
exit();
$regex = '/Participio:<\/b> <span class="normal">(.*?)<\/span>/';
preg_match ( $regex, $contents, $treffer, PREG_OFFSET_CAPTURE, 3 );
$regex = '/Participio:<\/b> <span class="irregular">(.*?)<\/span>/';
preg_match ( $regex, $contents, $trefferIre, PREG_OFFSET_CAPTURE, 3 );
if (! empty ( $treffer [1] [0] ) || ! empty ($trefferIre [1] [0])){
$perfect = $treffer [1] [0];
if(empty($perfect))
$perfect= $trefferIre [1] [0];
$perfect = str_replace("ä", "�", $perfect);
$perfect = str_replace("ü", "�", $perfect);
$perfect = str_replace("ö", "�", $perfect);
}
else
$perfect = "-";
$this->updatePerfect($word,$perfect);
}
return $perfect;
}
}
class ConjDatabase extends DatabaseHandler{
public $var;
function __construct(){
parent::__construct("conjuct");
}
public function conjucateVerbs(){
$i=0;
$verbs = $this->getVerbsFromDatabse();
// $verbs = [['word' => 'möchten']];
foreach ($verbs as $verb){
if(!empty($verb)){
$i++;
$this->addVerbRelection($verb['word']);
echo $i."-".$verb['word'].PHP_EOL;
}
}
}
public function getVerbsFromDatabse(){
$sql = "SELECT word FROM `dictionary` WHERE LENGTH(perfect) >1 AND translationrate = 1 GROUP BY word";
$this->connection->query ( "SET NAMES utf8" );
$result = $this->connection->query ( $sql ) or die ( $this->connection->error );
while ($wordArrayResult[] = mysqli_fetch_assoc($result));
return $wordArrayResult;
}
public function addVerbConjuctions($verb){
$conjuctor = new FillConjuction($verb);
}
public function updateVerb($form,$person,$cVerb, $infinitive){
$sql = "";
$this->connection->query ( "SET NAMES utf8" );
$result = $this->connection->query ( $sql ) or die( $this->connection->error );
$sql = "UPDATE `".DatabaseHandler::$databaseName."`.`dictionary` SET translationrate = 1 where word='$infinitive'";
$this->connection->query ( "SET NAMES utf8" );
$result = $this->connection->query ( $sql ) or die( $this->connection->error );
return 1;
}
}
$conjDb = new ConjDatabase();
$conjDb->conjucateVerbs();
?>