Đang chuẩn bị liên kết để tải về tài liệu:
Thiết kế mạng xã hội với PHP - 21

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Khái niệm này là rất tương tự như phần trạng thái của hồ sơ của người dùng, chúng tôi tạo ra trong Chương 5, ngoại trừ các thay vào đó liên quan đến người sử dụng cụ thể, điều này cần kết hợp các hoạt động của tất cả người dùng kết nối trực tiếp đến đăng nhập vào người sử dụng | Status Stream The concept is very similar to the statuses section of a user s profile we created in Chapter 5 except that instead of relating to one specific user this should combine the activity of all users directly connected to the logged-in user. Although at this stage it is primarily simple statuses this will involve some logic to determine the context of the status. There will after all be five different types of status to list in the stream all of which will require different wording to present to the user The user s own status update The logged-in user posting a status update on the profile of another user A contact posting a status update on the profile of the logged-in user A contact updating their status A contact posting a status update on the profile of another contact Stream model We will require a stream model to build the status stream from the database. The functionalities required are Looking up an activity in the user s network Formatting the time of these updates to make them more relevant for example 5 minutes ago Retuning the stream Knowing if the stream is empty Code for the model is saved in the models stream.php file. Building the stream Let s walk through the logic of how building a stream of updates would work 1. We will need to get the IDs of users the current user is connected to. 2. As the IDs will be imploded and used as part of an IN condition the list of IDs cannot be empty. So in case it is we should add an ID of zero to the list. 3. We then need to query the database pulling in the 20 most recent statuses that have been posted by the user posted onto the user s profile or posted between two contacts of the user. 4. If there are rows we update our empty variable to false so the object knows if the stream is empty or not. ---------------------------------- 182 --------------------------------- Download from Wow eBook www.wowebook.com Chapter 6 5. We then iterate through the results making the time the status was posted more friendly