19 include_once(
'TranslationWordList.php');
65 function __construct($stringID = 0, $projectID = 0, $original =
"", $localeID = 1, $translation =
"", $sentenceID = 0, $lastSeen = 0, $rowOrder = 0)
71 if($stringID != 0 && $original ==
"")
73 $rs =
$DB->Execute(
"SELECT ID, ProjectID, Original, LocaleID, Translation, SentenceID, LastSeen, RowOrder FROM ".$Tables[
"Strings"].
" WHERE ID=?", array($stringID));
76 if($row = $rs->FetchRow())
79 $this->StringID = $row[
"ID"];
80 $this->ProjectID = $row[
"ProjectID"];
81 $this->Original = $row[
"Original"];
82 $this->LocaleID = $row[
"LocaleID"];
83 $this->Translation = $row[
"Translation"];
84 $this->SentenceID = ($row[
"SentenceID"] != null ? $row[
"SentenceID"] : 0);
85 $this->LastSeen = $row[
"LastSeen"];
86 $this->RowOrder = $row[
"RowOrder"];
90 throw new Exception(
"TranslationString: Requested not existing string from databse. ID: $stringID");
99 $this->StringID = $stringID;
100 $this->ProjectID = $projectID;
101 $this->Original = $original;
102 $this->LocaleID = $localeID;
103 $this->Translation = $translation;
104 $this->SentenceID = ($sentenceID != null ? $sentenceID : 0);
105 $this->LastSeen = $lastSeen;
106 $this->RowOrder = $rowOrder;
130 $rs =
$DB->Execute(
"SELECT SentenceID, Sum(Occurences) AS Count FROM ".$Tables[
"SentenceIndex"].
" GROUP BY SentenceID");
132 while($row = $rs->FetchRow())
149 $rs =
$DB->Execute(
"SELECT SentenceID, WordID FROM ".$Tables[
"SentenceIndex"]);
151 while($row = $rs->FetchRow())
244 $this->Translation = $translation;
257 $this->RowOrder= $index;
278 if($this->Original ==
"")
280 throw new Exception(
"TranslationString->Save() called without Original string.");
287 $rs =
$DB->Execute(
"SELECT ID, SentenceID, ProjectID FROM ".$Tables[
"Strings"].
" WHERE Original = ? AND LocaleID = ?", array($this->Original, $this->LocaleID));
290 while($row = $rs->FetchRow())
292 if($this->SentenceID == 0)
295 $this->SentenceID = ($row[
"SentenceID"] != null ? $row[
"SentenceID"] : 0);
299 if($row[
"ProjectID"] == $this->ProjectID)
301 $this->StringID = $row[
"ID"];
306 if($this->SentenceID == 0 && $this->Words->SumCount() != 0)
312 if($this->SentenceID == 0)
323 if($this->StringID == 0)
327 $DB->Execute(
"INSERT INTO ".$Tables[
"Strings"].
" (ProjectID, Original, SentenceID, LocaleID, Translation, LastSeen, RowOrder) VALUES (?,?,?,?,?, now(), ?)",
331 ($this->SentenceID != 0 ? $this->SentenceID : null),
336 if(!
$DB->Insert_ID())
338 throw new Exception(
"DB Error: Insert_ID not supported");
342 $this->StringID =
$DB->Insert_ID();
347 $DB->Execute(
"UPDATE ".$Tables[
"Strings"].
" SET Translation = ?, SentenceID = ?, LastSeen = now(), RowOrder = ? WHERE ID = ?",
350 ($this->SentenceID != 0 ? $this->SentenceID : null),
370 if($this->StringID == 0)
372 throw new Exception(
"String DestroyData called on a not loaded string.");
374 $DB->Execute(
"DELETE FROM Strings WHERE ID = ?", array($this->StringID));
396 function FindSimilar($FindText =
"", $localeID = 0, $FilterPercent = 60)
401 unset($translations);
406 $this->Original = $FindText;
410 $this->LocaleID = $localeID;
416 if($this->Words->SumCount() == 0)
425 if(empty($this->Matches))
434 foreach($res as $id => $percent)
436 if($percent >= $FilterPercent)
438 $filtered[$id] = $percent;
452 foreach($filtered as $id => $percent)
454 $translations[$id][
"percent"] = $percent;
458 $idSQL = join(array_keys($filtered),
",");
460 $rs =
$DB->Execute(
"SELECT ID, ProjectID, Original, Translation, LocaleID, SentenceID, TIMESTAMP(LastSeen) as LastSeen, RowOrder FROM ".$Tables[
"Strings"].
" WHERE SentenceID IN ($idSQL) AND LocaleID = ".$this->LocaleID);
463 while($row = $rs->FetchRow())
478 foreach($translations as $id => $tr)
480 if(empty($translations[$id][
"strings"]))
482 unset($translations[$id]);
487 return $translations;
503 function FindText($findText =
"", $localeID = 0, $findOriginal, $start = 0, $limit = 100)
508 unset($translations);
538 $column =
"Original";
542 $column =
"Translation";
546 $rs =
$DB->Execute(
"SELECT ID, ProjectID, Original, Translation, LocaleID, SentenceID, TIMESTAMP(LastSeen) as LastSeen, RowOrder FROM ".$Tables[
"Strings"].
" WHERE $column LIKE '%".
fixstr($findText).
"%' AND LocaleID = ? LIMIT ?,?", array($localeID, $start, $limit));
549 while($row = $rs->FetchRow())
563 if(empty($translations))
568 return $translations;
589 unset($this->Matches);
593 foreach($this->Words as $w)
595 $idSQL .= ($idSQL !=
"") ?
"," :
"";
596 $idSQL .= $w->GetID();
600 $rs =
$DB->Execute(
"SELECT SentenceID, WordID, Occurences FROM ".$Tables[
"SentenceIndex"].
" WHERE WordID IN ($idSQL) ORDER BY SentenceID");
607 $row = $rs->FetchRow();
610 if($row ==
false || $row[
"SentenceID"] != $sID)
617 $percent = $this->Words->CompareByID($oldWords);
622 $this->Matches[$sID] = $percent;
641 $sID = $row[
"SentenceID"];
649 $oldWords->AddID($row[
"WordID"], $row[
"Occurences"]);
672 $newID =
$DB->GetOne(
"SELECT Max(SentenceID)+1 FROM ".$Tables[
"SentenceIndex"]);
680 foreach($this->Words as $w)
682 $DB->Execute(
"INSERT INTO ".$Tables[
"SentenceIndex"].
" VALUES (?,?,?)", array($newID, $w->GetID(), $w->GetCount()));
static InitSentenceLengthCache()
static $SentenceLengthCache
static $WordSentencesCache
FindText($findText="", $localeID=0, $findOriginal, $start=0, $limit=100)
__construct($stringID=0, $projectID=0, $original="", $localeID=1, $translation="", $sentenceID=0, $lastSeen=0, $rowOrder=0)
FindSentenceIndex($findSimilarToo)
SetTranslation($translation)
FindSimilar($FindText="", $localeID=0, $FilterPercent=60)
static InitWordSentencesCache()