<?php
use DiDom\Document;
class Task_Matches extends Minion_Task {
protected static $_timeout = 3;
protected function _execute(array $params) {
$matches = array();
// Загрузка HTML кода страницы матчей
$document = new Document('http://www.hltv.org/results/', true);
$elements = $document->find('div.matchListRow');
// Преобразование матчей до массива
foreach($elements as $element) {
$match['match_format'] = $element->find('div.matchTimeCell')[0]->text(); // ТУТ ОШИБКА
//PHP Parse error: syntax error, unexpected '['
$match['team1_name'] = $element->find('div.matchTeam1Cell')[0]->text();
$match['team1_logo'] = $element->find('div.matchTeam1Cell')[0]->find('span')[0]->find('img')[0]->attr('src');
$match['result1'] = $element->find('div.matchScoreCell')[0]->find('span')[0]->text();
$match['result2'] = $element->find('div.matchScoreCell')[0]->find('span')[1]->text();
$match['team2_name'] = $element->find('div.matchTeam2Cell')[0]->find('a')[0]->text();
$match['team2_logo'] = $element->find('div.matchTeam2Cell')[0]->find('span')[0]->find('img')[0]->attr('src');
$match['details_link'] = $element->find('div.matchActionCell')[0]->find('a')[0]->attr('href');
$match['enabled'] = 1;
$match['date'] = time();
$matches[] = $match;
Minion_CLI::write($match['date']);
}
Minion_CLI::write('Detected '. count($matches) . ' matches ');
<?php
use DiDom\Document;
class Task_Matches extends Minion_Task {
protected static $_timeout = 3;
/**
* @param array $params
*/
protected function _execute(array $params) {
$matches = array();
// Загрузка HTML кода страницы матчей
$document = new Document('http://www.hltv.org/results/', true);
$elements = $document->find('div.matchListRow');
// Преобразование матчей до массива
foreach($elements as $element) {
//Временный багфикс
$match_format = $element->find('div.matchTimeCell');
$team1_name = $element->find('div.matchTeam1Cell');
$team1_logo = $element->find('div.matchTeam1Cell span img');
$result1 = $element->find('div.matchScoreCell span');
$result2 = $element->find('div.matchScoreCell span');
$team2_name = $element->find('div.matchTeam2Cell');
$team2_logo = $element->find('div.matchTeam2Cell span img');
$details = $element->find('div.matchActionCell a');
//Получаем данные 1-го матча
$match = array(
'match_format' => $match_format[0]->text(),
'team1_name' => $team1_name[0]->text(),
'team1_logo' => $team1_logo[0]->attr('src'),
'result1' => $result1[0]->text(),
'result2' => $result2[1]->text(),
'team2_name' => $team2_name[0]->text(),
'team2_logo' => $team2_logo[0]->attr('src'),
'details_link' => $details[0]->attr('href'),
'enabled' => 1,
'date' => time(),
);
$matches[] = $match;
Minion_CLI::write($match['date']);
}
Minion_CLI::write('Detected: '. count($elements) . ' matches');
foreach($matches as $match) {
$match_orm = new Model_Match;
// Загрузка матча, если он уже есть в БД
$match_orm->where('details_link', '=', $match['details_link'])->find();
// Внесение новых данных о матче
$match_orm->values($match);
$match_orm->save();
}
Minion_CLI::write('Ready!');
}
}
$match = [
'match_format' => $element->find('div.matchTimeCell')[0]->text()
];