<?php

class DModelSettingSendTask extends Model
{

    public function getQueueTask($task_queue_id)
    {
        $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "task_queue WHERE task_queue_id = '" . (int)$task_queue_id . "'");

        return $query->row;
    }

    public function getQueueTasks($data = array())
    {
        $this->load->type('tipocomum');

        $sql = "SELECT * FROM " . DB_PREFIX . "task_queue WHERE NOT task_queue_id IS NULL ";

        if (isset($data['mode_tipo_queue']) && isset($data['tipo_queue'])) {
            $sql .= ftr_geral::getContentSqlValue(" AND tipo_queue ", $data['tipo_queue'], $data['mode_tipo_queue']) . " OR (tipo_queue is null)";
        } else if (isset($data['tipo_queue'])) {
            $sql .= " AND tipo_queue = " . $data['tipo_queue'];
        }

        if (isset($data['tipo_task'])) {
            $sql .= " AND tipo_task = " . $data['tipo_task'];
        }

        $sql .= " ORDER BY task_queue_id ASC ";

        if (isset($data['start']) || isset($data['limit'])) {
            if ($data['start'] < 0) {
                $data['start'] = 0;
            }

            if ($data['limit'] < 1) {
                $data['limit'] = 20;
            }

            $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
        }

        $query = $this->db->query($sql);
        return $query->rows;

    }

    public function getQueueTotalTasks()
    {
        $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "task_queue");

        return $query->row['total'];
    }


}
