| @@ 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 | ||
| @@ 966-1000 (lines=35) @@ | ||
| 963 | } |
|
| 964 | } |
|
| 965 | ||
| 966 | private function addUser($userId) |
|
| 967 | { |
|
| 968 | $stmt = $this->db->prepare( |
|
| 969 | <<< 'SQL' |
|
| 970 | SELECT |
|
| 971 | COUNT(*) |
|
| 972 | FROM |
|
| 973 | users |
|
| 974 | WHERE user_id = :user_id |
|
| 975 | SQL |
|
| 976 | ); |
|
| 977 | ||
| 978 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 979 | $stmt->execute(); |
|
| 980 | ||
| 981 | if (1 !== (int) $stmt->fetchColumn()) { |
|
| 982 | // user does not exist yet |
|
| 983 | $stmt = $this->db->prepare( |
|
| 984 | <<< 'SQL' |
|
| 985 | INSERT INTO |
|
| 986 | users ( |
|
| 987 | user_id, |
|
| 988 | date_time |
|
| 989 | ) |
|
| 990 | VALUES ( |
|
| 991 | :user_id, |
|
| 992 | :date_time |
|
| 993 | ) |
|
| 994 | SQL |
|
| 995 | ); |
|
| 996 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 997 | $stmt->bindValue(':date_time', $this->dateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 998 | $stmt->execute(); |
|
| 999 | } |
|
| 1000 | } |
|
| 1001 | } |
|
| 1002 | ||