diff --git a/README.md b/README.md
index 27cbb36..06a6b2b 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,9 @@
# Sportlink Club.Dataservice
This package contains a PHP wrapper around the Sportlink Club.Dataservice API. It aims to make working with the API a breeze.
+#### API
+For a list of available atricles see: `https://dexels.github.io/navajofeeds-json-parser/`.
+
#### Installation
Install the package using composer:
diff --git a/src/Api.php b/src/Api.php
index 2a26a18..668621b 100644
--- a/src/Api.php
+++ b/src/Api.php
@@ -36,6 +36,8 @@ public function __construct($api_key = '', HttpClientInterface $client = null)
{
$this->api_key = $api_key;
$this->client = $client ?: new HttpClient();
+
+ $this->setTimeZone();
}
/**
@@ -56,6 +58,18 @@ public function setApiKey($api_key)
return $this;
}
+ /**
+ * @param string $timezone
+ *
+ * @sse https://www.php.net/manual/en/timezones.php
+ */
+ public function setTimeZone($timezone = 'Europe/Amsterdam')
+ {
+ date_default_timezone_set($timezone);
+
+ return $this;
+ }
+
/**
* Make a request to the API
*
diff --git a/src/Birthday.php b/src/Birthday.php
new file mode 100644
index 0000000..ba97001
--- /dev/null
+++ b/src/Birthday.php
@@ -0,0 +1,71 @@
+isShielded()
+ ? explode(' ', $this->volledigenaam, 2)[0]
+ : static::UNKNOWN;
+ }
+
+ /**
+ * The member lastname.
+ *
+ * @return string
+ */
+ public function getLastName()
+ {
+ return !$this->isShielded()
+ ? explode(' ', $this->volledigenaam, 2)[1]
+ : static::UNKNOWN;
+ }
+
+ /**
+ * Get member full name.
+ *
+ * @return string
+ */
+ public function getFullName()
+ {
+ return $this->volledigenaam;
+ }
+
+ /**
+ * Get a date time object for birthday value.
+ *
+ * @return \DateTimeInterface
+ */
+ public function getDate()
+ {
+ return \DateTime::createFromFormat(
+ 'j M H:i:s', $this->verjaardag . ' 00:00:00'
+ );
+ }
+
+ /**
+ * @return bool
+ */
+ public function isShielded()
+ {
+ return $this->volledigenaam === static::SHIELDED;
+ }
+}
diff --git a/src/Club.php b/src/Club.php
index 5b48ae6..e332a72 100644
--- a/src/Club.php
+++ b/src/Club.php
@@ -2,16 +2,37 @@
namespace PendoNL\ClubDataservice;
+use PendoNL\ClubDataservice\Exception\InvalidResponseException;
+
+/**
+ * Club class.
+ *
+ * @see https://dexels.github.io/navajofeeds-json-parser/
+ */
class Club extends AbstractItem
{
+ /** @var Team[]|array */
public $teams = [];
+
+ /** @var array{id: int, info: TeamInfo} */
+ public $teamInfo = [];
+
public $afgelastingen = [];
+ /** @var Committee[]|array */
+ public $committees = [];
+
+ /** @var Birthday[]|array */
+ public $birthdays = [];
+
/**
* Return all teams (and map competitions).
*
* @param array $arguments
- * @return array
+ *
+ * @return Team[]|array
+ *
+ * @throws InvalidResponseException
*/
public function getTeams($arguments = [])
{
@@ -40,43 +61,82 @@ public function getTeams($arguments = [])
}
/**
- * Return all competitions.
+ * Return a single team.
*
- * @return array
+ * @param string $code
+ *
+ * @return Team|null
+ *
+ * @throws InvalidResponseException
*/
- public function getCompetitions()
+ public function getTeam($code)
{
if(count($this->teams) == 0) {
$this->getTeams();
}
- return $this->competitions;
+ if (isset($this->teams[$code])) {
+ return $this->teams[$code];
+ }
+
+ return null;
}
/**
- * Return a single team.
+ * Get team info.
*
- * @param string $code
- * @return Team|null
+ * @param int $teamCode The team code.
+ * @param int $localTeamCode The local team code.
+ *
+ * @return TeamInfo|null
*/
- public function getTeam($code)
+ public function getTeamInfo($teamCode, $localTeamCode = -1)
{
- if(count($this->teams) == 0) {
- $this->getTeams();
+ // Set cache key.
+ $key = $teamCode . '-' . $localTeamCode;
+
+ if (isset($this->teamInfo[$key])) {
+ return $this->teamInfo[$key];
}
- if (isset($this->teams[$code])) {
- return $this->teams[$code];
+ try {
+ $response = $this->api->request(TeamInfo::ARTICLE, [
+ 'teamcode' => $teamCode,
+ 'lokaleteamcode' => $localTeamCode,
+ ]);
+
+ $this->teamInfo[$key] = new TeamInfo($this->api, $response['team']);
+
+ return $this->teamInfo[$key];
+ } catch (InvalidResponseException $ex) {
+ return null;
}
+ }
- return null;
+ /**
+ * Return all competitions.
+ *
+ * @return Competition[]|array
+ *
+ * @throws InvalidResponseException
+ */
+ public function getCompetitions()
+ {
+ if(count($this->teams) == 0) {
+ $this->getTeams();
+ }
+
+ return $this->competitions;
}
/**
* Return a single competition.
*
- * @param string $code
+ * @param string $code
+ *
* @return Team|null
+ *
+ * @throws InvalidResponseException
*/
public function getCompetition($code)
{
@@ -93,7 +153,10 @@ public function getCompetition($code)
* Afgelastingen.
*
* @param array $arguments
+ *
* @return array
+ *
+ * @throws InvalidResponseException
*/
public function afgelastingen($arguments = [])
{
@@ -104,11 +167,79 @@ public function afgelastingen($arguments = [])
$response = $this->api->request('afgelastingen', $arguments);
foreach($response as $item){
- $afgelasting = new Match($this->api, $item);
- $this->afgelastingen[] = $afgelasting;
+ $this->afgelastingen[] = new Game($this->api, $item);
}
return $this->afgelastingen;
}
+ /**
+ * Return all committees.
+ *
+ * @param array $arguments
+ *
+ * @return Committee[]|array
+ *
+ * @throws InvalidResponseException
+ */
+ public function getCommittees($arguments = [])
+ {
+ if ($this->committees) {
+ return $this->committees;
+ }
+
+ $response = $this->api->request(Committee::ARTICLE, $arguments);
+
+ // Loop committees.
+ foreach ($response as $item) {
+ $committee = new Committee($this->api, $item);
+
+ if(!array_key_exists($committee->commissiecode, $this->committees)) {
+ $this->committees[$committee->commissiecode] = $committee;
+ }
+ }
+
+ return $this->committees;
+ }
+
+ /**
+ * Get Committee.
+ *
+ * @param int $commissiecode The unique commission code.
+ *
+ * @return Committee|null
+ *
+ * @throws InvalidResponseException
+ */
+ public function getCommittee($commissiecode)
+ {
+ $committees = $this->getCommittees();
+
+ if (isset($committees[$commissiecode])) {
+ return $committees[$commissiecode];
+ }
+
+ return null;
+ }
+
+ /**
+ * Get birthdays.
+ *
+ * @return Birthday[]|array
+ */
+ public function getBirthdays($arguments = [])
+ {
+ if ($this->birthdays) {
+ return $this->birthdays;
+ }
+
+ $response = $this->api->request(Birthday::ARTICLE, $arguments);
+
+ // Loop birthdays.
+ foreach ($response as $item) {
+ $this->birthdays[] = new Birthday($this->api, $item);
+ }
+
+ return $this->birthdays;
+ }
}
diff --git a/src/Committee.php b/src/Committee.php
new file mode 100644
index 0000000..bbd81f0
--- /dev/null
+++ b/src/Committee.php
@@ -0,0 +1,45 @@
+members) != 0) {
+ return $this->members;
+ }
+
+ $membersData = $this->api->request(CommitteeMember::ARTICLE, [
+ 'commissiecode' => (int)$this->commissiecode,
+ 'toonlidfoto' => $showPicture,
+ ]);
+
+ foreach ($membersData as $memberData) {
+ $this->members[] = new CommitteeMember($this->api, $memberData);
+ }
+
+ return $this->members;
+ }
+}
diff --git a/src/CommitteeMember.php b/src/CommitteeMember.php
new file mode 100644
index 0000000..e34544b
--- /dev/null
+++ b/src/CommitteeMember.php
@@ -0,0 +1,80 @@
+isShielded()
+ ? explode(', ', $this->lid)[1]
+ : static::UNKNOWN;
+ }
+
+ /**
+ * Team member lastname.
+ *
+ * @return string
+ */
+ public function getLastName()
+ {
+ return !$this->isShielded()
+ ? explode(', ', $this->lid)[0]
+ : static::UNKNOWN;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isShielded()
+ {
+ return $this->lid === static::SHIELDED;
+ }
+
+ /**
+ * Get team member photo.
+ *
+ * @return string|null
+ */
+ public function getImageTag()
+ {
+ if (!$this->lid) {
+ return null;
+ }
+
+ $alt = $this->lid;
+ $src = 'data:image/jpeg;base64,' . $this->foto;
+
+ return '
';
+ }
+}
diff --git a/src/Competition.php b/src/Competition.php
index 75b9b71..55e2e45 100644
--- a/src/Competition.php
+++ b/src/Competition.php
@@ -68,7 +68,7 @@ public function fixtures($arguments = [])
], $arguments));
foreach($response as $item) {
- $match = new Match($this->api, $item);
+ $match = new Game($this->api, $item);
$this->fixtures[$match->wedstrijdcode] = $match;
}
@@ -124,7 +124,7 @@ public function results($arguments = [])
], $arguments));
foreach($response as $item) {
- $result = new Match($this->api, $item);
+ $result = new Game($this->api, $item);
$this->results[$result->wedstrijdcode] = $result;
}
diff --git a/src/Match.php b/src/Game.php
similarity index 58%
rename from src/Match.php
rename to src/Game.php
index fe53a70..521cf8b 100644
--- a/src/Match.php
+++ b/src/Game.php
@@ -2,6 +2,6 @@
namespace PendoNL\ClubDataservice;
-class Match extends AbstractItem
+class Game extends AbstractItem
{
}
diff --git a/src/Team.php b/src/Team.php
index 1cdc3e1..871c874 100644
--- a/src/Team.php
+++ b/src/Team.php
@@ -2,8 +2,33 @@
namespace PendoNL\ClubDataservice;
+use PendoNL\ClubDataservice\Exception\InvalidResponseException;
+
+/**
+ * @property-read int|string $lokaleteamcode The local team code.
+ * @property-read int $poulecode The poul code.
+ * @property-read string $teamnaam The name of the team.
+ * @property-read string $compeitienaam The team competition name.
+ * @property-read string $klasse The team order.
+ * @property-read string $poule The team poule.
+ * @property-read string $klassepoule The team poule order.
+ * @property-read string $spelsoort The team game/day.
+ * @property-read string $competitiesoort Competition type.
+ * @property-read string $geslacht The team gender.
+ * @property-read string $teamsoort Type of team.
+ * @property-read string $leeftijdscategorie Team age category.
+ * @property-read string $kalespelsoort Team "kalespel" type.
+ * @property-read string $speeldag Team day of game.
+ * @property-read string $speeldagteam $speeldag + "speeldag".
+ * @property-read string $more API more link.
+ *
+ * @see https://dexels.github.io/navajofeeds-json-parser/article/?teams
+ */
class Team extends AbstractItem
{
+ /** @var int|null */
+ public $teamcode;
+
/** @var array $competitions */
private $competitions = [];
@@ -32,8 +57,10 @@ public function getCompetitions()
/**
* Get all team members.
- *
+ *
* @return TeamMember[]|array
+ *
+ * @throws InvalidResponseException
*/
public function getMembers()
{
@@ -41,7 +68,7 @@ public function getMembers()
return $this->teamMembers;
}
- $membersData = $this->api->request('team-indeling', [
+ $membersData = $this->api->request(TeamMember::ARTICLE, [
'teamcode' => $this->teamcode,
'lokaleteamcode' => $this->lokaleteamcode,
]);
diff --git a/src/TeamInfo.php b/src/TeamInfo.php
new file mode 100644
index 0000000..bc5df3a
--- /dev/null
+++ b/src/TeamInfo.php
@@ -0,0 +1,42 @@
+teamfoto) {
+ return null;
+ }
+
+ $alt = $this->teamnaam;
+ $src = 'data:image/jpeg;base64,' . $this->teamfoto;
+
+ return '
';
+ }
+}
diff --git a/src/TeamMember.php b/src/TeamMember.php
index 3096d4e..c165a3e 100644
--- a/src/TeamMember.php
+++ b/src/TeamMember.php
@@ -2,8 +2,26 @@
namespace PendoNL\ClubDataservice;
+/**
+ * @property-read string|null $relatiecode The member relation code.
+ * @property-read string $naam The member name.
+ * @property-read string|null $geslacht The member gender.
+ * @property-read string $rol The member role.
+ * @property-read string $functie The member function.
+ * @property-read string|null $einddatum The member end date.
+ * @property-read string|null $email The member e-mail address.
+ * @property-read string|null $email2 The member secondary e-mail address.
+ * @property-read string|null $telefoon The member phone number.
+ * @property-read string|null $telefoon2 The member secondary phone number.
+ * @property-read string|null $mobiel The member cellphone number.
+ * @property-read string|null $foto The member photo (binary format).
+ *
+ * @see https://dexels.github.io/navajofeeds-json-parser/article/?team-indeling
+ */
class TeamMember extends AbstractItem
{
+ const ARTICLE = 'team-indeling';
+
const SHIELDED = 'Afgeschermd';
const UNKNOWN = 'Onbekend';
@@ -32,12 +50,27 @@ public function getLastName()
}
/**
- *
- *
* @return bool
*/
public function isShielded()
{
return $this->naam === static::SHIELDED;
}
+
+ /**
+ * Get team member photo.
+ *
+ * @return string|null
+ */
+ public function getImageTag()
+ {
+ if (!$this->naam) {
+ return null;
+ }
+
+ $alt = $this->naam;
+ $src = 'data:image/jpeg;base64,' . $this->foto;
+
+ return '
';
+ }
}