Добавлен класс 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user