Добавлен класс ContingentManager и начата обработка неудачных попыток парсинга (запись в yaml-файл)
This commit is contained in:
88
app/library/ContingentManager.php
Normal file
88
app/library/ContingentManager.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace App\Library;
|
||||
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
|
||||
|
||||
final class ContingentManager
|
||||
{
|
||||
private static ?ContingentManager $instance;
|
||||
private ?GenericBuilder $builder;
|
||||
private function __construct()
|
||||
{
|
||||
$this->builder = new GenericBuilder();
|
||||
}
|
||||
|
||||
public static function getInstance() : ContingentManager
|
||||
{
|
||||
self::$instance ??= new self();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function getSites(Database $db): array
|
||||
{
|
||||
// select kod as org_id, site from niimko.s_vuzes
|
||||
// where ootype = 'vuz' and deleted = 'n' and fake = 'n'
|
||||
$params = ['vuz', 'n', 'n'];
|
||||
$query = $this->builder->select()
|
||||
->setTable('s_vuzes')
|
||||
->setColumns(['org_id' => 'kod', 'site'])
|
||||
->where('AND')
|
||||
->equals('ootype', 'vuz')
|
||||
->equals('deleted', 'n')
|
||||
->equals('fake', 'n')
|
||||
->end();
|
||||
$sql = $this->builder->write($query);
|
||||
$sites = $db->executeQuery($sql, $params);
|
||||
|
||||
return $sites;
|
||||
}
|
||||
|
||||
public function getSpecializations(Database $db) : array
|
||||
{
|
||||
// select id, kod from niimko.s_specs where oopkodes = 'gos3p'
|
||||
$params = ['gos3p'];
|
||||
$query = $this->builder->select()
|
||||
->setTable('s_specs')
|
||||
->setColumns(['id', 'kod'])
|
||||
->where()
|
||||
->equals('oopkodes','gos3p')
|
||||
->end();
|
||||
$sql = $this->builder->write($query);
|
||||
$specializations = $db->executeQuery($sql, $params);
|
||||
|
||||
return $specializations;
|
||||
}
|
||||
|
||||
public function buildURL(string $url): string
|
||||
{
|
||||
// TODO - сделать base_url
|
||||
$url = "$url/sveden/education/";
|
||||
if (str_contains($url, "http://")) {
|
||||
$url = str_replace("http://","https://", $url);
|
||||
} else {
|
||||
$url = "https://$url";
|
||||
}
|
||||
$url = str_replace("www.","", $url);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function addSpecId(array &$contingent, array $specializations) : void
|
||||
{
|
||||
foreach ($contingent as $key => $con) {
|
||||
$needle = $con['spec_code'];
|
||||
foreach ($specializations as $spec) {
|
||||
if ($needle == $spec['kod']) {
|
||||
$cont['spec_id'] = $spec['id'];
|
||||
}
|
||||
}
|
||||
$contingent[$key]['spec_id'] = $cont['spec_id'];
|
||||
}
|
||||
}
|
||||
|
||||
public function addOrgId(array &$contingent, int $orgId) : void
|
||||
{
|
||||
for($i = 0; $i < count($contingent); $i++) {
|
||||
$contingent[$i]['org_id'] = $orgId;
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ class Database
|
||||
$password,
|
||||
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
|
||||
);
|
||||
echo "Подлючено успешно!\n";
|
||||
print("Подлючено успешно!\n");
|
||||
} catch (PDOException $e) {
|
||||
echo "Ошибка подключения:". $e->getMessage() . "\n";
|
||||
}
|
||||
@ -34,9 +34,9 @@ class Database
|
||||
{
|
||||
try {
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$params = array_values($params);
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$stmt->bindParam(":v".$i++, $params[$i]);
|
||||
// $params = array_values($params);
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$stmt->bindParam(":v".$i+1, $params[$i]);
|
||||
}
|
||||
$stmt->execute();
|
||||
$array = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
Reference in New Issue
Block a user