mirror of
https://github.com/retailcrm/NameCaseLib.git
synced 2025-02-06 09:09:23 +03:00
86 lines
2.8 KiB
PHP
86 lines
2.8 KiB
PHP
|
<?php
|
|||
|
|
|||
|
class TestGeneratorDB
|
|||
|
{
|
|||
|
|
|||
|
public $maintemplate;
|
|||
|
public $testtemplate;
|
|||
|
public $resultArr = array();
|
|||
|
private $gender;
|
|||
|
private $tests;
|
|||
|
private $count = 0;
|
|||
|
|
|||
|
public function __construct()
|
|||
|
{
|
|||
|
mysql_connect('localhost', 'root', '');
|
|||
|
mysql_select_db('names');
|
|||
|
mysql_set_charset('utf8');
|
|||
|
//$this->resultArr[]=file('Names/boy_full_result.txt');
|
|||
|
//$this->resultArr[]=file('Names/girl_full_result.txt');
|
|||
|
}
|
|||
|
|
|||
|
public function generate($fname, $gender)
|
|||
|
{
|
|||
|
$this->maintemplate = file_get_contents('Template/NCLNameCaseUaTest.main');
|
|||
|
$this->testtemplate = file_get_contents('Template/NCLNameCaseRuTest' . $fname . $gender . '.test');
|
|||
|
//$this->resultArr=file('Names/'.$gender.'_full_result.txt');
|
|||
|
$this->count = 0;
|
|||
|
if ($gender == 'boy')
|
|||
|
{
|
|||
|
$this->gender = 1;
|
|||
|
$this->dbTable = 'boy' . strtolower($fname);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
$this->gender = 2;
|
|||
|
$this->dbTable = 'girl' . strtolower($fname) ;
|
|||
|
}
|
|||
|
$this->resultArr = mysql_query("SELECT * FROM {$this->dbTable}");
|
|||
|
//foreach ($this->resultArr as $key=>$value)
|
|||
|
//{
|
|||
|
//$this->gender=$key+1;
|
|||
|
$all = array();
|
|||
|
while ($row = mysql_fetch_assoc($this->resultArr))
|
|||
|
{
|
|||
|
//$tmpnames=explode("#",trim(str_replace('ё','е',$name)));
|
|||
|
|
|||
|
$firstRes = array();
|
|||
|
$secondRes = array();
|
|||
|
$fatherRes = array();
|
|||
|
$secondRes = $fatherRes = $firstRes = explode('#', $row['nameCase']);
|
|||
|
|
|||
|
$this->generateTest($firstRes, $secondRes, $fatherRes);
|
|||
|
}
|
|||
|
//}
|
|||
|
$res = str_replace('{% tests %}', $this->tests, $this->maintemplate);
|
|||
|
$res = str_replace('{% name %}', $fname, $res);
|
|||
|
file_put_contents('../Library/NCLNameCaseUaTest' . $fname . $gender . '.php', $res);
|
|||
|
}
|
|||
|
|
|||
|
private function generateTest($firstRes, $secondRes, $fatherRes)
|
|||
|
{
|
|||
|
$tpl = $this->testtemplate;
|
|||
|
$tpl = str_replace('{% id %}', $this->count, $tpl);
|
|||
|
$tpl=str_replace('{% second %}', $secondRes[0], $tpl);
|
|||
|
$tpl = str_replace('{% first %}', $firstRes[0], $tpl);
|
|||
|
$tpl=str_replace('{% father %}', $fatherRes[0], $tpl);
|
|||
|
$tpl = str_replace('{% gender %}', $this->gender, $tpl);
|
|||
|
$tpl = str_replace('{% firstOK %}', implode(',', $firstRes), $tpl);
|
|||
|
$tpl = str_replace('{% secondOK %}', implode(',', $secondRes), $tpl);
|
|||
|
$tpl = str_replace('{% fatherOK %}', implode(',', $fatherRes), $tpl);
|
|||
|
$this->tests.=$tpl;
|
|||
|
$this->count++;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
$p = new TestGeneratorDB;
|
|||
|
$p->generate('Names', 'boy');
|
|||
|
$p = new TestGeneratorDB;
|
|||
|
$p->generate('Names', 'girl');
|
|||
|
|
|||
|
$p = new TestGeneratorDB;
|
|||
|
$p->generate('Father', 'boy');
|
|||
|
$p = new TestGeneratorDB;
|
|||
|
$p->generate('Father', 'girl');
|
|||
|
?>
|