id = filterId($id); $this->date = DateTime::createFromFormat('Y-m-d', $date); $this->shiaiId = filterId($shiaiId); $this->deadline = DateTime::createFromFormat('Y-m-d', $deadline); $this->remarks = $remarks; } // Getter /** Getter for the id * * @return (int) Id of the event */ public function getId() { return $this->id; } /** Getter for the date * * @return DateTime date of the event */ public function getDate() { return $this->date; } /** Getter for the shiaiId * * @return int>0 id for the shiai in the db */ public function getShiaiId() { return $this->shiaiId; } /** Getter for the deadline * * @return DateTime deadline for the event */ public function getDeadLine() { return $this->deadline; } /** Getter for the linked Shiai * * - lazy loading: only load if not already loaded (overridable by the $forceLoading param) * * @param boolean $forceLoading if true, the loading is enforced even if there already is a shiai linked * * @return Shiai reference to the linked Shiai */ public function shiai($forceLoading = false) { // We want to load if it isn't loaded yet or we want to enforce it. But in either case we need an id to load if ((!isset($this->shiai) || $forceLoading) && isset($this->shiaiId)) { $this->shiai = Shiai::loadFromDb($this->shiaiId); } return $this->shiai; } /** load the Event by id from the db * * - Frontend function: sanitizes the input and calls the backend function * * @param integer>0 $id id of the Event to load from the data base * @return Event Event from the db with this id, null in case the Event couldn't be loaded */ public static function loadFromDb($id) { $id = filterId($id); if ($id) { return self::loadFromDbById($id); } return null; } /** * loads an event from the db by id * * - Backend function, input is supposed to be sanitized * * @param integer>0 $id sanitized id of the event to load * @return Event Event from the db with this id, null in case the Event couldn't be loaded */ private static function loadFromDbById(int $id) { $query = 'SELECT * FROM `cwsvjudo`.`wkParticipo_Events` WHERE `id` = :id;'; $params = [':id' => ['value' => $id, 'data_type' => PDO::PARAM_INT]]; $response = dbConnector::query($query, $params); // ids are considered unique. so every other count then 1 is treated as error to prevent unprivileged access if (count($response) != 1) { return null; } return self::fromDbArray($response[0]); } public function htmlDate($format = 'Y-m-d') { return $this->date->format($format); } public function htmlDeadLine($format = 'Y-m-d') { return $this->deadline->format($format); } /** Representation of an event as (materializeCss) card * * @return string string with the html code of the event */ public function asHtmlCard() { $shiai = $this->shiai(); return '