The application im working on needs to get posts in an order according to the user's preferences ,if the user is not logged in it directly sorts them in descending order.if the user is logged in it should check the User model and get the preferences from the database.and should get posts in a similar way as the facebook news feed for a particular user.How do i do it?
if(Yii::app()->user->isGuest)
{
$criteria=new CDbCriteria(array(
'order'=>'likes DESC',
));}
else{
$criteria=new CDbCriteria(array(
'order'=>'likes DESC',
));
}
$total = Post::model()->count();
$pages = new CPagination($total);
$pages->pageSize = 10;
$pages->applyLimit($criteria);
$posts = Post::model()->findAll($criteria);
$this->render('index', array(
'posts' => $posts,
'pages' => $pages,
));