public function retrieveEvents() { $url = NEFUB_ROOT . '/../pages/default.asp?subject_id=20'; $postData = array('category_id' => 205); $html = $this->getNefubContents($url, 2, $postData); if (!$html) { $this->retrieveLog->successfully = 0; } else { $this->retrieveLog->successfully = 1; } $this->retrieveLog->finish_time = date('Y-m-d H:i:s'); $this->retrieveLog->total_time = $this->retrieveLog->getDuration(); $this->retrieveLog->finished = 1; $this->retrieveLog->save(); $pattern = '|<td width=\\"100\\" valign=top class=\\"kalender_subtitle\\">(.*){4,16}<td valign=top class=\\"kalender_subtitle\\">([^<]{4,})<br|U'; $result = array(); preg_match_all($pattern, $html, $result, PREG_SET_ORDER); $aEvents = array(); foreach ($result as $event) { /* [35]: Array [35][0]: <td width="100" valign=top class="kalender_subtitle">za. 12.04.2014</td><td valign=top class="kalender_subtitle"> NeFUB Competitie ronde 15 <br [35][1]: za. 12.04.2014</td> [35][2]: NeFUB Competitie ronde 15 */ $nefubName = utf8_encode(trim($event[2])); $lowerName = strtolower($nefubName); $oGenre = null; $oGender = null; $oGender2 = null; if (strpos($lowerName, 'jeugd') !== false) { $oGenre = Genre::getByNefubName(GENRE_JEUGD_NEFUB_NAME); $oGender = Gender::getByNefubName(GENDER_MIXED_NEFUB_NAME); } elseif (strpos($lowerName, 'mixed') !== false) { $oGenre = Genre::getByNefubName(GENRE_COMPETITIE_NEFUB_NAME); $oGender = Gender::getByNefubName(GENDER_MIXED_NEFUB_NAME); } else { if (strpos($lowerName, 'heren') !== false) { $oGender = Gender::getByNefubName(GENDER_HEREN_NEFUB_NAME); } elseif (strpos($lowerName, 'dames') !== false) { $oGender = Gender::getByNefubName(GENDER_DAMES_NEFUB_NAME); } else { $oGender = Gender::getByNefubName(GENDER_HEREN_NEFUB_NAME); $oGender2 = Gender::getByNefubName(GENDER_DAMES_NEFUB_NAME); } if (strpos($lowerName, 'cup') !== false || strpos($lowerName, 'beker') !== false) { $oGenre = Genre::getByNefubName(GENRE_BEKER_NEFUB_NAME); } else { $oGenre = Genre::getByNefubName(GENRE_COMPETITIE_NEFUB_NAME); } } $date = str_replace('</td>', '', $event[1]); $date = array_pop(explode(' ', $date)); $dates = explode('-', $date); if (count($dates) > 1) { if (count($dates) == 2) { $lastDate = array_pop($dates); list($lastDay, $month, $year) = explode('.', trim($lastDate)); $firstDay = $dates[0]; $firstDate = $year . '-' . $month . '-' . $firstDay; $oEvent = self::convertEvent($nefubName, $firstDate, $oGenre, $oGender); $eventIds[] = $oEvent->getId(); if ($oGender2) { $oEvent = self::convertEvent($nefubName, $firstDate, $oGenre, $oGender2); $eventIds[] = $oEvent->getId(); } $lastDate = $year . '-' . $month . '-' . $lastDay; $oEvent = self::convertEvent($nefubName, $lastDate, $oGenre, $oGender); $eventIds[] = $oEvent->getId(); if ($oGender2) { $oEvent = self::convertEvent($nefubName, $firstDate, $oGenre, $oGender2); $eventIds[] = $oEvent->getId(); } self::put("Event " . $nefubName . " toegevoegd"); } else { self::put("Event " . $nefubName . " niet toegevoegd, ongeldige data:"); self::put($date); } } else { list($day, $month, $year) = explode('.', $date); $formattedDate = $year . '-' . $month . '-' . $day; $oEvent = self::convertEvent($nefubName, $formattedDate, $oGenre, $oGender); $eventIds[] = $oEvent->getId(); if ($oGender2) { $oEvent = self::convertEvent($nefubName, $formattedDate, $oGenre, $oGender2); $eventIds[] = $oEvent->getId(); } self::put("Event " . $nefubName . " toegevoegd"); } if (count($eventIds)) { $query = 'DELETE FROM Event WHERE id NOT IN (' . implode(', ', $eventIds) . ') AND season_nefub_id = ' . Season::getInstance()->nefub_id; Database::query($query); } else { Database::delete_rows('Event', array('season_nefub_id' => Season::getInstance()->nefub_id)); } } }
/** * */ public function buildSearchTable() { self::put('Zoekresultaten maken'); // Personen $aPersons = Person::getAll(); $personCount = 0; $deletePersonCount = 0; foreach ($aPersons as $oPerson) { $query = "SELECT DISTINCT(Team.competition_nefub_id), Competition.id\n\t\t\t\t\t\tFROM TeamPerson\n\t\t\t\t\t\tLEFT JOIN Team ON Team.nefub_id = TeamPerson.team_nefub_id\n\t\t\t\t\t\tLEFT JOIN Competition ON Team.competition_nefub_id = Competition.nefub_id\n\t\t\t\t\t\tWHERE TeamPerson.person_nefub_id = '" . $oPerson->nefub_id . "'\n\t\t\t\t\t\tAND Competition.season_nefub_id = '" . Season::getInstance()->nefub_id . "'\n\t\t\t\t\t\tORDER BY Team.competition_nefub_id ASC"; $aCompetitions = Competition::getAllFromQuery($query); $personCompetitions = array(); foreach ($aCompetitions as $oCompetition) { if (trim($oCompetition->name)) { $personCompetitions[] = $oCompetition->name; } } if (count($personCompetitions)) { $oSearchResult = SearchResult::selectByNefubId($oPerson->nefub_id, 'person'); if (!$oSearchResult) { $oSearchResult = new SearchResult(); $oSearchResult->nefub_id = $oPerson->nefub_id; $oSearchResult->type = 'person'; $oSearchResult->url = '/persoon/' . $oPerson->nefub_id; $personCount++; } $oSearchResult->name = $oPerson->name; $oSearchResult->subtitle = implode(', ', $personCompetitions); $oSearchResult->save(); } else { $deletePersonCount += Database::delete_rows('SearchResult', array('nefub_id' => $oPerson->nefub_id, 'type' => 'person')); } } self::put($deletePersonCount . ' perso(o)n(en) verwijderd van zoekresultatenlijst'); self::put($personCount . ' perso(o)n(en) toegevoegd aan zoekresultatenlijst'); // Teams $aTeams = Team::getAll(); $teamCount = 0; $deleteTeamCount = 0; foreach ($aTeams as $oTeam) { if ($oTeam->getCompetition() && $oTeam->season_nefub_id == Season::getInstance()->nefub_id) { $oSearchResult = SearchResult::selectByNefubId($oTeam->nefub_id, 'team'); if (!$oSearchResult) { $oSearchResult = new SearchResult(); $oSearchResult->nefub_id = $oTeam->nefub_id; $oSearchResult->name = $oTeam->name; $oSearchResult->type = 'team'; $oSearchResult->url = '/team/' . $oTeam->nefub_id; $teamCount++; } $oSearchResult->subtitle = $oTeam->getCompetition()->name; $oSearchResult->save(); } else { $deleteTeamCount += Database::delete_rows('SearchResult', array('nefub_id' => $oTeam->nefub_id, 'type' => 'team')); } } self::put($deleteTeamCount . ' team(s) verwijderd van zoekresultatenlijst'); self::put($teamCount . ' team(s) toegevoegd aan zoekresultatenlijst'); }