Author Topic: Special request  (Read 1871 times)

mcfrojd

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Special request
« on: June 12, 2016, 01:28:29 PM »
Hi Corey, or if someone else knows..

How do i modify a copy of statusListener.php so that it output a text file called tdplayers.txt
and the only value in that file is the number of players?

players=20 is the only line i want, and the value (20) is the only thing i want in the .txt file.

Would be very grateful if i was shown how to modify the file to be able to do that.
If so i could use that number on a dashboard in the club.

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 6216
    • View Profile
Re: Special request
« Reply #1 on: June 15, 2016, 10:42:18 AM »
Sorry for the late response.  The TD hosting service is moving the site to a new server, with updated versions of supporting applications, so I've been tied up making that work and putting together a plan for the move.

This is actually pretty easy.  Here's a modified version of statusListener.php:

Code: [Select]
<?php

// receives a POST or GET request from the TD and writes out the included variables
// it's up to the viewer page to interpret those; we do no validation here

$kFileOutput "tdplayers.txt";

$handle fopen($kFileOutput"w");

$playersleft $_GET["playersleft"];

if(
is_null($playersleft))
    
$playersleft $_POST["playersleft"];

fputs($handle"players=$playersleft");

fclose($handle);

?>


Checking both $_GET and $_POST allows for the method to be configured as either GET or POST.  You can omit:

Code: [Select]
if(is_null($playersleft))
    $playersleft = $_POST["playersleft"];

... if you just make sure to set the method as GET in the Status Updates Preferences.

mcfrojd

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Special request
« Reply #2 on: June 15, 2016, 12:15:45 PM »
Great this was really nice..

I was trying to make an adjustment by my self, but it don't seem to work, most likely some coding error by my part.

// rebuysallowed
$kFileOutput = "tdrebuysallowed.txt";
$handle = fopen($kFileOutput, "w");
$rebuysallowed = $_GET["rebuysallowed"];
if $rebuysallowed = "1"
fputs($handle, "Yes")
else
fputs($handle, "No");
fclose($handle);

As you can see i try to achieve that the file tdrebuysallowed.txt will contain "Yes" or "No" instead of the value "1" or "0"
But my coding skills are not good enough.

You can see a default mock up of my info dash i will use at the club here https://www.thedash.com/dashboard/ByOATlkB/fullscreen
Also possible to use in mobile for the players. (easy to setup a cheap raspberry pi to any tv / monitor and use as free dash with TD info in it.

mcfrojd

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Special request
« Reply #3 on: June 15, 2016, 12:37:25 PM »
One token i really would like for the status update is a token for the number of players added to the tournament (not buyin only in the list on the players tab.)
Today there is many tokens for players, but only if they have been buyin and when tournament is started:

buyins=7
numberofplayers=7
n=7
numberofleaguemembers=7
nm=7
playersleft=6
players=6

Maybe a "playersadded=" would be nice.
Now i have to buy them in and then when they arrive and make the payment i have to tick "paid in full", it works but doesn't feel optimal.

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 6216
    • View Profile
Re: Special request
« Reply #4 on: June 16, 2016, 03:38:51 PM »
Great this was really nice..

I was trying to make an adjustment by my self, but it don't seem to work, most likely some coding error by my part.

// rebuysallowed
$kFileOutput = "tdrebuysallowed.txt";
$handle = fopen($kFileOutput, "w");
$rebuysallowed = $_GET["rebuysallowed"];
if $rebuysallowed = "1"
fputs($handle, "Yes")
else
fputs($handle, "No");
fclose($handle);

As you can see i try to achieve that the file tdrebuysallowed.txt will contain "Yes" or "No" instead of the value "1" or "0"
But my coding skills are not good enough.

You can see a default mock up of my info dash i will use at the club here https://www.thedash.com/dashboard/ByOATlkB/fullscreen
Also possible to use in mobile for the players. (easy to setup a cheap raspberry pi to any tv / monitor and use as free dash with TD info in it.

At a glance it looks like you've just got one issue:

Code: [Select]
if $rebuysallowed = "1"
should be:

Code: [Select]
if($rebuysallowed == "1")

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 6216
    • View Profile
Re: Special request
« Reply #5 on: June 16, 2016, 03:41:12 PM »
One token i really would like for the status update is a token for the number of players added to the tournament (not buyin only in the list on the players tab.)
Today there is many tokens for players, but only if they have been buyin and when tournament is started:

buyins=7
numberofplayers=7
n=7
numberofleaguemembers=7
nm=7
playersleft=6
players=6

Maybe a "playersadded=" would be nice.
Now i have to buy them in and then when they arrive and make the payment i have to tick "paid in full", it works but doesn't feel optimal.

I guess this was never included since the number of players added to a tournament but not bought in doesn't have any effect at all on the tournament.  I'll put a note to add it.

mcfrojd

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Special request
« Reply #6 on: June 17, 2016, 04:58:02 PM »
Damn Corey, you are the best..

mcfrojd

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Special request
« Reply #7 on: June 17, 2016, 05:32:05 PM »
Something is not right, must be somethin missing / wrong still with that code.

$kFileOutput = "tdrebuysallowed.txt";
$handle = fopen($kFileOutput, "w");
$rebuysallowed = $_GET["rebuysallowed"];
if($rebuysallowed == "1");
fputs($handle, "Yes");
else;
fputs($handle, "No");
fclose($handle);

I still get a "fail" when i try to run with that bit of code in there

Corey Cooper

  • Administrator
  • Hero Member
  • *****
  • Posts: 6216
    • View Profile
Re: Special request
« Reply #8 on: June 19, 2016, 11:02:52 PM »
You've added semicolons, which weren't in the first version.  One of them might have been necessary.  Frankly I'm not sure without looking it up because I only code PHP when necessary.  :)  In Javascript, which I'm currently most fluent, semicolons are technically optional (although they should be required).

I've added some indentation to make it a little bit more clear:

Code: [Select]
$kFileOutput = "tdrebuysallowed.txt";
$handle = fopen($kFileOutput, "w");
$rebuysallowed = $_GET["rebuysallowed"];
if($rebuysallowed == "1")
  fputs($handle, "Yes");
else
  fputs($handle, "No");
fclose($handle);

The semicolons on the "if" and "else" line are what caused the problem.  Semicolons end the statement, but an "if" statement needs a "then" clause ("then" is assumed).  "IF rebuys are allowed THEN write "yes" to the file".  Same with an "else" statement (which is only valid after an "if" statement).