/** * @inheritdoc * @throws ParserExceprion */ public function parseClients() { $html = $this->getClientsPage(); $js = $html->search_noise('new RichFaces.ui.Select("accountDetailPanel:j_idt'); //get raw html with clients $clients = Parser::getJsonArray($js, 'clientSelectItems'); //debug //$clients = array(0 => array('id' => 'accountDetailPanel:j_idt77:j_idt77Item0', 'label' => '357010219510 (Sight Account - EUR - FEKOTRIS INVESTMENTS LIMITED )', 'value' => 'e0579306-ad71-4997-b9b6-c1dc0d530a96')); if (empty($clients)) { throw new ParserExceprion("Can't find clients"); } $this->status = self::OK; $this->save(); //get ID for linking $transaction = Yii::$app->db->beginTransaction(); try { foreach ($clients as $client) { if (preg_match('/^(\\d+) \\(Sight Account - (\\w+) - (.+) \\)$/', $client['label'], $m)) { $companyName = $m[3]; $currency = $m[2]; $company = new Company(); $company->name = $companyName; $company->currency = $currency; $company->risk = $company->parseRisk(); if ($company->skip) { continue; //do not add } $company->link('bank', $this); $company->params = ['hash' => $client['value'], 'htmlId' => $this->parseHtmlId($client['id']), 'raw' => $client['label']]; $company->save(); } } $transaction->commit(); } catch (ParserExceprion $e) { $transaction->rollBack(); throw $e; } return self::OK; }