diff options
| author | David Siegfried <david.siegfried@uni-vechta.de> | 2022-12-15 13:33:04 +0000 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2022-12-15 13:33:04 +0000 |
| commit | 74b970a8275a3894744f9b9c4969ff4dce647782 (patch) | |
| tree | 7e34c982811acb6e6fe3f3718c9bc0fc8ac595c4 /lib/classes/AutoInsert.class.php | |
| parent | 4333e038692f5d422125b76a56b7540f0d5f34fc (diff) | |
use SORM instead plain sql, closes #29
Closes #29
Merge request studip/studip!888
Diffstat (limited to 'lib/classes/AutoInsert.class.php')
| -rw-r--r-- | lib/classes/AutoInsert.class.php | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/lib/classes/AutoInsert.class.php b/lib/classes/AutoInsert.class.php index d9b1558..8aac873 100644 --- a/lib/classes/AutoInsert.class.php +++ b/lib/classes/AutoInsert.class.php @@ -150,44 +150,30 @@ class AutoInsert private function addUser($user_id, $seminar) { - $query = "INSERT IGNORE INTO seminar_user (Seminar_id, user_id, status, gruppe, mkdate) - VALUES (?, ?, 'autor', ?, UNIX_TIMESTAMP())"; - $statement = DBManager::get()->prepare($query); - $statement->execute([$seminar['Seminar_id'], $user_id, select_group($seminar['start_time'])]); - $rows = $statement->rowCount(); - if ($rows > 0) return true; - - return false; + $course_member = new CourseMember([$seminar['Seminar_id'], $user_id]); + $course_member->setData([ + 'Seminar_id' => $seminar['Seminar_id'], + 'user_id' => $user_id, + 'status' => 'autor', + 'gruppe' => select_group($seminar['start_time']), + ]); + + return $course_member->store() > 0; } private function removeUser($user_id, $seminar) { - $query = "DELETE FROM seminar_user " . "WHERE user_id = ? " . "AND Seminar_id = ? "; - - $statement = DBManager::get()->prepare($query); - $statement->execute([$user_id, $seminar['Seminar_id']]); - $rows = $statement->rowCount(); - - $query = "DELETE FROM statusgruppe_user " . "WHERE user_id = ? " . "AND statusgruppe_id IN (SELECT statusgruppe_id FROM statusgruppen WHERE range_id = ?)"; - $statusgruppe_stmt = DBManager::get()->prepare($query); - $statusgruppe_stmt->execute([$user_id, $seminar['Seminar_id']]); - $statusgruppe_rows = $statusgruppe_stmt->rowCount(); + $rows = CourseMember::deleteBySQL(' user_id = ? AND Seminar_id = ?', [$user_id, $seminar['Seminar_id']]); + $statusgruppe_rows = StatusgruppeUser::deleteBySQL( + 'user_id = ? AND statusgruppe_id IN (SELECT statusgruppe_id FROM statusgruppen WHERE range_id = ?)', + [$user_id, $seminar['Seminar_id']] + ); if ($rows > 0 || $statusgruppe_rows > 0) return true; return false; } /** - * - * @param type $user_id - */ - public function deleteUserSeminare($user_id) - { - $db = DBManager::get(); - $db->exec("DELETE FROM seminar_user " . "WHERE user_id = " . $db->quote($user_id)); - } - - /** * Tests if a seminar already has an autoinsert record * @param string $seminar_id Id of the seminar * @return bool Indicating whether the seminar already has an autoinsert record |
