name = $name; $this->value = $value; $this->type = $type; } /** * @param array $row * @return array */ public static function collect(array $row): array { $names = []; foreach ($row as $entry) { if (isset($entry->name)) { $names[] = $entry->name; } } return $names; } public function value() { return $this->value; } /** * @param mixed $value * @return void */ public function setValue($value): void { $this->value = $value; } // private member variables private ?string $name = null; private $value = null; private ?int $type = null; } class Ride { /** Constructor * * - filters/sanitizes all inputs * - sets all members * * @param mixed $id setValue for the id * @param mixed $eventId setValue for the eventId * @param mixed $driverId setValue for the driverId * @param mixed $seats setValue for the seats * @param string $passengerIds string of comma separated values */ public function __construct( $id, $eventId, $driverId, $seats, string $passengerIds, ) { $this->id = new PdoCellValue("id", filterId($id), PDO::PARAM_INT); $this->eventId = new PdoCellValue( "eventId", filterId($eventId), PDO::PARAM_INT, ); $this->driverId = new PdoCellValue( "fahrerId", filterId($driverId), PDO::PARAM_INT, ); $this->seats = new PdoCellValue( "plaetze", filterCount($seats), PDO::PARAM_INT, ); $this->passengerIds = new PdoCellValue( "mitfahrer", self::filterCsv($passengerIds, "filterId"), PDO::PARAM_STR, ); } /** parse and sanitize a csvFormatted string * @param callable(): mixed $callback * @return string[]|bool */ public function filterCsv( string $list, callable $callback, string $separator = ",", bool $dontTrim = false, ): array|false { $list = explode($separator, $list); foreach ($list as &$element) { $element = $callback($element); if (!$dontTrim) { $element = trim($element); } } return $list; } //// // private functions //// // DbInterface private const dbName = "cwsvjudo"; private const dbTableName = "wkParticipo_Fahrten"; private const dbFullTableNameString = "`" . self::dbName . "`.`" . self::dbTableName . "`"; /** Slice a list of arrays 'horizontal' through a specific key * * - iterate through a list of arrays and collect the values under a specific key * - if the key doesn't exist nothing (not even null) will be collected * * @param array $array source array * @param mixed $key key to collect * @return array list of array entries */ public function sliceArrayByKey(array $array, $key) { $sliced = []; foreach ($array as $entry) { if (isset($entry[$key])) { $sliced[] = $entry[$key]; } } return $sliced; } /** * @return void */ private static function dbSelect(): void {} /** * @param array $values */ private static function dbInsert(array $values) { $names = []; $binds = []; $params = []; foreach ($values as $value) { $names[] = $value->name; $binds[] = ":" . $value->name; $params[":" . $value->name] = [ "value" => $value->name, "data_type" => $value->type, ]; } $query = "INSERT INTO " . self::dbFullTableNameString . " (" . implode(",", $names) . ") values (" . implode(",", $binds) . ");"; // @todo remove ignoreErrors again // @todo Inserting-Starter-Statement returns false on execution: Why? It seems to succeed! $response = dbConnector::query($query, $params, [ "ignoreErrors" => true, ]); return dbConnector::getLastInsertId(); } /** * @return void */ private static function dbDelete(): void {} /** * @return void */ private static function dbUpdate(): void {} //// // private variables //// /** Unique Identifier for the Ride * * @var int > 0 */ private $id = null; /** Id of the event for the ride * * @var int > 0 */ private $eventId = null; /** Id of the user who offered the drive * * @var int > 0 */ private $driverId = null; /** number of seats the drive offers * * @var int > 0 */ private $seats = null; /** List of Ids of the users this ride chauffeurs * * @var array(int > 0) */ private $passengerIds = null; private $event = null; private $driver = null; private $passengers = null; }