<?php
require_once 'Pager.php';
class PostPager extends Pager
{
    public function __construct ($catId = '', $nameLike = '', $size = 10, $pagerArg = 'p', $span = 5)
    {
        global $nsodb;
        $sql = 'SELECT Distinct posts.postId as postId, postTitle, postContent, postDate, users.userId as userId, ttId, userName
				FROM posts, post2tt, termTaxonomy, users
				WHERE posts.postId = post2tt.postId
				AND ttId = termTaxonomyId
				AND posts.userId = users.userId';

        if ($catId != '') {
            $sql .= " AND ttId = $catId ";
        }

        if ($nameLike != '') {
            $sql .= " AND postTitle Like '%$nameLike%' ";
        }

        $sql .= ' GROUP BY posts.postId ORDER BY postUpdateDate DESC, postId DESC';
        parent::__construct($nsodb, $sql, $size, $pagerArg, $span);
    }
}