<?php

/*
 * Title                   : Pinpoint Booking System
 * File                    : application/models/schedule/model-calendars.php
 * Author                  : Dot on Paper
 * Copyright               : © 2017 Dot on Paper
 * Website                 : https://www.dotonpaper.net
 * Description             : Calendars model PHP class.
 */

if (!class_exists('DOTModelCalendars')){
    class DOTModelCalendars{
        /*
         * Constructor
     *
     * @usage
     *	    The constructor is called when a class instance is created.
     *
         * @params
     *	    -
     *
     * @post
     *	    -
     *
     * @get
     *	    -
     *
     * @sessions
     *	    -
     *
     * @cookies
     *	    -
     *
     * @constants
     *	    -
     *
     * @globals
     *	    -
     *
     * @functions
     *	    -
     *
     * @hooks
     *	    -
     *
     * @layouts
     *	    -
     *
     * @return
     *	    -
     *
     * @return_details
     *	    -
     *
     * @dv
     *	    -
     *
     * @tests
     *	    -
         */
        function __construct(){
        }

        /*
         * Get calendars.
     *
     * @usage
     *	    -
     *
         * @params
     *	    user_id (integer): user ID
     *
     * @post
     *	    -
     *
     * @get
     *	    -
     *
     * @sessions
     *	    -
     *
     * @cookies
     *	    -
     *
     * @constants
     *	    -
     *
     * @globals
     *	    DOT (object): DOT framework main class variable
     *
     * @functions
     *	    framework : db->results() // Get query results.
     *	    framework : db->safe() // Clean query string.
     *
     * @hooks
     *	    -
     *
     * @layouts
     *	    -
     *
     * @return
     *	    Calendars list.
     *
     * @return_details
     *	    -
     *
     * @dv
     *	    -
     *
     * @tests
     *	    -
         */
        function get($user_id = 0){
            global $DOT;

            if ($user_id == 0){
                $calendars = $DOT->db->results('SELECT * FROM '.$DOT->tables->calendars);
            }
            else{
                $calendars = $DOT->db->results($DOT->db->safe('SELECT * FROM %i WHERE user_id=%d',
                                                              array($DOT->tables->calendars,
                                                                    $user_id)));
            }

            return $calendars;
        }
    }
}