Добавлено логирование и исправлены некоторые ошибки в классах
This commit is contained in:
@ -31,11 +31,28 @@ final class ContingentManager
|
||||
->equals('fake', 'n')
|
||||
->end();
|
||||
$sql = $this->builder->write($query);
|
||||
$sites = $db->executeQuery($sql, $params);
|
||||
$sites = $db->selectQuery($sql, $params);
|
||||
|
||||
return $sites;
|
||||
}
|
||||
|
||||
public function insertContingent(Database $db, array $contingent) : void
|
||||
{
|
||||
$params = ['spec_code', 'spec_name', 'edu_level', 'edu_forms', 'contingent', 'spec_id', 'org_id'];
|
||||
$sql = "insert into sveden_education_contingent"
|
||||
."(". implode(',', $params) .") values";
|
||||
for ($i = 0; $i < count($contingent); $i++) {
|
||||
$sql .= "(";
|
||||
foreach ($contingent[$i] as $key => $value) {
|
||||
$sql .= ":$key". ($i+1).",";
|
||||
}
|
||||
$sql = substr_replace($sql,"),", -1);
|
||||
}
|
||||
$sql = substr_replace($sql,"", -1);
|
||||
|
||||
$db->insertQuery($sql, $contingent);
|
||||
}
|
||||
|
||||
public function getSpecializations(Database $db) : array
|
||||
{
|
||||
// select id, kod from niimko.s_specs where oopkodes = 'gos3p'
|
||||
@ -47,14 +64,19 @@ final class ContingentManager
|
||||
->equals('oopkodes','gos3p')
|
||||
->end();
|
||||
$sql = $this->builder->write($query);
|
||||
$specializations = $db->executeQuery($sql, $params);
|
||||
$specializations = $db->selectQuery($sql, $params);
|
||||
|
||||
return $specializations;
|
||||
}
|
||||
|
||||
public function buildURL(string $url): string
|
||||
{
|
||||
// TODO - сделать base_url
|
||||
// Строит -> https://<base_uri>/sveden/education/
|
||||
$offset = strpos($url, '/', strlen('http://'));
|
||||
if ($offset) {
|
||||
$url = substr_replace($url, '', $offset);
|
||||
}
|
||||
|
||||
$url = "$url/sveden/education/";
|
||||
if (str_contains($url, "http://")) {
|
||||
$url = str_replace("http://","https://", $url);
|
||||
@ -69,13 +91,15 @@ final class ContingentManager
|
||||
public function addSpecId(array &$contingent, array $specializations) : void
|
||||
{
|
||||
foreach ($contingent as $key => $con) {
|
||||
$buf = null;
|
||||
$needle = $con['spec_code'];
|
||||
foreach ($specializations as $spec) {
|
||||
if ($needle == $spec['kod']) {
|
||||
$cont['spec_id'] = $spec['id'];
|
||||
$buf = $spec['id'];
|
||||
}
|
||||
}
|
||||
$contingent[$key]['spec_id'] = $cont['spec_id'];
|
||||
$contingent[$key]['spec_id'] = $buf;
|
||||
unset($buf);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,4 +109,13 @@ final class ContingentManager
|
||||
$contingent[$i]['org_id'] = $orgId;
|
||||
}
|
||||
}
|
||||
|
||||
public function checkContingent(array $contingent) : bool
|
||||
{
|
||||
$count = 0;
|
||||
foreach ($contingent as $value) {
|
||||
$count += $value['contingent'];
|
||||
}
|
||||
return $count ? true : false;
|
||||
}
|
||||
}
|
@ -12,14 +12,14 @@ class ContingentParser
|
||||
"eduName" => "td",
|
||||
"eduLevel" => "td",
|
||||
"eduForm" => "td",
|
||||
"numberBF" => "th",
|
||||
"numberBFF" => "th",
|
||||
"numberBR" => "th",
|
||||
"numberBRF" => "th",
|
||||
"numberBM" => "th",
|
||||
"numberBMF" => "th",
|
||||
"numberP" => "th",
|
||||
"numberPF" => "th",
|
||||
// "numberBF" => "th",
|
||||
// "numberBFF" => "th",
|
||||
// "numberBR" => "th",
|
||||
// "numberBRF" => "th",
|
||||
// "numberBM" => "th",
|
||||
// "numberBMF" => "th",
|
||||
// "numberP" => "th",
|
||||
// "numberPF" => "th",
|
||||
"numberAll" => ["th", "td"]
|
||||
];
|
||||
|
||||
@ -41,7 +41,7 @@ class ContingentParser
|
||||
} else {
|
||||
$th = $this->xpath->query($this->template . $tag[0] . "[@itemprop=\"$field\"]");
|
||||
$td = $this->xpath->query($this->template . $tag[1] . "[@itemprop=\"$field\"]");
|
||||
$data[$field] = $th > $td ? $th : $td;
|
||||
$data[$field] = $th->length > $td->length ? $th : $td;
|
||||
}
|
||||
|
||||
}
|
||||
@ -53,6 +53,19 @@ class ContingentParser
|
||||
$data = $this->parse();
|
||||
$records = array();
|
||||
|
||||
// var_dump($data['eduName']->item(0));
|
||||
// exit(0);
|
||||
|
||||
$equel = $data['eduName']->length;
|
||||
foreach ($data as $field) {
|
||||
if ($field->length == 0) {
|
||||
return [];
|
||||
}
|
||||
if ($field->length != $equel) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $data['eduCode']->length; $i++) {
|
||||
$contingentRow = new ContingentRow(
|
||||
$data['eduCode']->item($i)->textContent,
|
||||
|
@ -19,18 +19,21 @@ class Database
|
||||
$password,
|
||||
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
|
||||
);
|
||||
print("Подлючено успешно!\n");
|
||||
$log = date('Y-m-d H:i:s') . ' Подлючение к успешно!';
|
||||
file_put_contents(__DIR__ . '/../database.log', $log . PHP_EOL, FILE_APPEND);
|
||||
} catch (PDOException $e) {
|
||||
echo "Ошибка подключения:". $e->getMessage() . "\n";
|
||||
$log = date('Y-m-d H:i:s') . " Ошибка подключения:" . $e->getMessage();
|
||||
file_put_contents(__DIR__ . '/../database.log', $log . PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
echo "Подключение прервано!\n";
|
||||
$log = date('Y-m-d H:i:s') . ' Подлючение прервано!';
|
||||
file_put_contents(__DIR__ . '/../database.log', $log . PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
|
||||
public function executeQuery(string $sql, array $params) : array|null
|
||||
public function selectQuery(string $sql, array $params = []) : array
|
||||
{
|
||||
try {
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
@ -41,9 +44,32 @@ class Database
|
||||
$stmt->execute();
|
||||
$array = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
echo "Ошибка запроса: " . $e->getMessage() . "\n";
|
||||
$log = date('Y-m-d H:i:s') . " Ошибка запроса:" . $e->getMessage();
|
||||
file_put_contents(__DIR__ . '/../database.log', $log . PHP_EOL, FILE_APPEND);
|
||||
} finally {
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
public function insertQuery(string $sql, array $params)
|
||||
{
|
||||
try {
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$stmt->bindParam(":spec_code".$i+1, $params[$i]['spec_code']);
|
||||
$stmt->bindParam(":spec_name".$i+1, $params[$i]['spec_name']);
|
||||
$stmt->bindParam(":edu_forms".$i+1, $params[$i]['edu_forms']);
|
||||
$stmt->bindParam(":edu_level".$i+1, $params[$i]['edu_level']);
|
||||
$stmt->bindParam(":contingent".$i+1, $params[$i]['contingent']);
|
||||
$stmt->bindParam(":org_id".$i+1, $params[$i]['org_id']);
|
||||
$stmt->bindParam(":spec_id".$i+1, $params[$i]['spec_id']);
|
||||
}
|
||||
$stmt->execute();
|
||||
$log = date('Y-m-d H:i:s') . " Запрос выполнен успешно!";
|
||||
file_put_contents(__DIR__ . '/../database.log', $log . PHP_EOL, FILE_APPEND);
|
||||
} catch (PDOException $e) {
|
||||
$log = date('Y-m-d H:i:s') . " Ошибка запроса:" . $e->getMessage();
|
||||
file_put_contents(__DIR__ . '/../database.log', $log . PHP_EOL, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user