Skip to content

Commit

Permalink
extract source link (permalink)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubosdz committed Oct 21, 2024
1 parent bb3fb35 commit 35b57ce
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
35 changes: 30 additions & 5 deletions ConnectorOrsr.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class ConnectorOrsr
/** @var array Extracted data */
protected $data = [];

/** @var string e.g. "ID=54190&SID=7&P=0" URL to source page, where data have been downloaded from, napr. zaznam firmy v ORSR */
protected $srcUrl;

/** @var bool Semaphore to avoid double output, e.g. if matched 1 item (DIC, ICO) we instantly return detail */
protected $outputSent = false;

Expand Down Expand Up @@ -211,6 +214,14 @@ protected function msleep($msec = 0)
}
}

/**
* Return source URL link from which last data have been fetched
*/
public function getSrcUrl()
{
return $this->srcUrl;
}

/**
* Clear previosuly extracted data & semaphore that output has been already sent
* Use e.g. to re-send request with the same instance
Expand All @@ -219,6 +230,7 @@ public function resetOutput()
{
$this->outputSent = false;
$this->data = [];
$this->srcUrl = null;
}

/**
Expand Down Expand Up @@ -363,6 +375,10 @@ public function getOutput()
] + $this->data;
}

if($this->srcUrl && empty($this->data['srcUrl'])){
$this->data['srcUrl'] = $this->srcUrl;
}

$this->outputSent = true;

if ($this->debug) {
Expand Down Expand Up @@ -397,26 +413,27 @@ public function getOutput()
* Fetch company page from ORSR and return parsed data
* @param int $id Company database identifier, e.g. 19456
* @param int $sid ID 0 - 8, prislusny sud/judikatura (jurisdiction district ID)
* @param int $p 0|1 Typ vypisu, default 0 = aktualny, 1 - uplny (vratane historickych zrusenych zaznamov)
* @param int $plny 0|1 Typ vypisu, default 0 = aktualny, 1 - uplny (vratane historickych zrusenych zaznamov)
* @param bool $onlyHtml If true return only fetched HTML, dont parse into attributes
*/
public function getDetailById($id, $sid, $p = 0, $onlyHtml = false)
public function getDetailById($id, $sid, $plny = 0, $onlyHtml = false)
{
$id = intval($id);
if ($id < 1) {
throw new \Exception('Invalid company ID.');
}

$hash = $id . '-' . $sid . '-' . $p;
$path = $this->dirCache . 'orsr-detail-' . $hash . '-raw.html';
$this->srcUrl = "vypis.asp?ID={$id}&SID={$sid}&P={$plny}"; // without repetitive "https://www.orsr.sk/"
$hash = $id . '-' . $sid . '-' . $plny;
$path = $this->dirCache . 'orsr-detail-' .$hash. '-raw.html';

if ($this->debug && is_file($path) && filesize($path)) {
$html = file_get_contents($path);
} else {
// ID + SID = jedinecny identifikator subjektu
// SID (ID sudu dla kraja) = 1 .. 8 different companies :-(
// P = 1 - uplny, otherwise 0 = aktualny
$url = self::URL_BASE . "/vypis.asp?ID={$id}&SID={$sid}&P={$p}";
$url = self::URL_BASE . "/{$this->srcUrl}";
$html = $this->loadUrl($url);
if ($html && $this->debug) {
file_put_contents($path, $html);
Expand Down Expand Up @@ -454,6 +471,9 @@ public function getDetailByPartialLink($link, $onlyHtml = false)

if (isset($params['ID'], $params['SID'], $params['P'])) {
$data = $this->getDetailById($params['ID'], $params['SID'], $params['P'], $onlyHtml);
if($data && is_array($data) && $this->srcUrl){
$data['srcUrl'] = $this->srcUrl;
}
}
}

Expand Down Expand Up @@ -841,6 +861,11 @@ protected function extractDetail($html)
}
}

// add source ORSR link
if ($this->srcUrl) {
$this->data['srcUrl'] = $this->srcUrl;
}

// add meta data
$this->data = [
'meta' => [
Expand Down
14 changes: 10 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Príklad odpovede:
----------------

```
// sample #1
$list = $orsr->findByObchodneMeno('Matador');
$list : array (
Expand All @@ -107,7 +108,7 @@ $list : array (
'MATADOR-TOYS, s. r. o.' => 'vypis.asp?ID=313211&SID=6&P=0',
)
// sample #2
$detail = $orsr->getDetailById(1319, 9); // z linky 'vypis.asp?ID=1319&SID=9&P=0'
$detail : Array
Expand Down Expand Up @@ -234,7 +235,7 @@ $("#company_ico").on("keyup", function(){
alert("Zadajte len číslice 0-9.");
}else{
$.ajax({
url: "/orsr/find-detail-by-ico",
url: "/orsr/find-detail-by-ico", // implement your own OrsrController
data: {ico: ico},
success: function (response) {
if(response.ico != undefined && response.ico){
Expand All @@ -255,10 +256,15 @@ $("#company_ico").on("keyup", function(){
Changelog
=========

1.1.2 - 21.10.2024
------------------
* ENH - store fetched source link (permalink) as attribute "srcUrl" along with extracted data
* ENH - documentation improvements - see [demo](https://synet.sk/blog/php/360-ORSR-API-rozhranie-obchodny-register)

1.1.1 - 16.10.2024
------------------
* ENH - Extract Kontrolná komisia
* FIX - multiple minor parsing improvements - hodnota akcií, štatutári, neštandardné poznámky pri mene osôb apod.
* ENH - extract Kontrolná komisia
* ENH - multiple minor parsing improvements - hodnota akcií, štatutári, neštandardné poznámky osobách apod.

1.1.0 - 13.11.2023
------------------
Expand Down

0 comments on commit 35b57ce

Please sign in to comment.