| @@ 828-845 (lines=18) @@ | ||
| 825 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 826 | } |
|
| 827 | ||
| 828 | public function addUserMessage($userId, $type, $message) |
|
| 829 | { |
|
| 830 | $this->addUser($userId); |
|
| 831 | $stmt = $this->db->prepare( |
|
| 832 | <<< 'SQL' |
|
| 833 | INSERT INTO user_messages |
|
| 834 | (user_id, type, message, date_time) |
|
| 835 | VALUES |
|
| 836 | (:user_id, :type, :message, :date_time) |
|
| 837 | SQL |
|
| 838 | ); |
|
| 839 | ||
| 840 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 841 | $stmt->bindValue(':type', $type, PDO::PARAM_STR); |
|
| 842 | $stmt->bindValue(':message', $message, PDO::PARAM_STR); |
|
| 843 | $stmt->bindValue(':date_time', $this->dateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 844 | $stmt->execute(); |
|
| 845 | } |
|
| 846 | ||
| 847 | public function init() |
|
| 848 | { |
|
| @@ 927-961 (lines=35) @@ | ||
| 924 | } |
|
| 925 | } |
|
| 926 | ||
| 927 | private function addUser($userId) |
|
| 928 | { |
|
| 929 | $stmt = $this->db->prepare( |
|
| 930 | <<< 'SQL' |
|
| 931 | SELECT |
|
| 932 | COUNT(*) |
|
| 933 | FROM |
|
| 934 | users |
|
| 935 | WHERE user_id = :user_id |
|
| 936 | SQL |
|
| 937 | ); |
|
| 938 | ||
| 939 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 940 | $stmt->execute(); |
|
| 941 | ||
| 942 | if (1 !== (int) $stmt->fetchColumn()) { |
|
| 943 | // user does not exist yet |
|
| 944 | $stmt = $this->db->prepare( |
|
| 945 | <<< 'SQL' |
|
| 946 | INSERT INTO |
|
| 947 | users ( |
|
| 948 | user_id, |
|
| 949 | date_time |
|
| 950 | ) |
|
| 951 | VALUES ( |
|
| 952 | :user_id, |
|
| 953 | :date_time |
|
| 954 | ) |
|
| 955 | SQL |
|
| 956 | ); |
|
| 957 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 958 | $stmt->bindValue(':date_time', $this->dateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 959 | $stmt->execute(); |
|
| 960 | } |
|
| 961 | } |
|
| 962 | } |
|
| 963 | ||