Different type of object for admin and user

I am building an intranet application and i want to be able to have 2 different types of users a regular user and an admin user. I am trying to figure out what would be the best way to go about doing this. Either to have one object for admin type stuff and then one object for user type stuff. Or combine both of that into one object. But i keep getting stuck and not sure how to go about doing that, or if that is even the best way.

Lets say I have the following situations:

1. query the db to get all tasks for all projects that are active.
    Admin Query
2. query the db to get all tasks for all projects that are due today and active.
    Admin Query
3. Query the db to get all tasks for a specific project that are active.
    Admin Query
    User Query
4. Query the db to get all tasks for a specific project that are active and due today.
    Admin Query
    User Query
5. Query the db to get all tasks for a specific project.
    Admin Query
    User Query
6. Query the db to get all tasks for a specific project, with different status specified.
    Admin Query
7. Any one of those queries has an optional parameter to either get the count or the data.

I started the following object but now im a little stuck as which route to go:

public function getTasks($status, $project, $type = "count", $duetoday = NULL)
    {
        try
        {
            if($duetoday != NULL){
                $today = date("Y-m-d"); 
                $stmt = $this->db->prepare("SELECT * FROM tasks WHERE status=:status
                                            AND $project=:project AND duedate BETWEEN :duedate 
                                            AND :duedate");
                $stmt->execute(array(':status'=>$status,':project'=>$project,':duedate'=>$today));
            }else{
                $stmt = $this->db->prepare("SELECT * FROM tasks WHERE status=:status
                                            AND $project=:project");
                $stmt->execute(array(':status'=>$status,':project'=>$project)); 
            }

            $tasks=$stmt->fetch(PDO::FETCH_ASSOC);

            if($stmt->rowCount() > 0)
            {
                if($type == "count"){
                    return $stmt->rowCount();
                }else{
                    return $tasks;
                }
            }else{
                return false;   
            }
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s