| @@ 747-764 (lines=18) @@ | ||
| 744 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 745 | } |
|
| 746 | ||
| 747 | public function addUserMessage($userId, $type, $message) |
|
| 748 | { |
|
| 749 | $this->addUser($userId); |
|
| 750 | $stmt = $this->db->prepare( |
|
| 751 | <<< 'SQL' |
|
| 752 | INSERT INTO user_messages |
|
| 753 | (user_id, type, message, date_time) |
|
| 754 | VALUES |
|
| 755 | (:user_id, :type, :message, :date_time) |
|
| 756 | SQL |
|
| 757 | ); |
|
| 758 | ||
| 759 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 760 | $stmt->bindValue(':type', $type, PDO::PARAM_STR); |
|
| 761 | $stmt->bindValue(':message', $message, PDO::PARAM_STR); |
|
| 762 | $stmt->bindValue(':date_time', $this->dateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 763 | $stmt->execute(); |
|
| 764 | } |
|
| 765 | ||
| 766 | public function init() |
|
| 767 | { |
|
| @@ 846-880 (lines=35) @@ | ||
| 843 | } |
|
| 844 | } |
|
| 845 | ||
| 846 | private function addUser($userId) |
|
| 847 | { |
|
| 848 | $stmt = $this->db->prepare( |
|
| 849 | <<< 'SQL' |
|
| 850 | SELECT |
|
| 851 | COUNT(*) |
|
| 852 | FROM |
|
| 853 | users |
|
| 854 | WHERE user_id = :user_id |
|
| 855 | SQL |
|
| 856 | ); |
|
| 857 | ||
| 858 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 859 | $stmt->execute(); |
|
| 860 | ||
| 861 | if (1 !== (int) $stmt->fetchColumn()) { |
|
| 862 | // user does not exist yet |
|
| 863 | $stmt = $this->db->prepare( |
|
| 864 | <<< 'SQL' |
|
| 865 | INSERT INTO |
|
| 866 | users ( |
|
| 867 | user_id, |
|
| 868 | date_time |
|
| 869 | ) |
|
| 870 | VALUES ( |
|
| 871 | :user_id, |
|
| 872 | :date_time |
|
| 873 | ) |
|
| 874 | SQL |
|
| 875 | ); |
|
| 876 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 877 | $stmt->bindValue(':date_time', $this->dateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 878 | $stmt->execute(); |
|
| 879 | } |
|
| 880 | } |
|
| 881 | } |
|
| 882 | ||