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