getMessage() . "\n"; return $ans; } return 0; } function updateRemoteData() { global $DATAACCESS_TOKEN; global $APP_NAME; $string = file_get_contents("https://git.aliberksandikci.com.tr/api/v1/repos/ifl/YurdleBackend/raw/data.toml?access_token=" . $DATAACCESS_TOKEN); if ($string === FALSE) { echo "fileError: Could not read the file or could not get the file from server"; return; } else if (testData($string) != 0) { echo "parseError: " . testData($string); return; } else { $file = __DIR__ . "/../data.toml"; file_put_contents($file, $string, LOCK_EX); } chmod("$file", 0700); chown("$file", $APP_NAME); parseTOML(); // not necessary echo "success"; } # Choose the todays person (running each day with cronjob) function chooseTodayPerson() { global $APP_NAME; $data = parseTOML()["data"]; $personArr = array(); foreach ($data as $key => $value) { array_push($personArr, $key); } print_r($personArr); srand(); $random_number = random_int(0, count($personArr) - 1); $choosen = $personArr[$random_number]; // TODO control each person if already choosed recently? (make all persons avaliable AFTER all of them choosed ) $string = " aliberk_sandikci24 function reversePerson($str) { $data = parseTOML()["data"]; foreach ($data as $key => $value) { if ($value["isim_soyisim"] == $str) { return $key; } } } # compare a person with todays person, returns equalities (0-red, 1-orange, 2-green, 10-orange(küçük), 12-orange(büyük)) function comparePerson($person) { global $TODAYS_PERSON; $statGuess = getAPersonStats($person); $statTodays = getAPersonStats($TODAYS_PERSON); $kriterler = parseTOML()["public"]["kriterler"]; // $RESULT = array_fill(0, count($kriterler), 0); for ($i = 0; $i < count($kriterler); $i++) { $curCrit = array_keys($kriterler)[$i]; switch (array_values($kriterler)[$i]) { case 'comp': $RESULT[$curCrit] = [compareCOMP($statGuess[$curCrit], $statTodays[$curCrit]), $statGuess[$curCrit]]; break; case 'arr': $RESULT[$curCrit] = [compareARR($statGuess[$curCrit], $statTodays[$curCrit], $curCrit), $statGuess[$curCrit]]; break; default: $RESULT[$curCrit] = [compareEQ($statGuess[$curCrit], $statTodays[$curCrit]), $statGuess[$curCrit]]; break; } } return $RESULT; } # compare 2 data in EQ format function compareEQ($guess, $todays) { if ($guess == $todays) { return 2; } else { return 0; } } # compare 2 data in COMP format function compareCOMP($guess, $todays) { if ($guess == $todays) { return 2; } else if ($guess <= $todays) { return 12; } else { return 10; } } # compare 2 data in ARR format function compareARR($guess, $todays, $krit) { $equalNum = 0; foreach ($guess as $key1 => $value1) { foreach ($todays as $key2 => $value2) { if ($value1 == $value2) { $equalNum++; } } } if ($equalNum == 0) { return 0; } else if ($equalNum == count($todays) && $equalNum == count($guess)) { return 2; } else if ($equalNum >= 1) { return 1; } else { return 0; } } # get a person stat, can be used in other functions function getAPersonStats($person) { return parseTOML()["data"][$person]; } # parse toml function parseTOML() { global $parser; $array = $parser::ParseFile(__DIR__ . "/../data.toml"); return $array; } if ($_POST['updateData'] != null && $_POST['updateData'] == "yes") { updateRemoteData(); }