query = "INSERT INTO " . self::TABLE . " (uniqueid, calldate, src, dst, duration, billsec, disposition, fora_horario, data_bilhete) VALUES(:uniqueid, :calldate, :src, :dst, :duration, :billsec, :disposition, :fora_horario, :data_bilhete);"; $data['uniqueid'] = $unique; $data['calldate'] = $calldate; $data['src'] = $src; $data['dst'] = $dst; $data['duration'] = $duration; $data['billsec'] = abs($billsec); $data['disposition'] = $disposition; $data['fora_horario'] = $forahorario; $data['data_bilhete'] = date('Y-m-d H:i:s'); $return = $this->create($this->query, $data); if ($return) { return $unique; } return $return; } public function findByUniqueid($uniqueid) { $this->query = "SELECT * FROM " . self::TABLE . " WHERE uniqueid = :uniqueid"; return $this->read($this->query, ['uniqueid' => $uniqueid])->fetch(); } public function findBilheteByEventosDacs($queue = null, $dataBilhete = 'now', $eventos = ['COMPLETEAGENT', 'COMPLETECALLER', 'COMPLETAAGENT', 'COMPLETACALLER', 'TRANSFER', 'ABANDON'], $agente = null, $media) { $this->query = "SELECT * FROM " . self::TABLE . " a INNER JOIN " . self::EVENTOS_DACS . " b ON a.uniqueid = b.uid2 WHERE 1=1 AND evento IN(:evento) "; $data['evento'] = is_array($eventos) ? implode(",", $eventos) : $eventos; if ($queue) { $this->query .= " AND b.fila = :queue "; $data['queue'] = $queue; } if ($dataBilhete) { $this->query .= " AND data_bilhete = :data_bilhete "; $data['data_bilhete'] = $dataBilhete; } if ($media) { $this->query .= " AND param2 = :param2 "; $data['param2'] = $media; } if ($agente) { $this->query .= " AND b.agente = :agente "; $data['agente'] = $agente; } $this->query .= " ORDER BY calldate"; return $this->read($this->query, $data)->fetchAll(); } public function findBilheteBySrc($src, $eventos = ['COMPLETEAGENT', 'COMPLETECALLER', 'COMPLETAAGENT', 'COMPLETACALLER', 'TRANSFER', 'ABANDON']) { $this->query = "SELECT * FROM " . self::TABLE . " a INNER JOIN " . self::EVENTOS_DACS . " b ON a.uniqueid = b.uid2 WHERE 1=1 "; $this->query .= " AND a.src = :src "; $this->query .= " AND evento IN(:evento) "; $this->query .= " ORDER BY calldate"; $data['src'] = $src; $data['evento'] = is_array($eventos) ? implode(",", $eventos) : $eventos; return $this->read($this->query, $data)->fetch(); } public function updateBilheteForaHorario($uniqueid, $ramalorigem, $forahorario, $disposition) { $this->query = "UPDATE " . self::TABLE . " SET disposition = :disposition, fora_horario = :fora_horario, ramal_origem = :ramal_origem WHERE uniqueid = :uniqueid;"; $data['disposition'] = $disposition; $data['fora_horario'] = $forahorario; $data['ramal_origem'] = $ramalorigem; $data['uniqueid'] = $uniqueid; return $this->update($this->query, $data); } }