Skip to content

Commit

Permalink
PHPDoc-ed + added more functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
huwcbjones committed Oct 20, 2019
1 parent c6c7e14 commit b21464f
Show file tree
Hide file tree
Showing 14 changed files with 509 additions and 200 deletions.
13 changes: 12 additions & 1 deletion src/Club.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace RankingsDB;

/**
* Club object
*
* @package RankingsDB
*/
class Club
{
protected $_club;
Expand All @@ -16,6 +21,8 @@ public function __construct($club_code, $ranked)
}

/**
* Club Code
*
* @return string
*/
public function Club()
Expand All @@ -24,6 +31,8 @@ public function Club()
}

/**
* County Code
*
* @return string
*/
public function County()
Expand All @@ -32,7 +41,9 @@ public function County()
}

/**
* @return boolean
* Is this club a member's ranked club
*
* @return boolean true if this club is a member's ranked club
*/
public function IsRanked()
{
Expand Down
75 changes: 69 additions & 6 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,69 @@

namespace RankingsDB;

/**
* Event obj
*
* @package RankingsDB
*/
class Event
{
static protected $_event_map = [
1 => Stroke::FREESTYLE . "50",
2 => Stroke::FREESTYLE . "100",
3 => Stroke::FREESTYLE . "200",
4 => Stroke::FREESTYLE . "400",
5 => Stroke::FREESTYLE . "800",
6 => Stroke::FREESTYLE . "1500",
7 => Stroke::BREASTSTROKE . "50",
8 => Stroke::BREASTSTROKE . "100",
9 => Stroke::BREASTSTROKE . "200",
10 => Stroke::BUTTERFLY . "50",
11 => Stroke::BUTTERFLY . "100",
12 => Stroke::BUTTERFLY . "200",
13 => Stroke::BACKSTROKE . "50",
14 => Stroke::BACKSTROKE . "100",
15 => Stroke::BACKSTROKE . "200",
16 => Stroke::INDIVIDUAL_MEDLEY . "100",
17 => Stroke::INDIVIDUAL_MEDLEY . "200",
18 => Stroke::INDIVIDUAL_MEDLEY . "400"
];
static protected $_reverse_map = [];
protected $_stroke;
protected $_distance;

public function __construct($stroke, $distance)
{
$this->_stroke = $stroke;
$this->_distance = $distance;

if (count(Event::$_reverse_map) == 0) {
Event::$_reverse_map = array_flip(Event::$_event_map);
}
}

public static function fromEventCode($code)
{
$event_id = Event::$_event_map[$code];
return Event::fromEventID($event_id);
}

/**
* Creates an event from an event ID
*
* @param $event_id
* @return Event
*/
public static function fromEventID($event_id)
{
$stroke = substr($event_id, 0, 2);
$distance = intval(substr($event_id, 2));
return new Event($stroke, $distance);
}

/**
* Stroke
*
* @return Stroke
*/
public function stroke()
Expand All @@ -22,21 +73,33 @@ public function stroke()
}

/**
* Distance
*
* @return int
*/
public function distance()
{
return $this->_distance;
}

public function eventID(){
return $this->_stroke . $this->_distance;
/**
* Returns the event code for this event object
*
* @return int
*/
public function eventCode()
{
return Event::$_reverse_map[$this->eventID()];
}

public static function fromEventID($event_id){
$stroke = substr($event_id, 0, 2);
$distance = intval(substr($event_id, 2));
return new Event($stroke, $distance);
/**
* Returns the event ID for this event object
*
* @return string
*/
public function eventID()
{
return $this->_stroke . $this->_distance;
}

}
131 changes: 85 additions & 46 deletions src/GetTimesBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

namespace RankingsDB;

use Cassandra\Date;
use DateTime;
use Exception;

/**
* Builder to create options for GetTimes
*
* @package RankingsDB
*/
class GetTimesBuilder
{
protected $_member_id;
Expand All @@ -15,52 +20,23 @@ class GetTimesBuilder
protected $_include_masters = true;
protected $_include_relays = false;

public function __construct($member_id)
{
$this->_member_id = $member_id;
}

/**
* @param null $from_date
* @return GetTimesBuilder
*/
public function setFromDate($from_date)
{
$this->_from_date = $from_date;
return $this;
}

/**
* @param null $to_date
* @return GetTimesBuilder
* Create a GetTimesBuilder object
*
* @param $member int|MemberDetails SE Membership ID, or Member Details object
*/
public function setToDate($to_date)
public function __construct($member)
{
$this->_to_date = $to_date;
return $this;
}

/**
* @param string $course
* @return GetTimesBuilder
*/
public function setCourse($course)
{
$this->_course = $course;
return $this;
}

/**
* @param int $level
* @return GetTimesBuilder
*/
public function setLevel($level)
{
$this->_level = $level;
return $this;
if (is_int($member)) {
$this->_member_id = $member;
} else {
$this->_member_id = $member->MemberID();
}
}

/**
* Include times from masters events
*
* @param bool $include_masters
* @return GetTimesBuilder
*/
Expand All @@ -71,6 +47,8 @@ public function setIncludeMasters($include_masters)
}

/**
* Include times from relays
*
* @param bool $include_relays
* @return GetTimesBuilder
*/
Expand All @@ -81,7 +59,7 @@ public function setIncludeRelays($include_relays)
}

/**
* @return mixed
* @return int
*/
public function getMemberID()
{
Expand All @@ -93,23 +71,55 @@ public function getMemberID()
*/
public function getFromDate()
{
if ($this->_from_date === null){
return (new DateTime("1970-01-01"))->setTime(0, 0, 0);
if ($this->_from_date === null) {
try {
return (new DateTime("1970-01-01"))->setTime(0, 0, 0);
} catch (Exception $e) {

}
}
return $this->_from_date;
}

/**
* Set the from date
*
* @param null|DateTime $from_date
* @return GetTimesBuilder
*/
public function setFromDate($from_date)
{
$this->_from_date = $from_date;
return $this;
}

/**
* @return DateTime
*/
public function getToDate()
{
if ($this->_to_date === null){
return (new DateTime());
if ($this->_to_date === null) {
try {
return (new DateTime());
} catch (Exception $e) {

}
}
return $this->_to_date;
}

/**
* Set the to date
*
* @param null|DateTime $to_date
* @return GetTimesBuilder
*/
public function setToDate($to_date)
{
$this->_to_date = $to_date;
return $this;
}

/**
* @return string
*/
Expand All @@ -118,6 +128,18 @@ public function getCourse()
return $this->_course;
}

/**
* Set the course code
*
* @param string $course
* @return GetTimesBuilder
*/
public function setCourse($course)
{
$this->_course = $course;
return $this;
}

/**
* @return int
*/
Expand All @@ -126,6 +148,23 @@ public function getLevel()
return $this->_level;
}

/**
* Set the minimum required competition level
*
* - 0: ALL
* - 1: Level 1
* - 2: Level 2
* - 3: Level 3
*
* @param int $level
* @return GetTimesBuilder
*/
public function setLevel($level)
{
$this->_level = $level;
return $this;
}

/**
* @return bool
*/
Expand Down
Loading

0 comments on commit b21464f

Please sign in to comment.