| @@ 493-539 (lines=47) @@ | ||
| 490 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 491 | } |
|
| 492 | ||
| 493 | public function clientConnect($profileId, $commonName, $ip4, $ip6, DateTime $connectedAt) |
|
| 494 | { |
|
| 495 | // this query is so complex, because we want to store the user_id in the |
|
| 496 | // log as well, not just the common_name... the user may delete the |
|
| 497 | // certificate, or the user account may be deleted... |
|
| 498 | $stmt = $this->db->prepare( |
|
| 499 | <<< 'SQL' |
|
| 500 | INSERT INTO connection_log |
|
| 501 | ( |
|
| 502 | user_id, |
|
| 503 | profile_id, |
|
| 504 | common_name, |
|
| 505 | ip4, |
|
| 506 | ip6, |
|
| 507 | connected_at |
|
| 508 | ) |
|
| 509 | VALUES |
|
| 510 | ( |
|
| 511 | ( |
|
| 512 | SELECT |
|
| 513 | u.user_id |
|
| 514 | FROM |
|
| 515 | users u, certificates c |
|
| 516 | WHERE |
|
| 517 | u.id = c.user_id |
|
| 518 | AND |
|
| 519 | c.common_name = :common_name |
|
| 520 | ), |
|
| 521 | :profile_id, |
|
| 522 | :common_name, |
|
| 523 | :ip4, |
|
| 524 | :ip6, |
|
| 525 | :connected_at |
|
| 526 | ) |
|
| 527 | SQL |
|
| 528 | ); |
|
| 529 | ||
| 530 | $stmt->bindValue(':profile_id', $profileId, PDO::PARAM_STR); |
|
| 531 | $stmt->bindValue(':common_name', $commonName, PDO::PARAM_STR); |
|
| 532 | $stmt->bindValue(':ip4', $ip4, PDO::PARAM_STR); |
|
| 533 | $stmt->bindValue(':ip6', $ip6, PDO::PARAM_STR); |
|
| 534 | $stmt->bindValue(':connected_at', $connectedAt->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 535 | ||
| 536 | $stmt->execute(); |
|
| 537 | // XXX |
|
| 538 | return 1 === $stmt->rowCount(); |
|
| 539 | } |
|
| 540 | ||
| 541 | public function clientDisconnect($profileId, $commonName, $ip4, $ip6, DateTime $connectedAt, DateTime $disconnectedAt, $bytesTransferred) |
|
| 542 | { |
|
| @@ 778-798 (lines=21) @@ | ||
| 775 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 776 | } |
|
| 777 | ||
| 778 | public function addUserMessage($userId, $type, $message, DateTime $dateTime) |
|
| 779 | { |
|
| 780 | $userId = $this->getId($userId); |
|
| 781 | ||
| 782 | $stmt = $this->db->prepare( |
|
| 783 | <<< 'SQL' |
|
| 784 | INSERT INTO user_messages |
|
| 785 | (user_id, type, message, date_time) |
|
| 786 | VALUES |
|
| 787 | (:user_id, :type, :message, :date_time) |
|
| 788 | SQL |
|
| 789 | ); |
|
| 790 | ||
| 791 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 792 | $stmt->bindValue(':type', $type, PDO::PARAM_STR); |
|
| 793 | $stmt->bindValue(':message', $message, PDO::PARAM_STR); |
|
| 794 | $stmt->bindValue(':date_time', $dateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 795 | $stmt->execute(); |
|
| 796 | ||
| 797 | return 1 === $stmt->rowCount(); |
|
| 798 | } |
|
| 799 | ||
| 800 | public function init() |
|
| 801 | { |
|