function getTactics(fixtureId, label, venueName, thn, tan, isMobile, imageURL) {
getData('fixtures/' + fixtureId + '/analysis/fixture/last/detail',
null,
(data) => {
// console.log(data);
if (!data?.fixture) {
return;
}
const width = 1080;
const height = 608;
const top = 40;
const left = 140;
const pw = 70;
const ph = 64;
const areaWidth = width / 2 - left;
const areaHeight = height * 0.87;
const teams = { 'home': [], 'away': [] };
const teamTypes = ['home', 'away'];
const fixtureData = data.fixture;
if (fixtureData && fixtureData.team_home_tactic && fixtureData.team_home_tactic?.substitutes) {
for (const i in fixtureData.team_home_tactic.substitutes) {
teams['home'].push(fixtureData.team_home_tactic.substitutes[i]);
}
}
if (fixtureData && fixtureData.team_away_tactic && fixtureData.team_away_tactic?.substitutes) {
for (const i in fixtureData.team_away_tactic.substitutes) {
teams['away'].push(fixtureData.team_away_tactic.substitutes[i]);
}
}
const players = [];
if (fixtureData) {
let palyers_ = [];
if (fixtureData['fixture']) {
palyers_ = fixtureData['fixture']['players'];
} else {
if (fixtureData['team_home_tactic'] && fixtureData['team_home_tactic']['players']) {
palyers_ = palyers_.concat(fixtureData['team_home_tactic']['players']);
}
if (fixtureData['team_away_tactic'] && fixtureData['team_away_tactic']['players']) {
palyers_ = palyers_.concat(palyers_, fixtureData['team_away_tactic']['players']);
}
}
for (const i in palyers_) {
const ts = palyers_[i];
for (const j in ts.players) {
const p = ts.players[j];
id = p['player']['id'];
players[id] = {
'goal': 0,
'assist': 0,
'yellow': 0,
'red': 0,
'minutes': 0,
'substitute': false,
};
if (p['statistics'] && p['statistics'][0]) {
const s = p['statistics'][0];
if (s['goals']) {
players[id]['goal'] = s['goals']['total'];
players[id]['assist'] = s['goals']['assists'];
}
if (s['cards']) {
players[id]['yellow'] = s['cards']['yellow'];
players[id]['red'] = s['cards']['red'];
}
if (s['games']) {
players[id]['minute'] = s['games']['minutes'];
players[id]['substitute'] = s['games']['substitute'];
}
}
}
}
}
const arrayUnshift = (arr, ...elements) => {
return elements.concat(arr);
}
let f, cc, r_, c_, gridW, gridH, t, l, col, row, formation, rc;
html = ``;
html += ``;
if (label) {
html += `${label}
`;
}
html += ``;
html += `
`;
if (!isMobile) {
html += `
`;
if (fixtureData) {
if (venueName) {
html += `
สนาม: ${venueName}
`;
}
if (fixtureData['fixture']) {
html += `
กรรมการ: ${fixtureData['fixture']['fixture']['referee']}
`;
}
html += `
${fixtureData['team_home_tactic']['formation']}
`;
html += `
${fixtureData['team_away_tactic']['formation']}
`;
}
html += `
`;
html += `
`;
if (fixtureData.team_home_tactic && fixtureData.team_home_tactic?.start_XI) {
formation = fixtureData['team_home_tactic']['formation'];
if (!formation) {
formation = '4-4-2';
}
f = formation.split('-');
cc = f.length;
gridW = areaWidth / cc;
f = arrayUnshift(f, '', '1');
r_ = 1;
c_ = 2;
for (const k in fixtureData['team_home_tactic']['start_XI']) {
const p = fixtureData['team_home_tactic']['start_XI'][k];
t = 0;
l = 0;
if (p['pos'] == 'G' || (!p['pos'] && k == 0)) {
t = top + (areaHeight - ph) / 2;
l = width * .05;
} else {
if (p['grid']) {
let g = p['grid'].split(':');
col = g[0];
row = g[1];
} else {
col = c_;
row = r_;
r_++;
if (r_ > 4) {
c_++;
r_ = 1;
}
}
rc = f[col];
gridH = areaHeight / rc;
t = top + (row - 1) * gridH + (gridH - ph) / 2;
l = left + (col - 2) * gridW + (gridW - pw) / 2;
}
html += renderPlayerLineUp(p, `top:${t}px;left:${l}px`, players, imageURL);
}
}
if (fixtureData['team_away_tactic'] && fixtureData.team_away_tactic?.start_XI) {
formation = fixtureData['team_away_tactic']['formation'];
if (!formation) {
formation = '4-4-2';
}
f = formation.split('-');
cc = f.length;
gridW = areaWidth / cc;
f = arrayUnshift(f, '', '1');
r_ = 1;
c_ = 2;
for (const k in fixtureData['team_away_tactic']['start_XI']) {
const p = fixtureData['team_away_tactic']['start_XI'][k];
t = 0;
l = 0;
if (p['pos'] == 'G' || (!p['pos'] && k == 0)) {
t = top + (areaHeight - ph) / 2;
l = width - width * .05 - pw;
} else {
if (p['grid']) {
g = p['grid'].split(':');
col = g[0];
row = g[1];
} else {
col = c_;
row = r_;
r_++;
if (r_ > 4) {
c_++;
r_ = 1;
}
}
rc = f[col];
gridH = areaHeight / rc;
t = top + (row - 1) * gridH + (gridH - ph) / 2;
l = width - (left + (col - 2) * gridW + (gridW - pw) / 2) - pw;
}
html += renderPlayerLineUp(p, `top:${t}px;left:${l}px`, players, imageURL);
}
}
html += `
`;
html += `
`;
html += `

`;
html += `
`;
html += `
เกมจะเริ่มในอีก
`;
html += `
00 : 00 : 00
`;
html += `
`;
html += `
`;
} else {
html += `
`;
if (fixtureData) {
html += `
กรรมการ: ${venueName}
`;
html += `
${fixtureData['team_home_tactic']['formation']}
`;
html += `
${fixtureData['team_away_tactic']['formation']}
`;
}
html += `
`;
html += `
`;
if (fixtureData.team_home_tactic && fixtureData.team_home_tactic?.start_XI) {
formation = fixtureData['team_home_tactic']['formation'];
if (!formation) {
formation = '4-4-2';
}
f = formation.split('-');
cc = f.length;
gridW = areaWidth / cc;
f = arrayUnshift(f, '', '1');
r_ = 1;
c_ = 2;
for (const k in fixtureData['team_home_tactic']['start_XI']) {
const p = fixtureData['team_home_tactic']['start_XI'][k];
t = 0;
l = 0;
if (p['pos'] == 'G' || (!p['pos'] && k == 0)) {
t = top + (areaHeight - ph) / 2;
l = width * .05;
} else {
if (p['grid']) {
g = p['grid'].split(':');
col = g[0];
row = g[1];
} else {
col = c_;
row = r_;
r_++;
if (r_ > 4) {
c_++;
r_ = 1;
}
}
rc = f[col];
// dd(rc, formation, col);
gridH = areaHeight / rc;
t = top + (row - 1) * gridH + (gridH - ph) / 2;
l = left + (col - 2) * gridW + (gridW - pw) / 2;
}
html += renderPlayerLineUp(p, `top:${t}px;left:${l}px`, players, imageURL);
}
}
if (fixtureData.team_away_tactic && fixtureData.team_away_tactic?.start_XI) {
formation = fixtureData['team_away_tactic']['formation'];
if (!formation) {
formation = '4-4-2';
}
f = formation.split('-');
cc = f.length;
gridW = areaWidth / cc;
f = arrayUnshift(f, '', '1');
r_ = 1;
c_ = 2;
for (const k in fixtureData['team_away_tactic']['start_XI']) {
const p = fixtureData['team_away_tactic']['start_XI'][k];
t = 0;
l = 0;
if (p['pos'] == 'G' || (!p['pos'] && k == 0)) {
t = top + (areaHeight - ph) / 2;
l = width - width * .05 - pw;
} else {
if (p['grid']) {
g = p['grid'].split(':');
col = g[0];
row = g[1];
} else {
col = c_;
row = r_;
r_++;
if (r_ > 4) {
c_++;
r_ = 1;
}
}
rc = f[col];
gridH = areaHeight / rc;
t = top + (row - 1) * gridH + (gridH - ph) / 2;
l = width - (left + (col - 2) * gridW + (gridW - pw) / 2) - pw;
}
html += renderPlayerLineUp(p, `top:${t}px;left:${l}px`, players, imageURL);
}
}
html += `
`;
html += `
`;
html += `

`;
html += `
`;
html += `
เกมจะเริ่มในอีก
`;
html += `
00 : 00 : 00
`;
html += `
`;
html += `
`;
}
html += `
`;
if (players.length) {
html += `
`;
html += `
`;
for (const team in teams) {
const ps = teams[team];
html += `
`;
html += `
`;
if (team == 'home') {
html += `
`;
html += `
${homeTeam}
`;
html += `
`;
} else {
html += `
`;
html += `
${awayTeam}
`;
html += `
`;
}
for (const k in ps) {
const p = ps[k];
html += `
`;
html += `
`;
html += `
![${p['name']}](${p['photo'] ? imageURL + p['photo'] : '/images/icons/user.svg'})
`;
if (p['rating'] !== '') {
r = p['rating'];
bg = '';
c = 'text-white ';
if (r >= 8.1) {
bg = 'bg-success';
} else if (r >= 6.1) {
bg = 'bg-warning';
c = '';
} else {
bg = 'bg-danger';
}
html += `
${p.rating.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}
`;
}
html += `
`;
html += `
${p['pos']}
`;
html += `
${p['number']}`;
html += `
${p['name']}`;
if (players[p['id']] && players[p['id']]['goal']) {
for (i = 0; i < players[p['id']]['goal']; i++) {
html += `

`;
}
}
if (players[p['id']] && players[p['id']]['assist']) {
for (i = 0; i < players[p['id']]['assist']; i++) {
html += `

`;
}
}
if (players[p['id']] && players[p['id']]['yellow']) {
for (i = 0; i < players[p['id']]['yellow']; i++) {
html += `

`;
}
}
if (players[p['id']] && players[p['id']]['red']) {
for (i = 0; i < players[p['id']]['red']; i++) {
html += `

`;
}
}
html += `
`;
}
html += `
`;
html += `
`;
}
html += `
`;
html += `
`;
}
html += `
`;
html += ``;
$('#lastFixtureSection').html(html);
validateFormation();
},
(error) => {
console.log(error);
});
}
function renderPlayerLineUp(p, s, map, imageURL) {
html = ``;
html += `
`;
html += `
`;
html += `
![${p['name']}](${p['photo'] ? imageURL + p['photo'] : '/images/icons/user.svg'})
`;
html += `
${p['name']}
`;
html += `
#${p['number']}
`;
if (p['rating'] !== '') {
r = p['rating'];
bg = '';
c = 'text-white ';
if (r >= 8.0) {
bg = 'bg-success';
} else if (r >= 7.0) {
bg = 'bg-warning';
c = '';
} else if (r >= 6.0) {
bg = 'bg-info';
c = '';
} else {
bg = 'bg-danger';
}
html += `
${p.rating.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}
`;
x = 5;
if (map[p['id']] && map[p['id']]['goal']) {
for (i = 0; i < map[p['id']]['goal']; i++) {
html += `

`;
x -= 18;
}
}
if (map[p['id']] && map[p['id']]['assist']) {
for (i = 0; i < map[p['id']]['assist']; i++) {
html += `

`;
x -= 18;
}
}
if (map[p['id']] && map[p['id']]['yellow']) {
for (i = 0; i < map[p['id']]['yellow']; i++) {
html += `

`;
x -= 18;
}
}
if (map[p['id']] && map[p['id']]['red']) {
for (i = 0; i < map[p['id']]['red']; i++) {
html += `

`;
x -= 18;
}
}
}
html += `
`;
html += `
`;
return html;
}