| @@ 821-838 (lines=18) @@ | ||
| 818 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 819 | } |
|
| 820 | ||
| 821 | public function addUserMessage($userId, $type, $message) |
|
| 822 | { |
|
| 823 | $this->addUser($userId); |
|
| 824 | $stmt = $this->db->prepare( |
|
| 825 | <<< 'SQL' |
|
| 826 | INSERT INTO user_messages |
|
| 827 | (user_id, type, message, date_time) |
|
| 828 | VALUES |
|
| 829 | (:user_id, :type, :message, :date_time) |
|
| 830 | SQL |
|
| 831 | ); |
|
| 832 | ||
| 833 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 834 | $stmt->bindValue(':type', $type, PDO::PARAM_STR); |
|
| 835 | $stmt->bindValue(':message', $message, PDO::PARAM_STR); |
|
| 836 | $stmt->bindValue(':date_time', $this->dateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 837 | $stmt->execute(); |
|
| 838 | } |
|
| 839 | ||
| 840 | // TokenStorageInterface |
|
| 841 | ||
| @@ 957-991 (lines=35) @@ | ||
| 954 | } |
|
| 955 | } |
|
| 956 | ||
| 957 | private function addUser($userId) |
|
| 958 | { |
|
| 959 | $stmt = $this->db->prepare( |
|
| 960 | <<< 'SQL' |
|
| 961 | SELECT |
|
| 962 | COUNT(*) |
|
| 963 | FROM |
|
| 964 | users |
|
| 965 | WHERE user_id = :user_id |
|
| 966 | SQL |
|
| 967 | ); |
|
| 968 | ||
| 969 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 970 | $stmt->execute(); |
|
| 971 | ||
| 972 | if (1 !== (int) $stmt->fetchColumn()) { |
|
| 973 | // user does not exist yet |
|
| 974 | $stmt = $this->db->prepare( |
|
| 975 | <<< 'SQL' |
|
| 976 | INSERT INTO |
|
| 977 | users ( |
|
| 978 | user_id, |
|
| 979 | date_time |
|
| 980 | ) |
|
| 981 | VALUES ( |
|
| 982 | :user_id, |
|
| 983 | :date_time |
|
| 984 | ) |
|
| 985 | SQL |
|
| 986 | ); |
|
| 987 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 988 | $stmt->bindValue(':date_time', $this->dateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 989 | $stmt->execute(); |
|
| 990 | } |
|
| 991 | } |
|
| 992 | } |
|
| 993 | ||