O'Reilly logo

PHP 5 Social Networking by Michael Peacock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required