<?php

class Call {
    private $id             = NULL;
    private $callDate       = NULL;
    private $callerTelNr    = NULL;
    private $labelID        = NULL;
    private $notes          = NULL;
    private $reminderID     = NULL;

    public function __construct($id, $callDate, $callerTelNr, $labelID, $notes, $reminderID) {
        $this->id           = $id;
        $this->callDate     = $callDate;
        $this->callerTelNr  = $callerTelNr;
        $this->labelID      = $labelID;
        $this->notes        = $notes;
        $this->reminderID   = $reminderID;
    }

    public function getID() {
        return $this->id;
    }

    public function getCallDate() {
        return $this->callDate;
    }

    public function getCallerTelNr() {
        return $this->callerTelNr;
    }

    public function getLabelID() {
        return $this->labelID;
    }

    public function getNotes() {
        return $this->notes;
    }

    public function getReminderID() {
        return $this->reminderID;
    }

    /**
     * Add a Call to DB
     *
     * @param string $callDate  DateTime of Call
     * @param string $callerTelNr  Telephone number of caller
     * @param int $labelID  ID of Label
     * @param string $callNotes  Notes from Call
     * @param int $reminderID  ID of the Call-reminder, default: -1 (=> automatically add a Call)
     *
     * @return void
     *
     */

     public static function addCall($userID, $callDate, $callerTelNr, $labelID, $callNotes, $reminderID = -1) { // if reminder == -1 auto create one ?
         global $db;

         if($reminderID == -1) {
             Reminder::addReminder($userID, date("Y-m-d H:i:s", strtotime("+30 minutes")));
             $reminderID = Reminder::getLastReminder()->getID();
         }

         $db->insertQuery("INSERT INTO `calls`(`call_date`, `caller_telnr`, `label_id`, `notes`, `reminder_id`) VALUES ('" . $callDate . "', '" . $callerTelNr . "', " . $labelID . ", '" . $callNotes . "', " . $reminderID . ");");
     }

     /**
     * Get Call-Array by Label-ID
     *
     * @param int $labelID  ID of Call-Label
     *
     * @return Array(Call)  Array with selected Calls
     *
     */

     public static function getCallsByLabelID($labelID) {
         global $db;

         $calls = $db->selectQuery("SELECT * FROM `calls` WHERE `label_id` = " . $labelID . ";");

         $return = array();

         foreach($calls as $call) {
             $return[] = new Call($call->id, $call->call_date, $call->caller_telnr, $call->label_id, $call->notes, $call->reminder_id);
         }

         return $return;
     }
}


?>
