diff options
author | msquare <msquare@notrademark.de> | 2017-06-20 16:50:21 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2017-06-20 16:50:21 +0200 |
commit | 56814fa2fdf58b4013f4d57c5ea87619c7122957 (patch) | |
tree | 640945769b7e9626cdf43162c786147f5c962029 /includes/model/ShiftTypes_model.php | |
parent | a5fc5bd0979e8de1fce8a8addd351a6e7bd6aeb8 (diff) | |
parent | cd30017b97afc3c7001fbb9eb14b54dbb980b7b6 (diff) |
Merge branch 'pr/316' into feature-igel-rewrite
Diffstat (limited to 'includes/model/ShiftTypes_model.php')
-rw-r--r-- | includes/model/ShiftTypes_model.php | 114 |
1 files changed, 75 insertions, 39 deletions
diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php index 89704a65..96a823d4 100644 --- a/includes/model/ShiftTypes_model.php +++ b/includes/model/ShiftTypes_model.php @@ -1,69 +1,105 @@ <?php +use Engelsystem\Database\DB; + /** * Delete a shift type. + * * @param int $shifttype_id + * @return bool */ -function ShiftType_delete($shifttype_id) { - return sql_query("DELETE FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'"); +function ShiftType_delete($shifttype_id) +{ + return DB::delete('DELETE FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]); } /** * Update a shift type. * - * @param int $shifttype_id - * @param string $name - * @param int $angeltype_id - * @param string $description + * @param int $shifttype_id + * @param string $name + * @param int $angeltype_id + * @param string $description + * @return bool */ -function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) { - return sql_query("UPDATE `ShiftTypes` SET - `name`='" . sql_escape($name) . "', - `angeltype_id`=" . sql_null($angeltype_id) . ", - `description`='" . sql_escape($description) . "' - WHERE `id`='" . sql_escape($shifttype_id) . "'"); +function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) +{ + DB::update(' + UPDATE `ShiftTypes` SET + `name`=?, + `angeltype_id`=?, + `description`=? + WHERE `id`=? + ', + [ + $name, + $angeltype_id, + $description, + $shifttype_id, + ] + ); + + return DB::getStm()->errorCode() == '00000'; } /** * Create a shift type. * - * @param string $name - * @param int $angeltype_id - * @param string $description - * @return new shifttype id + * @param string $name + * @param int $angeltype_id + * @param string $description + * @return int|false new shifttype id */ -function ShiftType_create($name, $angeltype_id, $description) { - $result = sql_query("INSERT INTO `ShiftTypes` SET - `name`='" . sql_escape($name) . "', - `angeltype_id`=" . sql_null($angeltype_id) . ", - `description`='" . sql_escape($description) . "'"); - if ($result === false) { - return false; - } - return sql_id(); +function ShiftType_create($name, $angeltype_id, $description) +{ + $result = DB::insert(' + INSERT INTO `ShiftTypes` (`name`, `angeltype_id`, `description`) + VALUES(?, ?, ?) + ', + [ + $name, + $angeltype_id, + $description + ] + ); + + if ($result === false) { + return false; + } + + return DB::getPdo()->lastInsertId(); } /** * Get a shift type by id. * - * @param int $shifttype_id + * @param int $shifttype_id + * @return array|null */ -function ShiftType($shifttype_id) { - $shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'"); - if ($shifttype === false) { - engelsystem_error('Unable to load shift type.'); - } - if ($shifttype == null) { - return null; - } - return $shifttype[0]; +function ShiftType($shifttype_id) +{ + $shifttype = DB::select('SELECT * FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]); + if (DB::getStm()->errorCode() != '00000') { + engelsystem_error('Unable to load shift type.'); + } + if (empty($shifttype)) { + return null; + } + return array_shift($shifttype); } /** * Get all shift types. + * + * @return array|false */ -function ShiftTypes() { - return sql_select("SELECT * FROM `ShiftTypes` ORDER BY `name`"); -} +function ShiftTypes() +{ + $result = DB::select('SELECT * FROM `ShiftTypes` ORDER BY `name`'); -?>
\ No newline at end of file + if (DB::getStm()->errorCode() != '00000') { + return false; + } + + return $result; +} |