1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186:
<?php
/**
* Spanish Guest Report Generator
*
* @package Spanish Guest Report Generator
* @author Javier Zapata <javierzapata82@gmail.com>
* @copyright 2021 Javier Zapata <javierzapata82@gmail.com>
* @license https://opensource.org/licenses/MIT The MIT License
* @link https://github.com/bahiazul/spanish-guest-report-generator
*/
namespace SpanishGuestReportGenerator;
/**
* Hotel
*
* @package Spanish Guest Report Generator
* @author Javier Zapata <javierzapata82@gmail.com>
* @copyright 2021 Javier Zapata <javierzapata82@gmail.com>
* @license https://opensource.org/licenses/MIT The MIT License
* @link https://github.com/bahiazul/spanish-guest-report-generator
*/
class Hotel
{
use FormatterTrait;
use SanitizerTrait;
/**
* First digit for the Hotel info line
*
* @var integer
*/
const ROW_TYPE = 1;
/**
* Unique code (given by the authorities) for the Hotel
*
* @var string
*/
private $hotelCode = '';
/**
* Name of the Hotel
*
* @var string
*/
private $hotelName = '';
/**
* Date and time of the report
*
* @var \DateTime
*/
private $reportDateTime;
/**
* Holds all the Guests
*
* @var array
*/
private $guests = [];
/**
* Create a new Hotel
*
* @param string $hotelCode Code of the Hotel
* @param string $hotelName Name of the Hotel
* @param \DateTime|null $reportDateTime Date and time of the report
* @param array $guests Guests that belong to this Hotel
*/
public function __construct(
$hotelCode = '',
$hotelName = '',
$reportDateTime = null,
$guests = []
) {
$this->setHotelCode($hotelCode);
$this->setHotelName($hotelName);
$this->setReportDateTime($reportDateTime ?: new \DateTime);
$this->setGuests($guests);
}
/**
* Sets the Hotel's code
*
* @param string $hotelCode
* @return Hotel
*/
public function setHotelCode($hotelCode)
{
$this->hotelCode = $this->sanitizeCode($hotelCode);
return $this;
}
/**
* Sets the Hotel's name
*
* @param string $hotelName
* @return Hotel
*/
public function setHotelName($hotelName)
{
$this->hotelName = $this->sanitizeBizName($hotelName);
return $this;
}
/**
* Sets the report date and time
*
* @param \DateTime $reportDateTime
* @return Hotel
*/
public function setReportDateTime(\DateTime $reportDateTime)
{
$this->reportDateTime = $reportDateTime;
return $this;
}
/**
* Set multiple Guests at once
*
* @param array $guests
* @return Hotel
*/
public function setGuests(array $guests)
{
$this->guests = [];
foreach ($guests as $guest) {
$this->addGuest($guest);
}
return $this;
}
/**
* Return all the Guests and the Hotel info
*
* @return array
*/
public function getRows()
{
$rows = [];
foreach ($this->guests as $guest) {
array_push($rows, $guest->getCols());
}
if (count($this->guests)) {
array_unshift($rows, $this->getHeadRow());
}
return $rows;
}
/**
* Add a single Guest
*
* @param Guest $guest Guest object
*/
private function addGuest(Guest $guest)
{
array_push($this->guests, $guest);
}
/**
* Returns the data for the Hotel info row
*
* @return array
*/
private function getHeadRow()
{
$cols = [];
$cols[] = self::ROW_TYPE;
$cols[] = $this->hotelCode;
$cols[] = $this->hotelName;
$cols[] = $this->formatDate($this->reportDateTime);
$cols[] = $this->formatTime($this->reportDateTime);
$cols[] = count($this->guests);
return $cols;
}
}