Changeset 19
- Timestamp:
- Sep 6, 2019, 9:44:30 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Database.php
r10 r19 57 57 $this->LogFile = dirname(__FILE__).'/../../Query.log'; 58 58 } 59 59 60 60 61 61 function Connect($Host, $User, $Password, $Database) … … 109 109 $this->insert_id = $this->PDO->lastInsertId(); 110 110 } else 111 { 111 { 112 112 $this->Error = $this->PDO->errorInfo(); 113 113 $this->Error = $this->Error[2]; … … 134 134 $this->insert_id = $this->PDO->lastInsertId(); 135 135 } 136 136 137 137 function GetInsert($Table, $Data) 138 138 { … … 158 158 $this->query($this->GetUpdate($Table, $Condition, $Data)); 159 159 } 160 160 161 161 function GetUpdate($Table, $Condition, $Data) 162 162 { … … 219 219 { 220 220 } 221 221 222 222 public function Transaction($Queries) 223 223 { 224 $this->PDO->beginTransaction(); 225 foreach ($Queries as $Query) 226 { 227 $Statement = $this->PDO->prepare($Query); 228 $Statement->execute(); 229 } 230 $this->PDO->commit(); 224 $this->PDO->beginTransaction(); 225 foreach ($Queries as $Query) 226 { 227 $Statement = $this->PDO->prepare($Query); 228 $Statement->execute(); 229 } 230 if (!$this->PDO->commit()) 231 { 232 $this->Error = $this->PDO->errorInfo(); 233 $this->Error = $this->Error[2]; 234 if(($this->Error != '') and ($this->ShowSQLError == true)) 235 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); 236 throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query); 237 } 231 238 } 232 239 } -
trunk/index.php
r18 r19 28 28 var $Database; 29 29 var $Config; 30 var $ Year;30 var $LeaderboardURL; 31 31 32 32 function __construct() 33 33 { 34 $this->LeaderboardURL = 'https://registrace.teribear.cz/Leaderboard'; 34 35 } 35 36 … … 93 94 function QueryRunners($Category, $Page = 0, $TeamId = null, $Query = null, $StartNumber = null, $Count = null) 94 95 { 95 $URL = 'https://registrace.teribear.cz/Leaderboard/Home/GetRunners?category='.$Category;96 $URL = $this->LeaderboardURL.'/Home/GetRunners?category='.$Category; 96 97 if ($Page != 0) $URL .= '&page='.$Page; 97 98 if ($TeamId != null) $URL .= '&teamId='.$TeamId; … … 179 180 } else 180 181 { 181 if (!array_key_exists($Item['TeamId'], $Teams)) 182 { 183 $TeamId = $NextTeamId; 184 $Queries[] = $this->Database->GetInsert('Team', array( 185 'Id' => $TeamId, 186 'Name' => '', 187 'WebId' => $Item['TeamId'], 188 'Year' => $Year, 189 )); 190 $Teams[$Item['TeamId']] = array('Id' => $TeamId, 'Distance' => -1); 191 $NextTeamId++; 192 } else 193 $TeamId = $Teams[$Item['TeamId']]['Id']; 182 if (!array_key_exists($Item['TeamId'], $Teams)) 183 { 184 $TeamId = $NextTeamId; 185 $Queries[] = $this->Database->GetInsert('Team', array( 186 'Id' => $TeamId, 187 'Name' => '', 188 'WebId' => $Item['TeamId'], 189 'Year' => $Year, 190 'IsFamily' => 0, 191 )); 192 $Teams[$Item['TeamId']] = array('Id' => $TeamId, 'Distance' => -1); 193 $NextTeamId++; 194 } else 195 $TeamId = $Teams[$Item['TeamId']]['Id']; 194 196 } 195 197 … … 223 225 if (($Item['Type'] == 'team') or ($Item['Type'] == 'rodina')) 224 226 { 227 if ($Item['Type'] == 'rodina') $IsFamily = 1; 228 else $IsFamily = 0; 225 229 if (!array_key_exists($Item['GroupId'], $Teams)) 226 230 { 227 if ($Item['Type'] == 'rodina') $IsFamily = 1;228 else $IsFamily = 0;229 231 $Queries[] = $this->Database->GetInsert('Team', array( 230 232 'Id' => $NextTeamId, … … 240 242 $TeamId = $Teams[$Item['GroupId']]['Id']; 241 243 244 242 245 // Update missing team names 243 if ($Teams[ 'Name'] == "")246 if ($Teams[$Item['GroupId']]['Name'] == "") 244 247 { 245 $Queries[] = $this->Database->GetUpdate('Team', 'Id='.$Team['Id'], array('Name' => $Item['Name'])); 246 $Teams['Name'] = $Item['Name']; 247 echo($Team['Name'].' '); 248 $Queries[] = $this->Database->GetUpdate('Team', 'Id='.$TeamId, array( 249 'Name' => $Item['Name'], 250 'IsFamily' => $IsFamily 251 )); 252 $Teams[$Item['GroupId']]['Name'] = $Item['Name']; 253 $Teams[$Item['GroupId']]['IsFamily'] = $IsFamily; 248 254 } 249 255 … … 262 268 } 263 269 //print_r($Queries); 270 //foreach ($Queries as $Query) $this->Database->query($Query); 264 271 $this->Database->Transaction($Queries); 265 272 } … … 269 276 $Time = time(); 270 277 $Items = $this->QueryRunnersAll(); 271 //print_r($Items);272 278 $ItemsWithoutProgress = array(); 273 279 foreach ($Items as $Item) … … 292 298 'ItemCount' => count($Items) 293 299 )); 294 file_put_contents('/home/teribear/www/import/'.$Hash.'.txt', print_r($Items, true));300 //file_put_contents('import/'.$Hash.'.txt', print_r($Items, true)); 295 301 } 296 302 } … … 301 307 $Output .= '<div class="page-title">Families</div>'; 302 308 303 $Year = 1;309 $Year = 0; 304 310 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != '')) 305 311 $Year = $this->PathItems[count($this->PathItems) - 1] * 1; … … 419 425 $Output .= '<div class="page-title">Teams</div>'; 420 426 421 $Year = 1;427 $Year = 0; 422 428 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != '')) 423 429 $Year = $this->PathItems[count($this->PathItems) - 1] * 1; … … 537 543 $Output = '<div class="page-title">Runners</div>'; 538 544 539 $Year = 1;545 $Year = 0; 540 546 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != '')) 541 547 $Year = $this->PathItems[count($this->PathItems) - 1] * 1; … … 711 717 { 712 718 $Output = ''; 713 $Output .= '<p>This website collects data from offical <a href=" http://leaderboard.teribear.cz/">leaderboard</a> site and tracks and presents progress of runners.</p>';714 $Output .= '<div class="page-title">Summary '.$Year.'</div>';719 $Output .= '<p>This website collects data from offical <a href="'.$this->LeaderboardURL.'">leaderboard</a> site and tracks and presents progress of runners.</p>'; 720 $Output .= '<div class="page-title">Summary</div>'; 715 721 716 722 $Year = 0; … … 772 778 $this->Database->Prefix = $this->Config['Database']['Prefix']; 773 779 $this->Database->charset($this->Config['Database']['Charset']); 780 //$this->Database->ShowSQLError = true; 774 781 $this->PathItems = $this->ProcessURL(); 775 782
Note:
See TracChangeset
for help on using the changeset viewer.